fog-scaleway 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.ruby-version +1 -0
- data/.travis.yml +9 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +58 -0
- data/Rakefile +21 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/fog-scaleway.gemspec +31 -0
- data/lib/fog/scaleway.rb +15 -0
- data/lib/fog/scaleway/account.rb +306 -0
- data/lib/fog/scaleway/client.rb +54 -0
- data/lib/fog/scaleway/compute.rb +350 -0
- data/lib/fog/scaleway/errors.rb +37 -0
- data/lib/fog/scaleway/models/account/organization.rb +42 -0
- data/lib/fog/scaleway/models/account/organizations.rb +22 -0
- data/lib/fog/scaleway/models/account/token.rb +60 -0
- data/lib/fog/scaleway/models/account/tokens.rb +22 -0
- data/lib/fog/scaleway/models/account/user.rb +69 -0
- data/lib/fog/scaleway/models/account/users.rb +23 -0
- data/lib/fog/scaleway/models/compute/bootscript.rb +19 -0
- data/lib/fog/scaleway/models/compute/bootscripts.rb +22 -0
- data/lib/fog/scaleway/models/compute/image.rb +83 -0
- data/lib/fog/scaleway/models/compute/images.rb +22 -0
- data/lib/fog/scaleway/models/compute/ip.rb +70 -0
- data/lib/fog/scaleway/models/compute/ips.rb +22 -0
- data/lib/fog/scaleway/models/compute/security_group.rb +77 -0
- data/lib/fog/scaleway/models/compute/security_group_rule.rb +59 -0
- data/lib/fog/scaleway/models/compute/security_group_rules.rb +34 -0
- data/lib/fog/scaleway/models/compute/security_groups.rb +22 -0
- data/lib/fog/scaleway/models/compute/server.rb +243 -0
- data/lib/fog/scaleway/models/compute/servers.rb +47 -0
- data/lib/fog/scaleway/models/compute/snapshot.rb +90 -0
- data/lib/fog/scaleway/models/compute/snapshots.rb +22 -0
- data/lib/fog/scaleway/models/compute/task.rb +31 -0
- data/lib/fog/scaleway/models/compute/tasks.rb +22 -0
- data/lib/fog/scaleway/models/compute/volume.rb +96 -0
- data/lib/fog/scaleway/models/compute/volumes.rb +22 -0
- data/lib/fog/scaleway/request_helper.rb +32 -0
- data/lib/fog/scaleway/requests/account/create_token.rb +62 -0
- data/lib/fog/scaleway/requests/account/delete_token.rb +21 -0
- data/lib/fog/scaleway/requests/account/get_organization.rb +19 -0
- data/lib/fog/scaleway/requests/account/get_organization_quotas.rb +21 -0
- data/lib/fog/scaleway/requests/account/get_token.rb +19 -0
- data/lib/fog/scaleway/requests/account/get_token_permissions.rb +21 -0
- data/lib/fog/scaleway/requests/account/get_user.rb +19 -0
- data/lib/fog/scaleway/requests/account/list_organizations.rb +19 -0
- data/lib/fog/scaleway/requests/account/list_tokens.rb +19 -0
- data/lib/fog/scaleway/requests/account/update_token.rb +27 -0
- data/lib/fog/scaleway/requests/account/update_user.rb +39 -0
- data/lib/fog/scaleway/requests/compute/create_image.rb +61 -0
- data/lib/fog/scaleway/requests/compute/create_ip.rb +68 -0
- data/lib/fog/scaleway/requests/compute/create_security_group.rb +49 -0
- data/lib/fog/scaleway/requests/compute/create_security_group_rule.rb +49 -0
- data/lib/fog/scaleway/requests/compute/create_server.rb +129 -0
- data/lib/fog/scaleway/requests/compute/create_snapshot.rb +54 -0
- data/lib/fog/scaleway/requests/compute/create_volume.rb +88 -0
- data/lib/fog/scaleway/requests/compute/delete_image.rb +27 -0
- data/lib/fog/scaleway/requests/compute/delete_ip.rb +29 -0
- data/lib/fog/scaleway/requests/compute/delete_security_group.rb +31 -0
- data/lib/fog/scaleway/requests/compute/delete_security_group_rule.rb +23 -0
- data/lib/fog/scaleway/requests/compute/delete_server.rb +40 -0
- data/lib/fog/scaleway/requests/compute/delete_snapshot.rb +29 -0
- data/lib/fog/scaleway/requests/compute/delete_task.rb +21 -0
- data/lib/fog/scaleway/requests/compute/delete_user_data.rb +21 -0
- data/lib/fog/scaleway/requests/compute/delete_volume.rb +31 -0
- data/lib/fog/scaleway/requests/compute/execute_server_action.rb +101 -0
- data/lib/fog/scaleway/requests/compute/get_bootscript.rb +19 -0
- data/lib/fog/scaleway/requests/compute/get_container.rb +19 -0
- data/lib/fog/scaleway/requests/compute/get_dashboard.rb +37 -0
- data/lib/fog/scaleway/requests/compute/get_image.rb +19 -0
- data/lib/fog/scaleway/requests/compute/get_ip.rb +19 -0
- data/lib/fog/scaleway/requests/compute/get_security_group.rb +19 -0
- data/lib/fog/scaleway/requests/compute/get_security_group_rule.rb +23 -0
- data/lib/fog/scaleway/requests/compute/get_server.rb +48 -0
- data/lib/fog/scaleway/requests/compute/get_snapshot.rb +19 -0
- data/lib/fog/scaleway/requests/compute/get_task.rb +25 -0
- data/lib/fog/scaleway/requests/compute/get_user_data.rb +25 -0
- data/lib/fog/scaleway/requests/compute/get_volume.rb +19 -0
- data/lib/fog/scaleway/requests/compute/list_bootscripts.rb +23 -0
- data/lib/fog/scaleway/requests/compute/list_containers.rb +19 -0
- data/lib/fog/scaleway/requests/compute/list_images.rb +27 -0
- data/lib/fog/scaleway/requests/compute/list_ips.rb +19 -0
- data/lib/fog/scaleway/requests/compute/list_security_group_rules.rb +21 -0
- data/lib/fog/scaleway/requests/compute/list_security_groups.rb +19 -0
- data/lib/fog/scaleway/requests/compute/list_server_actions.rb +21 -0
- data/lib/fog/scaleway/requests/compute/list_servers.rb +19 -0
- data/lib/fog/scaleway/requests/compute/list_snapshots.rb +19 -0
- data/lib/fog/scaleway/requests/compute/list_tasks.rb +19 -0
- data/lib/fog/scaleway/requests/compute/list_user_data.rb +21 -0
- data/lib/fog/scaleway/requests/compute/list_volumes.rb +19 -0
- data/lib/fog/scaleway/requests/compute/update_image.rb +31 -0
- data/lib/fog/scaleway/requests/compute/update_ip.rb +47 -0
- data/lib/fog/scaleway/requests/compute/update_security_group.rb +29 -0
- data/lib/fog/scaleway/requests/compute/update_security_group_rule.rb +31 -0
- data/lib/fog/scaleway/requests/compute/update_server.rb +71 -0
- data/lib/fog/scaleway/requests/compute/update_snapshot.rb +24 -0
- data/lib/fog/scaleway/requests/compute/update_user_data.rb +25 -0
- data/lib/fog/scaleway/requests/compute/update_volume.rb +24 -0
- data/lib/fog/scaleway/version.rb +5 -0
- metadata +285 -0
@@ -0,0 +1,54 @@
|
|
1
|
+
module Fog
|
2
|
+
module Scaleway
|
3
|
+
class Compute
|
4
|
+
class Real
|
5
|
+
def create_snapshot(name, volume_id)
|
6
|
+
create('/snapshots', organization: @organization,
|
7
|
+
name: name,
|
8
|
+
volume_id: volume_id)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class Mock
|
13
|
+
def create_snapshot(name, volume_id)
|
14
|
+
body = {
|
15
|
+
organization: @organization,
|
16
|
+
name: name,
|
17
|
+
volume_id: volume_id
|
18
|
+
}
|
19
|
+
|
20
|
+
body = jsonify(body)
|
21
|
+
|
22
|
+
base_volume = lookup(:volumes, body['volume_id'])
|
23
|
+
|
24
|
+
server_id = base_volume['server'] && base_volume['server']['id']
|
25
|
+
server = lookup(:servers, server_id) if server_id
|
26
|
+
in_use = server && server['state'] != 'stopped'
|
27
|
+
|
28
|
+
raise_invalid_request_error('server must be stopped to snapshot') if in_use
|
29
|
+
|
30
|
+
creation_date = now
|
31
|
+
|
32
|
+
snapshot = {
|
33
|
+
'state' => 'snapshotting',
|
34
|
+
'base_volume' => {
|
35
|
+
'id' => base_volume['id'],
|
36
|
+
'name' => base_volume['name']
|
37
|
+
},
|
38
|
+
'name' => body['name'],
|
39
|
+
'modification_date' => creation_date,
|
40
|
+
'organization' => body['organization'],
|
41
|
+
'size' => base_volume['size'],
|
42
|
+
'id' => Fog::UUID.uuid,
|
43
|
+
'volume_type' => base_volume['volume_type'],
|
44
|
+
'creation_date' => creation_date
|
45
|
+
}
|
46
|
+
|
47
|
+
data[:snapshots][snapshot['id']] = snapshot
|
48
|
+
|
49
|
+
response(status: 201, body: { 'snapshot' => snapshot })
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
module Fog
|
2
|
+
module Scaleway
|
3
|
+
class Compute
|
4
|
+
class Real
|
5
|
+
def create_volume(name, volume_type, options)
|
6
|
+
if options[:size].nil? && options[:base_volume].nil? && options[:base_snapshot].nil?
|
7
|
+
raise ArgumentError, 'size, base_volume or base_snapshot are required to create a volume'
|
8
|
+
end
|
9
|
+
|
10
|
+
body = {
|
11
|
+
organization: @organization,
|
12
|
+
name: name,
|
13
|
+
volume_type: volume_type
|
14
|
+
}
|
15
|
+
|
16
|
+
if !options[:size].nil?
|
17
|
+
body[:size] = options[:size]
|
18
|
+
elsif !options[:base_volume].nil?
|
19
|
+
body[:base_volume] = options[:base_volume]
|
20
|
+
else
|
21
|
+
body[:base_snapshot] = options[:base_snapshot]
|
22
|
+
end
|
23
|
+
|
24
|
+
create('/volumes', body)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
class Mock
|
29
|
+
def create_volume(name, volume_type, options)
|
30
|
+
if options[:size].nil? && options[:base_volume].nil? && options[:base_snapshot].nil?
|
31
|
+
raise ArgumentError, 'size, base_volume or base_snapshot are required to create a volume'
|
32
|
+
end
|
33
|
+
|
34
|
+
body = {
|
35
|
+
organization: @organization,
|
36
|
+
name: name,
|
37
|
+
volume_type: volume_type
|
38
|
+
}
|
39
|
+
|
40
|
+
if !options[:size].nil?
|
41
|
+
body[:size] = options[:size]
|
42
|
+
elsif !options[:base_volume].nil?
|
43
|
+
body[:base_volume] = options[:base_volume]
|
44
|
+
else
|
45
|
+
body[:base_snapshot] = options[:base_snapshot]
|
46
|
+
end
|
47
|
+
|
48
|
+
body = jsonify(body)
|
49
|
+
|
50
|
+
creation_date = now
|
51
|
+
|
52
|
+
if body['size']
|
53
|
+
size = body['size']
|
54
|
+
elsif body['base_volume']
|
55
|
+
base_volume = lookup(:volumes, body['base_volume'])
|
56
|
+
|
57
|
+
server_id = base_volume['server'] && base_volume['server']['id']
|
58
|
+
server = lookup(:servers, server_id) if server_id
|
59
|
+
in_use = server && server['state'] != 'stopped'
|
60
|
+
|
61
|
+
raise_invalid_request_error('Base volume is in use') if in_use
|
62
|
+
|
63
|
+
size = base_volume['size']
|
64
|
+
elsif body['base_snapshot']
|
65
|
+
base_snapshot = lookup(:snapshots, body['base_snapshot'])
|
66
|
+
size = base_snapshot['size']
|
67
|
+
end
|
68
|
+
|
69
|
+
volume = {
|
70
|
+
'size' => size,
|
71
|
+
'name' => body['name'],
|
72
|
+
'modification_date' => creation_date,
|
73
|
+
'organization' => body['organization'],
|
74
|
+
'export_uri' => nil,
|
75
|
+
'creation_date' => creation_date,
|
76
|
+
'id' => Fog::UUID.uuid,
|
77
|
+
'volume_type' => body['volume_type'],
|
78
|
+
'server' => nil
|
79
|
+
}
|
80
|
+
|
81
|
+
data[:volumes][volume['id']] = volume
|
82
|
+
|
83
|
+
response(status: 201, body: { 'volume' => volume })
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Fog
|
2
|
+
module Scaleway
|
3
|
+
class Compute
|
4
|
+
class Real
|
5
|
+
def delete_image(image_id)
|
6
|
+
delete("/images/#{image_id}")
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
class Mock
|
11
|
+
def delete_image(image_id)
|
12
|
+
image = lookup(:images, image_id)
|
13
|
+
|
14
|
+
data[:images].delete(image['id'])
|
15
|
+
|
16
|
+
data[:servers].each do |_id, server|
|
17
|
+
if server['image'] && server['image']['id'] == image['id']
|
18
|
+
server['image'] = nil
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
response(status: 204)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Fog
|
2
|
+
module Scaleway
|
3
|
+
class Compute
|
4
|
+
class Real
|
5
|
+
def delete_ip(ip_id)
|
6
|
+
delete("/ips/#{ip_id}")
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
class Mock
|
11
|
+
def delete_ip(ip_id)
|
12
|
+
ip = lookup(:ips, ip_id)
|
13
|
+
|
14
|
+
data[:ips].delete(ip['id'])
|
15
|
+
|
16
|
+
if ip['server']
|
17
|
+
server = lookup(:servers, ip['server']['id'])
|
18
|
+
|
19
|
+
server['public_ip'] = if server['dynamic_ip_required']
|
20
|
+
create_dynamic_ip
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
response(status: 204)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Fog
|
2
|
+
module Scaleway
|
3
|
+
class Compute
|
4
|
+
class Real
|
5
|
+
def delete_security_group(security_group_id)
|
6
|
+
delete("/security_groups/#{security_group_id}")
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
class Mock
|
11
|
+
def delete_security_group(security_group_id)
|
12
|
+
security_group = lookup(:security_groups, security_group_id)
|
13
|
+
|
14
|
+
unless security_group['servers'].empty?
|
15
|
+
raise_conflict('Group is in use. You cannot delete it.')
|
16
|
+
end
|
17
|
+
|
18
|
+
if security_group['organization_default']
|
19
|
+
raise_conflict('Group is default group. You cannot delete it.')
|
20
|
+
end
|
21
|
+
|
22
|
+
data[:security_groups].delete(security_group['id'])
|
23
|
+
|
24
|
+
data[:security_group_rules].delete(security_group['id'])
|
25
|
+
|
26
|
+
response(status: 204)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Fog
|
2
|
+
module Scaleway
|
3
|
+
class Compute
|
4
|
+
class Real
|
5
|
+
def delete_security_group_rule(security_group_id, rule_id)
|
6
|
+
delete("/security_groups/#{security_group_id}/rules/#{rule_id}")
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
class Mock
|
11
|
+
def delete_security_group_rule(security_group_id, rule_id)
|
12
|
+
security_group = lookup(:security_groups, security_group_id)
|
13
|
+
|
14
|
+
unless data[:security_group_rules][security_group_id].delete(rule_id)
|
15
|
+
raise_unknown_resource(rule_id)
|
16
|
+
end
|
17
|
+
|
18
|
+
response(status: 204)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Fog
|
2
|
+
module Scaleway
|
3
|
+
class Compute
|
4
|
+
class Real
|
5
|
+
def delete_server(server_id)
|
6
|
+
delete("/servers/#{server_id}")
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
class Mock
|
11
|
+
def delete_server(server_id)
|
12
|
+
server = lookup(:servers, server_id)
|
13
|
+
|
14
|
+
if server['state'] != 'stopped'
|
15
|
+
raise_invalid_request_error('server should be stopped')
|
16
|
+
end
|
17
|
+
|
18
|
+
data[:servers].delete(server['id'])
|
19
|
+
|
20
|
+
data[:user_data].delete(server['id'])
|
21
|
+
|
22
|
+
data[:server_actions].delete(server['id'])
|
23
|
+
|
24
|
+
if server['public_ip'] && !server['public_ip']['dynamic']
|
25
|
+
ip = lookup(:ips, server['public_ip']['id'])
|
26
|
+
ip['server'] = nil
|
27
|
+
end
|
28
|
+
|
29
|
+
security_group = lookup(:security_groups, server['security_group']['id'])
|
30
|
+
security_group['servers'].reject! { |s| s['id'] == server['id'] }
|
31
|
+
|
32
|
+
volumes = server['volumes'].values
|
33
|
+
volumes.each { |volume| volume['server'] = nil }
|
34
|
+
|
35
|
+
response(status: 204)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Fog
|
2
|
+
module Scaleway
|
3
|
+
class Compute
|
4
|
+
class Real
|
5
|
+
def delete_snapshot(snapshot_id)
|
6
|
+
delete("/snapshots/#{snapshot_id}")
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
class Mock
|
11
|
+
def delete_snapshot(snapshot_id)
|
12
|
+
snapshot = lookup(:snapshots, snapshot_id)
|
13
|
+
|
14
|
+
in_use = data[:images].any? do |_id, image|
|
15
|
+
image['root_volume']['id'] == snapshot['id']
|
16
|
+
end
|
17
|
+
|
18
|
+
if in_use
|
19
|
+
raise_invalid_request_error('one or more images are attached to this snapshot')
|
20
|
+
end
|
21
|
+
|
22
|
+
data[:snapshots].delete(snapshot['id'])
|
23
|
+
|
24
|
+
response(status: 204)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Fog
|
2
|
+
module Scaleway
|
3
|
+
class Compute
|
4
|
+
class Real
|
5
|
+
def delete_task(task_id)
|
6
|
+
delete("/tasks/#{task_id}")
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
class Mock
|
11
|
+
def delete_task(task_id)
|
12
|
+
task = lookup(:tasks, task_id)
|
13
|
+
|
14
|
+
data[:tasks].delete(task['id'])
|
15
|
+
|
16
|
+
response(status: 204)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Fog
|
2
|
+
module Scaleway
|
3
|
+
class Compute
|
4
|
+
class Real
|
5
|
+
def delete_user_data(server_id, key)
|
6
|
+
delete("/servers/#{server_id}/user_data/#{key}")
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
class Mock
|
11
|
+
def delete_user_data(server_id, key)
|
12
|
+
server = lookup(:servers, server_id)
|
13
|
+
|
14
|
+
data[:user_data][server['id']].delete(key)
|
15
|
+
|
16
|
+
response(status: 204)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Fog
|
2
|
+
module Scaleway
|
3
|
+
class Compute
|
4
|
+
class Real
|
5
|
+
def delete_volume(volume_id)
|
6
|
+
delete("/volumes/#{volume_id}")
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
class Mock
|
11
|
+
def delete_volume(volume_id)
|
12
|
+
volume = lookup(:volumes, volume_id)
|
13
|
+
|
14
|
+
if volume['server']
|
15
|
+
raise_invalid_request_error('a server is attached to this volume')
|
16
|
+
end
|
17
|
+
|
18
|
+
data[:volumes].delete(volume_id)
|
19
|
+
|
20
|
+
data[:snapshots].each do |_id, snapshot|
|
21
|
+
if snapshot['base_volume'] && snapshot['base_volume']['id'] == volume_id
|
22
|
+
snapshot['base_volume'] = nil
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
response(status: 204)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
module Fog
|
2
|
+
module Scaleway
|
3
|
+
class Compute
|
4
|
+
class Real
|
5
|
+
def execute_server_action(server_id, action)
|
6
|
+
request(method: :post,
|
7
|
+
path: "/servers/#{server_id}/action",
|
8
|
+
body: {
|
9
|
+
action: action
|
10
|
+
},
|
11
|
+
expects: [202])
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class Mock
|
16
|
+
def execute_server_action(server_id, action)
|
17
|
+
server = lookup(:servers, server_id)
|
18
|
+
|
19
|
+
started_at = now
|
20
|
+
|
21
|
+
task = {
|
22
|
+
'status' => 'pending',
|
23
|
+
'terminated_at' => nil,
|
24
|
+
'href_from' => "/servers/#{server_id}/action",
|
25
|
+
'progress' => 0,
|
26
|
+
'started_at' => started_at,
|
27
|
+
'id' => Fog::UUID.uuid
|
28
|
+
}
|
29
|
+
|
30
|
+
case action
|
31
|
+
when 'poweron'
|
32
|
+
unless server['state'] == 'stopped'
|
33
|
+
raise_invalid_request_error('server should be stopped')
|
34
|
+
end
|
35
|
+
|
36
|
+
task['description'] = 'server_batch_poweron'
|
37
|
+
|
38
|
+
server['ipv6'] = create_ipv6 if server['enable_ipv6']
|
39
|
+
|
40
|
+
server['location'] = {
|
41
|
+
'platform_id' => Fog::Mock.random_numbers(2),
|
42
|
+
'node_id' => Fog::Mock.random_numbers(2),
|
43
|
+
'cluster_id' => Fog::Mock.random_numbers(2),
|
44
|
+
'chassis_id' => Fog::Mock.random_numbers(2)
|
45
|
+
}
|
46
|
+
|
47
|
+
server['private_ip'] = Fog::Mock.random_ip
|
48
|
+
|
49
|
+
if server['dynamic_ip_required'] && server['public_ip'].nil?
|
50
|
+
server['public_ip'] = create_dynamic_ip
|
51
|
+
end
|
52
|
+
|
53
|
+
server['state'] = 'starting'
|
54
|
+
server['state_detail'] = 'provisioning node'
|
55
|
+
server['modification_date'] = started_at
|
56
|
+
when 'poweroff'
|
57
|
+
if server['state'] == 'stopping'
|
58
|
+
raise_invalid_request_error('server is being stopped or rebooted')
|
59
|
+
elsif server['state'] != 'running'
|
60
|
+
raise_invalid_request_error('server should be running')
|
61
|
+
end
|
62
|
+
|
63
|
+
task['description'] = 'server_poweroff'
|
64
|
+
|
65
|
+
server['state'] = 'stopping'
|
66
|
+
server['state_detail'] = 'stopping'
|
67
|
+
server['modification_date'] = started_at
|
68
|
+
when 'reboot'
|
69
|
+
if server['state'] == 'stopping'
|
70
|
+
raise_invalid_request_error('server is being stopped or rebooted')
|
71
|
+
elsif server['state'] != 'running'
|
72
|
+
raise_invalid_request_error('server should be running')
|
73
|
+
end
|
74
|
+
|
75
|
+
task['description'] = 'server_reboot'
|
76
|
+
|
77
|
+
server['state'] = 'stopping'
|
78
|
+
server['state_detail'] = 'rebooting'
|
79
|
+
server['modification_date'] = started_at
|
80
|
+
when 'terminate'
|
81
|
+
if server['state'] == 'stopping'
|
82
|
+
raise_invalid_request_error('server is being stopped or rebooted')
|
83
|
+
elsif server['state'] != 'running'
|
84
|
+
raise_invalid_request_error('server should be running')
|
85
|
+
end
|
86
|
+
|
87
|
+
task['description'] = 'server_terminate'
|
88
|
+
|
89
|
+
server['state'] = 'stopping'
|
90
|
+
server['state_detail'] = 'terminating'
|
91
|
+
server['modification_date'] = started_at
|
92
|
+
end
|
93
|
+
|
94
|
+
data[:tasks][task['id']] = task
|
95
|
+
|
96
|
+
response(status: 202, body: { 'task' => task })
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|