fog-aliyun 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
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,178 @@
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
+ if nil == files
23
+ return
24
+ end
25
+ data = Array.new
26
+ i = 0
27
+ files.each do |file|
28
+ if file["Key"][0][-1] != "/"
29
+ content_length = file["Size"][0].to_i
30
+ key = file["Key"][0]
31
+ lastModified = file["LastModified"][0]
32
+ if lastModified != nil && lastModified != ""
33
+ last_modified = (Time.parse(lastModified)).localtime
34
+ else
35
+ last_modified = nil
36
+ end
37
+ data[i] = {:content_length => content_length,
38
+ :key => key,
39
+ :last_modified => last_modified,
40
+ :etag => file["ETag"][0]}
41
+ i = i + 1
42
+ end
43
+ end
44
+
45
+ load(data)
46
+
47
+ end
48
+
49
+ alias_method :each_file_this_page, :each
50
+ def each
51
+ if !block_given?
52
+ self
53
+ else
54
+ subset = dup.all
55
+
56
+ subset.each_file_this_page {|f| yield f}
57
+ while subset.length == (subset.limit || 10000)
58
+ subset = subset.all(:marker => subset.last.key)
59
+ subset.each_file_this_page {|f| yield f}
60
+ end
61
+
62
+ self
63
+ end
64
+ end
65
+
66
+ def get(key, &block)
67
+ requires :directory
68
+ if directory.key == ""
69
+ object = key
70
+ else
71
+ object = directory.key+"/"+key
72
+ end
73
+
74
+ data = service.head_object(object).data
75
+ contentLen = data[:headers]["Content-Length"].to_i
76
+ if data[:status] != 200
77
+ return nil
78
+ end
79
+ lastModified = data[:headers]["Last-Modified"]
80
+ if lastModified != nil && lastModified != ""
81
+ last_modified = (Time.parse(lastModified)).localtime
82
+ else
83
+ last_modified = nil
84
+ end
85
+
86
+
87
+ file_data = {
88
+ :content_length => contentLen,
89
+ :key => key,
90
+ :last_modified => last_modified,
91
+ :content_type => data[:headers]["Content-Type"],
92
+ :etag => data[:headers]["ETag"]
93
+ }
94
+
95
+ if block_given?
96
+ pagesNum = (contentLen + Excon::CHUNK_SIZE - 1)/Excon::CHUNK_SIZE
97
+
98
+ for i in 1..pagesNum
99
+ _start = (i-1)*(Excon::CHUNK_SIZE)
100
+ _end = i*(Excon::CHUNK_SIZE) - 1
101
+ range = "#{_start}-#{_end}"
102
+ chunk = service.get_object(object, range)[:body]
103
+ yield(chunk)
104
+ end
105
+ new(file_data)
106
+ else
107
+ data = service.get_object(object)
108
+ file_data.merge!(:body => data[:body])
109
+ new(file_data)
110
+ end
111
+
112
+ end
113
+
114
+ def get_url(key)
115
+ requires :directory
116
+ if directory.key == ""
117
+ object = key
118
+ else
119
+ object = directory.key+"/"+key
120
+ end
121
+ service.get_object_http_url_public(object, 3600)
122
+ end
123
+
124
+ def get_http_url(key, expires, options = {})
125
+ requires :directory
126
+ if directory.key == ""
127
+ object = key
128
+ else
129
+ object = directory.key+"/"+key
130
+ end
131
+ service.get_object_http_url_public(object, expires, options)
132
+ end
133
+
134
+ def get_https_url(key, expires, options = {})
135
+ requires :directory
136
+ if directory.key == ""
137
+ object = key
138
+ else
139
+ object = directory.key+"/"+key
140
+ end
141
+ service.get_object_https_url_public(object, expires, options)
142
+ end
143
+
144
+ def head(key, options = {})
145
+ requires :directory
146
+ if directory.key == ""
147
+ object = key
148
+ else
149
+ object = directory.key+"/"+key
150
+ end
151
+ data = service.head_object(object).data
152
+ lastModified = data[:headers]["Last-Modified"]
153
+ if lastModified != nil && lastModified != ""
154
+ last_modified = (Time.parse(lastModified)).localtime
155
+ else
156
+ last_modified = nil
157
+ end
158
+
159
+ file_data = {
160
+ :content_length => data[:headers]["Content-Length"].to_i,
161
+ :key => key,
162
+ :last_modified => last_modified,
163
+ :content_type => data[:headers]["Content-Type"],
164
+ :etag => data[:headers]["ETag"]
165
+ }
166
+ new(file_data)
167
+ rescue Fog::Storage::Aliyun::NotFound
168
+ nil
169
+ end
170
+
171
+ def new(attributes = {})
172
+ requires :directory
173
+ super({ :directory => directory }.merge!(attributes))
174
+ end
175
+ end
176
+ end
177
+ end
178
+ end
@@ -0,0 +1,79 @@
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
+
24
+ _action = 'AllocateEipAddress'
25
+ _sigNonce = randonStr()
26
+ _time = Time.new.utc
27
+
28
+ _parameters = defalutParameters(_action, _sigNonce, _time)
29
+ _pathURL = defaultAliyunUri(_action, _sigNonce, _time)
30
+
31
+ #optional parameters
32
+ _Bandwidth = options[:aliyun_Bandwidth]
33
+ if _Bandwidth
34
+ _parameters['Bandwidth']=_Bandwidth
35
+ _pathURL += '&Bandwidth='+_Bandwidth
36
+ end
37
+
38
+ _InternetChargeType = options[:aliyun_InternetChargeType]
39
+ if _InternetChargeType
40
+ _parameters['InternetChargeType']=_InternetChargeType
41
+ _pathURL += '&InternetChargeType='+_InternetChargeType
42
+ end
43
+
44
+ _signature = sign(@aliyun_accesskey_secret, _parameters)
45
+ _pathURL += '&Signature='+_signature
46
+
47
+ request(
48
+ :expects => [200, 204],
49
+ :method => 'GET',
50
+ :path => _pathURL
51
+ )
52
+ end
53
+ end
54
+
55
+ class Mock
56
+ def allocate_address(pool = nil)
57
+ response = Excon::Response.new
58
+ response.status = 200
59
+ response.headers = {
60
+ "X-Compute-Request-Id" => "req-d4a21158-a86c-44a6-983a-e25645907f26",
61
+ "Content-Type" => "application/json",
62
+ "Content-Length" => "105",
63
+ "Date"=> Date.new
64
+ }
65
+ response.body = {
66
+ "floating_ip" => {
67
+ "instance_id" => nil,
68
+ "ip" => "192.168.27.132",
69
+ "fixed_ip" => nil,
70
+ "id" => 4,
71
+ "pool"=>"nova"
72
+ }
73
+ }
74
+ response
75
+ end
76
+ end # mock
77
+ end # aliyun
78
+ end #compute
79
+ end
@@ -0,0 +1,63 @@
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
+
18
+ _action = 'AllocatePublicIpAddress'
19
+ _sigNonce = randonStr()
20
+ _time = Time.new.utc
21
+
22
+ _parameters = defalutParameters(_action, _sigNonce, _time)
23
+ _pathURL = defaultAliyunUri(_action, _sigNonce, _time)
24
+
25
+ _parameters['InstanceId']=server_id
26
+ _pathURL += '&InstanceId='+server_id
27
+
28
+ _signature = sign(@aliyun_accesskey_secret, _parameters)
29
+ _pathURL += '&Signature='+_signature
30
+
31
+ request(
32
+ :expects => [200, 204],
33
+ :method => 'GET',
34
+ :path => _pathURL
35
+ )
36
+ end
37
+ end
38
+
39
+ class Mock
40
+ def allocate_address(pool = nil)
41
+ response = Excon::Response.new
42
+ response.status = 200
43
+ response.headers = {
44
+ "X-Compute-Request-Id" => "req-d4a21158-a86c-44a6-983a-e25645907f26",
45
+ "Content-Type" => "application/json",
46
+ "Content-Length" => "105",
47
+ "Date"=> Date.new
48
+ }
49
+ response.body = {
50
+ "floating_ip" => {
51
+ "instance_id" => nil,
52
+ "ip" => "192.168.27.132",
53
+ "fixed_ip" => nil,
54
+ "id" => 4,
55
+ "pool"=>"nova"
56
+ }
57
+ }
58
+ response
59
+ end
60
+ end # mock
61
+ end # aliyun
62
+ end #compute
63
+ end
@@ -0,0 +1,66 @@
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)
17
+
18
+ _action = 'AssociateEipAddress'
19
+ _sigNonce = randonStr()
20
+ _time = Time.new.utc
21
+
22
+ _parameters = defalutParameters(_action, _sigNonce, _time)
23
+ _pathURL = defaultAliyunUri(_action, _sigNonce, _time)
24
+
25
+ _parameters['InstanceId'] = server_id
26
+ _pathURL += '&InstanceId='+server_id
27
+
28
+ _parameters['AllocationId'] = allocationId
29
+ _pathURL += '&AllocationId='+allocationId
30
+
31
+ _signature = sign(@aliyun_accesskey_secret, _parameters)
32
+ _pathURL += '&Signature='+_signature
33
+
34
+ request(
35
+ :expects => [200, 204],
36
+ :method => 'GET',
37
+ :path => _pathURL
38
+ )
39
+ end
40
+ end
41
+
42
+ class Mock
43
+ def allocate_address(pool = nil)
44
+ response = Excon::Response.new
45
+ response.status = 200
46
+ response.headers = {
47
+ "X-Compute-Request-Id" => "req-d4a21158-a86c-44a6-983a-e25645907f26",
48
+ "Content-Type" => "application/json",
49
+ "Content-Length" => "105",
50
+ "Date"=> Date.new
51
+ }
52
+ response.body = {
53
+ "floating_ip" => {
54
+ "instance_id" => nil,
55
+ "ip" => "192.168.27.132",
56
+ "fixed_ip" => nil,
57
+ "id" => 4,
58
+ "pool"=>"nova"
59
+ }
60
+ }
61
+ response
62
+ end
63
+ end # mock
64
+ end # Aliyun
65
+ end #compute
66
+ end
@@ -0,0 +1,82 @@
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
+ unless deleteWithInstance
39
+ deleteWithInstance = 'true'
40
+ end
41
+
42
+ parameters["DeleteWithInstance"] = deleteWithInstance
43
+ pathUrl += '&DeleteWithInstance='
44
+ pathUrl += deleteWithInstance
45
+
46
+
47
+ if device
48
+ parameters["Device"] = device
49
+ pathUrl += '&Device='
50
+ pathUrl += URI.encode(device,'/[^!*\'()\;?:@#&%=+$,{}[]<>`" ')
51
+ end
52
+
53
+ signature = sign(@aliyun_accesskey_secret, parameters)
54
+ pathUrl += '&Signature='
55
+ pathUrl += signature
56
+
57
+ request(
58
+ :expects => [200, 203],
59
+ :method => 'GET',
60
+ :path => pathUrl
61
+ )
62
+ end
63
+ end
64
+
65
+ class Mock
66
+ def attach_volume(volume_id, server_id, device)
67
+ response = Excon::Response.new
68
+ response.status = 200
69
+ data = {
70
+ 'id' => volume_id,
71
+ 'volumeId' => volume_id,
72
+ 'serverId' => server_id,
73
+ 'device' => device
74
+ }
75
+ self.data[:volumes][volume_id]['attachments'] << data
76
+ response.body = { 'volumeAttachment' => data }
77
+ response
78
+ end
79
+ end
80
+ end
81
+ end
82
+ end