Class: Hcloud::Server

Inherits:
Object
  • Object
show all
Includes:
EntryLoader
Defined in:
lib/hcloud/server.rb

Instance Attribute Summary

Attributes included from EntryLoader

#response

Instance Method Summary collapse

Methods included from EntryLoader

#_attributes, #_load, #_run_callbacks, #_update_attribute, #client, #initialize, #inspect, #method_missing, #prepare_request, #resource_path, #resource_url, #respond_to_missing?, #rollback, #save, #update

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Hcloud::EntryLoader

Instance Method Details

#attach_iso(iso:) ⇒ Object



58
59
60
61
62
# File 'lib/hcloud/server.rb', line 58

def attach_iso(iso:)
  raise Hcloud::Error::InvalidInput, 'no iso given' if iso.blank?

  prepare_request('actions/attach_iso', j: { iso: iso })
end

#attach_to_network(network:, ip: nil, alias_ips: nil) ⇒ Object



64
65
66
67
68
# File 'lib/hcloud/server.rb', line 64

def attach_to_network(network:, ip: nil, alias_ips: nil)
  raise Hcloud::Error::InvalidInput, 'no network given' if network.nil?

  prepare_request('actions/attach_to_network', j: COLLECT_ARGS.call(__method__, binding))
end

#change_type(server_type:, upgrade_disk:) ⇒ Object



45
46
47
48
49
50
# File 'lib/hcloud/server.rb', line 45

def change_type(server_type:, upgrade_disk:)
  raise Hcloud::Error::InvalidInput, 'no server_type given' if server_type.blank?
  raise Hcloud::Error::InvalidInput, 'no upgrade_disk given' if upgrade_disk.nil?

  prepare_request('actions/change_type', j: COLLECT_ARGS.call(__method__, binding))
end

#create_image(description: nil, type: nil) ⇒ Object



34
35
36
37
# File 'lib/hcloud/server.rb', line 34

def create_image(description: nil, type: nil)
  query = COLLECT_ARGS.call(__method__, binding)
  prepare_request('actions/create_image', j: query) { |j| Image.new(client, j[:image]) }
end

#detach_from_network(network:) ⇒ Object



70
71
72
73
74
# File 'lib/hcloud/server.rb', line 70

def detach_from_network(network:)
  raise Hcloud::Error::InvalidInput, 'no network given' if network.nil?

  prepare_request('actions/detach_from_network', j: { network: network })
end

#enable_backup(**_kwargs) ⇒ Object

Specifying a backup window is not supported anymore. We keep this method to ensure backwards compatibility, but ignore the argument if provided.



54
55
56
# File 'lib/hcloud/server.rb', line 54

def enable_backup(**_kwargs)
  prepare_request('actions/enable_backup', method: :post)
end

#enable_rescue(type: 'linux64', ssh_keys: []) ⇒ Object



25
26
27
28
# File 'lib/hcloud/server.rb', line 25

def enable_rescue(type: 'linux64', ssh_keys: [])
  query = COLLECT_ARGS.call(__method__, binding)
  prepare_request('actions/enable_rescue', j: query) { |j| j[:root_password] }
end

#rebuild(image:) ⇒ Object



39
40
41
42
43
# File 'lib/hcloud/server.rb', line 39

def rebuild(image:)
  raise Hcloud::Error::InvalidInput, 'no image given' if image.blank?

  prepare_request('actions/rebuild', j: { image: image }) { |j| j[:root_password] }
end

#request_consoleObject



86
87
88
# File 'lib/hcloud/server.rb', line 86

def request_console
  prepare_request('actions/request_console', method: :post) { |j| [j[:wss_url], j[:password]] }
end

#reset_passwordObject



30
31
32
# File 'lib/hcloud/server.rb', line 30

def reset_password
  prepare_request('actions/reset_password', method: :post) { |j| j[:root_password] }
end