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.
Files changed (106) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +5 -0
  3. data/.rubocop_todo.yml +149 -0
  4. data/.ruby-gemset +1 -0
  5. data/.ruby-version +1 -0
  6. data/Rakefile +3 -3
  7. data/fog-aliyun.gemspec +16 -13
  8. data/lib/fog/aliyun.rb +8 -8
  9. data/lib/fog/aliyun/compute.rb +99 -113
  10. data/lib/fog/aliyun/models/compute/eip_address.rb +23 -29
  11. data/lib/fog/aliyun/models/compute/eip_addresses.rb +3 -5
  12. data/lib/fog/aliyun/models/compute/image.rb +26 -28
  13. data/lib/fog/aliyun/models/compute/images.rb +2 -6
  14. data/lib/fog/aliyun/models/compute/route_entry.rb +9 -11
  15. data/lib/fog/aliyun/models/compute/route_entrys.rb +7 -7
  16. data/lib/fog/aliyun/models/compute/route_table.rb +10 -11
  17. data/lib/fog/aliyun/models/compute/route_tables.rb +2 -2
  18. data/lib/fog/aliyun/models/compute/security_group.rb +24 -24
  19. data/lib/fog/aliyun/models/compute/security_group_rule.rb +20 -20
  20. data/lib/fog/aliyun/models/compute/security_group_rules.rb +4 -4
  21. data/lib/fog/aliyun/models/compute/security_groups.rb +6 -7
  22. data/lib/fog/aliyun/models/compute/server.rb +42 -43
  23. data/lib/fog/aliyun/models/compute/servers.rb +9 -11
  24. data/lib/fog/aliyun/models/compute/snapshot.rb +15 -15
  25. data/lib/fog/aliyun/models/compute/snapshots.rb +6 -10
  26. data/lib/fog/aliyun/models/compute/volume.rb +36 -40
  27. data/lib/fog/aliyun/models/compute/volumes.rb +7 -11
  28. data/lib/fog/aliyun/models/compute/vpc.rb +18 -19
  29. data/lib/fog/aliyun/models/compute/vpcs.rb +5 -6
  30. data/lib/fog/aliyun/models/compute/vrouter.rb +13 -13
  31. data/lib/fog/aliyun/models/compute/vrouters.rb +4 -5
  32. data/lib/fog/aliyun/models/compute/vswitch.rb +18 -20
  33. data/lib/fog/aliyun/models/compute/vswitches.rb +6 -6
  34. data/lib/fog/aliyun/models/storage/directories.rb +10 -16
  35. data/lib/fog/aliyun/models/storage/directory.rb +8 -8
  36. data/lib/fog/aliyun/models/storage/file.rb +58 -64
  37. data/lib/fog/aliyun/models/storage/files.rb +95 -115
  38. data/lib/fog/aliyun/requests/compute/allocate_eip_address.rb +18 -44
  39. data/lib/fog/aliyun/requests/compute/allocate_public_ip_address.rb +12 -36
  40. data/lib/fog/aliyun/requests/compute/associate_eip_address.rb +16 -40
  41. data/lib/fog/aliyun/requests/compute/attach_disk.rb +19 -22
  42. data/lib/fog/aliyun/requests/compute/create_disk.rb +33 -63
  43. data/lib/fog/aliyun/requests/compute/create_image.rb +21 -21
  44. data/lib/fog/aliyun/requests/compute/create_security_group.rb +16 -16
  45. data/lib/fog/aliyun/requests/compute/create_security_group_egress_ip_rule.rb +22 -63
  46. data/lib/fog/aliyun/requests/compute/create_security_group_egress_sg_rule.rb +23 -61
  47. data/lib/fog/aliyun/requests/compute/create_security_group_ip_rule.rb +22 -63
  48. data/lib/fog/aliyun/requests/compute/create_security_group_sg_rule.rb +23 -61
  49. data/lib/fog/aliyun/requests/compute/create_server.rb +76 -78
  50. data/lib/fog/aliyun/requests/compute/create_snapshot.rb +12 -26
  51. data/lib/fog/aliyun/requests/compute/create_vpc.rb +11 -38
  52. data/lib/fog/aliyun/requests/compute/create_vswitch.rb +13 -40
  53. data/lib/fog/aliyun/requests/compute/delete_disk.rb +8 -35
  54. data/lib/fog/aliyun/requests/compute/delete_image.rb +6 -33
  55. data/lib/fog/aliyun/requests/compute/delete_security_group.rb +13 -13
  56. data/lib/fog/aliyun/requests/compute/delete_security_group_egress_ip_rule.rb +22 -63
  57. data/lib/fog/aliyun/requests/compute/delete_security_group_egress_sg_rule.rb +23 -61
  58. data/lib/fog/aliyun/requests/compute/delete_security_group_ip_rule.rb +22 -62
  59. data/lib/fog/aliyun/requests/compute/delete_security_group_sg_rule.rb +23 -61
  60. data/lib/fog/aliyun/requests/compute/delete_server.rb +15 -15
  61. data/lib/fog/aliyun/requests/compute/delete_snapshot.rb +6 -20
  62. data/lib/fog/aliyun/requests/compute/delete_vpc.rb +9 -26
  63. data/lib/fog/aliyun/requests/compute/delete_vswitch.rb +9 -25
  64. data/lib/fog/aliyun/requests/compute/detach_disk.rb +11 -27
  65. data/lib/fog/aliyun/requests/compute/join_security_group.rb +15 -16
  66. data/lib/fog/aliyun/requests/compute/leave_security_group.rb +15 -16
  67. data/lib/fog/aliyun/requests/compute/list_disks.rb +24 -43
  68. data/lib/fog/aliyun/requests/compute/list_eip_addresses.rb +26 -52
  69. data/lib/fog/aliyun/requests/compute/list_images.rb +21 -24
  70. data/lib/fog/aliyun/requests/compute/list_route_tables.rb +16 -19
  71. data/lib/fog/aliyun/requests/compute/list_security_group_rules.rb +22 -23
  72. data/lib/fog/aliyun/requests/compute/list_security_groups.rb +21 -24
  73. data/lib/fog/aliyun/requests/compute/list_server_types.rb +50 -50
  74. data/lib/fog/aliyun/requests/compute/list_servers.rb +25 -28
  75. data/lib/fog/aliyun/requests/compute/list_snapshots.rb +20 -37
  76. data/lib/fog/aliyun/requests/compute/list_vpcs.rb +12 -29
  77. data/lib/fog/aliyun/requests/compute/list_vrouters.rb +13 -16
  78. data/lib/fog/aliyun/requests/compute/list_vswitchs.rb +14 -31
  79. data/lib/fog/aliyun/requests/compute/list_zones.rb +16 -16
  80. data/lib/fog/aliyun/requests/compute/modify_vpc.rb +17 -17
  81. data/lib/fog/aliyun/requests/compute/modify_vswitch.rb +11 -39
  82. data/lib/fog/aliyun/requests/compute/reboot_server.rb +15 -16
  83. data/lib/fog/aliyun/requests/compute/release_eip_address.rb +12 -36
  84. data/lib/fog/aliyun/requests/compute/start_server.rb +14 -15
  85. data/lib/fog/aliyun/requests/compute/stop_server.rb +13 -14
  86. data/lib/fog/aliyun/requests/compute/unassociate_eip_address.rb +16 -41
  87. data/lib/fog/aliyun/requests/storage/copy_object.rb +11 -14
  88. data/lib/fog/aliyun/requests/storage/delete_bucket.rb +30 -30
  89. data/lib/fog/aliyun/requests/storage/delete_container.rb +11 -14
  90. data/lib/fog/aliyun/requests/storage/delete_object.rb +20 -22
  91. data/lib/fog/aliyun/requests/storage/get_bucket.rb +141 -148
  92. data/lib/fog/aliyun/requests/storage/get_container.rb +26 -38
  93. data/lib/fog/aliyun/requests/storage/get_containers.rb +20 -32
  94. data/lib/fog/aliyun/requests/storage/get_object.rb +12 -12
  95. data/lib/fog/aliyun/requests/storage/get_object_http_url.rb +11 -11
  96. data/lib/fog/aliyun/requests/storage/get_object_https_url.rb +11 -11
  97. data/lib/fog/aliyun/requests/storage/head_object.rb +11 -11
  98. data/lib/fog/aliyun/requests/storage/list_buckets.rb +40 -47
  99. data/lib/fog/aliyun/requests/storage/list_objects.rb +91 -104
  100. data/lib/fog/aliyun/requests/storage/put_bucket.rb +22 -23
  101. data/lib/fog/aliyun/requests/storage/put_container.rb +12 -12
  102. data/lib/fog/aliyun/requests/storage/put_object.rb +100 -110
  103. data/lib/fog/aliyun/storage.rb +209 -214
  104. data/lib/fog/aliyun/version.rb +1 -1
  105. data/lib/fog/bin/aliyun.rb +5 -5
  106. 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["SecurityGroupId"] = securitygroup_id
