Class: Fog::Scaleway::Compute::Real
- Inherits:
-
Object
- Object
- Fog::Scaleway::Compute::Real
show all
- Includes:
- RequestHelper
- Defined in:
- lib/fog/scaleway/compute.rb,
lib/fog/scaleway/requests/compute/get_ip.rb,
lib/fog/scaleway/requests/compute/get_task.rb,
lib/fog/scaleway/requests/compute/list_ips.rb,
lib/fog/scaleway/requests/compute/create_ip.rb,
lib/fog/scaleway/requests/compute/delete_ip.rb,
lib/fog/scaleway/requests/compute/get_image.rb,
lib/fog/scaleway/requests/compute/update_ip.rb,
lib/fog/scaleway/requests/compute/get_server.rb,
lib/fog/scaleway/requests/compute/get_volume.rb,
lib/fog/scaleway/requests/compute/list_tasks.rb,
lib/fog/scaleway/requests/compute/delete_task.rb,
lib/fog/scaleway/requests/compute/list_images.rb,
lib/fog/scaleway/requests/compute/create_image.rb,
lib/fog/scaleway/requests/compute/delete_image.rb,
lib/fog/scaleway/requests/compute/get_snapshot.rb,
lib/fog/scaleway/requests/compute/list_servers.rb,
lib/fog/scaleway/requests/compute/list_volumes.rb,
lib/fog/scaleway/requests/compute/update_image.rb,
lib/fog/scaleway/requests/compute/create_server.rb,
lib/fog/scaleway/requests/compute/create_volume.rb,
lib/fog/scaleway/requests/compute/delete_server.rb,
lib/fog/scaleway/requests/compute/delete_volume.rb,
lib/fog/scaleway/requests/compute/get_container.rb,
lib/fog/scaleway/requests/compute/get_dashboard.rb,
lib/fog/scaleway/requests/compute/get_user_data.rb,
lib/fog/scaleway/requests/compute/update_server.rb,
lib/fog/scaleway/requests/compute/update_volume.rb,
lib/fog/scaleway/requests/compute/get_bootscript.rb,
lib/fog/scaleway/requests/compute/list_snapshots.rb,
lib/fog/scaleway/requests/compute/list_user_data.rb,
lib/fog/scaleway/requests/compute/create_snapshot.rb,
lib/fog/scaleway/requests/compute/delete_snapshot.rb,
lib/fog/scaleway/requests/compute/list_containers.rb,
lib/fog/scaleway/requests/compute/update_snapshot.rb,
lib/fog/scaleway/requests/compute/delete_user_data.rb,
lib/fog/scaleway/requests/compute/list_bootscripts.rb,
lib/fog/scaleway/requests/compute/update_user_data.rb,
lib/fog/scaleway/requests/compute/get_security_group.rb,
lib/fog/scaleway/requests/compute/list_server_actions.rb,
lib/fog/scaleway/requests/compute/list_security_groups.rb,
lib/fog/scaleway/requests/compute/create_security_group.rb,
lib/fog/scaleway/requests/compute/delete_security_group.rb,
lib/fog/scaleway/requests/compute/execute_server_action.rb,
lib/fog/scaleway/requests/compute/update_security_group.rb,
lib/fog/scaleway/requests/compute/get_security_group_rule.rb,
lib/fog/scaleway/requests/compute/list_security_group_rules.rb,
lib/fog/scaleway/requests/compute/create_security_group_rule.rb,
lib/fog/scaleway/requests/compute/delete_security_group_rule.rb,
lib/fog/scaleway/requests/compute/update_security_group_rule.rb
Instance Method Summary
collapse
-
#create_image(name, arch, root_volume, options = {}) ⇒ Object
-
#create_ip(options = {}) ⇒ Object
-
#create_security_group(name, options = {}) ⇒ Object
-
#create_security_group_rule(security_group_id, action, direction, ip_range, protocol, dest_port_from = nil) ⇒ Object
-
#create_server(name, image, volumes, options = {}) ⇒ Object
-
#create_snapshot(name, volume_id) ⇒ Object
-
#create_volume(name, volume_type, options) ⇒ Object
-
#delete_image(image_id) ⇒ Object
-
#delete_ip(ip_id) ⇒ Object
-
#delete_security_group(security_group_id) ⇒ Object
-
#delete_security_group_rule(security_group_id, rule_id) ⇒ Object
-
#delete_server(server_id) ⇒ Object
-
#delete_snapshot(snapshot_id) ⇒ Object
-
#delete_task(task_id) ⇒ Object
-
#delete_user_data(server_id, key) ⇒ Object
-
#delete_volume(volume_id) ⇒ Object
-
#execute_server_action(server_id, action) ⇒ Object
-
#get_bootscript(bootscript_id) ⇒ Object
-
#get_container(container_id) ⇒ Object
-
#get_dashboard ⇒ Object
rubocop:disable Style/AccessorMethodName.
-
#get_image(image_id) ⇒ Object
-
#get_ip(ip_id) ⇒ Object
-
#get_security_group(security_group_id) ⇒ Object
-
#get_security_group_rule(security_group_id, rule_id) ⇒ Object
-
#get_server(server_id) ⇒ Object
-
#get_snapshot(snapshot_id) ⇒ Object
-
#get_task(task_id) ⇒ Object
-
#get_user_data(server_id, key) ⇒ Object
-
#get_volume(volume_id) ⇒ Object
-
#initialize(options) ⇒ Real
constructor
-
#list_bootscripts(filters = {}) ⇒ Object
-
#list_containers ⇒ Object
-
#list_images(filters = {}) ⇒ Object
-
#list_ips ⇒ Object
-
#list_security_group_rules(security_group_id) ⇒ Object
-
#list_security_groups ⇒ Object
-
#list_server_actions(server_id) ⇒ Object
-
#list_servers ⇒ Object
-
#list_snapshots ⇒ Object
-
#list_tasks ⇒ Object
-
#list_user_data(server_id) ⇒ Object
-
#list_volumes ⇒ Object
-
#request(params) ⇒ Object
-
#update_image(image_id, body) ⇒ Object
-
#update_ip(ip_id, body) ⇒ Object
-
#update_security_group(security_group_id, body) ⇒ Object
-
#update_security_group_rule(security_group_id, rule_id, body) ⇒ Object
-
#update_server(server_id, body) ⇒ Object
-
#update_snapshot(snapshot_id, body) ⇒ Object
-
#update_user_data(server_id, key, value) ⇒ Object
-
#update_volume(volume_id, body) ⇒ Object
#create, #delete, #get, #update
Constructor Details
#initialize(options) ⇒ Real
Returns a new instance of Real.
115
116
117
118
119
|
# File 'lib/fog/scaleway/compute.rb', line 115
def initialize(options)
@token = options[:scaleway_token]
@organization = options[:scaleway_organization]
@region = options[:scaleway_region] || 'par1'
end
|
Instance Method Details
#create_image(name, arch, root_volume, options = {}) ⇒ Object
5
6
7
8
9
10
11
12
13
14
15
16
|
# File 'lib/fog/scaleway/requests/compute/create_image.rb', line 5
def create_image(name, arch, root_volume, options = {})
body = {
organization: @organization,
name: name,
arch: arch,
root_volume: root_volume
}
body.merge!(options)
create('/images', body)
end
|
#create_ip(options = {}) ⇒ Object
5
6
7
8
9
10
11
12
13
|
# File 'lib/fog/scaleway/requests/compute/create_ip.rb', line 5
def create_ip(options = {})
body = {
organization: @organization
}
body.merge!(options)
create('/ips', body)
end
|
#create_security_group(name, options = {}) ⇒ Object
5
6
7
8
9
10
11
12
13
14
|
# File 'lib/fog/scaleway/requests/compute/create_security_group.rb', line 5
def create_security_group(name, options = {})
body = {
organization: @organization,
name: name
}
body.merge!(options)
create('/security_groups', body)
end
|
#create_security_group_rule(security_group_id, action, direction, ip_range, protocol, dest_port_from = nil) ⇒ Object
5
6
7
8
9
10
11
|
# File 'lib/fog/scaleway/requests/compute/create_security_group_rule.rb', line 5
def create_security_group_rule(security_group_id, action, direction, ip_range, protocol, dest_port_from = nil)
create("/security_groups/#{security_group_id}/rules", action: action,
direction: direction,
ip_range: ip_range,
protocol: protocol,
dest_port_from: dest_port_from)
end
|
#create_server(name, image, volumes, options = {}) ⇒ Object
5
6
7
8
9
10
11
12
13
14
15
16
|
# File 'lib/fog/scaleway/requests/compute/create_server.rb', line 5
def create_server(name, image, volumes, options = {})
body = {
organization: @organization,
name: name,
image: image,
volumes: volumes
}
body.merge!(options)
create('/servers', body)
end
|
#create_snapshot(name, volume_id) ⇒ Object
5
6
7
8
9
|
# File 'lib/fog/scaleway/requests/compute/create_snapshot.rb', line 5
def create_snapshot(name, volume_id)
create('/snapshots', organization: @organization,
name: name,
volume_id: volume_id)
end
|
#create_volume(name, volume_type, options) ⇒ Object
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/fog/scaleway/requests/compute/create_volume.rb', line 5
def create_volume(name, volume_type, options)
if options[:size].nil? && options[:base_volume].nil? && options[:base_snapshot].nil?
raise ArgumentError, 'size, base_volume or base_snapshot are required to create a volume'
end
body = {
organization: @organization,
name: name,
volume_type: volume_type
}
if !options[:size].nil?
body[:size] = options[:size]
elsif !options[:base_volume].nil?
body[:base_volume] = options[:base_volume]
else
body[:base_snapshot] = options[:base_snapshot]
end
create('/volumes', body)
end
|
#delete_image(image_id) ⇒ Object
5
6
7
|
# File 'lib/fog/scaleway/requests/compute/delete_image.rb', line 5
def delete_image(image_id)
delete("/images/#{image_id}")
end
|
#delete_ip(ip_id) ⇒ Object
5
6
7
|
# File 'lib/fog/scaleway/requests/compute/delete_ip.rb', line 5
def delete_ip(ip_id)
delete("/ips/#{ip_id}")
end
|
#delete_security_group(security_group_id) ⇒ Object
5
6
7
|
# File 'lib/fog/scaleway/requests/compute/delete_security_group.rb', line 5
def delete_security_group(security_group_id)
delete("/security_groups/#{security_group_id}")
end
|
#delete_security_group_rule(security_group_id, rule_id) ⇒ Object
5
6
7
|
# File 'lib/fog/scaleway/requests/compute/delete_security_group_rule.rb', line 5
def delete_security_group_rule(security_group_id, rule_id)
delete("/security_groups/#{security_group_id}/rules/#{rule_id}")
end
|
#delete_server(server_id) ⇒ Object
5
6
7
|
# File 'lib/fog/scaleway/requests/compute/delete_server.rb', line 5
def delete_server(server_id)
delete("/servers/#{server_id}")
end
|
#delete_snapshot(snapshot_id) ⇒ Object
5
6
7
|
# File 'lib/fog/scaleway/requests/compute/delete_snapshot.rb', line 5
def delete_snapshot(snapshot_id)
delete("/snapshots/#{snapshot_id}")
end
|
#delete_task(task_id) ⇒ Object
5
6
7
|
# File 'lib/fog/scaleway/requests/compute/delete_task.rb', line 5
def delete_task(task_id)
delete("/tasks/#{task_id}")
end
|
#delete_user_data(server_id, key) ⇒ Object
5
6
7
|
# File 'lib/fog/scaleway/requests/compute/delete_user_data.rb', line 5
def delete_user_data(server_id, key)
delete("/servers/#{server_id}/user_data/#{key}")
end
|
#delete_volume(volume_id) ⇒ Object
5
6
7
|
# File 'lib/fog/scaleway/requests/compute/delete_volume.rb', line 5
def delete_volume(volume_id)
delete("/volumes/#{volume_id}")
end
|
#execute_server_action(server_id, action) ⇒ Object
5
6
7
8
9
10
11
12
|
# File 'lib/fog/scaleway/requests/compute/execute_server_action.rb', line 5
def execute_server_action(server_id, action)
request(method: :post,
path: "/servers/#{server_id}/action",
body: {
action: action
},
expects: [202])
end
|
#get_bootscript(bootscript_id) ⇒ Object
5
6
7
|
# File 'lib/fog/scaleway/requests/compute/get_bootscript.rb', line 5
def get_bootscript(bootscript_id)
get("/bootscripts/#{bootscript_id}")
end
|
#get_container(container_id) ⇒ Object
5
6
7
|
# File 'lib/fog/scaleway/requests/compute/get_container.rb', line 5
def get_container(container_id)
get("/containers/#{container_id}")
end
|
#get_dashboard ⇒ Object
rubocop:disable Style/AccessorMethodName
5
6
7
|
# File 'lib/fog/scaleway/requests/compute/get_dashboard.rb', line 5
def get_dashboard get('/dashboard')
end
|
#get_image(image_id) ⇒ Object
5
6
7
|
# File 'lib/fog/scaleway/requests/compute/get_image.rb', line 5
def get_image(image_id)
get("/images/#{image_id}")
end
|
#get_ip(ip_id) ⇒ Object
5
6
7
|
# File 'lib/fog/scaleway/requests/compute/get_ip.rb', line 5
def get_ip(ip_id)
get("/ips/#{ip_id}")
end
|
#get_security_group(security_group_id) ⇒ Object
5
6
7
|
# File 'lib/fog/scaleway/requests/compute/get_security_group.rb', line 5
def get_security_group(security_group_id)
get("/security_groups/#{security_group_id}")
end
|
#get_security_group_rule(security_group_id, rule_id) ⇒ Object
5
6
7
|
# File 'lib/fog/scaleway/requests/compute/get_security_group_rule.rb', line 5
def get_security_group_rule(security_group_id, rule_id)
get("/security_groups/#{security_group_id}/rules/#{rule_id}")
end
|
#get_server(server_id) ⇒ Object
5
6
7
|
# File 'lib/fog/scaleway/requests/compute/get_server.rb', line 5
def get_server(server_id)
get("/servers/#{server_id}")
end
|
#get_snapshot(snapshot_id) ⇒ Object
5
6
7
|
# File 'lib/fog/scaleway/requests/compute/get_snapshot.rb', line 5
def get_snapshot(snapshot_id)
get("/snapshots/#{snapshot_id}")
end
|
#get_task(task_id) ⇒ Object
5
6
7
|
# File 'lib/fog/scaleway/requests/compute/get_task.rb', line 5
def get_task(task_id)
get("/tasks/#{task_id}")
end
|
#get_user_data(server_id, key) ⇒ Object
5
6
7
|
# File 'lib/fog/scaleway/requests/compute/get_user_data.rb', line 5
def get_user_data(server_id, key)
get("/servers/#{server_id}/user_data/#{key}")
end
|
#get_volume(volume_id) ⇒ Object
5
6
7
|
# File 'lib/fog/scaleway/requests/compute/get_volume.rb', line 5
def get_volume(volume_id)
get("/volumes/#{volume_id}")
end
|
#list_bootscripts(filters = {}) ⇒ Object
5
6
7
|
# File 'lib/fog/scaleway/requests/compute/list_bootscripts.rb', line 5
def list_bootscripts(filters = {})
get('/bootscripts', filters)
end
|
#list_containers ⇒ Object
5
6
7
|
# File 'lib/fog/scaleway/requests/compute/list_containers.rb', line 5
def list_containers
get('/containers')
end
|
#list_images(filters = {}) ⇒ Object
5
6
7
|
# File 'lib/fog/scaleway/requests/compute/list_images.rb', line 5
def list_images(filters = {})
get('/images', filters)
end
|
#list_ips ⇒ Object
5
6
7
|
# File 'lib/fog/scaleway/requests/compute/list_ips.rb', line 5
def list_ips
get('/ips')
end
|
#list_security_group_rules(security_group_id) ⇒ Object
5
6
7
|
# File 'lib/fog/scaleway/requests/compute/list_security_group_rules.rb', line 5
def list_security_group_rules(security_group_id)
get("/security_groups/#{security_group_id}/rules")
end
|
#list_security_groups ⇒ Object
5
6
7
|
# File 'lib/fog/scaleway/requests/compute/list_security_groups.rb', line 5
def list_security_groups
get('/security_groups')
end
|
#list_server_actions(server_id) ⇒ Object
5
6
7
|
# File 'lib/fog/scaleway/requests/compute/list_server_actions.rb', line 5
def list_server_actions(server_id)
get("/servers/#{server_id}/action")
end
|
#list_servers ⇒ Object
5
6
7
|
# File 'lib/fog/scaleway/requests/compute/list_servers.rb', line 5
def list_servers
get('/servers')
end
|
#list_snapshots ⇒ Object
5
6
7
|
# File 'lib/fog/scaleway/requests/compute/list_snapshots.rb', line 5
def list_snapshots
get('/snapshots')
end
|
#list_tasks ⇒ Object
5
6
7
|
# File 'lib/fog/scaleway/requests/compute/list_tasks.rb', line 5
def list_tasks
get('tasks')
end
|
#list_user_data(server_id) ⇒ Object
5
6
7
|
# File 'lib/fog/scaleway/requests/compute/list_user_data.rb', line 5
def list_user_data(server_id)
get("/servers/#{server_id}/user_data")
end
|
#list_volumes ⇒ Object
5
6
7
|
# File 'lib/fog/scaleway/requests/compute/list_volumes.rb', line 5
def list_volumes
get('/volumes')
end
|
#request(params) ⇒ Object
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
# File 'lib/fog/scaleway/compute.rb', line 121
def request(params)
client.request(params)
rescue Excon::Errors::HTTPStatusError => error
decoded = Fog::Scaleway::Errors.decode_error(error)
raise if decoded.nil?
type = decoded[:type]
message = decoded[:message]
raise case type
when 'invalid_request_error', 'invalid_auth', 'authorization_required', 'unknown_resource', 'conflict'
Fog::Scaleway::Compute.const_get(camelize(type)).slurp(error, message)
when 'api_error'
Fog::Scaleway::Compute::APIError.slurp(error, message)
else
Fog::Scaleway::Compute::Error.slurp(error, message)
end
end
|
#update_image(image_id, body) ⇒ Object
5
6
7
|
# File 'lib/fog/scaleway/requests/compute/update_image.rb', line 5
def update_image(image_id, body)
update("/images/#{image_id}", body)
end
|
#update_ip(ip_id, body) ⇒ Object
5
6
7
|
# File 'lib/fog/scaleway/requests/compute/update_ip.rb', line 5
def update_ip(ip_id, body)
update("/ips/#{ip_id}", body)
end
|
#update_security_group(security_group_id, body) ⇒ Object
5
6
7
|
# File 'lib/fog/scaleway/requests/compute/update_security_group.rb', line 5
def update_security_group(security_group_id, body)
update("/security_groups/#{security_group_id}", body)
end
|
#update_security_group_rule(security_group_id, rule_id, body) ⇒ Object
5
6
7
|
# File 'lib/fog/scaleway/requests/compute/update_security_group_rule.rb', line 5
def update_security_group_rule(security_group_id, rule_id, body)
update("/security_groups/#{security_group_id}/rules/#{rule_id}", body)
end
|
#update_server(server_id, body) ⇒ Object
5
6
7
|
# File 'lib/fog/scaleway/requests/compute/update_server.rb', line 5
def update_server(server_id, body)
update("/servers/#{server_id}", body)
end
|
#update_snapshot(snapshot_id, body) ⇒ Object
5
6
7
|
# File 'lib/fog/scaleway/requests/compute/update_snapshot.rb', line 5
def update_snapshot(snapshot_id, body)
update("/snapshots/#{snapshot_id}", body)
end
|
#update_user_data(server_id, key, value) ⇒ Object
5
6
7
8
9
10
11
|
# File 'lib/fog/scaleway/requests/compute/update_user_data.rb', line 5
def update_user_data(server_id, key, value)
request(method: :patch,
path: "/servers/#{server_id}/user_data/#{key}",
headers: { 'Content-Type' => 'text/plain' },
body: value,
expects: [204])
end
|
#update_volume(volume_id, body) ⇒ Object
5
6
7
|
# File 'lib/fog/scaleway/requests/compute/update_volume.rb', line 5
def update_volume(volume_id, body)
update("/volumes/#{volume_id}", body)
end
|