Class: Hetzner::Server
- Inherits:
-
Object
- Object
- Hetzner::Server
- Defined in:
- lib/hetzner/infra/server.rb
Instance Method Summary collapse
- #create(location:, instance_type:, instance_id:, firewall_id:, network_id:, ssh_key_id:, placement_group_id:, image:, additional_packages: [], additional_post_create_commands: []) ⇒ Object
- #delete(server_name:) ⇒ Object
-
#initialize(hetzner_client:, cluster_name:) ⇒ Server
constructor
A new instance of Server.
Constructor Details
#initialize(hetzner_client:, cluster_name:) ⇒ Server
Returns a new instance of Server.
5 6 7 8 |
# File 'lib/hetzner/infra/server.rb', line 5 def initialize(hetzner_client:, cluster_name:) @hetzner_client = hetzner_client @cluster_name = cluster_name end |
Instance Method Details
#create(location:, instance_type:, instance_id:, firewall_id:, network_id:, ssh_key_id:, placement_group_id:, image:, additional_packages: [], additional_post_create_commands: []) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/hetzner/infra/server.rb', line 10 def create(location:, instance_type:, instance_id:, firewall_id:, network_id:, ssh_key_id:, placement_group_id:, image:, additional_packages: [], additional_post_create_commands: []) @location = location @instance_type = instance_type @instance_id = instance_id @firewall_id = firewall_id @network_id = network_id @ssh_key_id = ssh_key_id @placement_group_id = placement_group_id @image = image @additional_packages = additional_packages @additional_post_create_commands = additional_post_create_commands puts if (server = find_server(server_name)) puts "Server #{server_name} already exists, skipping." puts return server end puts "Creating server #{server_name}..." if (server = make_request) puts "...server #{server_name} created." puts server else puts "Error creating server #{server_name}. Response details below:" puts end end |
#delete(server_name:) ⇒ Object
43 44 45 46 47 48 49 50 51 |
# File 'lib/hetzner/infra/server.rb', line 43 def delete(server_name:) if (server = find_server(server_name)) puts "Deleting server #{server_name}..." hetzner_client.delete '/servers', server['id'] puts "...server #{server_name} deleted." else puts "Server #{server_name} no longer exists, skipping." end end |