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
@@ -16,38 +16,35 @@ module Fog
16
16
  # * 'RequestId'<~String> - Id of the request
17
17
  #
18
18
  # {Aliyun API Reference}[https://docs.aliyun.com/?spm=5176.100054.201.106.DGkmH7#/pub/ecs/open-api/disk&attachdisk]
19
- def attach_disk(instanceId, diskId, options={})
19
+ def attach_disk(instanceId, diskId, options = {})
20
20
  action = 'AttachDisk'
21
- sigNonce = randonStr()
21
+ sigNonce = randonStr
22
22
  time = Time.new.utc
23
23
 
24
24
  parameters = defalutParameters(action, sigNonce, time)
25
25
  pathUrl = defaultAliyunUri(action, sigNonce, time)
26
-
27
- parameters["InstanceId"] = instanceId
26
+
27
+ parameters['InstanceId'] = instanceId
28
28
  pathUrl += '&InstanceId='
29
- pathUrl += instanceId
29
+ pathUrl += instanceId
30
30
 
31
- parameters["DiskId"] = diskId
31
+ parameters['DiskId'] = diskId
32
32
  pathUrl += '&DiskId='
33
33
  pathUrl += diskId
34
-
34
+
35
35
  deleteWithInstance = options[:deleteWithInstance]
36
36
  device = options[:device]
37
-
38
- unless deleteWithInstance
39
- deleteWithInstance = 'true'
40
- end
41
37
 
42
- parameters["DeleteWithInstance"] = deleteWithInstance
38
+ deleteWithInstance = 'true' unless deleteWithInstance
39
+
40
+ parameters['DeleteWithInstance'] = deleteWithInstance
43
41
  pathUrl += '&DeleteWithInstance='
44
42
  pathUrl += deleteWithInstance
45
43
 
46
-
47
44
  if device
48
- parameters["Device"] = device
45
+ parameters['Device'] = device
49
46
  pathUrl += '&Device='
50
- pathUrl += URI.encode(device,'/[^!*\'()\;?:@#&%=+$,{}[]<>`" ')
47
+ pathUrl += URI.encode(device, '/[^!*\'()\;?:@#&%=+$,{}[]<>`" ')
51
48
  end
52
49
 
53
50
  signature = sign(@aliyun_accesskey_secret, parameters)
@@ -55,9 +52,9 @@ module Fog
55
52
  pathUrl += signature
56
53
 
57
54
  request(
58
- :expects => [200, 203],
59
- :method => 'GET',
60
- :path => pathUrl
55
+ expects: [200, 203],
56
+ method: 'GET',
57
+ path: pathUrl
61
58
  )
62
59
  end
63
60
  end
@@ -67,10 +64,10 @@ module Fog
67
64
  response = Excon::Response.new
68
65
  response.status = 200
69
66
  data = {
70
- 'id' => volume_id,
71
- 'volumeId' => volume_id,
72
- 'serverId' => server_id,
73
- 'device' => device
67
+ 'id' => volume_id,
68
+ 'volumeId' => volume_id,
69
+ 'serverId' => server_id,
70
+ 'device' => device
74
71
  }
75
72
  self.data[:volumes][volume_id]['attachments'] << data
76
73
  response.body = { 'volumeAttachment' => data }
@@ -7,7 +7,7 @@ module Fog
7
7
  # ==== Parameters
8
8
  # * size<~String> - the size of the disk (GB).--cloud:5~2000GB,cloud_efficiency: 20~2048GB,cloud_ssd:20~1024GB
9
9
  # * options<~hash>
10
- # * :name - The name of the disk,default nil. If not nil, it must start with english or chinise character.
10
+ # * :name - The name of the disk,default nil. If not nil, it must start with english or chinise character.
11
11
  # The length should be within [2,128]. It can contain digits,'.','_' or '-'.It shouldn't start with 'http://' or 'https://'
12
12
  # * :description - The name of the disk,default nil. If not nil, the length should be within [2,255].It shouldn't start with 'http://' or 'https://'
13
13
  # * :category - Default 'cloud'. can be set to 'cloud','cloud_efficiency' or 'cloud_ssd'
@@ -18,42 +18,40 @@ module Fog
18
18
  # * 'DiskId'<~String> - Id of the created disk
19
19
  #
20
20
  # {Aliyun API Reference}[https://docs.aliyun.com/?spm=5176.100054.201.106.DGkmH7#/pub/ecs/open-api/disk&createdisk]
21
- def create_disk(size, options={})
22
-
21
+ def create_disk(size, options = {})
23
22
  action = 'CreateDisk'
24
- sigNonce = randonStr()
23
+ sigNonce = randonStr
25
24
  time = Time.new.utc
26
25
 
27
26
  parameters = defalutParameters(action, sigNonce, time)
