fog-aliyun 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +309 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/fog-aliyun.gemspec +30 -0
- data/lib/fog/aliyun.rb +19 -0
- data/lib/fog/aliyun/compute.rb +346 -0
- data/lib/fog/aliyun/models/compute/vpc.rb +69 -0
- data/lib/fog/aliyun/models/compute/vpcs.rb +89 -0
- data/lib/fog/aliyun/models/compute/vswitch.rb +70 -0
- data/lib/fog/aliyun/models/compute/vswitches.rb +87 -0
- data/lib/fog/aliyun/models/storage/directories.rb +45 -0
- data/lib/fog/aliyun/models/storage/directory.rb +48 -0
- data/lib/fog/aliyun/models/storage/file.rb +197 -0
- data/lib/fog/aliyun/models/storage/files.rb +178 -0
- data/lib/fog/aliyun/requests/compute/allocate_eip_address.rb +79 -0
- data/lib/fog/aliyun/requests/compute/allocate_public_ip_address.rb +63 -0
- data/lib/fog/aliyun/requests/compute/associate_eip_address.rb +66 -0
- data/lib/fog/aliyun/requests/compute/attach_disk.rb +82 -0
- data/lib/fog/aliyun/requests/compute/create_disk.rb +135 -0
- data/lib/fog/aliyun/requests/compute/create_image.rb +79 -0
- data/lib/fog/aliyun/requests/compute/create_security_group.rb +77 -0
- data/lib/fog/aliyun/requests/compute/create_security_group_ip_rule.rb +86 -0
- data/lib/fog/aliyun/requests/compute/create_security_group_sg_rule.rb +86 -0
- data/lib/fog/aliyun/requests/compute/create_server.rb +188 -0
- data/lib/fog/aliyun/requests/compute/create_snapshot.rb +60 -0
- data/lib/fog/aliyun/requests/compute/create_vpc.rb +73 -0
- data/lib/fog/aliyun/requests/compute/create_vswitch.rb +81 -0
- data/lib/fog/aliyun/requests/compute/delete_disk.rb +58 -0
- data/lib/fog/aliyun/requests/compute/delete_image.rb +58 -0
- data/lib/fog/aliyun/requests/compute/delete_security_group.rb +51 -0
- data/lib/fog/aliyun/requests/compute/delete_security_group_ip_rule.rb +85 -0
- data/lib/fog/aliyun/requests/compute/delete_security_group_sg_rule.rb +86 -0
- data/lib/fog/aliyun/requests/compute/delete_server.rb +48 -0
- data/lib/fog/aliyun/requests/compute/delete_snapshot.rb +45 -0
- data/lib/fog/aliyun/requests/compute/delete_vpc.rb +52 -0
- data/lib/fog/aliyun/requests/compute/delete_vswitch.rb +51 -0
- data/lib/fog/aliyun/requests/compute/detach_disk.rb +51 -0
- data/lib/fog/aliyun/requests/compute/join_security_group.rb +41 -0
- data/lib/fog/aliyun/requests/compute/leave_security_group.rb +41 -0
- data/lib/fog/aliyun/requests/compute/list_disks.rb +75 -0
- data/lib/fog/aliyun/requests/compute/list_eip_addresses.rb +81 -0
- data/lib/fog/aliyun/requests/compute/list_images.rb +85 -0
- data/lib/fog/aliyun/requests/compute/list_security_group_rules.rb +74 -0
- data/lib/fog/aliyun/requests/compute/list_security_groups.rb +81 -0
- data/lib/fog/aliyun/requests/compute/list_server_types.rb +77 -0
- data/lib/fog/aliyun/requests/compute/list_servers.rb +74 -0
- data/lib/fog/aliyun/requests/compute/list_snapshots.rb +86 -0
- data/lib/fog/aliyun/requests/compute/list_vpcs.rb +64 -0
- data/lib/fog/aliyun/requests/compute/list_vswitchs.rb +67 -0
- data/lib/fog/aliyun/requests/compute/list_zones.rb +44 -0
- data/lib/fog/aliyun/requests/compute/modify_vpc.rb +73 -0
- data/lib/fog/aliyun/requests/compute/modify_vswitch.rb +73 -0
- data/lib/fog/aliyun/requests/compute/reboot_server.rb +44 -0
- data/lib/fog/aliyun/requests/compute/release_eip_address.rb +53 -0
- data/lib/fog/aliyun/requests/compute/start_server.rb +42 -0
- data/lib/fog/aliyun/requests/compute/stop_server.rb +42 -0
- data/lib/fog/aliyun/requests/compute/unassociate_eip_address.rb +56 -0
- data/lib/fog/aliyun/requests/storage/copy_object.rb +42 -0
- data/lib/fog/aliyun/requests/storage/delete_bucket.rb +30 -0
- data/lib/fog/aliyun/requests/storage/delete_container.rb +38 -0
- data/lib/fog/aliyun/requests/storage/delete_object.rb +53 -0
- data/lib/fog/aliyun/requests/storage/get_bucket.rb +148 -0
- data/lib/fog/aliyun/requests/storage/get_container.rb +72 -0
- data/lib/fog/aliyun/requests/storage/get_containers.rb +76 -0
- data/lib/fog/aliyun/requests/storage/get_object.rb +45 -0
- data/lib/fog/aliyun/requests/storage/get_object_http_url.rb +43 -0
- data/lib/fog/aliyun/requests/storage/get_object_https_url.rb +43 -0
- data/lib/fog/aliyun/requests/storage/head_object.rb +34 -0
- data/lib/fog/aliyun/requests/storage/list_buckets.rb +47 -0
- data/lib/fog/aliyun/requests/storage/list_objects.rb +104 -0
- data/lib/fog/aliyun/requests/storage/put_bucket.rb +23 -0
- data/lib/fog/aliyun/requests/storage/put_container.rb +35 -0
- data/lib/fog/aliyun/requests/storage/put_object.rb +199 -0
- data/lib/fog/aliyun/storage.rb +214 -0
- data/lib/fog/aliyun/version.rb +5 -0
- data/lib/fog/bin/aliyun.rb +31 -0
- metadata +227 -0
@@ -0,0 +1,346 @@
|
|
1
|
+
module Fog
|
2
|
+
module Compute
|
3
|
+
class Aliyun < Fog::Service
|
4
|
+
recognizes :aliyun_url,
|
5
|
+
:aliyun_accesskey_id,
|
6
|
+
:aliyun_accesskey_secret,
|
7
|
+
:aliyun_region_id,
|
8
|
+
:aliyun_zone_id
|
9
|
+
|
10
|
+
## MODELS
|
11
|
+
#
|
12
|
+
model_path 'fog/aliyun/models/compute'
|
13
|
+
model :vpc
|
14
|
+
collection :vpcs
|
15
|
+
model :vswitch
|
16
|
+
collection :vswitches
|
17
|
+
|
18
|
+
## REQUESTS
|
19
|
+
#
|
20
|
+
request_path 'fog/aliyun/requests/compute'
|
21
|
+
|
22
|
+
|
23
|
+
# Server CRUD
|
24
|
+
request :list_servers
|
25
|
+
request :list_server_types
|
26
|
+
request :create_server
|
27
|
+
request :delete_server
|
28
|
+
|
29
|
+
|
30
|
+
# Server Actions
|
31
|
+
request :reboot_server
|
32
|
+
request :start_server
|
33
|
+
request :stop_server
|
34
|
+
|
35
|
+
|
36
|
+
#SnapShoot CRUD
|
37
|
+
request :list_snapshots
|
38
|
+
request :create_snapshot
|
39
|
+
request :delete_snapshot
|
40
|
+
|
41
|
+
|
42
|
+
# Image CRUD
|
43
|
+
request :list_images
|
44
|
+
request :create_image
|
45
|
+
request :delete_image
|
46
|
+
|
47
|
+
|
48
|
+
# Eip
|
49
|
+
request :list_eip_addresses
|
50
|
+
request :allocate_eip_address
|
51
|
+
request :release_eip_address
|
52
|
+
request :associate_eip_address
|
53
|
+
request :unassociate_eip_address
|
54
|
+
|
55
|
+
|
56
|
+
# Security Group
|
57
|
+
request :list_security_groups
|
58
|
+
request :list_security_group_rules
|
59
|
+
request :create_security_group
|
60
|
+
request :create_security_group_ip_rule
|
61
|
+
request :create_security_group_sg_rule
|
62
|
+
request :delete_security_group
|
63
|
+
request :delete_security_group_ip_rule
|
64
|
+
request :delete_security_group_sg_rule
|
65
|
+
request :join_security_group
|
66
|
+
request :leave_security_group
|
67
|
+
|
68
|
+
|
69
|
+
# Zones
|
70
|
+
request :list_zones
|
71
|
+
|
72
|
+
|
73
|
+
# VPC
|
74
|
+
request :create_vpc
|
75
|
+
request :delete_vpc
|
76
|
+
request :list_vpcs
|
77
|
+
request :create_vswitch
|
78
|
+
request :delete_vswitch
|
79
|
+
request :list_vswitchs
|
80
|
+
request :modify_vpc
|
81
|
+
|
82
|
+
|
83
|
+
#clouddisk
|
84
|
+
request :list_disks
|
85
|
+
request :create_disk
|
86
|
+
request :delete_disk
|
87
|
+
request :attach_disk
|
88
|
+
request :detach_disk
|
89
|
+
|
90
|
+
|
91
|
+
class Mock
|
92
|
+
attr_reader :auth_token
|
93
|
+
attr_reader :auth_token_expiration
|
94
|
+
attr_reader :current_user
|
95
|
+
attr_reader :current_tenant
|
96
|
+
|
97
|
+
def self.data
|
98
|
+
@data ||= Hash.new do |hash, key|
|
99
|
+
hash[key] = {
|
100
|
+
:last_modified => {
|
101
|
+
:images => {},
|
102
|
+
:servers => {},
|
103
|
+
:key_pairs => {},
|
104
|
+
:security_groups => {},
|
105
|
+
:addresses => {}
|
106
|
+
},
|
107
|
+
:images => {
|
108
|
+
"0e09fbd6-43c5-448a-83e9-0d3d05f9747e" => {
|
109
|
+
"id"=>"0e09fbd6-43c5-448a-83e9-0d3d05f9747e",
|
110
|
+
"name"=>"cirros-0.3.0-x86_64-blank",
|
111
|
+
'progress' => 100,
|
112
|
+
'status' => "ACTIVE",
|
113
|
+
'updated' => "",
|
114
|
+
'minRam' => 0,
|
115
|
+
'minDisk' => 0,
|
116
|
+
'metadata' => {},
|
117
|
+
'links' => [{"href"=>"http://nova1:8774/v1.1/admin/images/1", "rel"=>"self"}, {"href"=>"http://nova1:8774/admin/images/2", "rel"=>"bookmark"}]
|
118
|
+
}
|
119
|
+
},
|
120
|
+
:servers => {},
|
121
|
+
:key_pairs => {},
|
122
|
+
:security_groups => {
|
123
|
+
'0' => {
|
124
|
+
"id" => 0,
|
125
|
+
"tenant_id" => Fog::Mock.random_hex(8),
|
126
|
+
"name" => "default",
|
127
|
+
"description" => "default",
|
128
|
+
"rules" => [
|
129
|
+
{ "id" => 0,
|
130
|
+
"parent_group_id" => 0,
|
131
|
+
"from_port" => 68,
|
132
|
+
"to_port" => 68,
|
133
|
+
"ip_protocol" => "udp",
|
134
|
+
"ip_range" => { "cidr" => "0.0.0.0/0" },
|
135
|
+
"group" => {}, },
|
136
|
+
],
|
137
|
+
},
|
138
|
+
},
|
139
|
+
:server_security_group_map => {},
|
140
|
+
:addresses => {},
|
141
|
+
:quota => {
|
142
|
+
'security_group_rules' => 20,
|
143
|
+
'security_groups' => 10,
|
144
|
+
'injected_file_content_bytes' => 10240,
|
145
|
+
'injected_file_path_bytes' => 256,
|
146
|
+
'injected_files' => 5,
|
147
|
+
'metadata_items' => 128,
|
148
|
+
'floating_ips' => 10,
|
149
|
+
'instances' => 10,
|
150
|
+
'key_pairs' => 10,
|
151
|
+
'gigabytes' => 5000,
|
152
|
+
'volumes' => 10,
|
153
|
+
'cores' => 20,
|
154
|
+
'ram' => 51200
|
155
|
+
},
|
156
|
+
:volumes => {}
|
157
|
+
}
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
def self.reset
|
162
|
+
@data = nil
|
163
|
+
end
|
164
|
+
|
165
|
+
def initialize(options={})
|
166
|
+
@openstack_username = options[:openstack_username]
|
167
|
+
@openstack_user_domain = options[:openstack_user_domain] || options[:openstack_domain]
|
168
|
+
@openstack_project_domain = options[:openstack_project_domain] || options[:openstack_domain] || 'Default'
|
169
|
+
@openstack_auth_uri = URI.parse(options[:openstack_auth_url])
|
170
|
+
|
171
|
+
@current_tenant = options[:openstack_tenant]
|
172
|
+
@current_tenant_id = options[:openstack_tenant_id]
|
173
|
+
|
174
|
+
@auth_token = Fog::Mock.random_base64(64)
|
175
|
+
@auth_token_expiration = (Time.now.utc + 86400).iso8601
|
176
|
+
|
177
|
+
management_url = URI.parse(options[:openstack_auth_url])
|
178
|
+
management_url.port = 8774
|
179
|
+
management_url.path = '/v1.1/1'
|
180
|
+
@openstack_management_url = management_url.to_s
|
181
|
+
|
182
|
+
identity_public_endpoint = URI.parse(options[:openstack_auth_url])
|
183
|
+
identity_public_endpoint.port = 5000
|
184
|
+
@openstack_identity_public_endpoint = identity_public_endpoint.to_s
|
185
|
+
end
|
186
|
+
|
187
|
+
def data
|
188
|
+
self.class.data["#{@openstack_username}-#{@current_tenant}"]
|
189
|
+
end
|
190
|
+
|
191
|
+
def reset_data
|
192
|
+
self.class.data.delete("#{@openstack_username}-#{@current_tenant}")
|
193
|
+
end
|
194
|
+
|
195
|
+
def credentials
|
196
|
+
{ :provider => 'openstack',
|
197
|
+
:openstack_auth_url => @openstack_auth_uri.to_s,
|
198
|
+
:openstack_auth_token => @auth_token,
|
199
|
+
:openstack_management_url => @openstack_management_url,
|
200
|
+
:openstack_identity_endpoint => @openstack_identity_public_endpoint }
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
class Real
|
205
|
+
|
206
|
+
# Initialize connection to ECS
|
207
|
+
#
|
208
|
+
# ==== Notes
|
209
|
+
# options parameter must include values for :aliyun_url, :aliyun_accesskey_id,
|
210
|
+
# :aliyun_secret_access_key, :aliyun_region_id and :aliyun_zone_id in order to create a connection.
|
211
|
+
# if you haven't set these values in the configuration file.
|
212
|
+
#
|
213
|
+
# ==== Examples
|
214
|
+
# sdb = Fog::Compute.new(:provider=>'aliyun',
|
215
|
+
# :aliyun_accesskey_id => your_:aliyun_accesskey_id,
|
216
|
+
# :aliyun_secret_access_key => your_aliyun_secret_access_key
|
217
|
+
# )
|
218
|
+
#
|
219
|
+
# ==== Parameters
|
220
|
+
# * options<~Hash> - config arguments for connection. Defaults to {}.
|
221
|
+
#
|
222
|
+
# ==== Returns
|
223
|
+
# * ECS object with connection to aliyun.
|
224
|
+
attr_reader :aliyun_accesskey_id
|
225
|
+
attr_reader :aliyun_accesskey_secret
|
226
|
+
attr_reader :aliyun_region_id
|
227
|
+
attr_reader :aliyun_url
|
228
|
+
attr_reader :aliyun_zone_id
|
229
|
+
|
230
|
+
def initialize(options={})
|
231
|
+
|
232
|
+
#initialize the parameters
|
233
|
+
@aliyun_url = options[:aliyun_url]
|
234
|
+
@aliyun_accesskey_id = options[:aliyun_accesskey_id]
|
235
|
+
@aliyun_accesskey_secret = options[:aliyun_accesskey_secret]
|
236
|
+
@aliyun_region_id = options[:aliyun_region_id]
|
237
|
+
@aliyun_zone_id = options[:aliyun_zone_id]
|
238
|
+
|
239
|
+
#check for the parameters
|
240
|
+
missing_credentials = Array.new
|
241
|
+
missing_credentials << :aliyun_accesskey_id unless @aliyun_accesskey_id
|
242
|
+
missing_credentials << :aliyun_accesskey_secret unless @aliyun_accesskey_secret
|
243
|
+
missing_credentials << :aliyun_region_id unless @aliyun_region_id
|
244
|
+
missing_credentials << :aliyun_url unless @aliyun_url
|
245
|
+
missing_credentials << :aliyun_zone_id unless @aliyun_zone_id
|
246
|
+
raise ArgumentError, "Missing required arguments: #{missing_credentials.join(', ')}" unless missing_credentials.empty?
|
247
|
+
|
248
|
+
@connection_options = options[:connection_options] || {}
|
249
|
+
|
250
|
+
uri = URI.parse(@aliyun_url)
|
251
|
+
@host = uri.host
|
252
|
+
@path = uri.path
|
253
|
+
@port = uri.port
|
254
|
+
@scheme = uri.scheme
|
255
|
+
|
256
|
+
@persistent = options[:persistent] || false
|
257
|
+
@connection = Fog::Core::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options)
|
258
|
+
|
259
|
+
end
|
260
|
+
|
261
|
+
def reload
|
262
|
+
@connection.reset
|
263
|
+
end
|
264
|
+
|
265
|
+
def request(params)
|
266
|
+
begin
|
267
|
+
response = @connection.request(params.merge({
|
268
|
+
:headers => {
|
269
|
+
'Content-Type' => 'application/json',
|
270
|
+
'Accept' => 'application/json',
|
271
|
+
'X-Auth-Token' => @auth_token
|
272
|
+
}.merge!(params[:headers] || {}),
|
273
|
+
:path => "#{@path}/#{params[:path]}",
|
274
|
+
:query => params[:query]
|
275
|
+
}))
|
276
|
+
rescue Excon::Errors::HTTPStatusError => error
|
277
|
+
raise case error
|
278
|
+
when Excon::Errors::NotFound
|
279
|
+
Fog::Compute::Aliyun::NotFound.slurp(error)
|
280
|
+
else
|
281
|
+
error
|
282
|
+
end
|
283
|
+
end
|
284
|
+
|
285
|
+
if !response.body.empty? and response.get_header('Content-Type') == 'application/json'
|
286
|
+
response.body = Fog::JSON.decode(response.body)
|
287
|
+
end
|
288
|
+
|
289
|
+
response
|
290
|
+
end
|
291
|
+
|
292
|
+
#operation compute-- default URL
|
293
|
+
def defaultAliyunUri(action, sigNonce, time)
|
294
|
+
parTimeFormat = time.strftime("%Y-%m-%dT%H:%M:%SZ")
|
295
|
+
urlTimeFormat = URI.encode(parTimeFormat,':')
|
296
|
+
return '?Format=JSON&AccessKeyId='+@aliyun_accesskey_id+'&Action='+action+'&SignatureMethod=HMAC-SHA1&RegionId='+@aliyun_region_id+'&SignatureNonce='+sigNonce+'&SignatureVersion=1.0&Version=2014-05-26&Timestamp='+urlTimeFormat
|
297
|
+
end
|
298
|
+
|
299
|
+
#generate random num
|
300
|
+
def randonStr ()
|
301
|
+
numStr = rand(100000).to_s
|
302
|
+
timeStr = Time.now.to_f.to_s
|
303
|
+
ranStr = timeStr+"-"+numStr
|
304
|
+
return ranStr
|
305
|
+
end
|
306
|
+
|
307
|
+
#operation compute--collection of default parameters
|
308
|
+
def defalutParameters(action, sigNonce, time)
|
309
|
+
parTimeFormat = time.strftime("%Y-%m-%dT%H:%M:%SZ")
|
310
|
+
para = {
|
311
|
+
'Format'=>'JSON',
|
312
|
+
'Version'=>'2014-05-26',
|
313
|
+
'Action'=>action,
|
314
|
+
'AccessKeyId'=>@aliyun_accesskey_id,
|
315
|
+
'SignatureVersion'=>'1.0',
|
316
|
+
'SignatureMethod'=>'HMAC-SHA1',
|
317
|
+
'SignatureNonce'=>sigNonce,
|
318
|
+
'RegionId'=>@aliyun_region_id,
|
319
|
+
'Timestamp'=>parTimeFormat};
|
320
|
+
return para
|
321
|
+
end
|
322
|
+
|
323
|
+
#compute signature
|
324
|
+
def sign (accessKeySecret,parameters)
|
325
|
+
sortedParameters = parameters.sort
|
326
|
+
canonicalizedQueryString = ''
|
327
|
+
sortedParameters.each do | k, v |
|
328
|
+
canonicalizedQueryString += '&' + URI.encode(k,'/[^!*\'()\;?:@#&%=+$,{}[]<>`" ') + '=' + URI.encode(v,'/[^!*\'()\;?:@#&%=+$,{}[]<>`" ')
|
329
|
+
end
|
330
|
+
|
331
|
+
canonicalizedQueryString[0] = ''
|
332
|
+
stringToSign = 'GET&%2F&' + URI.encode(canonicalizedQueryString,'/[^!*\'()\;?:@#&%=+$,{}[]<>`" ')
|
333
|
+
key = accessKeySecret + '&'
|
334
|
+
|
335
|
+
digVer = OpenSSL::Digest.new("sha1")
|
336
|
+
digest = OpenSSL::HMAC.digest(digVer, key, stringToSign)
|
337
|
+
signature = Base64.encode64(digest)
|
338
|
+
signature[-1] = ''
|
339
|
+
encodedSig = URI.encode(signature,'/[^!*\'()\;?:@#&%=+$,{}[]<>`" ')
|
340
|
+
|
341
|
+
return encodedSig
|
342
|
+
end
|
343
|
+
end
|
344
|
+
end
|
345
|
+
end
|
346
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'fog/core/model'
|
2
|
+
module Fog
|
3
|
+
module Compute
|
4
|
+
class Aliyun
|
5
|
+
class VPC < Fog::Model
|
6
|
+
identity :id, :aliases => 'VpcId'
|
7
|
+
attribute :vpc_name, :aliases => 'VpcName'
|
8
|
+
attribute :state, :aliases => 'Status'
|
9
|
+
attribute :cidr_block, :aliases => 'CidrBlock'
|
10
|
+
attribute :v_switch_ids, :aliases => 'VSwitchIds'
|
11
|
+
attribute :description, :aliases => 'Description'
|
12
|
+
attribute :user_cidrs, :aliases => 'UserCidrs'
|
13
|
+
attribute :region_id, :aliases => 'RegionId'
|
14
|
+
attribute :v_router_id, :aliases => 'VRouterId'
|
15
|
+
attribute :creation_time, :aliases => 'CreationTime'
|
16
|
+
|
17
|
+
|
18
|
+
def ready?
|
19
|
+
requires :state
|
20
|
+
state == 'Available'
|
21
|
+
end
|
22
|
+
|
23
|
+
# Removes an existing vpc
|
24
|
+
#
|
25
|
+
# vpc.destroy
|
26
|
+
#
|
27
|
+
# ==== Returns
|
28
|
+
#
|
29
|
+
# True or false depending on the result
|
30
|
+
#
|
31
|
+
|
32
|
+
def destroy
|
33
|
+
requires :id
|
34
|
+
|
35
|
+
service.delete_vpc(id)
|
36
|
+
true
|
37
|
+
end
|
38
|
+
|
39
|
+
def vswitches
|
40
|
+
@vswitches ||= begin
|
41
|
+
Fog::Compute::Aliyun::Vswitches.new(
|
42
|
+
:vpc => self,
|
43
|
+
:service => service
|
44
|
+
)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
# Create a vpc
|
49
|
+
#
|
50
|
+
# >> g = Aliyun.vpcs.new(:cidr_block => "10.1.2.0/24")
|
51
|
+
# >> g.save
|
52
|
+
#
|
53
|
+
# == Returns:
|
54
|
+
#
|
55
|
+
# True or an exception depending on the result. Keep in mind that this *creates* a new vpc.
|
56
|
+
# As such, it yields an InvalidGroup.Duplicate exception if you attempt to save an existing vpc.
|
57
|
+
#
|
58
|
+
|
59
|
+
def save(options={})
|
60
|
+
requires :cidr_block
|
61
|
+
options[:name]=vpc_name if vpc_name
|
62
|
+
options[:description]=description if description
|
63
|
+
data = Fog::JSON.decode(service.create_vpc(cidr_block,options).body)
|
64
|
+
true
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
require 'fog/core/collection'
|
2
|
+
require 'fog/aliyun/models/compute/vpc'
|
3
|
+
|
4
|
+
module Fog
|
5
|
+
module Compute
|
6
|
+
class Aliyun
|
7
|
+
class Vpcs < Fog::Collection
|
8
|
+
attribute :filters
|
9
|
+
|
10
|
+
model Fog::Compute::Aliyun::VPC
|
11
|
+
|
12
|
+
# Creates a new VPC
|
13
|
+
#
|
14
|
+
# Aliyun.vpcs.new
|
15
|
+
#
|
16
|
+
# ==== Returns
|
17
|
+
#
|
18
|
+
# Returns the details of the new VPC
|
19
|
+
#
|
20
|
+
#>> Aliyun.vpcs.new
|
21
|
+
# <Fog::Aliyun::VPC::VPC
|
22
|
+
# id=nil,
|
23
|
+
# state=nil,
|
24
|
+
# cidr_block=nil,
|
25
|
+
# dhcp_options_id=nil
|
26
|
+
# tags=nil
|
27
|
+
# tenancy=nil
|
28
|
+
# >
|
29
|
+
#
|
30
|
+
|
31
|
+
def initialize(attributes)
|
32
|
+
self.filters ||= {}
|
33
|
+
super
|
34
|
+
end
|
35
|
+
|
36
|
+
# Returns an array of all VPCs that have been created
|
37
|
+
#
|
38
|
+
# Aliyun.vpcs.all
|
39
|
+
#
|
40
|
+
# ==== Returns
|
41
|
+
#
|
42
|
+
# Returns an array of all VPCs
|
43
|
+
#
|
44
|
+
#>> Aliyun.vpcs.all
|
45
|
+
# <Fog::Aliyun::VPC::VPCs
|
46
|
+
# filters={}
|
47
|
+
# [
|
48
|
+
# <Fog::Aliyun::VPC::VPC
|
49
|
+
# id="vpc-12345678",
|
50
|
+
# TODO
|
51
|
+
# >
|
52
|
+
# ]
|
53
|
+
# >
|
54
|
+
#
|
55
|
+
|
56
|
+
def all(filters_arg = filters)
|
57
|
+
unless filters_arg.is_a?(Hash)
|
58
|
+
Fog::Logger.warning("all with #{filters_arg.class} param is deprecated, use all('vpcId' => []) instead [light_black](#{caller.first})[/]")
|
59
|
+
filters_arg = {'vpcId' => [*filters_arg]}
|
60
|
+
end
|
61
|
+
filters = filters_arg
|
62
|
+
data = Fog::JSON.decode(service.list_vpcs(filters).body)['Vpcs']['Vpc']
|
63
|
+
load(data)
|
64
|
+
end
|
65
|
+
|
66
|
+
# Used to retrieve a VPC
|
67
|
+
# vpc_id is required to get the associated VPC information.
|
68
|
+
#
|
69
|
+
# You can run the following command to get the details:
|
70
|
+
# Aliyun.vpcs.get("vpc-12345678")
|
71
|
+
#
|
72
|
+
# ==== Returns
|
73
|
+
#
|
74
|
+
#>> Aliyun.vpcs.get("vpc-12345678")
|
75
|
+
# <Fog::Aliyun::Compute::VPC
|
76
|
+
# id="vpc-12345678",
|
77
|
+
# TODO
|
78
|
+
# >
|
79
|
+
#
|
80
|
+
|
81
|
+
def get(vpcId)
|
82
|
+
if vpcId
|
83
|
+
$vpc=self.class.new(:service => service).all('vpcId' => vpcId)[0]
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|