fog-xiaozhu 0.2.1
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/.rubocop.yml +5 -0
- data/.rubocop_todo.yml +149 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -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 +312 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/fog-aliyun.gemspec +33 -0
- data/lib/fog/aliyun/compute.rb +424 -0
- data/lib/fog/aliyun/models/compute/eip_address.rb +57 -0
- data/lib/fog/aliyun/models/compute/eip_addresses.rb +28 -0
- data/lib/fog/aliyun/models/compute/image.rb +66 -0
- data/lib/fog/aliyun/models/compute/images.rb +25 -0
- data/lib/fog/aliyun/models/compute/route_entry.rb +26 -0
- data/lib/fog/aliyun/models/compute/route_entrys.rb +41 -0
- data/lib/fog/aliyun/models/compute/route_table.rb +30 -0
- data/lib/fog/aliyun/models/compute/route_tables.rb +27 -0
- data/lib/fog/aliyun/models/compute/security_group.rb +81 -0
- data/lib/fog/aliyun/models/compute/security_group_rule.rb +47 -0
- data/lib/fog/aliyun/models/compute/security_group_rules.rb +23 -0
- data/lib/fog/aliyun/models/compute/security_groups.rb +32 -0
- data/lib/fog/aliyun/models/compute/server.rb +70 -0
- data/lib/fog/aliyun/models/compute/servers.rb +42 -0
- data/lib/fog/aliyun/models/compute/snapshot.rb +52 -0
- data/lib/fog/aliyun/models/compute/snapshots.rb +38 -0
- data/lib/fog/aliyun/models/compute/volume.rb +101 -0
- data/lib/fog/aliyun/models/compute/volumes.rb +135 -0
- data/lib/fog/aliyun/models/compute/vpc.rb +77 -0
- data/lib/fog/aliyun/models/compute/vpcs.rb +80 -0
- data/lib/fog/aliyun/models/compute/vrouter.rb +35 -0
- data/lib/fog/aliyun/models/compute/vrouters.rb +61 -0
- data/lib/fog/aliyun/models/compute/vswitch.rb +70 -0
- data/lib/fog/aliyun/models/compute/vswitches.rb +80 -0
- data/lib/fog/aliyun/models/storage/directories.rb +39 -0
- data/lib/fog/aliyun/models/storage/directory.rb +48 -0
- data/lib/fog/aliyun/models/storage/file.rb +192 -0
- data/lib/fog/aliyun/models/storage/files.rb +193 -0
- data/lib/fog/aliyun/requests/compute/allocate_eip_address.rb +54 -0
- data/lib/fog/aliyun/requests/compute/allocate_public_ip_address.rb +39 -0
- data/lib/fog/aliyun/requests/compute/associate_eip_address.rb +49 -0
- data/lib/fog/aliyun/requests/compute/attach_disk.rb +79 -0
- data/lib/fog/aliyun/requests/compute/create_disk.rb +137 -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_egress_ip_rule.rb +63 -0
- data/lib/fog/aliyun/requests/compute/create_security_group_egress_sg_rule.rb +71 -0
- data/lib/fog/aliyun/requests/compute/create_security_group_ip_rule.rb +63 -0
- data/lib/fog/aliyun/requests/compute/create_security_group_sg_rule.rb +71 -0
- data/lib/fog/aliyun/requests/compute/create_server.rb +186 -0
- data/lib/fog/aliyun/requests/compute/create_snapshot.rb +46 -0
- data/lib/fog/aliyun/requests/compute/create_vpc.rb +46 -0
- data/lib/fog/aliyun/requests/compute/create_vpn_connection.rb +58 -0
- data/lib/fog/aliyun/requests/compute/create_vpn_customergateway.rb +48 -0
- data/lib/fog/aliyun/requests/compute/create_vswitch.rb +54 -0
- data/lib/fog/aliyun/requests/compute/delete_disk.rb +41 -0
- data/lib/fog/aliyun/requests/compute/delete_image.rb +31 -0
- data/lib/fog/aliyun/requests/compute/delete_security_group.rb +51 -0
- data/lib/fog/aliyun/requests/compute/delete_security_group_egress_ip_rule.rb +63 -0
- data/lib/fog/aliyun/requests/compute/delete_security_group_egress_sg_rule.rb +71 -0
- data/lib/fog/aliyun/requests/compute/delete_security_group_ip_rule.rb +63 -0
- data/lib/fog/aliyun/requests/compute/delete_security_group_sg_rule.rb +71 -0
- data/lib/fog/aliyun/requests/compute/delete_server.rb +48 -0
- data/lib/fog/aliyun/requests/compute/delete_snapshot.rb +31 -0
- data/lib/fog/aliyun/requests/compute/delete_vpc.rb +35 -0
- data/lib/fog/aliyun/requests/compute/delete_vpn_connection.rb +35 -0
- data/lib/fog/aliyun/requests/compute/delete_vpn_customergateway.rb +35 -0
- data/lib/fog/aliyun/requests/compute/delete_vswitch.rb +35 -0
- data/lib/fog/aliyun/requests/compute/detach_disk.rb +41 -0
- data/lib/fog/aliyun/requests/compute/join_security_group.rb +40 -0
- data/lib/fog/aliyun/requests/compute/leave_security_group.rb +40 -0
- data/lib/fog/aliyun/requests/compute/list_disks.rb +150 -0
- data/lib/fog/aliyun/requests/compute/list_eip_addresses.rb +55 -0
- data/lib/fog/aliyun/requests/compute/list_images.rb +82 -0
- data/lib/fog/aliyun/requests/compute/list_route_tables.rb +64 -0
- data/lib/fog/aliyun/requests/compute/list_security_group_rules.rb +73 -0
- data/lib/fog/aliyun/requests/compute/list_security_groups.rb +78 -0
- data/lib/fog/aliyun/requests/compute/list_server_types.rb +77 -0
- data/lib/fog/aliyun/requests/compute/list_servers.rb +71 -0
- data/lib/fog/aliyun/requests/compute/list_snapshots.rb +97 -0
- data/lib/fog/aliyun/requests/compute/list_vpcs.rb +47 -0
- data/lib/fog/aliyun/requests/compute/list_vpn_connections.rb +49 -0
- data/lib/fog/aliyun/requests/compute/list_vpn_customergateways.rb +43 -0
- data/lib/fog/aliyun/requests/compute/list_vpn_gateways.rb +49 -0
- data/lib/fog/aliyun/requests/compute/list_vrouters.rb +61 -0
- data/lib/fog/aliyun/requests/compute/list_vswitchs.rb +50 -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 +45 -0
- data/lib/fog/aliyun/requests/compute/reboot_server.rb +43 -0
- data/lib/fog/aliyun/requests/compute/release_eip_address.rb +29 -0
- data/lib/fog/aliyun/requests/compute/start_server.rb +41 -0
- data/lib/fog/aliyun/requests/compute/stop_server.rb +41 -0
- data/lib/fog/aliyun/requests/compute/unassociate_eip_address.rb +49 -0
- data/lib/fog/aliyun/requests/storage/copy_object.rb +39 -0
- data/lib/fog/aliyun/requests/storage/delete_bucket.rb +30 -0
- data/lib/fog/aliyun/requests/storage/delete_container.rb +35 -0
- data/lib/fog/aliyun/requests/storage/delete_object.rb +51 -0
- data/lib/fog/aliyun/requests/storage/get_bucket.rb +141 -0
- data/lib/fog/aliyun/requests/storage/get_container.rb +60 -0
- data/lib/fog/aliyun/requests/storage/get_containers.rb +64 -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 +40 -0
- data/lib/fog/aliyun/requests/storage/list_objects.rb +91 -0
- data/lib/fog/aliyun/requests/storage/put_bucket.rb +22 -0
- data/lib/fog/aliyun/requests/storage/put_container.rb +35 -0
- data/lib/fog/aliyun/requests/storage/put_object.rb +189 -0
- data/lib/fog/aliyun/storage.rb +233 -0
- data/lib/fog/aliyun/version.rb +5 -0
- data/lib/fog/aliyun.rb +19 -0
- data/lib/fog/bin/aliyun.rb +31 -0
- metadata +311 -0
@@ -0,0 +1,192 @@
|
|
1
|
+
require 'fog/core/model'
|
2
|
+
|
3
|
+
module Fog
|
4
|
+
module Storage
|
5
|
+
class Aliyun
|
6
|
+
class File < Fog::Model
|
7
|
+
identity :key, aliases: 'name'
|
8
|
+
attribute :date, aliases: 'Date'
|
9
|
+
attribute :content_length, aliases: 'Content-Length', type: :integer
|
10
|
+
attribute :content_type, aliases: 'Content-Type'
|
11
|
+
attribute :connection, aliases: 'Connection'
|
12
|
+
attribute :content_disposition, aliases: 'Content-Disposition'
|
13
|
+
attribute :etag, aliases: 'Etag'
|
14
|
+
attribute :last_modified, aliases: 'Last-Modified', type: :time
|
15
|
+
attribute :accept_ranges, aliases: 'Accept-Ranges'
|
16
|
+
attribute :server, aliases: 'Server'
|
17
|
+
attribute :object_type, aliases: 'x-oss-object-type'
|
18
|
+
|
19
|
+
def body
|
20
|
+
attributes[:body] ||= if last_modified
|
21
|
+
collection.get(identity).body
|
22
|
+
else
|
23
|
+
''
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def body=(new_body)
|
28
|
+
attributes[:body] = new_body
|
29
|
+
end
|
30
|
+
|
31
|
+
attr_reader :directory
|
32
|
+
|
33
|
+
def copy(target_directory_key, target_file_key, options = {})
|
34
|
+
requires :directory, :key
|
35
|
+
source_object = if directory.key == ''
|
36
|
+
key
|
37
|
+
else
|
38
|
+
directory.key + '/' + key
|
39
|
+
end
|
40
|
+
if target_directory_key == ''
|
41
|
+
target_object = target_file_key
|
42
|
+
else
|
43
|
+
target_object = target_directory_key + '/' + target_file_key
|
44
|
+
end
|
45
|
+
service.copy_object(nil, source_object, nil, target_object, options)
|
46
|
+
target_directory = service.directories.new(key: target_directory_key)
|
47
|
+
target_directory.files.get(target_file_key)
|
48
|
+
end
|
49
|
+
|
50
|
+
def destroy
|
51
|
+
requires :directory, :key
|
52
|
+
object = if directory.key == ''
|
53
|
+
key
|
54
|
+
else
|
55
|
+
directory.key + '/' + key
|
56
|
+
end
|
57
|
+
service.delete_object(object)
|
58
|
+
true
|
59
|
+
end
|
60
|
+
|
61
|
+
def metadata
|
62
|
+
attributes[:metadata] ||= headers_to_metadata
|
63
|
+
end
|
64
|
+
|
65
|
+
def owner=(new_owner)
|
66
|
+
if new_owner
|
67
|
+
attributes[:owner] = {
|
68
|
+
display_name: new_owner['DisplayName'],
|
69
|
+
id: new_owner['ID']
|
70
|
+
}
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def public=(new_public)
|
75
|
+
new_public
|
76
|
+
end
|
77
|
+
|
78
|
+
# Get a url for file.
|
79
|
+
#
|
80
|
+
# required attributes: directory, key
|
81
|
+
#
|
82
|
+
# @param expires [String] number of seconds (since 1970-01-01 00:00) before url expires
|
83
|
+
# @param options [Hash]
|
84
|
+
# @return [String] url
|
85
|
+
#
|
86
|
+
def url(expires, options = {})
|
87
|
+
requires :directory, :key
|
88
|
+
object = if directory.key == ''
|
89
|
+
key
|
90
|
+
else
|
91
|
+
directory.key + '/' + key
|
92
|
+
end
|
93
|
+
service.get_object_http_url_public(object, expires, options)
|
94
|
+
end
|
95
|
+
|
96
|
+
def public_url
|
97
|
+
requires :key
|
98
|
+
collection.get_url(key)
|
99
|
+
end
|
100
|
+
|
101
|
+
def save(options = {})
|
102
|
+
requires :body, :directory, :key
|
103
|
+
options['Content-Type'] = content_type if content_type
|
104
|
+
options['Content-Disposition'] = content_disposition if content_disposition
|
105
|
+
options.merge!(metadata_to_headers)
|
106
|
+
|
107
|
+
object = if directory.key == ''
|
108
|
+
key
|
109
|
+
else
|
110
|
+
directory.key + '/' + key
|
111
|
+
end
|
112
|
+
if body.is_a?(::File)
|
113
|
+
data = service.put_object(object, body, options).data
|
114
|
+
elsif body.is_a?(String)
|
115
|
+
data = service.put_object_with_body(object, body, options).data
|
116
|
+
else
|
117
|
+
raise Fog::Storage::Aliyun::Error, " Forbidden: Invalid body type: #{body.class}!"
|
118
|
+
end
|
119
|
+
update_attributes_from(data)
|
120
|
+
refresh_metadata
|
121
|
+
|
122
|
+
self.content_length = Fog::Storage.get_body_size(body)
|
123
|
+
self.content_type ||= Fog::Storage.get_content_type(body)
|
124
|
+
true
|
125
|
+
end
|
126
|
+
|
127
|
+
private
|
128
|
+
|
129
|
+
attr_writer :directory
|
130
|
+
|
131
|
+
def refresh_metadata
|
132
|
+
metadata.reject! { |_k, v| v.nil? }
|
133
|
+
end
|
134
|
+
|
135
|
+
def headers_to_metadata
|
136
|
+
key_map = key_mapping
|
137
|
+
Hash[metadata_attributes.map { |k, v| [key_map[k], v] }]
|
138
|
+
end
|
139
|
+
|
140
|
+
def key_mapping
|
141
|
+
key_map = metadata_attributes
|
142
|
+
key_map.each_pair { |k, _v| key_map[k] = header_to_key(k) }
|
143
|
+
end
|
144
|
+
|
145
|
+
def header_to_key(opt)
|
146
|
+
opt.gsub(metadata_prefix, '').split('-').map { |k| k[0, 1].downcase + k[1..-1] }.join('_').to_sym
|
147
|
+
end
|
148
|
+
|
149
|
+
def metadata_to_headers
|
150
|
+
header_map = header_mapping
|
151
|
+
Hash[metadata.map { |k, v| [header_map[k], v] }]
|
152
|
+
end
|
153
|
+
|
154
|
+
def header_mapping
|
155
|
+
header_map = metadata.dup
|
156
|
+
header_map.each_pair { |k, _v| header_map[k] = key_to_header(k) }
|
157
|
+
end
|
158
|
+
|
159
|
+
def key_to_header(key)
|
160
|
+
metadata_prefix + key.to_s.split(/[-_]/).map(&:capitalize).join('-')
|
161
|
+
end
|
162
|
+
|
163
|
+
def metadata_attributes
|
164
|
+
if last_modified
|
165
|
+
object = if directory.key == ''
|
166
|
+
key
|
167
|
+
else
|
168
|
+
directory.key + '/' + key
|
169
|
+
end
|
170
|
+
|
171
|
+
headers = service.head_object(object).data[:headers]
|
172
|
+
headers.reject! { |k, _v| !metadata_attribute?(k) }
|
173
|
+
else
|
174
|
+
{}
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
def metadata_attribute?(key)
|
179
|
+
key.to_s =~ /^#{metadata_prefix}/
|
180
|
+
end
|
181
|
+
|
182
|
+
def metadata_prefix
|
183
|
+
'X-Object-Meta-'
|
184
|
+
end
|
185
|
+
|
186
|
+
def update_attributes_from(data)
|
187
|
+
merge_attributes(data[:headers].reject { |key, _value| ['Content-Length', 'Content-Type'].include?(key) })
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
191
|
+
end
|
192
|
+
end
|
@@ -0,0 +1,193 @@
|
|
1
|
+
require 'fog/core/collection'
|
2
|
+
require 'fog/aliyun/models/storage/file'
|
3
|
+
|
4
|
+
module Fog
|
5
|
+
module Storage
|
6
|
+
class Aliyun
|
7
|
+
class Files < Fog::Collection
|
8
|
+
attribute :directory
|
9
|
+
attribute :limit
|
10
|
+
attribute :marker
|
11
|
+
attribute :path
|
12
|
+
attribute :prefix
|
13
|
+
|
14
|
+
model Fog::Storage::Aliyun::File
|
15
|
+
|
16
|
+
def all(_options = {})
|
17
|
+
requires :directory
|
18
|
+
if directory.key != '' && directory.key != '.' && !directory.key.nil?
|
19
|
+
prefix = directory.key + '/'
|
20
|
+
end
|
21
|
+
files = service.list_objects(prefix: prefix)['Contents']
|
22
|
+
return if nil == files
|
23
|
+
data = []
|
24
|
+
i = 0
|
25
|
+
files.each do |file|
|
26
|
+
next unless file['Key'][0][-1] != '/'
|
27
|
+
content_length = file['Size'][0].to_i
|
28
|
+
key = file['Key'][0]
|
29
|
+
lastModified = file['LastModified'][0]
|
30
|
+
last_modified = if !lastModified.nil? && lastModified != ''
|
31
|
+
Time.parse(lastModified).localtime
|
32
|
+
end
|
33
|
+
type = file['Type'][0]
|
34
|
+
data[i] = { content_length: content_length,
|
35
|
+
key: key,
|
36
|
+
last_modified: last_modified,
|
37
|
+
etag: file['ETag'][0],
|
38
|
+
object_type: type }
|
39
|
+
i += 1
|
40
|
+
end
|
41
|
+
|
42
|
+
load(data)
|
43
|
+
end
|
44
|
+
|
45
|
+
alias each_file_this_page each
|
46
|
+
def each
|
47
|
+
if !block_given?
|
48
|
+
self
|
49
|
+
else
|
50
|
+
subset = dup.all
|
51
|
+
|
52
|
+
subset.each_file_this_page { |f| yield f }
|
53
|
+
while subset.length == (subset.limit || 10_000)
|
54
|
+
subset = subset.all(marker: subset.last.key)
|
55
|
+
subset.each_file_this_page { |f| yield f }
|
56
|
+
end
|
57
|
+
|
58
|
+
self
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def get(key)
|
63
|
+
requires :directory
|
64
|
+
object = if directory.key == ''
|
65
|
+
key
|
66
|
+
else
|
67
|
+
directory.key + '/' + key
|
68
|
+
end
|
69
|
+
begin
|
70
|
+
data = service.get_object(object)
|
71
|
+
rescue => error
|
72
|
+
case error.response.body
|
73
|
+
when /<Code>NoSuchKey<\/Code>/
|
74
|
+
nil
|
75
|
+
else
|
76
|
+
raise(error)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
contentLen = data[:headers]['Content-Length'].to_i
|
81
|
+
|
82
|
+
if block_given?
|
83
|
+
pagesNum = (contentLen + Excon::CHUNK_SIZE - 1) / Excon::CHUNK_SIZE
|
84
|
+
|
85
|
+
for i in 1..pagesNum
|
86
|
+
_start = (i - 1) * Excon::CHUNK_SIZE
|
87
|
+
_end = i * Excon::CHUNK_SIZE - 1
|
88
|
+
range = "#{_start}-#{_end}"
|
89
|
+
data = service.get_object(object, range)
|
90
|
+
chunk = data[:body]
|
91
|
+
yield(chunk)
|
92
|
+
body = nil
|
93
|
+
end
|
94
|
+
else
|
95
|
+
body = data[:body]
|
96
|
+
end
|
97
|
+
|
98
|
+
lastModified = data[:headers]['Last-Modified']
|
99
|
+
last_modified = if !lastModified.nil? && lastModified != ''
|
100
|
+
Time.parse(lastModified).localtime
|
101
|
+
end
|
102
|
+
|
103
|
+
date = data[:headers]['Date']
|
104
|
+
date = (Time.parse(date).localtime if !date.nil? && date != '')
|
105
|
+
file_data = {
|
106
|
+
body: body,
|
107
|
+
content_length: contentLen,
|
108
|
+
key: key,
|
109
|
+
last_modified: last_modified,
|
110
|
+
content_type: data[:headers]['Content-Type'],
|
111
|
+
etag: data[:headers]['ETag'],
|
112
|
+
date: date,
|
113
|
+
connection: data[:headers]['Connection'],
|
114
|
+
accept_ranges: data[:headers]['Accept-Ranges'],
|
115
|
+
server: data[:headers]['Server'],
|
116
|
+
object_type: data[:headers]['x-oss-object-type'],
|
117
|
+
content_disposition: data[:headers]['Content-Disposition']
|
118
|
+
}
|
119
|
+
|
120
|
+
new(file_data)
|
121
|
+
end
|
122
|
+
|
123
|
+
def get_url(key)
|
124
|
+
requires :directory
|
125
|
+
object = if directory.key == ''
|
126
|
+
key
|
127
|
+
else
|
128
|
+
directory.key + '/' + key
|
129
|
+
end
|
130
|
+
service.get_object_http_url_public(object, 3600)
|
131
|
+
end
|
132
|
+
|
133
|
+
def get_http_url(key, expires, options = {})
|
134
|
+
requires :directory
|
135
|
+
object = if directory.key == ''
|
136
|
+
key
|
137
|
+
else
|
138
|
+
directory.key + '/' + key
|
139
|
+
end
|
140
|
+
service.get_object_http_url_public(object, expires, options)
|
141
|
+
end
|
142
|
+
|
143
|
+
def get_https_url(key, expires, options = {})
|
144
|
+
requires :directory
|
145
|
+
object = if directory.key == ''
|
146
|
+
key
|
147
|
+
else
|
148
|
+
directory.key + '/' + key
|
149
|
+
end
|
150
|
+
service.get_object_https_url_public(object, expires, options)
|
151
|
+
end
|
152
|
+
|
153
|
+
def head(key, _options = {})
|
154
|
+
requires :directory
|
155
|
+
object = if directory.key == ''
|
156
|
+
key
|
157
|
+
else
|
158
|
+
directory.key + '/' + key
|
159
|
+
end
|
160
|
+
data = service.head_object(object).data
|
161
|
+
lastModified = data[:headers]['Last-Modified']
|
162
|
+
last_modified = if !lastModified.nil? && lastModified != ''
|
163
|
+
Time.parse(lastModified).localtime
|
164
|
+
end
|
165
|
+
|
166
|
+
date = data[:headers]['Date']
|
167
|
+
date = (Time.parse(date).localtime if !date.nil? && date != '')
|
168
|
+
|
169
|
+
file_data = {
|
170
|
+
content_length: data[:headers]['Content-Length'].to_i,
|
171
|
+
key: key,
|
172
|
+
last_modified: last_modified,
|
173
|
+
content_type: data[:headers]['Content-Type'],
|
174
|
+
etag: data[:headers]['ETag'],
|
175
|
+
date: date,
|
176
|
+
connection: data[:headers]['Connection'],
|
177
|
+
accept_ranges: data[:headers]['Accept-Ranges'],
|
178
|
+
server: data[:headers]['Server'],
|
179
|
+
object_type: data[:headers]['x-oss-object-type']
|
180
|
+
}
|
181
|
+
new(file_data)
|
182
|
+
rescue Fog::Storage::Aliyun::NotFound
|
183
|
+
nil
|
184
|
+
end
|
185
|
+
|
186
|
+
def new(attributes = {})
|
187
|
+
requires :directory
|
188
|
+
super({ directory: directory }.merge!(attributes))
|
189
|
+
end
|
190
|
+
end
|
191
|
+
end
|
192
|
+
end
|
193
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module Fog
|
2
|
+
module Compute
|
3
|
+
class Aliyun
|
4
|
+
class Real
|
5
|
+
# Allocate an eip IP address.
|
6
|
+
#
|
7
|
+
# ==== Notes
|
8
|
+
# The new eip Ip address would be avalable
|
9
|
+
# The allocated eip Ip address can only associate to the instance of the vpc in the same region
|
10
|
+
# Now the eip can support ICMP,TCP,UDP
|
11
|
+
# ==== Parameters
|
12
|
+
# * server_id<~String> - id of the instance
|
13
|
+
# * allocationId<~String> - id of the EIP
|
14
|
+
# ==== Returns
|
15
|
+
# * response<~Excon::Response>:
|
16
|
+
# * body<~Hash>:
|
17
|
+
# * 'EipAddress'<~String> - the allocated eip address
|
18
|
+
# * 'AllocationId'<~String> - the instance id on the public ip
|
19
|
+
# * 'RequestId'<~String> - Id of the request
|
20
|
+
#
|
21
|
+
# {Aliyun API Reference}[https://docs.aliyun.com/?spm=5176.100054.201.106.DGkmH7#/pub/ecs/open-api/network&allocateeipaddress]
|
22
|
+
def allocate_eip_address(options = {})
|
23
|
+
_action = 'AllocateEipAddress'
|
24
|
+
_sigNonce = randonStr
|
25
|
+
_time = Time.new.utc
|
26
|
+
|
27
|
+
_parameters = defalutParameters(_action, _sigNonce, _time)
|
28
|
+
_pathURL = defaultAliyunUri(_action, _sigNonce, _time)
|
29
|
+
|
30
|
+
# optional parameters
|
31
|
+
_Bandwidth = options[:bandwidth]
|
32
|
+
if _Bandwidth
|
33
|
+
_parameters['Bandwidth'] = _Bandwidth
|
34
|
+
_pathURL += '&Bandwidth=' + _Bandwidth
|
35
|
+
end
|
36
|
+
|
37
|
+
_InternetChargeType = options[:internet_charge_type]
|
38
|
+
_InternetChargeType = 'PayByTraffic' unless _InternetChargeType
|
39
|
+
_parameters['InternetChargeType'] = _InternetChargeType
|
40
|
+
_pathURL += '&InternetChargeType=' + _InternetChargeType
|
41
|
+
|
42
|
+
_signature = sign(@aliyun_accesskey_secret, _parameters)
|
43
|
+
_pathURL += '&Signature=' + _signature
|
44
|
+
|
45
|
+
request(
|
46
|
+
expects: [200, 204],
|
47
|
+
method: 'GET',
|
48
|
+
path: _pathURL
|
49
|
+
)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end # aliyun
|
53
|
+
end # compute
|
54
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Fog
|
2
|
+
module Compute
|
3
|
+
class Aliyun
|
4
|
+
class Real
|
5
|
+
# Allocate an avalable public IP address to the given instance.
|
6
|
+
#
|
7
|
+
# ==== Parameters
|
8
|
+
# * server_id<~String> - id of the instance
|
9
|
+
# ==== Returns
|
10
|
+
# * response<~Excon::Response>:
|
11
|
+
# * body<~Hash>:
|
12
|
+
# * 'IpAddress'<~String> - The allocated ip address
|
13
|
+
# * 'RequestId'<~String> - Id of the request
|
14
|
+
#
|
15
|
+
# {Aliyun API Reference}[https://docs.aliyun.com/?spm=5176.100054.201.106.DGkmH7#/pub/ecs/open-api/network&allocatepublicipaddress]
|
16
|
+
def allocate_public_ip_address(server_id)
|
17
|
+
_action = 'AllocatePublicIpAddress'
|
18
|
+
_sigNonce = randonStr
|
19
|
+
_time = Time.new.utc
|
20
|
+
|
21
|
+
_parameters = defalutParameters(_action, _sigNonce, _time)
|
22
|
+
_pathURL = defaultAliyunUri(_action, _sigNonce, _time)
|
23
|
+
|
24
|
+
_parameters['InstanceId'] = server_id
|
25
|
+
_pathURL += '&InstanceId=' + server_id
|
26
|
+
|
27
|
+
_signature = sign(@aliyun_accesskey_secret, _parameters)
|
28
|
+
_pathURL += '&Signature=' + _signature
|
29
|
+
|
30
|
+
request(
|
31
|
+
expects: [200, 204],
|
32
|
+
method: 'GET',
|
33
|
+
path: _pathURL
|
34
|
+
)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end # aliyun
|
38
|
+
end # compute
|
39
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module Fog
|
2
|
+
module Compute
|
3
|
+
class Aliyun
|
4
|
+
class Real
|
5
|
+
# Associate an avalable eip IP address to the given instance.
|
6
|
+
#
|
7
|
+
# ==== Parameters
|
8
|
+
# * server_id<~String> - id of the instance
|
9
|
+
# * allocationId<~String> - id of the EIP
|
10
|
+
# ==== Returns
|
11
|
+
# * response<~Excon::Response>:
|
12
|
+
# * body<~Hash>:
|
13
|
+
# * 'RequestId'<~String> - Id of the request
|
14
|
+
#
|
15
|
+
# {Aliyun API Reference}[https://docs.aliyun.com/?spm=5176.100054.201.106.DGkmH7#/pub/ecs/open-api/network&associateeipaddresss]
|
16
|
+
def associate_eip_address(server_id, allocationId, options = {})
|
17
|
+
_action = 'AssociateEipAddress'
|
18
|
+
_sigNonce = randonStr
|
19
|
+
_time = Time.new.utc
|
20
|
+
|
21
|
+
type = options['instance_type']
|
22
|
+
|
23
|
+
_parameters = defalutParameters(_action, _sigNonce, _time)
|
24
|
+
_pathURL = defaultAliyunUri(_action, _sigNonce, _time)
|
25
|
+
|
26
|
+
_parameters['InstanceId'] = server_id
|
27
|
+
_pathURL += '&InstanceId=' + server_id
|
28
|
+
|
29
|
+
_parameters['AllocationId'] = allocationId
|
30
|
+
_pathURL += '&AllocationId=' + allocationId
|
31
|
+
|
32
|
+
if type
|
33
|
+
_parameters['InstanceType'] = type
|
34
|
+
_pathURL += 'InstanceType=' + type
|
35
|
+
end
|
36
|
+
|
37
|
+
_signature = sign(@aliyun_accesskey_secret, _parameters)
|
38
|
+
_pathURL += '&Signature=' + _signature
|
39
|
+
|
40
|
+
request(
|
41
|
+
expects: [200, 204],
|
42
|
+
method: 'GET',
|
43
|
+
path: _pathURL
|
44
|
+
)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end # aliyun
|
48
|
+
end # compute
|
49
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
module Fog
|
2
|
+
module Compute
|
3
|
+
class Aliyun
|
4
|
+
class Real
|
5
|
+
# Mount a disk.
|
6
|
+
#
|
7
|
+
# ==== Parameters
|
8
|
+
# * instanceId<~String> - id of the instance
|
9
|
+
# * diskId<~String> - id of the disk
|
10
|
+
# * options<~hash>
|
11
|
+
# * :deleteWithInstance - if 'true',the disk will be relese with the instance.else, won't
|
12
|
+
# * :device - if nil, the system will default allocate from /dev/xvdb to /dev/xvdz. default nil
|
13
|
+
# ==== Returns
|
14
|
+
# * response<~Excon::Response>:
|
15
|
+
# * body<~Hash>:
|
16
|
+
# * 'RequestId'<~String> - Id of the request
|
17
|
+
#
|
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 = {})
|
20
|
+
action = 'AttachDisk'
|
21
|
+
sigNonce = randonStr
|
22
|
+
time = Time.new.utc
|
23
|
+
|
24
|
+
parameters = defalutParameters(action, sigNonce, time)
|
25
|
+
pathUrl = defaultAliyunUri(action, sigNonce, time)
|
26
|
+
|
27
|
+
parameters['InstanceId'] = instanceId
|
28
|
+
pathUrl += '&InstanceId='
|
29
|
+
pathUrl += instanceId
|
30
|
+
|
31
|
+
parameters['DiskId'] = diskId
|
32
|
+
pathUrl += '&DiskId='
|
33
|
+
pathUrl += diskId
|
34
|
+
|
35
|
+
deleteWithInstance = options[:deleteWithInstance]
|
36
|
+
device = options[:device]
|
37
|
+
|
38
|
+
deleteWithInstance = 'true' unless deleteWithInstance
|
39
|
+
|
40
|
+
parameters['DeleteWithInstance'] = deleteWithInstance
|
41
|
+
pathUrl += '&DeleteWithInstance='
|
42
|
+
pathUrl += deleteWithInstance
|
43
|
+
|
44
|
+
if device
|
45
|
+
parameters['Device'] = device
|
46
|
+
pathUrl += '&Device='
|
47
|
+
pathUrl += URI.encode(device, '/[^!*\'()\;?:@#&%=+$,{}[]<>`" ')
|
48
|
+
end
|
49
|
+
|
50
|
+
signature = sign(@aliyun_accesskey_secret, parameters)
|
51
|
+
pathUrl += '&Signature='
|
52
|
+
pathUrl += signature
|
53
|
+
|
54
|
+
request(
|
55
|
+
expects: [200, 203],
|
56
|
+
method: 'GET',
|
57
|
+
path: pathUrl
|
58
|
+
)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
class Mock
|
63
|
+
def attach_volume(volume_id, server_id, device)
|
64
|
+
response = Excon::Response.new
|
65
|
+
response.status = 200
|
66
|
+
data = {
|
67
|
+
'id' => volume_id,
|
68
|
+
'volumeId' => volume_id,
|
69
|
+
'serverId' => server_id,
|
70
|
+
'device' => device
|
71
|
+
}
|
72
|
+
self.data[:volumes][volume_id]['attachments'] << data
|
73
|
+
response.body = { 'volumeAttachment' => data }
|
74
|
+
response
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|