28
27
  pathUrl = defaultAliyunUri(action, sigNonce, time)
29
28
 
30
- parameters["ZoneId"] = @aliyun_zone_id
29
+ parameters['ZoneId'] = @aliyun_zone_id
31
30
  pathUrl += '&ZoneId='
32
- pathUrl += @aliyun_zone_id
33
-
34
- parameters["Size"] = size
31
+ pathUrl += @aliyun_zone_id
32
+
33
+ parameters['Size'] = size
35
34
  pathUrl += '&Size='
36
- pathUrl += size
35
+ pathUrl += size
37
36
 
38
37
  name = options[:name]
39
38
  desc = options[:description]
40
39
  category = options[:category]
41
40
 
42
-
43
41
  if name
44
- parameters["DiskName"] = name
42
+ parameters['DiskName'] = name
45
43
  pathUrl += '&DiskName='
46
- pathUrl += name
44
+ pathUrl += name
47
45
  end
48
46
 
49
47
  if desc
50
- parameters["Description"] = desc
48
+ parameters['Description'] = desc
51
49
  pathUrl += '&Description='
52
- pathUrl += desc
50
+ pathUrl += desc
53
51
  end
54
52
 
55
53
  if category
56
- parameters["DiskCategory"] = category
54
+ parameters['DiskCategory'] = category
57
55
  pathUrl += 'DiskCategory'
58
56
  pathUrl += category
59
57
  end
@@ -63,17 +61,18 @@ module Fog
63
61
  pathUrl += signature
64
62
 
65
63
  request(
66
- :expects => [200, 203],
67
- :method => 'GET',
68
- :path => pathUrl
64
+ expects: [200, 203],
65
+ method: 'GET',
66
+ path: pathUrl
69
67
  ).merge(options)
70
68
  end
69
+
71
70
  # Create a disk By the snapshot with given snapshot_id.
72
71
  #
73
72
  # ==== Parameters
74
73
  # * snapshotId<~String> - the snapshot_id
75
74
  # * options<~hash>
76
- # * :name - The name of the disk,default nil. If not nil, it must start with english or chinise character.
75
+ # * :name - The name of the disk,default nil. If not nil, it must start with english or chinise character.
77
76
  # The length should be within [2,128]. It can contain digits,'.','_' or '-'.It shouldn't start with 'http://' or 'https://'
78
77
  # * :description - The name of the disk,default nil. If not nil, the length should be within [2,255].It shouldn't start with 'http://' or 'https://'
79
78
  # * :category - Default 'cloud'. can be set to 'cloud','cloud_efficiency' or 'cloud_ssd'
@@ -84,41 +83,40 @@ module Fog
84
83
  # * 'DiskId'<~String> - Id of the created disk
85
84
  #
86
85
  # {Aliyun API Reference}[https://docs.aliyun.com/?spm=5176.100054.201.106.DGkmH7#/pub/ecs/open-api/disk&createdisk]
87
- def create_disk_by_snapshot(snapshotId, options={})
88
-
86
+ def create_disk_by_snapshot(snapshotId, options = {})
89
87
  action = 'CreateDisk'
90
- sigNonce = randonStr()
88
+ sigNonce = randonStr
91
89
  time = Time.new.utc
92
90
 
93
91
  parameters = defalutParameters(action, sigNonce, time)
94
92
  pathUrl = defaultAliyunUri(action, sigNonce, time)
95
93
 
96
- parameters["ZoneId"] = @aliyun_zone_id
94
+ parameters['ZoneId'] = @aliyun_zone_id
97
95
  pathUrl += '&ZoneId='
98
- pathUrl += @aliyun_zone_id
99
-
100
- parameters["SnapshotId"] = snapshotId
96
+ pathUrl += @aliyun_zone_id
97
+
98
+ parameters['SnapshotId'] = snapshotId
101
99
  pathUrl += '&SnapshotId='
102
- pathUrl += snapshotId
100
+ pathUrl += snapshotId
103
101
 
104
102
  name = options[:name]
105
103
  desc = options[:description]
106
104
  category = options[:category]
107
105
 
108
106
  if name
109
- parameters["DiskName"] = name
107
+ parameters['DiskName'] = name
110
108
  pathUrl += '&DiskName='
111
- pathUrl += name
109
+ pathUrl += name
112
110
  end
113
111
 
114
112
  if desc
115
- parameters["Description"] = desc
113
+ parameters['Description'] = desc
116
114
  pathUrl += '&Description='
117
- pathUrl += desc
115
+ pathUrl += desc
118
116
  end
119
117
 
120
118
  if category
121
- parameters["DiskCategory"] = category
119
+ parameters['DiskCategory'] = category
122
120
  pathUrl += 'DiskCategory'
123
121
  pathUrl += category
