fog-aliyun 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +10 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +4 -0
  5. data/CODE_OF_CONDUCT.md +13 -0
  6. data/Gemfile +4 -0
  7. data/LICENSE.txt +21 -0
  8. data/README.md +309 -0
  9. data/Rakefile +6 -0
  10. data/bin/console +14 -0
  11. data/bin/setup +7 -0
  12. data/fog-aliyun.gemspec +30 -0
  13. data/lib/fog/aliyun.rb +19 -0
  14. data/lib/fog/aliyun/compute.rb +346 -0
  15. data/lib/fog/aliyun/models/compute/vpc.rb +69 -0
  16. data/lib/fog/aliyun/models/compute/vpcs.rb +89 -0
  17. data/lib/fog/aliyun/models/compute/vswitch.rb +70 -0
  18. data/lib/fog/aliyun/models/compute/vswitches.rb +87 -0
  19. data/lib/fog/aliyun/models/storage/directories.rb +45 -0
  20. data/lib/fog/aliyun/models/storage/directory.rb +48 -0
  21. data/lib/fog/aliyun/models/storage/file.rb +197 -0
  22. data/lib/fog/aliyun/models/storage/files.rb +178 -0
  23. data/lib/fog/aliyun/requests/compute/allocate_eip_address.rb +79 -0
  24. data/lib/fog/aliyun/requests/compute/allocate_public_ip_address.rb +63 -0
  25. data/lib/fog/aliyun/requests/compute/associate_eip_address.rb +66 -0
  26. data/lib/fog/aliyun/requests/compute/attach_disk.rb +82 -0
  27. data/lib/fog/aliyun/requests/compute/create_disk.rb +135 -0
  28. data/lib/fog/aliyun/requests/compute/create_image.rb +79 -0
  29. data/lib/fog/aliyun/requests/compute/create_security_group.rb +77 -0
  30. data/lib/fog/aliyun/requests/compute/create_security_group_ip_rule.rb +86 -0
  31. data/lib/fog/aliyun/requests/compute/create_security_group_sg_rule.rb +86 -0
  32. data/lib/fog/aliyun/requests/compute/create_server.rb +188 -0
  33. data/lib/fog/aliyun/requests/compute/create_snapshot.rb +60 -0
  34. data/lib/fog/aliyun/requests/compute/create_vpc.rb +73 -0
  35. data/lib/fog/aliyun/requests/compute/create_vswitch.rb +81 -0
  36. data/lib/fog/aliyun/requests/compute/delete_disk.rb +58 -0
  37. data/lib/fog/aliyun/requests/compute/delete_image.rb +58 -0
  38. data/lib/fog/aliyun/requests/compute/delete_security_group.rb +51 -0
  39. data/lib/fog/aliyun/requests/compute/delete_security_group_ip_rule.rb +85 -0
  40. data/lib/fog/aliyun/requests/compute/delete_security_group_sg_rule.rb +86 -0
  41. data/lib/fog/aliyun/requests/compute/delete_server.rb +48 -0
  42. data/lib/fog/aliyun/requests/compute/delete_snapshot.rb +45 -0
  43. data/lib/fog/aliyun/requests/compute/delete_vpc.rb +52 -0
  44. data/lib/fog/aliyun/requests/compute/delete_vswitch.rb +51 -0
  45. data/lib/fog/aliyun/requests/compute/detach_disk.rb +51 -0
  46. data/lib/fog/aliyun/requests/compute/join_security_group.rb +41 -0
  47. data/lib/fog/aliyun/requests/compute/leave_security_group.rb +41 -0
  48. data/lib/fog/aliyun/requests/compute/list_disks.rb +75 -0
  49. data/lib/fog/aliyun/requests/compute/list_eip_addresses.rb +81 -0
  50. data/lib/fog/aliyun/requests/compute/list_images.rb +85 -0
  51. data/lib/fog/aliyun/requests/compute/list_security_group_rules.rb +74 -0
  52. data/lib/fog/aliyun/requests/compute/list_security_groups.rb +81 -0
  53. data/lib/fog/aliyun/requests/compute/list_server_types.rb +77 -0
  54. data/lib/fog/aliyun/requests/compute/list_servers.rb +74 -0
  55. data/lib/fog/aliyun/requests/compute/list_snapshots.rb +86 -0
  56. data/lib/fog/aliyun/requests/compute/list_vpcs.rb +64 -0
  57. data/lib/fog/aliyun/requests/compute/list_vswitchs.rb +67 -0
  58. data/lib/fog/aliyun/requests/compute/list_zones.rb +44 -0
  59. data/lib/fog/aliyun/requests/compute/modify_vpc.rb +73 -0
  60. data/lib/fog/aliyun/requests/compute/modify_vswitch.rb +73 -0
  61. data/lib/fog/aliyun/requests/compute/reboot_server.rb +44 -0
  62. data/lib/fog/aliyun/requests/compute/release_eip_address.rb +53 -0
  63. data/lib/fog/aliyun/requests/compute/start_server.rb +42 -0
  64. data/lib/fog/aliyun/requests/compute/stop_server.rb +42 -0
  65. data/lib/fog/aliyun/requests/compute/unassociate_eip_address.rb +56 -0
  66. data/lib/fog/aliyun/requests/storage/copy_object.rb +42 -0
  67. data/lib/fog/aliyun/requests/storage/delete_bucket.rb +30 -0
  68. data/lib/fog/aliyun/requests/storage/delete_container.rb +38 -0
  69. data/lib/fog/aliyun/requests/storage/delete_object.rb +53 -0
  70. data/lib/fog/aliyun/requests/storage/get_bucket.rb +148 -0
  71. data/lib/fog/aliyun/requests/storage/get_container.rb +72 -0
  72. data/lib/fog/aliyun/requests/storage/get_containers.rb +76 -0
  73. data/lib/fog/aliyun/requests/storage/get_object.rb +45 -0
  74. data/lib/fog/aliyun/requests/storage/get_object_http_url.rb +43 -0
  75. data/lib/fog/aliyun/requests/storage/get_object_https_url.rb +43 -0
  76. data/lib/fog/aliyun/requests/storage/head_object.rb +34 -0
  77. data/lib/fog/aliyun/requests/storage/list_buckets.rb +47 -0
  78. data/lib/fog/aliyun/requests/storage/list_objects.rb +104 -0
  79. data/lib/fog/aliyun/requests/storage/put_bucket.rb +23 -0
  80. data/lib/fog/aliyun/requests/storage/put_container.rb +35 -0
  81. data/lib/fog/aliyun/requests/storage/put_object.rb +199 -0
  82. data/lib/fog/aliyun/storage.rb +214 -0
  83. data/lib/fog/aliyun/version.rb +5 -0
  84. data/lib/fog/bin/aliyun.rb +31 -0
  85. metadata +227 -0
