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

#add_to_placement_group(placement_group:) ⇒ Object



94
95
96
97
98
# File 'lib/hcloud/server.rb', line 94

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

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

#attach_iso(iso:) ⇒ Object



76
77
78
79
80
# File 'lib/hcloud/server.rb', line 76

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



82
83
84
85
86
# File 'lib/hcloud/server.rb', line 82

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_alias_ips(alias_ips:, network:) ⇒ Object



100
101
102
103
104
105
# File 'lib/hcloud/server.rb', line 100

def change_alias_ips(alias_ips:, network:)
  raise Hcloud::Error::InvalidInput, 'no alias_ips given' if alias_ips.to_a.count.zero?
  raise Hcloud::Error::InvalidInput, 'no network given' if network.nil?

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

#change_dns_ptr(ip:, dns_ptr:) ⇒ Object



107
108
109
110
111
112
# File 'lib/hcloud/server.rb', line 107

def change_dns_ptr(ip:, dns_ptr:)
  raise Hcloud::Error::InvalidInput, 'no IP given' if ip.blank?
  raise Hcloud::Error::InvalidInput, 'no dns_ptr given' if dns_ptr.blank?

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

#change_type(server_type:, upgrade_disk:) ⇒ Object



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

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



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

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



88
89
90
91
92
# File 'lib/hcloud/server.rb', line 88

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.



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

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

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



43
44
45
46
# File 'lib/hcloud/server.rb', line 43

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



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

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



124
125
126
# File 'lib/hcloud/server.rb', line 124

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

#reset_passwordObject



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

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