124
122
  end
@@ -128,40 +126,12 @@ module Fog
128
126
  pathUrl += signature
129
127
 
130
128
  request(
131
- :expects => [200, 203],
132
- :method => 'GET',
133
- :path => pathUrl
129
+ expects: [200, 203],
130
+ method: 'GET',
131
+ path: pathUrl
134
132
  )
135
133
  end
136
-
137
134
  end
138
-
139
- class Mock
140
- def create_security_group(name, description)
141
- Fog::Identity::OpenStack.new(:openstack_auth_url => credentials[:openstack_auth_url])
142
- tenant_id = Fog::Identity::OpenStack::V2::Mock.data[current_tenant][:tenants].keys.first
143
- security_group_id = Fog::Mock.random_numbers(2).to_i + 1
144
- self.data[:security_groups][security_group_id.to_s] = {
145
- 'tenant_id' => tenant_id,
146
- 'rules' => [],
147
- 'id' => security_group_id,
148
- 'name' => name,
149
- 'description' => description
150
- }
151
-
152
- response = Excon::Response.new
153
- response.status = 200
154
- response.headers = {
155
- 'X-Compute-Request-Id' => "req-#{Fog::Mock.random_hex(32)}",
156
- 'Content-Type' => 'application/json',
157
- 'Content-Length' => Fog::Mock.random_numbers(3).to_s,
158
- 'Date' => Date.new}
159
- response.body = {
160
- 'security_group' => self.data[:security_groups][security_group_id.to_s]
161
- }
162
- response
163
- end
164
- end # mock
165
135
  end # aliyun
166
136
  end # compute
167
137
  end # fog
@@ -3,35 +3,35 @@ module Fog
3
3
  class Aliyun
4
4
  class Real
5
5
  # {Aliyun API Reference}[https://docs.aliyun.com/?spm=5176.100054.201.106.DGkmH7#/pub/ecs/open-api/image&createimage]
6
- def create_image(snapshotId, options={})
6
+ def create_image(snapshotId, options = {})
7
7
  action = 'CreateImage'
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
13
 
14
- parameters["SnapshotId"] = snapshotId
14
+ parameters['SnapshotId'] = snapshotId
15
15
  pathUrl += '&SnapshotId='
16
- pathUrl += snapshotId
17
-
16
+ pathUrl += snapshotId
17
+
18
18
  name = options[:name]
19
19
  if name
20
- parameters["ImageName"] = name
20
+ parameters['ImageName'] = name
21
21
  pathUrl += '&ImageName='
22
- pathUrl += name
22
+ pathUrl += name
23
23
  end
24
-
24
+
25
25
  desc = options[:description]
26
26
  if desc
27
- parameters["Description"] = desc
27
+ parameters['Description'] = desc
28
28
  pathUrl += '&Description='
29
29
  pathUrl += desc
30
30
  end
31
-
31
+
32
32
  version = options[:version]
33
33
  if version
34
- parameters["ImageVersion"] = version
34
+ parameters['ImageVersion'] = version
35
35
  pathUrl += '&ImageVersion='
36
36
  pathUrl += version
37
37
  end
@@ -41,32 +41,32 @@ module Fog
41
41
  pathUrl += signature
42
42
 
43
43
  request(
44
- :expects => [200, 203],
45
- :method => 'GET',
46
- :path => pathUrl
44
+ expects: [200, 203],
45
+ method: 'GET',
46
+ path: pathUrl
47
47
  )
48
48
  end
49
49
  end
50
50
 
51
51
  class Mock
52
- def create_image(server_id, name, metadata={})
52
+ def create_image(server_id, name, metadata = {})
53
53
  response = Excon::Response.new
54
54
  response.status = 202
55
55
 
56
- img_id=Fog::Mock.random_numbers(6).to_s
56
+ img_id = Fog::Mock.random_numbers(6).to_s
57
57
 
58
58
  data = {
59
- 'id' => img_id,
60
- 'server' => {"id"=>"3", "links"=>[{"href"=>"http://nova1:8774/admin/servers/#{server_id}", "rel"=>"bookmark"}]},
61
- 'links' => [{"href"=>"http://nova1:8774/v1.1/admin/images/#{img_id}", "rel"=>"self"}, {"href"=>"http://nova1:8774/admin/images/#{img_id}", "rel"=>"bookmark"}],
59
+ 'id' => img_id,
60
+ 'server' => { 'id' => '3', 'links' => [{ 'href' => "http://nova1:8774/admin/servers/#{server_id}", 'rel' => 'bookmark' }] },
61
+ 'links' => [{ 'href' => "http://nova1:8774/v1.1/admin/images/#{img_id}", 'rel' => 'self' }, { 'href' => "http://nova1:8774/admin/images/#{img_id}", 'rel' => 'bookmark' }],
62
62
  'metadata' => metadata || {},
63
63
  'name' => name || "server_#{rand(999)}",
64
64
  'progress' => 0,
65
65
  'status' => 'SAVING',
66
66
  'minDisk' => 0,
67
67
  'minRam' => 0,
68
- 'updated' => "",
69
- 'created' => ""
68
+ 'updated' => '',
69
+ 'created' => ''
70
70
  }