@@ -0,0 +1,70 @@
1
+ require 'fog/core/model'
2
+ module Fog
3
+ module Compute
4
+ class Aliyun
5
+ class Vswitch < Fog::Model
6
+ identity :id, :aliases => 'VSwitchId'
7
+ attribute :vpc_id, :aliases => 'VpcId'
8
+ attribute :zone_id, :aliases => 'ZoneId'
9
+ attribute :name, :aliases => 'VSwitchName'
10
+ attribute :available_ip_count, :aliases => 'AvailableIpAddressCount'
11
+ attribute :state, :aliases => 'Status'
12
+ attribute :cidr_block, :aliases => 'CidrBlock'
13
+ attribute :description, :aliases => 'Description'
14
+ attribute :region_id, :aliases => 'RegionId'
15
+ attribute :creation_time, :aliases => 'CreationTime'
16
+ def initialize(attributes={})
17
+ super
18
+ end
19
+
20
+ def ready?
21
+ requires :state
22
+ state == 'Available'
23
+ end
24
+
25
+ # Removes an existing vpc
26
+ #
27
+ # vpc.destroy
28
+ #
29
+ # ==== Returns
30
+ #
31
+ # True or false depending on the result
32
+ #
33
+
34
+ def destroy
35
+ requires :id
36
+
37
+ service.delete_vswitch(id)
38
+ true
39
+ end
40
+
41
+ # Create a vpc
42
+ #
43
+ # >> g = Aliyun.vpcs.new(:cidr_block => "10.1.2.0/24")
44
+ # >> g.save
45
+ #
46
+ # == Returns:
47
+ #
48
+ # True or an exception depending on the result. Keep in mind that this *creates* a new vpc.
49
+ # As such, it yields an InvalidGroup.Duplicate exception if you attempt to save an existing vpc.
50
+ #
51
+
52
+ def save(options={})
53
+ requires :vpc,:cidr_block
54
+ data = Fog::JSON.decode(service.create_vswitch(vpc.id, cidr_block,options).body)
55
+
56
+ true
57
+ end
58
+
59
+ def vpc
60
+ $vpc
61
+ end
62
+
63
+ def all()
64
+ data = Fog::JSON.decode(service.list_vswitchs(vpc_id).body)['VSwitches']['VSwitch']
65
+ end
66
+
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,87 @@
1
+ require 'fog/core/collection'
2
+ require 'fog/aliyun/models/compute/vswitch'
3
+
4
+ module Fog
5
+ module Compute
6
+ class Aliyun
7
+ class Vswitches < Fog::Collection
8
+ attribute :vpc
9
+ attribute :filters
10
+
11
+ model Fog::Compute::Aliyun::Vswitch
12
+
13
+ # Creates a new VPC
14
+ #
15
+ # Aliyun.vpcs.new
16
+ #
17
+ # ==== Returns
18
+ #
19
+ # Returns the details of the new VPC
20
+ #
21
+ #>> Aliyun.vpcs.new
22
+ # <Fog::Aliyun::VPC::VPC
23
+ # id=nil,
24
+ # state=nil,
25
+ # cidr_block=nil,
26
+ # dhcp_options_id=nil
27
+ # tags=nil
28
+ # tenancy=nil
29
+ # >
30
+ #
31
+
32
+ def initialize(attributes)
33
+ self.filters ||={}
34
+ super
35
+ end
36
+
37
+ # Returns an array of all VPCs that have been created
38
+ #
39
+ # Aliyun.vpcs.all
40
+ #
41
+ # ==== Returns
42
+ #
43
+ # Returns an array of all VPCs
44
+ #
45
+ #>> Aliyun.vpcs.all
46
+ # <Fog::Aliyun::VPC::VPCs
47
+ # filters={}
48
+ # [
49
+ # <Fog::Aliyun::VPC::VPC
50
+ # id="vpc-12345678",
51
+ # TODO
52
+ # >
53
+ # ]
54
+ # >
55
+ #
56
+
57
+ def all(options={})
58
+ requires :vpc
59
+ data = Fog::JSON.decode(service.list_vswitchs(vpc.id, options).body)['VSwitches']['VSwitch']
60
+ load(data)
61
+ end
62
+
63
+ # Used to retrieve a VPC
64
+ # vpc_id is required to get the associated VPC information.
65
+ #
66
+ # You can run the following command to get the details:
67
+ # Aliyun.vpcs.get("vpc-12345678")
68
+ #
69
+ # ==== Returns
70
+ #
71
+ #>> Aliyun.vpcs.get("vpc-12345678")
72
+ # <Fog::Aliyun::Compute::VPC
73
+ # id="vpc-12345678",
74
+ # TODO
75
+ # >
76
+ #
77
+
78
+ def get(vswitchId)
79
+ requires :vpc
80
+ if vswitchId
81
+ self.class.new(:service => service,:vpc=>vpc).all(:vSwitchId=>vswitchId)[0]
82
+ end
83
+ end
84
+ end
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,45 @@
1
+ require 'fog/core/collection'
2
+ require 'fog/aliyun/models/storage/directory'
3
+
4
+ module Fog
5
+ module Storage
6
+ class Aliyun
7
+ class Directories < Fog::Collection
8
+ model Fog::Storage::Aliyun::Directory
9
+
10
+ def all
11
+ containers = service.get_containers()
12
+ if nil == containers
13
+ return nil
14
+ end
15
+ data = Array.new
16
+ i = 0
17
+ containers.each do |entry|
18
+ key = entry["Prefix"][0]
19
+ key[-1] = ''
20
+ data[i] = {:key=>key}
21
+ i = i + 1
22
+ end
23
+
24
+ load(data)
25
+ end
26
+
27
+ def get(key, options = {})
28
+ if key != nil && key != "" && key != '.'
29
+ dir = key+'/'
30
+ ret = service.head_object(dir, options)
31
+ if ret.data[:status] == 200
32
+ new(:key => key)
33
+ else
34
+ nil
35
+ end
36
+ else
37
+ new(:key => "")
38
+ end
39
+ rescue Fog::Storage::Aliyun::NotFound
40
+ nil
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,48 @@
1
+ require 'fog/core/model'
2
+ require 'fog/aliyun/models/storage/files'
3
+
4
+ module Fog
5
+ module Storage
6
+ class Aliyun
7
+ class Directory < Fog::Model
8
+ identity :key
9
+
10
+ def destroy
11
+ requires :key
12
+ prefix = key+'/'
13
+ ret = service.list_objects(:prefix=>prefix)["Contents"]
14
+
15
+ if ret.nil?
16
+ puts " Not found: Direction not exist!"
17
+ false
18
+ elsif ret.size == 1
19
+ service.delete_container(key)
20
+ true
21
+ else
22
+ raise Fog::Storage::Aliyun::Error, " Forbidden: Direction not empty!"
23
+ false
24
+ end
25
+ end
26
+
27
+ def files
28
+ @files ||= begin
29
+ Fog::Storage::Aliyun::Files.new(
30
+ :directory => self,
31
+ :service => service
32
+ )
33
+ end
34
+ end
35
+
36
+ def public_url
37
+ nil
38
+ end
39
+
40
+ def save
41
+ requires :key
42
+ service.put_container(key)
43
+ true
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,197 @@
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
+
9
+ attribute :access_control_allow_origin, :aliases => ['Access-Control-Allow-Origin']
10
+ attribute :content_length, :aliases => ['bytes', 'Content-Length'], :type => :integer
11
+ attribute :content_type, :aliases => ['content_type', 'Content-Type']
12
+ attribute :content_disposition, :aliases => ['content_disposition', 'Content-Disposition']
13
+ attribute :etag, :aliases => ['hash', 'Etag']
14
+ attribute :last_modified, :aliases => ['last_modified', 'Last-Modified'], :type => :time
15
+ attribute :metadata
16
+ attribute :origin, :aliases => ['Origin']
17
+
18
+ def body
19
+ attributes[:body] ||= if last_modified
20
+ collection.get(identity).body
21
+ else
22
+ ''
23
+ end
24
+ end
25
+
26
+ def body=(new_body)
27
+ attributes[:body] = new_body
28
+ end
29
+
30
+ def directory
31
+ @directory
32
+ end
33
+
34
+ def copy(target_directory_key, target_file_key, options={})
35
+ requires :directory, :key
36
+ if directory.key == ""
37
+ source_object = key
38
+ else
39
+ source_object = directory.key+"/"+key
40
+ end
41
+ if target_directory_key == ""
42
+ target_object = target_file_key
43
+ else
44
+ target_object = target_directory_key+"/"+target_file_key
45
+ end
46
+ service.copy_object(nil, source_object, nil, target_object, options)
47
+ target_directory = service.directories.new(:key => target_directory_key)
48
+ target_directory.files.get(target_file_key)
49
+ end
50
+
51
+ def destroy
52
+ requires :directory, :key
53
+ if directory.key == ""
54
+ object = key
55
+ else
56
+ object = directory.key+"/"+key
57
+ end
58
+ service.delete_object(object)
59
+ true
60
+ end
61
+
62
+ def metadata
63
+ attributes[:metadata] ||= headers_to_metadata
64
+ end
65
+
66
+ def owner=(new_owner)
67
+ if new_owner
68
+ attributes[:owner] = {
69
+ :display_name => new_owner['DisplayName'],
70
+ :id => new_owner['ID']
71
+ }
72
+ end
73
+ end
74
+
75
+ def public=(new_public)
76
+ new_public
77
+ end
78
+
79
+ # Get a url for file.
80
+ #
81
+ # required attributes: directory, key
82
+ #
83
+ # @param expires [String] number of seconds (since 1970-01-01 00:00) before url expires
84
+ # @param options [Hash]
85
+ # @return [String] url
86
+ #
87
+ def url(expires, options = {})
88
+ requires :directory, :key
89
+ if directory.key == ""
90
+ object = key
91
+ else
92
+ object = directory.key+"/"+key
93
+ end
94
+ self.service.get_object_http_url_public(object, expires, options)
95
+ end
96
+
97
+ def public_url
98
+ requires :key
99
+ self.collection.get_url(self.key)
100
+ end
101
+
102
+ def save(options = {})
103
+ requires :body, :directory, :key
104
+ options['Content-Type'] = content_type if content_type
105
+ options['Content-Disposition'] = content_disposition if content_disposition
106
+ options['Access-Control-Allow-Origin'] = access_control_allow_origin if access_control_allow_origin
107
+ options['Origin'] = origin if origin
108
+ options.merge!(metadata_to_headers)
109
+
110
+ if directory.key == ""
111
+ object = key
112
+ else
113
+ object = directory.key+"/"+key
114
+ end
115
+ if body.is_a?(::File)
116
+ data = service.put_object(object, body, options).data
117
+ elsif body.is_a?(String)
118
+ data = service.put_object_with_body(object, body, options).data
119
+ else
120
+ raise Fog::Storage::Aliyun::Error, " Forbidden: Invalid body type: #{body.class}!"
121
+ end
122
+ update_attributes_from(data)
123
+ refresh_metadata
124
+
125
+ self.content_length = Fog::Storage.get_body_size(body)
126
+ self.content_type ||= Fog::Storage.get_content_type(body)
127
+ true
128
+ end
129
+
130
+ private
131
+
132
+ def directory=(new_directory)
133
+ @directory = new_directory
134
+ end
135
+
136
+ def refresh_metadata
137
+ metadata.reject! {|k, v| v.nil? }
138
+ end
139
+
140
+ def headers_to_metadata
141
+ key_map = key_mapping
142
+ Hash[metadata_attributes.map {|k, v| [key_map[k], v] }]
143
+ end
144
+
145
+ def key_mapping
146
+ key_map = metadata_attributes
147
+ key_map.each_pair {|k, v| key_map[k] = header_to_key(k)}
148
+ end
149
+
150
+ def header_to_key(opt)
151
+ opt.gsub(metadata_prefix, '').split('-').map {|k| k[0, 1].downcase + k[1..-1]}.join('_').to_sym
152
+ end
153
+
154
+ def metadata_to_headers
155
+ header_map = header_mapping
156
+ Hash[metadata.map {|k, v| [header_map[k], v] }]
157
+ end
158
+
159
+ def header_mapping
160
+ header_map = metadata.dup
161
+ header_map.each_pair {|k, v| header_map[k] = key_to_header(k)}
162
+ end
163
+
164
+ def key_to_header(key)
165
+ metadata_prefix + key.to_s.split(/[-_]/).map(&:capitalize).join('-')
166
+ end
167
+
168
+ def metadata_attributes
169
+ if last_modified
170
+ if directory.key == ""
171
+ object = key
172
+ else
173
+ object = directory.key+"/"+key
174
+ end
175
+
176
+ headers = service.head_object(object).data[:headers]
177
+ headers.reject! {|k, v| !metadata_attribute?(k)}
178
+ else
179
+ {}
180
+ end
181
+ end
182
+
183
+ def metadata_attribute?(key)
184
+ key.to_s =~ /^#{metadata_prefix}/
185
+ end
186
+
187
+ def metadata_prefix
188
+ "X-Object-Meta-"
189
+ end
190
+
191
+ def update_attributes_from(data)
192
+ merge_attributes(data[:headers].reject {|key, value| ['Content-Length', 'Content-Type'].include?(key)})
193
+ end
194
+ end
195
+ end
196
+ end
197
+ end