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,19 @@
|
|
1
|
+
module Fog
|
2
|
+
module Scaleway
|
3
|
+
class Account
|
4
|
+
class Real
|
5
|
+
def get_token(token_id)
|
6
|
+
get("/tokens/#{token_id}")
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
class Mock
|
11
|
+
def get_token(token_id)
|
12
|
+
token = lookup(:tokens, token_id)
|
13
|
+
|
14
|
+
response(status: 200, body: { 'token' => token })
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Fog
|
2
|
+
module Scaleway
|
3
|
+
class Account
|
4
|
+
class Real
|
5
|
+
def get_token_permissions(token_id)
|
6
|
+
get("/tokens/#{token_id}/permissions")
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
class Mock
|
11
|
+
def get_token_permission(token_id)
|
12
|
+
token = lookup(:tokens, token_id)
|
13
|
+
|
14
|
+
permissions = lookup(:token_permissions, token['id'])
|
15
|
+
|
16
|
+
response(status: 200, body: { 'permissions' => permissions })
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Fog
|
2
|
+
module Scaleway
|
3
|
+
class Account
|
4
|
+
class Real
|
5
|
+
def get_user(user_id)
|
6
|
+
get("/users/#{user_id}")
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
class Mock
|
11
|
+
def get_user(user_id)
|
12
|
+
user = lookup(:users, user_id)
|
13
|
+
|
14
|
+
response(status: 200, body: { 'user' => user })
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Fog
|
2
|
+
module Scaleway
|
3
|
+
class Account
|
4
|
+
class Real
|
5
|
+
def list_organizations
|
6
|
+
get('/organizations')
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
class Mock
|
11
|
+
def list_organizations
|
12
|
+
organizations = data[:organizations].values
|
13
|
+
|
14
|
+
response(status: 200, body: { 'organizations' => organizations })
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Fog
|
2
|
+
module Scaleway
|
3
|
+
class Account
|
4
|
+
class Real
|
5
|
+
def list_tokens
|
6
|
+
get('/tokens')
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
class Mock
|
11
|
+
def list_tokens
|
12
|
+
tokens = data[:tokens].values
|
13
|
+
|
14
|
+
response(status: 200, body: { 'tokens' => tokens })
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Fog
|
2
|
+
module Scaleway
|
3
|
+
class Account
|
4
|
+
class Real
|
5
|
+
def update_token(token_id, options = {})
|
6
|
+
request(method: :patch,
|
7
|
+
path: "/tokens/#{token_id}",
|
8
|
+
body: options,
|
9
|
+
expects: [200])
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class Mock
|
14
|
+
def update_token(token_id, options = {})
|
15
|
+
options = jsonify(options)
|
16
|
+
|
17
|
+
token = lookup(:tokens, token_id)
|
18
|
+
|
19
|
+
token['description'] = options['description'] unless options['description'].nil?
|
20
|
+
token['expires'] = (Time.now + 30 * 60).utc.strftime(TIME_FORMAT)
|
21
|
+
|
22
|
+
response(status: 200, body: { 'token' => token })
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Fog
|
2
|
+
module Scaleway
|
3
|
+
class Account
|
4
|
+
class Real
|
5
|
+
def update_user(user_id, options = {})
|
6
|
+
request(method: :patch,
|
7
|
+
path: "/users/#{user_id}",
|
8
|
+
body: options,
|
9
|
+
expects: [200])
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class Mock
|
14
|
+
def update_user(user_id, options = {})
|
15
|
+
options = jsonify(options)
|
16
|
+
|
17
|
+
user = lookup(:users, user_id)
|
18
|
+
|
19
|
+
%w(phone_number firstname lastname).each do |attr|
|
20
|
+
user[attr] = options[attr] if options.key?(attr)
|
21
|
+
end
|
22
|
+
|
23
|
+
user['fullname'] = [user['firstname'], user['lastname']].compact.join(' ')
|
24
|
+
|
25
|
+
if (ssh_public_keys = options['ssh_public_keys'])
|
26
|
+
user['ssh_public_keys'] = ssh_public_keys.map do |key|
|
27
|
+
{
|
28
|
+
'key' => key['key'],
|
29
|
+
'fingerprint' => generate_fingerprint(key['key'])
|
30
|
+
}
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
response(status: 200, body: { 'user' => user })
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module Fog
|
2
|
+
module Scaleway
|
3
|
+
class Compute
|
4
|
+
class Real
|
5
|
+
def create_image(name, arch, root_volume, options = {})
|
6
|
+
body = {
|
7
|
+
organization: @organization,
|
8
|
+
name: name,
|
9
|
+
arch: arch,
|
10
|
+
root_volume: root_volume
|
11
|
+
}
|
12
|
+
|
13
|
+
body.merge!(options)
|
14
|
+
|
15
|
+
create('/images', body)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class Mock
|
20
|
+
def create_image(name, arch, root_volume, options = {})
|
21
|
+
body = {
|
22
|
+
organization: @organization,
|
23
|
+
name: name,
|
24
|
+
arch: arch,
|
25
|
+
root_volume: root_volume
|
26
|
+
}
|
27
|
+
|
28
|
+
body.merge!(options)
|
29
|
+
|
30
|
+
body = jsonify(body)
|
31
|
+
|
32
|
+
creation_date = now
|
33
|
+
|
34
|
+
root_volume = lookup(:snapshots, body['root_volume'])
|
35
|
+
|
36
|
+
image = {
|
37
|
+
'default_bootscript' => body['default_bootscript'],
|
38
|
+
'creation_date' => creation_date,
|
39
|
+
'name' => body['name'],
|
40
|
+
'modification_date' => creation_date,
|
41
|
+
'organization' => body['organization'],
|
42
|
+
'extra_volumes' => '[]',
|
43
|
+
'arch' => body['arch'],
|
44
|
+
'id' => Fog::UUID.uuid,
|
45
|
+
'root_volume' => {
|
46
|
+
'size' => root_volume['size'],
|
47
|
+
'id' => root_volume['id'],
|
48
|
+
'volume_type' => root_volume['volume_type'],
|
49
|
+
'name' => root_volume['name']
|
50
|
+
},
|
51
|
+
'public' => false
|
52
|
+
}
|
53
|
+
|
54
|
+
data[:images][image['id']] = image
|
55
|
+
|
56
|
+
response(status: 201, body: { 'image' => image })
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
module Fog
|
2
|
+
module Scaleway
|
3
|
+
class Compute
|
4
|
+
class Real
|
5
|
+
def create_ip(options = {})
|
6
|
+
body = {
|
7
|
+
organization: @organization
|
8
|
+
}
|
9
|
+
|
10
|
+
body.merge!(options)
|
11
|
+
|
12
|
+
create('/ips', body)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class Mock
|
17
|
+
def create_ip(options = {})
|
18
|
+
body = {
|
19
|
+
organization: @organization
|
20
|
+
}
|
21
|
+
|
22
|
+
body.merge!(options)
|
23
|
+
|
24
|
+
body = jsonify(body)
|
25
|
+
|
26
|
+
server = lookup(:servers, body['server']) if body['server']
|
27
|
+
|
28
|
+
ip = {
|
29
|
+
'organization' => body['organization'],
|
30
|
+
'reverse' => nil,
|
31
|
+
'id' => Fog::UUID.uuid,
|
32
|
+
'server' => nil,
|
33
|
+
'address' => Fog::Mock.random_ip
|
34
|
+
}
|
35
|
+
|
36
|
+
if server
|
37
|
+
ip['server'] = {
|
38
|
+
'id' => server['id'],
|
39
|
+
'name' => server['name']
|
40
|
+
}
|
41
|
+
end
|
42
|
+
|
43
|
+
if server && (public_ip = server['public_ip'])
|
44
|
+
if public_ip['dynamic']
|
45
|
+
ip['id'] = public_ip['id']
|
46
|
+
ip['address'] = public_ip['address']
|
47
|
+
else
|
48
|
+
message = "Server '#{server['id']}' is already attached to an IP address"
|
49
|
+
raise_invalid_request_error(message)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
data[:ips][ip['id']] = ip
|
54
|
+
|
55
|
+
if server
|
56
|
+
server['public_ip'] = {
|
57
|
+
'dynamic' => false,
|
58
|
+
'id' => ip['id'],
|
59
|
+
'address' => ip['address']
|
60
|
+
}
|
61
|
+
end
|
62
|
+
|
63
|
+
response(status: 201, body: { 'ip' => ip })
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module Fog
|
2
|
+
module Scaleway
|
3
|
+
class Compute
|
4
|
+
class Real
|
5
|
+
def create_security_group(name, options = {})
|
6
|
+
body = {
|
7
|
+
organization: @organization,
|
8
|
+
name: name
|
9
|
+
}
|
10
|
+
|
11
|
+
body.merge!(options)
|
12
|
+
|
13
|
+
create('/security_groups', body)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class Mock
|
18
|
+
def create_security_group(name, options = {})
|
19
|
+
body = {
|
20
|
+
organization: @organization,
|
21
|
+
name: name
|
22
|
+
}
|
23
|
+
|
24
|
+
body.merge!(options)
|
25
|
+
|
26
|
+
body = jsonify(body)
|
27
|
+
|
28
|
+
security_group = {
|
29
|
+
'description' => body['description'],
|
30
|
+
'enable_default_security' => body.fetch('enable_default_security', true),
|
31
|
+
'servers' => [],
|
32
|
+
'organization' => body['organization'],
|
33
|
+
'organization_default' => body.fetch('organization_default', false),
|
34
|
+
'id' => Fog::UUID.uuid,
|
35
|
+
'name' => body['name']
|
36
|
+
}
|
37
|
+
|
38
|
+
if security_group['organization_default'] && default_security_group
|
39
|
+
raise_conflict('Cannot have more than one organization default group')
|
40
|
+
end
|
41
|
+
|
42
|
+
data[:security_groups][security_group['id']] = security_group
|
43
|
+
|
44
|
+
response(status: 201, body: { 'security_group' => security_group })
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module Fog
|
2
|
+
module Scaleway
|
3
|
+
class Compute
|
4
|
+
class Real
|
5
|
+
def create_security_group_rule(security_group_id, action, direction, ip_range, protocol, dest_port_from = nil)
|
6
|
+
create("/security_groups/#{security_group_id}/rules", action: action,
|
7
|
+
direction: direction,
|
8
|
+
ip_range: ip_range,
|
9
|
+
protocol: protocol,
|
10
|
+
dest_port_from: dest_port_from)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class Mock
|
15
|
+
def create_security_group_rule(security_group_id, action, direction, ip_range, protocol, dest_port_from = nil)
|
16
|
+
body = {
|
17
|
+
action: action,
|
18
|
+
direction: direction,
|
19
|
+
ip_range: ip_range,
|
20
|
+
protocol: protocol,
|
21
|
+
dest_port_from: dest_port_from
|
22
|
+
}
|
23
|
+
|
24
|
+
body = jsonify(body)
|
25
|
+
|
26
|
+
rules = data[:security_group_rules][security_group_id].values
|
27
|
+
|
28
|
+
position = (rules.map { |r| r[:position] }.max || 0) + 1
|
29
|
+
|
30
|
+
rule = {
|
31
|
+
'direction' => body['direction'],
|
32
|
+
'protocol' => body['protocol'],
|
33
|
+
'ip_range' => body['ip_range'],
|
34
|
+
'dest_port_from' => body['dest_port_from'],
|
35
|
+
'action' => body['action'],
|
36
|
+
'position' => position,
|
37
|
+
'dest_port_to' => nil,
|
38
|
+
'editable' => nil,
|
39
|
+
'id' => Fog::UUID.uuid
|
40
|
+
}
|
41
|
+
|
42
|
+
data[:security_group_rules][security_group_id][rule['id']] = rule
|
43
|
+
|
44
|
+
response(status: 201, body: { 'rule' => rule })
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,129 @@
|
|
1
|
+
module Fog
|
2
|
+
module Scaleway
|
3
|
+
class Compute
|
4
|
+
class Real
|
5
|
+
def create_server(name, image, volumes, options = {})
|
6
|
+
body = {
|
7
|
+
organization: @organization,
|
8
|
+
name: name,
|
9
|
+
image: image,
|
10
|
+
volumes: volumes
|
11
|
+
}
|
12
|
+
|
13
|
+
body.merge!(options)
|
14
|
+
|
15
|
+
create('/servers', body)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class Mock
|
20
|
+
def create_server(name, image, volumes, options = {})
|
21
|
+
body = {
|
22
|
+
organization: @organization,
|
23
|
+
name: name,
|
24
|
+
image: image,
|
25
|
+
volumes: volumes
|
26
|
+
}
|
27
|
+
|
28
|
+
body.merge!(options)
|
29
|
+
|
30
|
+
body = jsonify(body)
|
31
|
+
|
32
|
+
image = lookup(:images, body['image'])
|
33
|
+
|
34
|
+
creation_date = now
|
35
|
+
|
36
|
+
volumes = {}
|
37
|
+
body['volumes'].each do |index, volume|
|
38
|
+
volume = lookup(:volumes, volume['id'])
|
39
|
+
|
40
|
+
if volume['server']
|
41
|
+
message = "volume #{volume['id']} is already attached to a server"
|
42
|
+
raise_invalid_request_error(message)
|
43
|
+
end
|
44
|
+
|
45
|
+
volumes[index] = volume
|
46
|
+
end
|
47
|
+
|
48
|
+
root_volume = image['root_volume']
|
49
|
+
volumes['0'] = {
|
50
|
+
'size' => root_volume['size'],
|
51
|
+
'name' => root_volume['name'],
|
52
|
+
'modification_date' => creation_date,
|
53
|
+
'organization' => body['organization'],
|
54
|
+
'export_uri' => nil,
|
55
|
+
'creation_date' => creation_date,
|
56
|
+
'id' => Fog::UUID.uuid,
|
57
|
+
'volume_type' => root_volume['volume_type'],
|
58
|
+
'server' => nil
|
59
|
+
}
|
60
|
+
|
61
|
+
public_ip = nil
|
62
|
+
if body['public_ip']
|
63
|
+
public_ip = lookup(:ips, body['public_ip'])
|
64
|
+
|
65
|
+
public_ip = {
|
66
|
+
'dynamic' => false,
|
67
|
+
'id' => public_ip['id'],
|
68
|
+
'address' => public_ip['address']
|
69
|
+
}
|
70
|
+
end
|
71
|
+
|
72
|
+
dynamic_ip_required = !public_ip && body.fetch('dynamic_ip_required', true)
|
73
|
+
|
74
|
+
default_bootscript_id = image['default_bootscript']['id']
|
75
|
+
bootscript_id = body.fetch('bootscript', default_bootscript_id)
|
76
|
+
bootscript = lookup(:bootscripts, bootscript_id)
|
77
|
+
|
78
|
+
if body['security_group']
|
79
|
+
security_group = lookup(:security_groups, body['security_group'])
|
80
|
+
else
|
81
|
+
security_group = default_security_group
|
82
|
+
security_group ||= create_default_security_group
|
83
|
+
end
|
84
|
+
|
85
|
+
server = {
|
86
|
+
'arch' => image['arch'],
|
87
|
+
'bootscript' => bootscript,
|
88
|
+
'commercial_type' => body.fetch('commercial_type', 'C1'),
|
89
|
+
'creation_date' => creation_date,
|
90
|
+
'dynamic_ip_required' => dynamic_ip_required,
|
91
|
+
'enable_ipv6' => body.fetch('enable_ipv6', false),
|
92
|
+
'extra_networks' => [],
|
93
|
+
'hostname' => body['name'],
|
94
|
+
'id' => Fog::UUID.uuid,
|
95
|
+
'image' => image,
|
96
|
+
'ipv6' => nil,
|
97
|
+
'location' => nil,
|
98
|
+
'modification_date' => creation_date,
|
99
|
+
'name' => body['name'],
|
100
|
+
'organization' => body['organization'],
|
101
|
+
'private_ip' => nil,
|
102
|
+
'public_ip' => public_ip,
|
103
|
+
'security_group' => {
|
104
|
+
'id' => security_group['id'],
|
105
|
+
'name' => security_group['name']
|
106
|
+
},
|
107
|
+
'state' => 'stopped',
|
108
|
+
'state_detail' => '',
|
109
|
+
'tags' => body.fetch('tags', []),
|
110
|
+
'volumes' => volumes
|
111
|
+
}
|
112
|
+
|
113
|
+
data[:servers][server['id']] = server
|
114
|
+
|
115
|
+
data[:volumes][server['volumes']['0']['id']] = server['volumes']['0']
|
116
|
+
|
117
|
+
server['volumes'].each do |_index, volume|
|
118
|
+
volume['server'] = {
|
119
|
+
'id' => server['id'],
|
120
|
+
'name' => server['name']
|
121
|
+
}
|
122
|
+
end
|
123
|
+
|
124
|
+
response(status: 201, body: { 'server' => server })
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|