71
71
  self.data[:last_modified][:images][data['id']] = Time.now
72
72
  self.data[:images][data['id']] = data
@@ -3,10 +3,9 @@ module Fog
3
3
  class Aliyun
4
4
  class Real
5
5
  # {Aliyun API Reference}[https://docs.aliyun.com/?spm=5176.100054.201.106.DGkmH7#/pub/ecs/open-api/securitygroup&createsecuritygroup]
6
- def create_security_group(options={})
7
-
6
+ def create_security_group(options = {})
8
7
  action = 'CreateSecurityGroup'
9
- sigNonce = randonStr()
8
+ sigNonce = randonStr
10
9
  time = Time.new.utc
11
10
 
12
11
  parameters = defalutParameters(action, sigNonce, time)
@@ -17,21 +16,21 @@ module Fog
17
16
  vpcid = options[:vpcId]
18
17
 
19
18
  if name
20
- parameters["SecurityGroupName"] = name
19
+ parameters['SecurityGroupName'] = name
21
20
  pathUrl += '&SecurityGroupName='
22
- pathUrl += name
21
+ pathUrl += name
23
22
  end
24
23
 
25
24
  if desc
26
- parameters["Description"] = desc
25
+ parameters['Description'] = desc
27
26
  pathUrl += '&Description='
28
- pathUrl += desc
27
+ pathUrl += desc
29
28
  end
30
29
 
31
30
  if vpcid
32
- parameters["VpcId"] = vpcid
31
+ parameters['VpcId'] = vpcid
33
32
  pathUrl += '&VpcId='
34
- pathUrl += vpcid
33
+ pathUrl += vpcid
35
34
  end
36
35
 
37
36
  signature = sign(@aliyun_accesskey_secret, parameters)
@@ -39,19 +38,19 @@ module Fog
39
38
  pathUrl += signature
40
39
 
41
40
  request(
42
- :expects => [200, 203],
43
- :method => 'GET',
44
- :path => pathUrl
41
+ expects: [200, 203],
42
+ method: 'GET',
43
+ path: pathUrl
45
44
  )
46
45
  end
47
46
  end
48
47
 
49
48
  class Mock
50
49
  def create_security_group(name, description)
51
- Fog::Identity::OpenStack.new(:openstack_auth_url => credentials[:openstack_auth_url])
50
+ Fog::Identity::OpenStack.new(openstack_auth_url: credentials[:openstack_auth_url])
52
51
  tenant_id = Fog::Identity::OpenStack::V2::Mock.data[current_tenant][:tenants].keys.first
53
52
  security_group_id = Fog::Mock.random_numbers(2).to_i + 1
54
- self.data[:security_groups][security_group_id.to_s] = {
53
+ data[:security_groups][security_group_id.to_s] = {
55
54
  'tenant_id' => tenant_id,
56
55
  'rules' => [],
57
56
  'id' => security_group_id,
@@ -65,9 +64,10 @@ module Fog
65
64
  'X-Compute-Request-Id' => "req-#{Fog::Mock.random_hex(32)}",
66
65
  'Content-Type' => 'application/json',
67
66
  'Content-Length' => Fog::Mock.random_numbers(3).to_s,
68
- 'Date' => Date.new}
67
+ 'Date' => Date.new
68
+ }
69
69
  response.body = {
70
- 'security_group' => self.data[:security_groups][security_group_id.to_s]
70
+ 'security_group' => data[:security_groups][security_group_id.to_s]
71
71
  }
72
72
  response
73
73
  end
@@ -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_egress_ip_rule(securitygroup_id,destCidrIp, nicType, option={})
7
-
6
+ def create_security_group_egress_ip_rule(securitygroup_id, destCidrIp, nicType, option = {})
8
7
  action = 'AuthorizeSecurityGroupEgress'
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["DestCidrIp"] = destCidrIp
18
+ parameters['DestCidrIp'] = destCidrIp
20
19
  pathUrl += '&DestCidrIp='
21
- pathUrl += URI.encode(destCidrIp,'/[^!*\'()\;?:@#&%=+$,{}[]<>`" ')
22
- unless nicType
23
- nicType='intranet'
24
- end
25
- parameters["NicType"] = nicType
20
+ pathUrl += URI.encode(destCidrIp, '/[^!*\'()\;?:@#&%=+$,{}[]<>`" ')
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