Class: Fog::Hetznercloud::Compute::Real
- Inherits:
-
Object
- Object
- Fog::Hetznercloud::Compute::Real
show all
- Includes:
- RequestHelper
- Defined in:
- lib/fog/hetznercloud/compute.rb,
lib/fog/hetznercloud/requests/compute/get_image.rb,
lib/fog/hetznercloud/requests/compute/get_action.rb,
lib/fog/hetznercloud/requests/compute/get_server.rb,
lib/fog/hetznercloud/requests/compute/get_ssh_key.rb,
lib/fog/hetznercloud/requests/compute/list_images.rb,
lib/fog/hetznercloud/requests/compute/delete_image.rb,
lib/fog/hetznercloud/requests/compute/get_location.rb,
lib/fog/hetznercloud/requests/compute/list_actions.rb,
lib/fog/hetznercloud/requests/compute/list_servers.rb,
lib/fog/hetznercloud/requests/compute/update_image.rb,
lib/fog/hetznercloud/requests/compute/create_server.rb,
lib/fog/hetznercloud/requests/compute/delete_server.rb,
lib/fog/hetznercloud/requests/compute/list_ssh_keys.rb,
lib/fog/hetznercloud/requests/compute/update_server.rb,
lib/fog/hetznercloud/requests/compute/create_ssh_key.rb,
lib/fog/hetznercloud/requests/compute/delete_ssh_key.rb,
lib/fog/hetznercloud/requests/compute/get_datacenter.rb,
lib/fog/hetznercloud/requests/compute/list_locations.rb,
lib/fog/hetznercloud/requests/compute/update_ssh_key.rb,
lib/fog/hetznercloud/requests/compute/get_floating_ip.rb,
lib/fog/hetznercloud/requests/compute/get_server_type.rb,
lib/fog/hetznercloud/requests/compute/list_datacenters.rb,
lib/fog/hetznercloud/requests/compute/list_floating_ips.rb,
lib/fog/hetznercloud/requests/compute/list_server_types.rb,
lib/fog/hetznercloud/requests/compute/create_floating_ip.rb,
lib/fog/hetznercloud/requests/compute/delete_floating_ip.rb,
lib/fog/hetznercloud/requests/compute/update_floating_ip.rb,
lib/fog/hetznercloud/requests/compute/floating_ip_unassign.rb,
lib/fog/hetznercloud/requests/compute/execute_server_action.rb,
lib/fog/hetznercloud/requests/compute/floating_ip_update_dns_ptr.rb,
lib/fog/hetznercloud/requests/compute/floating_ip_assign_to_server.rb
Instance Method Summary
collapse
-
#create_floating_ip(type, options = {}) ⇒ Object
-
#create_server(name, image, server_type, options = {}) ⇒ Object
-
#create_ssh_key(name, public_key, options = {}) ⇒ Object
-
#delete_floating_ip(id) ⇒ Object
-
#delete_image(id) ⇒ Object
-
#delete_server(server_id) ⇒ Object
-
#delete_ssh_key(id) ⇒ Object
-
#execute_server_action(id, action, body = {}) ⇒ Object
-
#floating_ip_assign_to_server(id, body) ⇒ Object
-
#floating_ip_unassign(id, body) ⇒ Object
-
#floating_ip_update_dns_ptr(id, body) ⇒ Object
-
#get_action(id) ⇒ Object
-
#get_datacenter(id) ⇒ Object
-
#get_floating_ip(id) ⇒ Object
-
#get_image(image_id) ⇒ Object
-
#get_location(id) ⇒ Object
-
#get_server(server_id) ⇒ Object
-
#get_server_type(server_type_id) ⇒ Object
-
#get_ssh_key(id) ⇒ Object
-
#initialize(options) ⇒ Real
constructor
FIXME: Make @location and @datacenter used in server creation as default.
-
#list_datacenters(filters = {}) ⇒ Object
-
#list_floating_ips(filters = {}) ⇒ Object
-
#list_images(filters = {}) ⇒ Object
-
#list_locations(filters = {}) ⇒ Object
-
#list_server_types(filters = {}) ⇒ Object
-
#list_servers(filters = {}) ⇒ Object
-
#list_ssh_keys(filters = {}) ⇒ Object
-
#request(params) ⇒ Object
-
#update_floating_ip(id, body) ⇒ Object
-
#update_image(id, body) ⇒ Object
-
#update_server(server_id, body) ⇒ Object
-
#update_ssh_key(id, body) ⇒ Object
#create, #delete, #get, #update
Constructor Details
#initialize(options) ⇒ Real
FIXME: Make @location and @datacenter used in server creation
as default
100
101
102
103
104
105
|
# File 'lib/fog/hetznercloud/compute.rb', line 100
def initialize(options)
@token = options[:hetznercloud_token]
@location = options[:hetznercloud_location] || 'fsn1'
@datacenter = options[:hetznercloud_datacenter] || 'fsn1-dc8'
@connection_options = options[:connection_options] || {}
end
|
Instance Method Details
#create_floating_ip(type, options = {}) ⇒ Object
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/fog/hetznercloud/requests/compute/create_floating_ip.rb', line 5
def create_floating_ip(type, options = {})
body = {
type: type
}
body.merge!(options)
create('/floating_ips', body)
end
|
#create_server(name, image, server_type, options = {}) ⇒ Object
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/fog/hetznercloud/requests/compute/create_server.rb', line 5
def create_server(name, image, server_type, options = {})
body = {
name: name,
image: image,
server_type: server_type
}
body.merge!(options)
create('/servers', body)
end
|
#create_ssh_key(name, public_key, options = {}) ⇒ Object
5
6
7
8
9
10
11
12
13
14
|
# File 'lib/fog/hetznercloud/requests/compute/create_ssh_key.rb', line 5
def create_ssh_key(name, public_key, options = {})
body = {
name: name,
public_key: public_key
}
body.merge!(options)
create('/ssh_keys', body)
end
|
#delete_floating_ip(id) ⇒ Object
5
6
7
|
# File 'lib/fog/hetznercloud/requests/compute/delete_floating_ip.rb', line 5
def delete_floating_ip(id)
delete("/floating_ips/#{id}")
end
|
#delete_image(id) ⇒ Object
5
6
7
|
# File 'lib/fog/hetznercloud/requests/compute/delete_image.rb', line 5
def delete_image(id)
delete("/images/#{id}")
end
|
#delete_server(server_id) ⇒ Object
5
6
7
|
# File 'lib/fog/hetznercloud/requests/compute/delete_server.rb', line 5
def delete_server(server_id)
delete("/servers/#{server_id}")
end
|
#delete_ssh_key(id) ⇒ Object
5
6
7
|
# File 'lib/fog/hetznercloud/requests/compute/delete_ssh_key.rb', line 5
def delete_ssh_key(id)
delete("/ssh_keys/#{id}")
end
|
#execute_server_action(id, action, body = {}) ⇒ Object
5
6
7
|
# File 'lib/fog/hetznercloud/requests/compute/execute_server_action.rb', line 5
def execute_server_action(id, action, body = {})
create("/servers/#{id}/actions/#{action}", body)
end
|
#floating_ip_assign_to_server(id, body) ⇒ Object
5
6
7
|
# File 'lib/fog/hetznercloud/requests/compute/floating_ip_assign_to_server.rb', line 5
def floating_ip_assign_to_server(id, body)
create("/floating_ips/#{id}/actions/assign", body)
end
|
#floating_ip_unassign(id, body) ⇒ Object
5
6
7
|
# File 'lib/fog/hetznercloud/requests/compute/floating_ip_unassign.rb', line 5
def floating_ip_unassign(id, body)
create("/floating_ips/#{id}/actions/unassign", body)
end
|
#floating_ip_update_dns_ptr(id, body) ⇒ Object
5
6
7
|
# File 'lib/fog/hetznercloud/requests/compute/floating_ip_update_dns_ptr.rb', line 5
def floating_ip_update_dns_ptr(id, body)
create("/floating_ips/#{id}/actions/change_dns_ptr", body)
end
|
#get_action(id) ⇒ Object
5
6
7
|
# File 'lib/fog/hetznercloud/requests/compute/get_action.rb', line 5
def get_action(id)
get("/actions/#{id}")
end
|
#get_datacenter(id) ⇒ Object
5
6
7
|
# File 'lib/fog/hetznercloud/requests/compute/get_datacenter.rb', line 5
def get_datacenter(id)
get("/datacenters/#{id}")
end
|
#get_floating_ip(id) ⇒ Object
5
6
7
|
# File 'lib/fog/hetznercloud/requests/compute/get_floating_ip.rb', line 5
def get_floating_ip(id)
get("/floating_ips/#{id}")
end
|
#get_image(image_id) ⇒ Object
5
6
7
|
# File 'lib/fog/hetznercloud/requests/compute/get_image.rb', line 5
def get_image(image_id)
get("/images/#{image_id}")
end
|
#get_location(id) ⇒ Object
5
6
7
|
# File 'lib/fog/hetznercloud/requests/compute/get_location.rb', line 5
def get_location(id)
get("/locations/#{id}")
end
|
#get_server(server_id) ⇒ Object
5
6
7
|
# File 'lib/fog/hetznercloud/requests/compute/get_server.rb', line 5
def get_server(server_id)
get("/servers/#{server_id}")
end
|
#get_server_type(server_type_id) ⇒ Object
5
6
7
|
# File 'lib/fog/hetznercloud/requests/compute/get_server_type.rb', line 5
def get_server_type(server_type_id)
get("/server_types/#{server_type_id}")
end
|
#get_ssh_key(id) ⇒ Object
5
6
7
|
# File 'lib/fog/hetznercloud/requests/compute/get_ssh_key.rb', line 5
def get_ssh_key(id)
get("/ssh_keys/#{id}")
end
|
#list_datacenters(filters = {}) ⇒ Object
5
6
7
|
# File 'lib/fog/hetznercloud/requests/compute/list_datacenters.rb', line 5
def list_datacenters(filters = {})
get('/datacenters', filters)
end
|
#list_floating_ips(filters = {}) ⇒ Object
5
6
7
|
# File 'lib/fog/hetznercloud/requests/compute/list_floating_ips.rb', line 5
def list_floating_ips(filters = {})
get('/floating_ips', filters)
end
|
#list_images(filters = {}) ⇒ Object
5
6
7
|
# File 'lib/fog/hetznercloud/requests/compute/list_images.rb', line 5
def list_images(filters = {})
get('/images', filters)
end
|
#list_locations(filters = {}) ⇒ Object
5
6
7
|
# File 'lib/fog/hetznercloud/requests/compute/list_ssh_keys.rb', line 5
def list_locations(filters = {})
get('/locations', filters)
end
|
#list_server_types(filters = {}) ⇒ Object
5
6
7
|
# File 'lib/fog/hetznercloud/requests/compute/list_server_types.rb', line 5
def list_server_types(filters = {})
get('/server_types', filters)
end
|
#list_servers(filters = {}) ⇒ Object
5
6
7
|
# File 'lib/fog/hetznercloud/requests/compute/list_servers.rb', line 5
def list_servers(filters = {})
get('/servers', filters)
end
|
#list_ssh_keys(filters = {}) ⇒ Object
5
6
7
|
# File 'lib/fog/hetznercloud/requests/compute/list_actions.rb', line 5
def list_ssh_keys(filters = {})
get('/ssh_keys', filters)
end
|
#request(params) ⇒ Object
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
# File 'lib/fog/hetznercloud/compute.rb', line 107
def request(params)
client.request(params)
rescue Excon::Errors::HTTPStatusError => error
decoded = Fog::Hetznercloud::Errors.decode_error(error)
raise if decoded.nil?
code = decoded[:code]
message = decoded[:message]
raise case code
when 'unauthorized', 'forbidden', 'invalid_input', 'json_error', 'locked', 'not_found', 'rate_limit_exceeded', 'resource_limit_exceeded', 'resource_unavailable', 'service_error', 'uniqueness_error'
Fog::Hetznercloud::Compute.const_get("#{camelize(code)}Error").slurp(error, message)
else
Fog::Hetznercloud::Compute::Error.slurp(error, message)
end
end
|
#update_floating_ip(id, body) ⇒ Object
5
6
7
|
# File 'lib/fog/hetznercloud/requests/compute/update_floating_ip.rb', line 5
def update_floating_ip(id, body)
update("/floating_ips/#{id}", body)
end
|
#update_image(id, body) ⇒ Object
5
6
7
|
# File 'lib/fog/hetznercloud/requests/compute/update_image.rb', line 5
def update_image(id, body)
update("/images/#{id}", body)
end
|
#update_server(server_id, body) ⇒ Object
5
6
7
|
# File 'lib/fog/hetznercloud/requests/compute/update_server.rb', line 5
def update_server(server_id, body)
update("/servers/#{server_id}", body)
end
|
#update_ssh_key(id, body) ⇒ Object
5
6
7
|
# File 'lib/fog/hetznercloud/requests/compute/update_ssh_key.rb', line 5
def update_ssh_key(id, body)
update("/ssh_keys/#{id}", body)
end
|