13
+
14
+ parameters['SecurityGroupId'] = securitygroup_id
15
15
  pathUrl += '&SecurityGroupId='
16
16
  pathUrl += securitygroup_id
17
17
 
18
- parameters["DestGroupId"] = dest_group_id
18
+ parameters['DestGroupId'] = dest_group_id
19
19
  pathUrl += '&DestGroupId='
20
20
  pathUrl += dest_group_id
21
21
 
22
22
  nicType = 'intranet'
23
- parameters["NicType"] = nicType
23
+ parameters['NicType'] = nicType
24
24
  pathUrl += '&NicType='
25
25
  pathUrl += nicType
26
-
26
+
27
27
  portRange = option[:portRange]
28
- unless portRange
29
- portRange = '-1/-1'
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
- protocol = 'all'
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
- parameters["DestGroupOwnerAccount"]=destGOAccount
46
- pathUrl += '&DestGroupOwnerAccount='
47
- pathUrl += destGOAccount
41
+ parameters['DestGroupOwnerAccount'] = destGOAccount
42
+ pathUrl += '&DestGroupOwnerAccount='
43
+ pathUrl += destGOAccount
48
44
  end
49
45
 
50
46
  policy = option[:policy]
51
- unless policy
52
- policy = 'accept'
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
- priority = '1'
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
- :expects => [200, 203],
72
- :method => 'GET',
73
- :path => pathUrl
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["SecurityGroupId"] = securitygroup_id
13
+
14
+ parameters['SecurityGroupId'] = securitygroup_id
16
15
  pathUrl += '&SecurityGroupId='
