fog-aliyun 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +5 -0
- data/.rubocop_todo.yml +149 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Rakefile +3 -3
- data/fog-aliyun.gemspec +16 -13
- data/lib/fog/aliyun.rb +8 -8
- data/lib/fog/aliyun/compute.rb +99 -113
- data/lib/fog/aliyun/models/compute/eip_address.rb +23 -29
- data/lib/fog/aliyun/models/compute/eip_addresses.rb +3 -5
- data/lib/fog/aliyun/models/compute/image.rb +26 -28
- data/lib/fog/aliyun/models/compute/images.rb +2 -6
- data/lib/fog/aliyun/models/compute/route_entry.rb +9 -11
- data/lib/fog/aliyun/models/compute/route_entrys.rb +7 -7
- data/lib/fog/aliyun/models/compute/route_table.rb +10 -11
- data/lib/fog/aliyun/models/compute/route_tables.rb +2 -2
- data/lib/fog/aliyun/models/compute/security_group.rb +24 -24
- data/lib/fog/aliyun/models/compute/security_group_rule.rb +20 -20
- data/lib/fog/aliyun/models/compute/security_group_rules.rb +4 -4
- data/lib/fog/aliyun/models/compute/security_groups.rb +6 -7
- data/lib/fog/aliyun/models/compute/server.rb +42 -43
- data/lib/fog/aliyun/models/compute/servers.rb +9 -11
- data/lib/fog/aliyun/models/compute/snapshot.rb +15 -15
- data/lib/fog/aliyun/models/compute/snapshots.rb +6 -10
- data/lib/fog/aliyun/models/compute/volume.rb +36 -40
- data/lib/fog/aliyun/models/compute/volumes.rb +7 -11
- data/lib/fog/aliyun/models/compute/vpc.rb +18 -19
- data/lib/fog/aliyun/models/compute/vpcs.rb +5 -6
- data/lib/fog/aliyun/models/compute/vrouter.rb +13 -13
- data/lib/fog/aliyun/models/compute/vrouters.rb +4 -5
- data/lib/fog/aliyun/models/compute/vswitch.rb +18 -20
- data/lib/fog/aliyun/models/compute/vswitches.rb +6 -6
- data/lib/fog/aliyun/models/storage/directories.rb +10 -16
- data/lib/fog/aliyun/models/storage/directory.rb +8 -8
- data/lib/fog/aliyun/models/storage/file.rb +58 -64
- data/lib/fog/aliyun/models/storage/files.rb +95 -115
- data/lib/fog/aliyun/requests/compute/allocate_eip_address.rb +18 -44
- data/lib/fog/aliyun/requests/compute/allocate_public_ip_address.rb +12 -36
- data/lib/fog/aliyun/requests/compute/associate_eip_address.rb +16 -40
- data/lib/fog/aliyun/requests/compute/attach_disk.rb +19 -22
- data/lib/fog/aliyun/requests/compute/create_disk.rb +33 -63
- data/lib/fog/aliyun/requests/compute/create_image.rb +21 -21
- data/lib/fog/aliyun/requests/compute/create_security_group.rb +16 -16
- data/lib/fog/aliyun/requests/compute/create_security_group_egress_ip_rule.rb +22 -63
- data/lib/fog/aliyun/requests/compute/create_security_group_egress_sg_rule.rb +23 -61
- data/lib/fog/aliyun/requests/compute/create_security_group_ip_rule.rb +22 -63
- data/lib/fog/aliyun/requests/compute/create_security_group_sg_rule.rb +23 -61
- data/lib/fog/aliyun/requests/compute/create_server.rb +76 -78
- data/lib/fog/aliyun/requests/compute/create_snapshot.rb +12 -26
- data/lib/fog/aliyun/requests/compute/create_vpc.rb +11 -38
- data/lib/fog/aliyun/requests/compute/create_vswitch.rb +13 -40
- data/lib/fog/aliyun/requests/compute/delete_disk.rb +8 -35
- data/lib/fog/aliyun/requests/compute/delete_image.rb +6 -33
- data/lib/fog/aliyun/requests/compute/delete_security_group.rb +13 -13
- data/lib/fog/aliyun/requests/compute/delete_security_group_egress_ip_rule.rb +22 -63
- data/lib/fog/aliyun/requests/compute/delete_security_group_egress_sg_rule.rb +23 -61
- data/lib/fog/aliyun/requests/compute/delete_security_group_ip_rule.rb +22 -62
- data/lib/fog/aliyun/requests/compute/delete_security_group_sg_rule.rb +23 -61
- data/lib/fog/aliyun/requests/compute/delete_server.rb +15 -15
- data/lib/fog/aliyun/requests/compute/delete_snapshot.rb +6 -20
- data/lib/fog/aliyun/requests/compute/delete_vpc.rb +9 -26
- data/lib/fog/aliyun/requests/compute/delete_vswitch.rb +9 -25
- data/lib/fog/aliyun/requests/compute/detach_disk.rb +11 -27
- data/lib/fog/aliyun/requests/compute/join_security_group.rb +15 -16
- data/lib/fog/aliyun/requests/compute/leave_security_group.rb +15 -16
- data/lib/fog/aliyun/requests/compute/list_disks.rb +24 -43
- data/lib/fog/aliyun/requests/compute/list_eip_addresses.rb +26 -52
- data/lib/fog/aliyun/requests/compute/list_images.rb +21 -24
- data/lib/fog/aliyun/requests/compute/list_route_tables.rb +16 -19
- data/lib/fog/aliyun/requests/compute/list_security_group_rules.rb +22 -23
- data/lib/fog/aliyun/requests/compute/list_security_groups.rb +21 -24
- data/lib/fog/aliyun/requests/compute/list_server_types.rb +50 -50
- data/lib/fog/aliyun/requests/compute/list_servers.rb +25 -28
- data/lib/fog/aliyun/requests/compute/list_snapshots.rb +20 -37
- data/lib/fog/aliyun/requests/compute/list_vpcs.rb +12 -29
- data/lib/fog/aliyun/requests/compute/list_vrouters.rb +13 -16
- data/lib/fog/aliyun/requests/compute/list_vswitchs.rb +14 -31
- data/lib/fog/aliyun/requests/compute/list_zones.rb +16 -16
- data/lib/fog/aliyun/requests/compute/modify_vpc.rb +17 -17
- data/lib/fog/aliyun/requests/compute/modify_vswitch.rb +11 -39
- data/lib/fog/aliyun/requests/compute/reboot_server.rb +15 -16
- data/lib/fog/aliyun/requests/compute/release_eip_address.rb +12 -36
- data/lib/fog/aliyun/requests/compute/start_server.rb +14 -15
- data/lib/fog/aliyun/requests/compute/stop_server.rb +13 -14
- data/lib/fog/aliyun/requests/compute/unassociate_eip_address.rb +16 -41
- data/lib/fog/aliyun/requests/storage/copy_object.rb +11 -14
- data/lib/fog/aliyun/requests/storage/delete_bucket.rb +30 -30
- data/lib/fog/aliyun/requests/storage/delete_container.rb +11 -14
- data/lib/fog/aliyun/requests/storage/delete_object.rb +20 -22
- data/lib/fog/aliyun/requests/storage/get_bucket.rb +141 -148
- data/lib/fog/aliyun/requests/storage/get_container.rb +26 -38
- data/lib/fog/aliyun/requests/storage/get_containers.rb +20 -32
- data/lib/fog/aliyun/requests/storage/get_object.rb +12 -12
- data/lib/fog/aliyun/requests/storage/get_object_http_url.rb +11 -11
- data/lib/fog/aliyun/requests/storage/get_object_https_url.rb +11 -11
- data/lib/fog/aliyun/requests/storage/head_object.rb +11 -11
- data/lib/fog/aliyun/requests/storage/list_buckets.rb +40 -47
- data/lib/fog/aliyun/requests/storage/list_objects.rb +91 -104
- data/lib/fog/aliyun/requests/storage/put_bucket.rb +22 -23
- data/lib/fog/aliyun/requests/storage/put_container.rb +12 -12
- data/lib/fog/aliyun/requests/storage/put_object.rb +100 -110
- data/lib/fog/aliyun/storage.rb +209 -214
- data/lib/fog/aliyun/version.rb +1 -1
- data/lib/fog/bin/aliyun.rb +5 -5
- metadata +55 -4
@@ -3,63 +3,55 @@ module Fog
|
|
3
3
|
class Aliyun
|
4
4
|
class Real
|
5
5
|
# {Aliyun API Reference}[https://docs.aliyun.com/?spm=5176.100054.3.1.DGkmH7#/pub/ecs/open-api/securitygroup&authorizesecuritygroup]
|
6
|
-
def create_security_group_egress_sg_rule(securitygroup_id, dest_group_id, option={})
|
6
|
+
def create_security_group_egress_sg_rule(securitygroup_id, dest_group_id, option = {})
|
7
7
|
action = 'AuthorizeSecurityGroupEgress'
|
8
|
-
sigNonce = randonStr
|
8
|
+
sigNonce = randonStr
|
9
9
|
time = Time.new.utc
|
10
10
|
|
11
11
|
parameters = defalutParameters(action, sigNonce, time)
|
12
12
|
pathUrl = defaultAliyunUri(action, sigNonce, time)
|
13
|
-
|
14
|
-
parameters[
|
13
|
+
|
14
|
+
parameters['SecurityGroupId'] = securitygroup_id
|
15
15
|
pathUrl += '&SecurityGroupId='
|
16
16
|
pathUrl += securitygroup_id
|
17
17
|
|
18
|
-
parameters[
|
18
|
+
parameters['DestGroupId'] = dest_group_id
|
19
19
|
pathUrl += '&DestGroupId='
|
20
20
|
pathUrl += dest_group_id
|
21
21
|
|
22
22
|
nicType = 'intranet'
|
23
|
-
parameters[
|
23
|
+
parameters['NicType'] = nicType
|
24
24
|
pathUrl += '&NicType='
|
25
25
|
pathUrl += nicType
|
26
|
-
|
26
|
+
|
27
27
|
portRange = option[:portRange]
|
28
|
-
unless portRange
|
29
|
-
|
30
|
-
end
|
31
|
-
parameters["PortRange"] = portRange
|
28
|
+
portRange = '-1/-1' unless portRange
|
29
|
+
parameters['PortRange'] = portRange
|
32
30
|
pathUrl += '&PortRange='
|
33
|
-
pathUrl += URI.encode(portRange,'/[^!*\'()\;?:@#&%=+$,{}[]<>`" ')
|
34
|
-
|
31
|
+
pathUrl += URI.encode(portRange, '/[^!*\'()\;?:@#&%=+$,{}[]<>`" ')
|
32
|
+
|
35
33
|
protocol = option[:protocol]
|
36
|
-
unless protocol
|
37
|
-
|
38
|
-
end
|
39
|
-
parameters["IpProtocol"] = protocol
|
34
|
+
protocol = 'all' unless protocol
|
35
|
+
parameters['IpProtocol'] = protocol
|
40
36
|
pathUrl += '&IpProtocol='
|
41
37
|
pathUrl += protocol
|
42
38
|
|
43
39
|
destGOAccount = option[:destGroupOwnerAccount]
|
44
40
|
if sourceGOAccount
|
45
|
-
|
46
|
-
|
47
|
-
|
41
|
+
parameters['DestGroupOwnerAccount'] = destGOAccount
|
42
|
+
pathUrl += '&DestGroupOwnerAccount='
|
43
|
+
pathUrl += destGOAccount
|
48
44
|
end
|
49
45
|
|
50
46
|
policy = option[:policy]
|
51
|
-
unless policy
|
52
|
-
|
53
|
-
end
|
54
|
-
parameters["Policy"] = policy
|
47
|
+
policy = 'accept' unless policy
|
48
|
+
parameters['Policy'] = policy
|
55
49
|
pathUrl += '&Policy='
|
56
50
|
pathUrl += policy
|
57
51
|
|
58
52
|
priority = option[:priority]
|
59
|
-
unless priority
|
60
|
-
|
61
|
-
end
|
62
|
-
parameters["Priority"] = priority
|
53
|
+
priority = '1' unless priority
|
54
|
+
parameters['Priority'] = priority
|
63
55
|
pathUrl += '&Priority='
|
64
56
|
pathUrl += priority
|
65
57
|
|
@@ -68,42 +60,12 @@ module Fog
|
|
68
60
|
pathUrl += signature
|
69
61
|
|
70
62
|
request(
|
71
|
-
:
|
72
|
-
:
|
73
|
-
:
|
63
|
+
expects: [200, 203],
|
64
|
+
method: 'GET',
|
65
|
+
path: pathUrl
|
74
66
|
)
|
75
67
|
end
|
76
68
|
end
|
77
|
-
|
78
|
-
class Mock
|
79
|
-
def create_security_group_rule(parent_group_id, ip_protocol, from_port, to_port, cidr, group_id=nil)
|
80
|
-
parent_group_id = parent_group_id.to_i
|
81
|
-
response = Excon::Response.new
|
82
|
-
response.status = 200
|
83
|
-
response.headers = {
|
84
|
-
'X-Compute-Request-Id' => "req-#{Fog::Mock.random_hex(32)}",
|
85
|
-
'Content-Type' => 'application/json',
|
86
|
-
'Content-Length' => Fog::Mock.random_numbers(3).to_s,
|
87
|
-
'Date' => Date.new
|
88
|
-
}
|
89
|
-
rule = {
|
90
|
-
'id' => Fog::Mock.random_numbers(2).to_i,
|
91
|
-
'from_port' => from_port,
|
92
|
-
'group' => group_id || {},
|
93
|
-
'ip_protocol' => ip_protocol,
|
94
|
-
'to_port' => to_port,
|
95
|
-
'parent_group_id' => parent_group_id,
|
96
|
-
'ip_range' => {
|
97
|
-
'cidr' => cidr
|
98
|
-
}
|
99
|
-
}
|
100
|
-
self.data[:security_groups][parent_group_id.to_s]['rules'].push(rule)
|
101
|
-
response.body = {
|
102
|
-
'security_group_rule' => rule
|
103
|
-
}
|
104
|
-
response
|
105
|
-
end
|
106
|
-
end # mock
|
107
69
|
end # aliyun
|
108
70
|
end # compute
|
109
71
|
end # fog
|
@@ -3,58 +3,47 @@ module Fog
|
|
3
3
|
class Aliyun
|
4
4
|
class Real
|
5
5
|
# {Aliyun API Reference}[https://docs.aliyun.com/?spm=5176.100054.3.1.DGkmH7#/pub/ecs/open-api/securitygroup&authorizesecuritygroup]
|
6
|
-
def create_security_group_ip_rule(securitygroup_id,sourceCidrIp, nicType, option={})
|
7
|
-
|
6
|
+
def create_security_group_ip_rule(securitygroup_id, sourceCidrIp, nicType, option = {})
|
8
7
|
action = 'AuthorizeSecurityGroup'
|
9
|
-
sigNonce = randonStr
|
8
|
+
sigNonce = randonStr
|
10
9
|
time = Time.new.utc
|
11
10
|
|
12
11
|
parameters = defalutParameters(action, sigNonce, time)
|
13
12
|
pathUrl = defaultAliyunUri(action, sigNonce, time)
|
14
|
-
|
15
|
-
parameters[
|
13
|
+
|
14
|
+
parameters['SecurityGroupId'] = securitygroup_id
|
16
15
|
pathUrl += '&SecurityGroupId='
|
17
16
|
pathUrl += securitygroup_id
|
18
17
|
|
19
|
-
parameters[
|
18
|
+
parameters['SourceCidrIp'] = sourceCidrIp
|
20
19
|
pathUrl += '&SourceCidrIp='
|
21
|
-
pathUrl += URI.encode(sourceCidrIp,'/[^!*\'()\;?:@#&%=+$,{}[]<>`" ')
|
22
|
-
unless nicType
|
23
|
-
|
24
|
-
end
|
25
|
-
parameters["NicType"] = nicType
|
20
|
+
pathUrl += URI.encode(sourceCidrIp, '/[^!*\'()\;?:@#&%=+$,{}[]<>`" ')
|
21
|
+
nicType = 'intranet' unless nicType
|
22
|
+
parameters['NicType'] = nicType
|
26
23
|
pathUrl += '&NicType='
|
27
24
|
pathUrl += nicType
|
28
|
-
|
25
|
+
|
29
26
|
portRange = option[:portRange]
|
30
|
-
unless portRange
|
31
|
-
|
32
|
-
end
|
33
|
-
parameters["PortRange"] = portRange
|
27
|
+
portRange = '-1/-1' unless portRange
|
28
|
+
parameters['PortRange'] = portRange
|
34
29
|
pathUrl += '&PortRange='
|
35
|
-
pathUrl += URI.encode(portRange,'/[^!*\'()\;?:@#&%=+$,{}[]<>`" ')
|
36
|
-
|
30
|
+
pathUrl += URI.encode(portRange, '/[^!*\'()\;?:@#&%=+$,{}[]<>`" ')
|
31
|
+
|
37
32
|
protocol = option[:protocol]
|
38
|
-
unless protocol
|
39
|
-
|
40
|
-
end
|
41
|
-
parameters["IpProtocol"] = protocol
|
33
|
+
protocol = 'all' unless protocol
|
34
|
+
parameters['IpProtocol'] = protocol
|
42
35
|
pathUrl += '&IpProtocol='
|
43
36
|
pathUrl += protocol
|
44
37
|
|
45
38
|
policy = option[:policy]
|
46
|
-
unless policy
|
47
|
-
|
48
|
-
end
|
49
|
-
parameters["Policy"] = policy
|
39
|
+
policy = 'accept' unless policy
|
40
|
+
parameters['Policy'] = policy
|
50
41
|
pathUrl += '&Policy='
|
51
42
|
pathUrl += policy
|
52
43
|
|
53
44
|
priority = option[:priority]
|
54
|
-
unless priority
|
55
|
-
|
56
|
-
end
|
57
|
-
parameters["Priority"] = priority
|
45
|
+
priority = '1' unless priority
|
46
|
+
parameters['Priority'] = priority
|
58
47
|
pathUrl += '&Priority='
|
59
48
|
pathUrl += priority
|
60
49
|
|
@@ -63,42 +52,12 @@ module Fog
|
|
63
52
|
pathUrl += signature
|
64
53
|
|
65
54
|
request(
|
66
|
-
:
|
67
|
-
:
|
68
|
-
:
|
55
|
+
expects: [200, 203],
|
56
|
+
method: 'GET',
|
57
|
+
path: pathUrl
|
69
58
|
)
|
70
59
|
end
|
71
60
|
end
|
72
|
-
|
73
|
-
class Mock
|
74
|
-
def create_security_group_rule(parent_group_id, ip_protocol, from_port, to_port, cidr, group_id=nil)
|
75
|
-
parent_group_id = parent_group_id.to_i
|
76
|
-
response = Excon::Response.new
|
77
|
-
response.status = 200
|
78
|
-
response.headers = {
|
79
|
-
'X-Compute-Request-Id' => "req-#{Fog::Mock.random_hex(32)}",
|
80
|
-
'Content-Type' => 'application/json',
|
81
|
-
'Content-Length' => Fog::Mock.random_numbers(3).to_s,
|
82
|
-
'Date' => Date.new
|
83
|
-
}
|
84
|
-
rule = {
|
85
|
-
'id' => Fog::Mock.random_numbers(2).to_i,
|
86
|
-
'from_port' => from_port,
|
87
|
-
'group' => group_id || {},
|
88
|
-
'ip_protocol' => ip_protocol,
|
89
|
-
'to_port' => to_port,
|
90
|
-
'parent_group_id' => parent_group_id,
|
91
|
-
'ip_range' => {
|
92
|
-
'cidr' => cidr
|
93
|
-
}
|
94
|
-
}
|
95
|
-
self.data[:security_groups][parent_group_id.to_s]['rules'].push(rule)
|
96
|
-
response.body = {
|
97
|
-
'security_group_rule' => rule
|
98
|
-
}
|
99
|
-
response
|
100
|
-
end
|
101
|
-
end # mock
|
102
61
|
end # aliyun
|
103
62
|
end # compute
|
104
63
|
end # fog
|
@@ -3,63 +3,55 @@ module Fog
|
|
3
3
|
class Aliyun
|
4
4
|
class Real
|
5
5
|
# {Aliyun API Reference}[https://docs.aliyun.com/?spm=5176.100054.3.1.DGkmH7#/pub/ecs/open-api/securitygroup&authorizesecuritygroup]
|
6
|
-
def create_security_group_sg_rule(securitygroup_id, source_securitygroup_id, option={})
|
6
|
+
def create_security_group_sg_rule(securitygroup_id, source_securitygroup_id, option = {})
|
7
7
|
action = 'AuthorizeSecurityGroup'
|
8
|
-
sigNonce = randonStr
|
8
|
+
sigNonce = randonStr
|
9
9
|
time = Time.new.utc
|
10
10
|
|
11
11
|
parameters = defalutParameters(action, sigNonce, time)
|
12
12
|
pathUrl = defaultAliyunUri(action, sigNonce, time)
|
13
|
-
|
14
|
-
parameters[
|
13
|
+
|
14
|
+
parameters['SecurityGroupId'] = securitygroup_id
|
15
15
|
pathUrl += '&SecurityGroupId='
|
16
16
|
pathUrl += securitygroup_id
|
17
17
|
|
18
|
-
parameters[
|
18
|
+
parameters['SourceGroupId'] = source_securitygroup_id
|
19
19
|
pathUrl += '&SourceGroupId='
|
20
20
|
pathUrl += source_securitygroup_id
|
21
21
|
|
22
22
|
nicType = 'intranet'
|
23
|
-
parameters[
|
23
|
+
parameters['NicType'] = nicType
|
24
24
|
pathUrl += '&NicType='
|
25
25
|
pathUrl += nicType
|
26
|
-
|
26
|
+
|
27
27
|
portRange = option[:portRange]
|
28
|
-
unless portRange
|
29
|
-
|
30
|
-
end
|
31
|
-
parameters["PortRange"] = portRange
|
28
|
+
portRange = '-1/-1' unless portRange
|
29
|
+
parameters['PortRange'] = portRange
|
32
30
|
pathUrl += '&PortRange='
|
33
|
-
pathUrl += URI.encode(portRange,'/[^!*\'()\;?:@#&%=+$,{}[]<>`" ')
|
34
|
-
|
31
|
+
pathUrl += URI.encode(portRange, '/[^!*\'()\;?:@#&%=+$,{}[]<>`" ')
|
32
|
+
|
35
33
|
protocol = option[:protocol]
|
36
|
-
unless protocol
|
37
|
-
|
38
|
-
end
|
39
|
-
parameters["IpProtocol"] = protocol
|
34
|
+
protocol = 'all' unless protocol
|
35
|
+
parameters['IpProtocol'] = protocol
|
40
36
|
pathUrl += '&IpProtocol='
|
41
37
|
pathUrl += protocol
|
42
38
|
|
43
39
|
sourceGOAccount = option[:sourceGroupOwnerAccount]
|
44
40
|
if sourceGOAccount
|
45
|
-
|
46
|
-
|
47
|
-
|
41
|
+
parameters['SourceGroupOwnerAccount'] = sourceGOAccount
|
42
|
+
pathUrl += '&SourceGroupOwnerAccount='
|
43
|
+
pathUrl += sourceGOAccount
|
48
44
|
end
|
49
45
|
|
50
46
|
policy = option[:policy]
|
51
|
-
unless policy
|
52
|
-
|
53
|
-
end
|
54
|
-
parameters["Policy"] = policy
|
47
|
+
policy = 'accept' unless policy
|
48
|
+
parameters['Policy'] = policy
|
55
49
|
pathUrl += '&Policy='
|
56
50
|
pathUrl += policy
|
57
51
|
|
58
52
|
priority = option[:priority]
|
59
|
-
unless priority
|
60
|
-
|
61
|
-
end
|
62
|
-
parameters["Priority"] = priority
|
53
|
+
priority = '1' unless priority
|
54
|
+
parameters['Priority'] = priority
|
63
55
|
pathUrl += '&Priority='
|
64
56
|
pathUrl += priority
|
65
57
|
|
@@ -68,42 +60,12 @@ module Fog
|
|
68
60
|
pathUrl += signature
|
69
61
|
|
70
62
|
request(
|
71
|
-
:
|
72
|
-
:
|
73
|
-
:
|
63
|
+
expects: [200, 203],
|
64
|
+
method: 'GET',
|
65
|
+
path: pathUrl
|
74
66
|
)
|
75
67
|
end
|
76
68
|
end
|
77
|
-
|
78
|
-
class Mock
|
79
|
-
def create_security_group_rule(parent_group_id, ip_protocol, from_port, to_port, cidr, group_id=nil)
|
80
|
-
parent_group_id = parent_group_id.to_i
|
81
|
-
response = Excon::Response.new
|
82
|
-
response.status = 200
|
83
|
-
response.headers = {
|
84
|
-
'X-Compute-Request-Id' => "req-#{Fog::Mock.random_hex(32)}",
|
85
|
-
'Content-Type' => 'application/json',
|
86
|
-
'Content-Length' => Fog::Mock.random_numbers(3).to_s,
|
87
|
-
'Date' => Date.new
|
88
|
-
}
|
89
|
-
rule = {
|
90
|
-
'id' => Fog::Mock.random_numbers(2).to_i,
|
91
|
-
'from_port' => from_port,
|
92
|
-
'group' => group_id || {},
|
93
|
-
'ip_protocol' => ip_protocol,
|
94
|
-
'to_port' => to_port,
|
95
|
-
'parent_group_id' => parent_group_id,
|
96
|
-
'ip_range' => {
|
97
|
-
'cidr' => cidr
|
98
|
-
}
|
99
|
-
}
|
100
|
-
self.data[:security_groups][parent_group_id.to_s]['rules'].push(rule)
|
101
|
-
response.body = {
|
102
|
-
'security_group_rule' => rule
|
103
|
-
}
|
104
|
-
response
|
105
|
-
end
|
106
|
-
end # mock
|
107
69
|
end # aliyun
|
108
70
|
end # compute
|
109
71
|
end # fog
|
@@ -4,93 +4,91 @@ module Fog
|
|
4
4
|
class Real
|
5
5
|
# {Aliyun API Reference}[https://docs.aliyun.com/?spm=5176.100054.3.1.DGkmH7#/pub/ecs/open-api/instance&createinstance]
|
6
6
|
def create_server(imageId, securityGroupId, instanceType, options = {})
|
7
|
-
|
8
7
|
_action = 'CreateInstance'
|
9
|
-
_sigNonce = randonStr
|
8
|
+
_sigNonce = randonStr
|
10
9
|
_time = Time.new.utc
|
11
10
|
|
12
11
|
_parameters = defalutParameters(_action, _sigNonce, _time)
|
13
|
-
_pathURL
|
12
|
+
_pathURL = defaultAliyunUri(_action, _sigNonce, _time)
|
14
13
|
|
15
14
|
_parameters['ImageId'] = imageId
|
16
|
-
_pathURL += '&ImageId='+imageId
|
15
|
+
_pathURL += '&ImageId=' + imageId
|
17
16
|
|
18
17
|
_parameters['InstanceType'] = instanceType
|
19
|
-
_pathURL += '&InstanceType='+instanceType
|
20
|
-
|
18
|
+
_pathURL += '&InstanceType=' + instanceType
|
19
|
+
|
21
20
|
_parameters['SecurityGroupId'] = securityGroupId
|
22
|
-
_pathURL += '&SecurityGroupId='+securityGroupId
|
23
|
-
|
21
|
+
_pathURL += '&SecurityGroupId=' + securityGroupId
|
22
|
+
|
24
23
|
_ZoneId = options[:ZoneId]
|
25
24
|
if _ZoneId
|
26
|
-
_parameters['ZoneId']=_ZoneId
|
27
|
-
_pathURL += '&ZoneId='+_ZoneId
|
25
|
+
_parameters['ZoneId'] = _ZoneId
|
26
|
+
_pathURL += '&ZoneId=' + _ZoneId
|
28
27
|
end
|
29
28
|
|
30
29
|
_InstanceName = options[:InstanceName]
|
31
30
|
if _InstanceName
|
32
|
-
_parameters['InstanceName']=_InstanceName
|
33
|
-
_pathURL += '&InstanceName='+_InstanceName
|
31
|
+
_parameters['InstanceName'] = _InstanceName
|
32
|
+
_pathURL += '&InstanceName=' + _InstanceName
|
34
33
|
end
|
35
|
-
|
34
|
+
|
36
35
|
_Description = options[:Description]
|
37
36
|
if _Description
|
38
|
-
_parameters['Description']=_Description
|
39
|
-
_pathURL += '&Description='+_Description
|
37
|
+
_parameters['Description'] = _Description
|
38
|
+
_pathURL += '&Description=' + _Description
|
40
39
|
end
|
41
|
-
|
40
|
+
|
42
41
|
_InternetChargeType = options[:InternetChargeType]
|
43
42
|
if _InternetChargeType
|
44
|
-
_parameters['InternetChargeType']=_InternetChargeType
|
45
|
-
_pathURL += '&InternetChargeType='+_InternetChargeType
|
43
|
+
_parameters['InternetChargeType'] = _InternetChargeType
|
44
|
+
_pathURL += '&InternetChargeType=' + _InternetChargeType
|
46
45
|
end
|
47
|
-
|
46
|
+
|
48
47
|
_HostName = options[:HostName]
|
49
48
|
if _HostName
|
50
|
-
_parameters['HostName']=_HostName
|
51
|
-
_pathURL += '&HostName='+_HostName
|
49
|
+
_parameters['HostName'] = _HostName
|
50
|
+
_pathURL += '&HostName=' + _HostName
|
52
51
|
end
|
53
|
-
|
52
|
+
|
54
53
|
_Password = options[:Password]
|
55
54
|
if _Password
|
56
|
-
_parameters['Password']=_Password
|
57
|
-
_pathURL += '&Password='+_Password
|
55
|
+
_parameters['Password'] = _Password
|
56
|
+
_pathURL += '&Password=' + _Password
|
58
57
|
end
|
59
|
-
|
58
|
+
|
60
59
|
_VSwitchId = options[:VSwitchId]
|
61
|
-
_PrivateIpAddress= options[:PrivateIpAddress]
|
60
|
+
_PrivateIpAddress = options[:PrivateIpAddress]
|
62
61
|
if _VSwitchId
|
63
|
-
_parameters['VSwitchId']=_VSwitchId
|
64
|
-
_pathURL += '&VSwitchId='+_VSwitchId
|
62
|
+
_parameters['VSwitchId'] = _VSwitchId
|
63
|
+
_pathURL += '&VSwitchId=' + _VSwitchId
|
65
64
|
|
66
65
|
if _PrivateIpAddress
|
67
|
-
_parameters['PrivateIpAddress']=_PrivateIpAddress
|
68
|
-
_pathURL += '&PrivateIpAddress='+_PrivateIpAddress
|
66
|
+
_parameters['PrivateIpAddress'] = _PrivateIpAddress
|
67
|
+
_pathURL += '&PrivateIpAddress=' + _PrivateIpAddress
|
69
68
|
end
|
70
69
|
else
|
71
70
|
|
72
71
|
_InternetMaxBandwidthIn = options[:InternetMaxBandwidthIn]
|
73
72
|
if _InternetMaxBandwidthIn
|
74
|
-
_parameters['InternetMaxBandwidthIn']=_InternetMaxBandwidthIn
|
75
|
-
_pathURL += '&InternetMaxBandwidthIn='+_InternetMaxBandwidthIn
|
73
|
+
_parameters['InternetMaxBandwidthIn'] = _InternetMaxBandwidthIn
|
74
|
+
_pathURL += '&InternetMaxBandwidthIn=' + _InternetMaxBandwidthIn
|
76
75
|
end
|
77
|
-
|
76
|
+
|
78
77
|
_InternetMaxBandwidthOut = options[:InternetMaxBandwidthOut]
|
79
78
|
if _InternetMaxBandwidthOut
|
80
|
-
_parameters['InternetMaxBandwidthOut']=_InternetMaxBandwidthOut
|
81
|
-
_pathURL += '&InternetMaxBandwidthOut='+_InternetMaxBandwidthOut
|
79
|
+
_parameters['InternetMaxBandwidthOut'] = _InternetMaxBandwidthOut
|
80
|
+
_pathURL += '&InternetMaxBandwidthOut=' + _InternetMaxBandwidthOut
|
82
81
|
end
|
83
82
|
end
|
84
83
|
|
85
84
|
_signature = sign(@aliyun_accesskey_secret, _parameters)
|
86
|
-
_pathURL += '&Signature='+_signature
|
85
|
+
_pathURL += '&Signature=' + _signature
|
87
86
|
|
88
87
|
request(
|
89
|
-
:
|
90
|
-
:
|
91
|
-
:
|
88
|
+
expects: [200, 203],
|
89
|
+
method: 'GET',
|
90
|
+
path: _pathURL
|
92
91
|
)
|
93
|
-
|
94
92
|
end
|
95
93
|
end
|
96
94
|
|
@@ -100,86 +98,86 @@ module Fog
|
|
100
98
|
response.status = 202
|
101
99
|
|
102
100
|
server_id = Fog::Mock.random_numbers(6).to_s
|
103
|
-
identity = Fog::Identity::OpenStack.new :
|
104
|
-
user = identity.users.find
|
101
|
+
identity = Fog::Identity::OpenStack.new openstack_auth_url: credentials[:openstack_auth_url]
|
102
|
+
user = identity.users.find do |u|
|
105
103
|
u.name == @openstack_username
|
106
|
-
|
104
|
+
end
|
107
105
|
|
108
|
-
user_id = if user
|
106
|
+
user_id = if user
|
109
107
|
user.id
|
110
108
|
else
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
109
|
+
response = identity.create_user(@openstack_username,
|
110
|
+
'password',
|
111
|
+
"#{@openstack_username}@example.com")
|
112
|
+
response.body['user']['id']
|
113
|
+
end
|
116
114
|
|
117
115
|
mock_data = {
|
118
|
-
'addresses' => {
|
119
|
-
'flavor' => {
|
116
|
+
'addresses' => { 'Private' => [{ 'addr' => Fog::Mock.random_ip }] },
|
117
|
+
'flavor' => { 'id' => flavor_ref, 'links' => [{ 'href' => 'http://nova1:8774/admin/flavors/1', 'rel' => 'bookmark' }] },
|
120
118
|
'id' => server_id,
|
121
|
-
'image' => {
|
122
|
-
'links' => [{
|
123
|
-
'hostId' =>
|
119
|
+
'image' => { 'id' => image_ref, 'links' => [{ 'href' => "http://nova1:8774/admin/images/#{image_ref}", 'rel' => 'bookmark' }] },
|
120
|
+
'links' => [{ 'href' => 'http://nova1:8774/v1.1/admin/servers/5', 'rel' => 'self' }, { 'href' => 'http://nova1:8774/admin/servers/5', 'rel' => 'bookmark' }],
|
121
|
+
'hostId' => '123456789ABCDEF01234567890ABCDEF',
|
124
122
|
'metadata' => options['metadata'] || {},
|
125
123
|
'name' => name || "server_#{rand(999)}",
|
126
|
-
'accessIPv4' => options['accessIPv4'] ||
|
127
|
-
'accessIPv6' => options['accessIPv6'] ||
|
124
|
+
'accessIPv4' => options['accessIPv4'] || '',
|
125
|
+
'accessIPv6' => options['accessIPv6'] || '',
|
128
126
|
'progress' => 0,
|
129
127
|
'status' => 'BUILD',
|
130
128
|
'created' => '2012-09-27T00:04:18Z',
|
131
129
|
'updated' => '2012-09-27T00:04:27Z',
|
132
|
-
'user_id' =>
|
133
|
-
'config_drive' => options['config_drive'] || ''
|
130
|
+
'user_id' => user_id,
|
131
|
+
'config_drive' => options['config_drive'] || ''
|
134
132
|
}
|
135
133
|
|
136
134
|
if nics = options['nics']
|
137
|
-
nics.each do |
|
138
|
-
mock_data[
|
139
|
-
|
135
|
+
nics.each do |_nic|
|
136
|
+
mock_data['addresses'].merge!(
|
137
|
+
'Public' => [{ 'addr' => Fog::Mock.random_ip }]
|
140
138
|
)
|
141
139
|
end
|
142
140
|
end
|
143
141
|
|
144
142
|
response_data = {}
|
145
|
-
if options['return_reservation_id'] == 'True'
|
146
|
-
response_data = { 'reservation_id' => "r-#{Fog::Mock.random_numbers(6)
|
143
|
+
if options['return_reservation_id'] == 'True'
|
144
|
+
response_data = { 'reservation_id' => "r-#{Fog::Mock.random_numbers(6)}" }
|
147
145
|
else
|
148
146
|
response_data = {
|
149
147
|
'adminPass' => 'password',
|
150
148
|
'id' => server_id,
|
151
|
-
'links' => mock_data['links']
|
149
|
+
'links' => mock_data['links']
|
152
150
|
}
|
153
151
|
end
|
154
152
|
|
155
|
-
if block_devices = options[
|
153
|
+
if block_devices = options['block_device_mapping_v2']
|
156
154
|
block_devices.each { |bd| compute.volumes.get(bd[:uuid]).attach(server_id, bd[:device_name]) }
|
157
|
-
elsif block_device = options[
|
155
|
+
elsif block_device = options['block_device_mapping']
|
158
156
|
compute.volumes.get(block_device[:volume_id]).attach(server_id, block_device[:device_name])
|
159
157
|
end
|
160
158
|
|
161
|
-
|
162
|
-
|
163
|
-
if
|
159
|
+
data[:last_modified][:servers][server_id] = Time.now
|
160
|
+
data[:servers][server_id] = mock_data
|
161
|
+
if options['security_groups']
|
164
162
|
groups = Array(options['security_groups']).map do |sg|
|
165
|
-
if sg.is_a?(Fog::Compute::OpenStack::SecurityGroup)
|
163
|
+
if sg.is_a?(Fog::Compute::OpenStack::SecurityGroup)
|
166
164
|
sg.name
|
167
165
|
else
|
168
166
|
sg
|
169
167
|
end
|
170
168
|
end
|
171
169
|
|
172
|
-
|
170
|
+
data[:server_security_group_map][server_id] = groups
|
173
171
|
response_data['security_groups'] = groups
|
174
172
|
end
|
175
173
|
|
176
|
-
|
177
|
-
|
178
|
-
if options['return_reservation_id'] == 'True'
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
174
|
+
data[:last_modified][:servers][server_id] = Time.now
|
175
|
+
data[:servers][server_id] = mock_data
|
176
|
+
response.body = if options['return_reservation_id'] == 'True'
|
177
|
+
response_data
|
178
|
+
else
|
179
|
+
{ 'server' => response_data }
|
180
|
+
end
|
183
181
|
response
|
184
182
|
end
|
185
183
|
end
|