17
16
  pathUrl += securitygroup_id
18
17
 
19
- parameters["SourceCidrIp"] = sourceCidrIp
18
+ parameters['SourceCidrIp'] = sourceCidrIp
20
19
  pathUrl += '&SourceCidrIp='
21
- pathUrl += URI.encode(sourceCidrIp,'/[^!*\'()\;?:@#&%=+$,{}[]<>`" ')
22
- unless nicType
23
- nicType='intranet'
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
- portRange = '-1/-1'
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
- protocol = 'all'
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
- policy = 'accept'
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
- priority = '1'
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
- :expects => [200, 203],
67
- :method => 'GET',
68
- :path => pathUrl
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["SecurityGroupId"] = securitygroup_id
13
+
14
+ parameters['SecurityGroupId'] = securitygroup_id
15
15
  pathUrl += '&SecurityGroupId='
16
16
  pathUrl += securitygroup_id
17
17
 
18
- parameters["SourceGroupId"] = source_securitygroup_id
18
+ parameters['SourceGroupId'] = source_securitygroup_id
19
19
  pathUrl += '&SourceGroupId='
20
20
  pathUrl += source_securitygroup_id
21
21
 
22
22
  nicType = 'intranet'
23
- parameters["NicType"] = nicType
23
+ parameters['NicType'] = nicType
24
24
  pathUrl += '&NicType='
25
25
  pathUrl += nicType
26
-
26
+
27
27
  portRange = option[:portRange]
28
- unless portRange
29
- portRange = '-1/-1'
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
- protocol = 'all'
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
- parameters["SourceGroupOwnerAccount"]=sourceGOAccount
46
- pathUrl += '&SourceGroupOwnerAccount='
47
- pathUrl += sourceGOAccount
41
+ parameters['SourceGroupOwnerAccount'] = sourceGOAccount
42
+ pathUrl += '&SourceGroupOwnerAccount='
43
+ pathUrl += sourceGOAccount
48
44
  end
49
45
 
50
46
  policy = option[:policy]
51
- unless policy
52
- policy = 'accept'
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
- priority = '1'
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
- :expects => [200, 203],
72
- :method => 'GET',
73
- :path => pathUrl
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 = defaultAliyunUri(_action, _sigNonce, _time)
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
- :expects => [200, 203],
90
- :method => 'GET',
91
- :path => _pathURL
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 :openstack_auth_url => credentials[:openstack_auth_url]
104
- user = identity.users.find { |u|
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 then
106
+ user_id = if user
109
107
  user.id
110
108
  else
111
- response = identity.create_user(@openstack_username,
112
- 'password',
113
- "#{@openstack_username}@example.com")
114
- response.body["user"]["id"]
115
- end
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' => {"Private" => [{"addr" => Fog::Mock.random_ip }]},
119
- 'flavor' => {"id" => flavor_ref, "links"=>[{"href"=>"http://nova1:8774/admin/flavors/1", "rel"=>"bookmark"}]},
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' => {"id" => image_ref, "links"=>[{"href"=>"http://nova1:8774/admin/images/#{image_ref}", "rel"=>"bookmark"}]},
122
- 'links' => [{"href"=>"http://nova1:8774/v1.1/admin/servers/5", "rel"=>"self"}, {"href"=>"http://nova1:8774/admin/servers/5", "rel"=>"bookmark"}],
123
- 'hostId' => "123456789ABCDEF01234567890ABCDEF",
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' => @openstack_username,
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 |nic|
138
- mock_data["addresses"].merge!(
139
- "Public" => [{ 'addr' => Fog::Mock.random_ip }]
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' then
146
- response_data = { 'reservation_id' => "r-#{Fog::Mock.random_numbers(6).to_s}" }
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["block_device_mapping_v2"]
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["block_device_mapping"]
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
- self.data[:last_modified][:servers][server_id] = Time.now
162
- self.data[:servers][server_id] = mock_data
163
- if security_groups = options['security_groups'] then
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) then
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
- self.data[:server_security_group_map][server_id] = groups
170
+ data[:server_security_group_map][server_id] = groups
173
171
  response_data['security_groups'] = groups
174
172
  end
175
173
 
176
- self.data[:last_modified][:servers][server_id] = Time.now
177
- self.data[:servers][server_id] = mock_data
178
- if options['return_reservation_id'] == 'True' then
179
- response.body = response_data
180
- else
181
- response.body = { 'server' => response_data }
182
- end
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