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,58 @@
1
+ module Fog
2
+ module Compute
3
+ class Aliyun
4
+ class Real
5
+ # {Aliyun API Reference}[https://docs.aliyun.com/?spm=5176.100054.201.106.DGkmH7#/pub/ecs/open-api/image&deleteimage]
6
+ def delete_image(imageId)
7
+ action = 'DeleteImage'
8
+ sigNonce = randonStr()
9
+ time = Time.new.utc
10
+
11
+ parameters = defalutParameters(action, sigNonce, time)
12
+ pathUrl = defaultAliyunUri(action, sigNonce, time)
13
+
14
+ parameters["ImageId"] = imageId
15
+ pathUrl += '&ImageId='
16
+ pathUrl += imageId
17
+
18
+ signature = sign(@aliyun_accesskey_secret, parameters)
19
+ pathUrl += '&Signature='
20
+ pathUrl += signature
21
+
22
+ request(
23
+ :expects => [200, 203],
24
+ :method => 'GET',
25
+ :path => pathUrl
26
+ )
27
+ end
28
+ end
29
+
30
+ class Mock
31
+ def create_image(server_id, name, metadata={})
32
+ response = Excon::Response.new
33
+ response.status = 202
34
+
35
+ img_id=Fog::Mock.random_numbers(6).to_s
36
+
37
+ data = {
38
+ 'id' => img_id,
39
+ 'server' => {"id"=>"3", "links"=>[{"href"=>"http://nova1:8774/admin/servers/#{server_id}", "rel"=>"bookmark"}]},
40
+ 'links' => [{"href"=>"http://nova1:8774/v1.1/admin/images/#{img_id}", "rel"=>"self"}, {"href"=>"http://nova1:8774/admin/images/#{img_id}", "rel"=>"bookmark"}],
41
+ 'metadata' => metadata || {},
42
+ 'name' => name || "server_#{rand(999)}",
43
+ 'progress' => 0,
44
+ 'status' => 'SAVING',
45
+ 'minDisk' => 0,
46
+ 'minRam' => 0,
47
+ 'updated' => "",
48
+ 'created' => ""
49
+ }
50
+ self.data[:last_modified][:images][data['id']] = Time.now
51
+ self.data[:images][data['id']] = data
52
+ response.body = { 'image' => data }
53
+ response
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,51 @@
1
+ module Fog
2
+ module Compute
3
+ class Aliyun
4
+ class Real
5
+ def delete_security_group(security_group_id)
6
+ # {Aliyun API Reference}[https://docs.aliyun.com/?spm=5176.100054.3.1.DGkmH7#/pub/ecs/open-api/securitygroup&deletesecuritygroup]
7
+ action = 'DeleteSecurityGroup'
8
+ sigNonce = randonStr()
9
+ time = Time.new.utc
10
+
11
+ parameters = defalutParameters(action, sigNonce, time)
12
+ pathUrl = defaultAliyunUri(action, sigNonce, time)
13
+
14
+ if security_group_id
15
+ parameters["SecurityGroupId"] = security_group_id
16
+ pathUrl += '&SecurityGroupId='
17
+ pathUrl += security_group_id
18
+ else
19
+ raise ArgumentError, "Missing required securyti id "
20
+ end
21
+
22
+ signature = sign(@aliyun_accesskey_secret, parameters)
23
+ pathUrl += '&Signature='
24
+ pathUrl += signature
25
+
26
+ request(
27
+ :expects => [200, 203],
28
+ :method => 'GET',
29
+ :path => pathUrl
30
+ )
31
+ end
32
+ end
33
+
34
+ class Mock
35
+ def delete_security_group(security_group_id)
36
+ self.data[:security_groups].delete security_group_id.to_s
37
+
38
+ response = Excon::Response.new
39
+ response.status = 202
40
+ response.headers = {
41
+ "Content-Type" => "text/html; charset=UTF-8",
42
+ "Content-Length" => "0",
43
+ "Date" => Date.new
44
+ }
45
+ response.body = {}
46
+ response
47
+ end
48
+ end # mock
49
+ end # Aliyun
50
+ end # compute
51
+ end #fog
@@ -0,0 +1,85 @@
1
+ module Fog
2
+ module Compute
3
+ class Aliyun
4
+ class Real
5
+ def delete_security_group_ip_rule(securyitgroup_id,sourceCidrIp, nicType, option={})
6
+ # {Aliyun API Reference}[https://docs.aliyun.com/?spm=5176.100054.3.1.DGkmH7#/pub/ecs/open-api/securitygroup&revokesecuritygroup]
7
+ action = 'RevokeSecurityGroup'
8
+ sigNonce = randonStr()
9
+ time = Time.new.utc
10
+
11
+ parameters = defalutParameters(action, sigNonce, time)
12
+ pathUrl = defaultAliyunUri(action, sigNonce, time)
13
+
14
+ parameters["SecurityGroupId"] = securyitgroup_id
15
+ pathUrl += '&SecurityGroupId='
16
+ pathUrl += securyitgroup_id
17
+
18
+ parameters["SourceCidrIp"] = sourceCidrIp
19
+ pathUrl += '&SourceCidrIp='
20
+ pathUrl += URI.encode(sourceCidrIp,'/[^!*\'()\;?:@#&%=+$,{}[]<>`" ')
21
+
22
+ parameters["NicType"] = nicType
23
+ pathUrl += '&NicType='
24
+ pathUrl += nicType
25
+
26
+ portRange = option[:portRange]
27
+ unless portRange
28
+ portRange = '-1/-1'
29
+ end
30
+ parameters["PortRange"] = portRange
31
+ pathUrl += '&PortRange='
32
+ pathUrl += URI.encode(portRange,'/[^!*\'()\;?:@#&%=+$,{}[]<>`" ')
33
+
34
+ protocol = option[:protocol]
35
+ unless protocol
36
+ protocol = 'all'
37
+ end
38
+ parameters["IpProtocol"] = protocol
39
+ pathUrl += '&IpProtocol='
40
+ pathUrl += protocol
41
+
42
+ signature = sign(@aliyun_accesskey_secret, parameters)
43
+ pathUrl += '&Signature='
44
+ pathUrl += signature
45
+
46
+ request(
47
+ :expects => [200, 203],
48
+ :method => 'GET',
49
+ :path => pathUrl
50
+ )
51
+ end
52
+ end
53
+
54
+ class Mock
55
+ def create_security_group_rule(parent_group_id, ip_protocol, from_port, to_port, cidr, group_id=nil)
56
+ parent_group_id = parent_group_id.to_i
57
+ response = Excon::Response.new
58
+ response.status = 200
59
+ response.headers = {
60
+ 'X-Compute-Request-Id' => "req-#{Fog::Mock.random_hex(32)}",
61
+ 'Content-Type' => 'application/json',
62
+ 'Content-Length' => Fog::Mock.random_numbers(3).to_s,
63
+ 'Date' => Date.new
64
+ }
65
+ rule = {
66
+ 'id' => Fog::Mock.random_numbers(2).to_i,
67
+ 'from_port' => from_port,
68
+ 'group' => group_id || {},
69
+ 'ip_protocol' => ip_protocol,
70
+ 'to_port' => to_port,
71
+ 'parent_group_id' => parent_group_id,
72
+ 'ip_range' => {
73
+ 'cidr' => cidr
74
+ }
75
+ }
76
+ self.data[:security_groups][parent_group_id.to_s]['rules'].push(rule)
77
+ response.body = {
78
+ 'security_group_rule' => rule
79
+ }
80
+ response
81
+ end
82
+ end # mock
83
+ end # aliyun
84
+ end # compute
85
+ end # fog
@@ -0,0 +1,86 @@
1
+ module Fog
2
+ module Compute
3
+ class Aliyun
4
+ class Real
5
+ def delete_security_group_sg_rule(securitygroup_id, source_securyitgroup_id, option={})
6
+ # {Aliyun API Reference}[https://docs.aliyun.com/?spm=5176.100054.3.1.DGkmH7#/pub/ecs/open-api/securitygroup&revokesecuritygroup]
7
+ action = 'RevokeSecurityGroup'
8
+ sigNonce = randonStr()
9
+ time = Time.new.utc
10
+
11
+ parameters = defalutParameters(action, sigNonce, time)
12
+ pathUrl = defaultAliyunUri(action, sigNonce, time)
13
+
14
+ parameters["SecurityGroupId"] = securitygroup_id
15
+ pathUrl += '&SecurityGroupId='
16
+ pathUrl += securitygroup_id
17
+
18
+ parameters["SourceGroupId"] = source_securyitgroup_id
19
+ pathUrl += '&SourceGroupId='
20
+ pathUrl += source_securyitgroup_id
21
+
22
+ nicType = 'intranet'
23
+ parameters["NicType"] = nicType
24
+ pathUrl += '&NicType='
25
+ pathUrl += nicType
26
+
27
+ portRange = option[:portRange]
28
+ unless portRange
29
+ portRange = '-1/-1'
30
+ end
31
+ parameters["PortRange"] = portRange
32
+ pathUrl += '&PortRange='
33
+ pathUrl += URI.encode(portRange,'/[^!*\'()\;?:@#&%=+$,{}[]<>`" ')
34
+
35
+ protocol = option[:protocol]
36
+ unless protocol
37
+ protocol = 'all'
38
+ end
39
+ parameters["IpProtocol"] = protocol
40
+ pathUrl += '&IpProtocol='
41
+ pathUrl += protocol
42
+
43
+ signature = sign(@aliyun_accesskey_secret, parameters)
44
+ pathUrl += '&Signature='
45
+ pathUrl += signature
46
+
47
+ request(
48
+ :expects => [200, 203],
49
+ :method => 'GET',
50
+ :path => pathUrl
51
+ )
52
+ end
53
+ end
54
+
55
+ class Mock
56
+ def create_security_group_rule(parent_group_id, ip_protocol, from_port, to_port, cidr, group_id=nil)
57
+ parent_group_id = parent_group_id.to_i
58
+ response = Excon::Response.new
59
+ response.status = 200
60
+ response.headers = {
61
+ 'X-Compute-Request-Id' => "req-#{Fog::Mock.random_hex(32)}",
62
+ 'Content-Type' => 'application/json',
63
+ 'Content-Length' => Fog::Mock.random_numbers(3).to_s,
64
+ 'Date' => Date.new
65
+ }
66
+ rule = {
67
+ 'id' => Fog::Mock.random_numbers(2).to_i,
68
+ 'from_port' => from_port,
69
+ 'group' => group_id || {},
70
+ 'ip_protocol' => ip_protocol,
71
+ 'to_port' => to_port,
72
+ 'parent_group_id' => parent_group_id,
73
+ 'ip_range' => {
74
+ 'cidr' => cidr
75
+ }
76
+ }
77
+ self.data[:security_groups][parent_group_id.to_s]['rules'].push(rule)
78
+ response.body = {
79
+ 'security_group_rule' => rule
80
+ }
81
+ response
82
+ end
83
+ end # mock
84
+ end # aliyun
85
+ end # compute
86
+ end # fog
@@ -0,0 +1,48 @@
1
+ module Fog
2
+ module Compute
3
+ class Aliyun
4
+ class Real
5
+ def delete_server(server_id)
6
+ # {Aliyun API Reference}[https://docs.aliyun.com/?spm=5176.100054.3.1.DGkmH7#/pub/ecs/open-api/instance&deleteinstance]
7
+ _action = 'DeleteInstance'
8
+ _sigNonce = randonStr()
9
+ _time = Time.new.utc
10
+
11
+ _parameters = defalutParameters(_action, _sigNonce, _time)
12
+ _pathURL = defaultAliyunUri(_action, _sigNonce, _time)
13
+
14
+ _parameters['InstanceId']=server_id
15
+ _pathURL += '&InstanceId='+server_id
16
+
17
+ _signature = sign(@aliyun_accesskey_secret, _parameters)
18
+ _pathURL += '&Signature='+_signature
19
+
20
+ request(
21
+ :expects => [200, 204],
22
+ :method => 'GET',
23
+ :path => _pathURL
24
+ )
25
+ end
26
+ end
27
+
28
+ class Mock
29
+ def delete_server(server_id)
30
+ response = Excon::Response.new
31
+ if server = list_servers_detail.body['servers'].find {|_| _['id'] == server_id}
32
+ if server['status'] == 'BUILD'
33
+ response.status = 409
34
+ raise(Excon::Errors.status_error({:expects => 204}, response))
35
+ else
36
+ self.data[:last_modified][:servers].delete(server_id)
37
+ self.data[:servers].delete(server_id)
38
+ response.status = 204
39
+ end
40
+ response
41
+ else
42
+ raise Fog::Compute::OpenStack::NotFound
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,45 @@
1
+ module Fog
2
+ module Compute
3
+ class Aliyun
4
+ class Real
5
+ def delete_snapshoot(snapshotId)
6
+ # {Aliyun API Reference}[https://docs.aliyun.com/?spm=5176.100054.3.1.DGkmH7#/pub/ecs/open-api/snapshot&deletesnapshot]
7
+ action = 'DeleteSnapshot'
8
+ sigNonce = randonStr()
9
+ time = Time.new.utc
10
+
11
+ parameters = defalutParameters(action, sigNonce, time)
12
+ pathUrl = defaultAliyunUri(action, sigNonce, time)
13
+
14
+ parameters["SnapshotId"] = snapshotId
15
+ pathUrl += '&SnapshotId='
16
+ pathUrl += snapshotId
17
+
18
+ signature = sign(@aliyun_accesskey_secret, parameters)
19
+ pathUrl += '&Signature='
20
+ pathUrl += signature
21
+
22
+ request(
23
+ :expects => [200, 203],
24
+ :method => 'GET',
25
+ :path => pathUrl
26
+ )
27
+ end
28
+ end
29
+
30
+ class Mock
31
+ def list_images
32
+ response = Excon::Response.new
33
+ data = list_images_detail.body['images']
34
+ images = []
35
+ for image in data
36
+ images << image.reject { |key, value| !['id', 'name', 'links'].include?(key) }
37
+ end
38
+ response.status = [200, 203][rand(1)]
39
+ response.body = { 'images' => images }
40
+ response
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,52 @@
1
+ module Fog
2
+ module Compute
3
+ class Aliyun
4
+ class Real
5
+ # {Aliyun API Reference}[https://docs.aliyun.com/?spm=5176.100054.3.1.DGkmH7#/pub/ecs/open-api/vpc&deletevpc]
6
+ def delete_vpc(vpc_id)
7
+
8
+ action = 'DeleteVpc'
9
+ sigNonce = randonStr()
10
+ time = Time.new.utc
11
+
12
+ parameters = defalutParameters(action, sigNonce, time)
13
+ pathUrl = defaultAliyunUri(action, sigNonce, time)
14
+
15
+ if vpc_id
16
+ parameters["VpcId"] = vpc_id
17
+ pathUrl += '&VpcId='
18
+ pathUrl += vpc_id
19
+ else
20
+ raise ArgumentError, "Missing required vpc_id"
21
+ end
22
+
23
+ signature = sign(@aliyun_accesskey_secret, parameters)
24
+ pathUrl += '&Signature='
25
+ pathUrl += signature
26
+
27
+ request(
28
+ :expects => [200, 203],
29
+ :method => 'GET',
30
+ :path => pathUrl
31
+ )
32
+ end
33
+ end
34
+
35
+ class Mock
36
+ def delete_security_group(security_group_id)
37
+ self.data[:security_groups].delete security_group_id.to_s
38
+
39
+ response = Excon::Response.new
40
+ response.status = 202
41
+ response.headers = {
42
+ "Content-Type" => "text/html; charset=UTF-8",
43
+ "Content-Length" => "0",
44
+ "Date" => Date.new
45
+ }
46
+ response.body = {}
47
+ response
48
+ end
49
+ end # mock
50
+ end # Aliyun
51
+ end # compute
52
+ end #fog
@@ -0,0 +1,51 @@
1
+ module Fog
2
+ module Compute
3
+ class Aliyun
4
+ class Real
5
+ def delete_vswitch(vswitch_id)
6
+ # {Aliyun API Reference}[https://docs.aliyun.com/?spm=5176.100054.3.1.DGkmH7#/pub/ecs/open-api/vswitch&deletevswitch]
7
+ action = 'DeleteVSwitch'
8
+ sigNonce = randonStr()
9
+ time = Time.new.utc
10
+
11
+ parameters = defalutParameters(action, sigNonce, time)
12
+ pathUrl = defaultAliyunUri(action, sigNonce, time)
13
+
14
+ if vswitch_id
15
+ parameters["VSwitchId"] = vswitch_id
16
+ pathUrl += '&VSwitchId='
17
+ pathUrl += vswitch_id
18
+ else
19
+ raise ArgumentError, "Missing required vswitch_id"
20
+ end
21
+
22
+ signature = sign(@aliyun_accesskey_secret, parameters)
23
+ pathUrl += '&Signature='
24
+ pathUrl += signature
25
+
26
+ request(
27
+ :expects => [200, 203],
28
+ :method => 'GET',
29
+ :path => pathUrl
30
+ )
31
+ end
32
+ end
33
+
34
+ class Mock
35
+ def delete_security_group(security_group_id)
36
+ self.data[:security_groups].delete security_group_id.to_s
37
+
38
+ response = Excon::Response.new
39
+ response.status = 202
40
+ response.headers = {
41
+ "Content-Type" => "text/html; charset=UTF-8",
42
+ "Content-Length" => "0",
43
+ "Date" => Date.new
44
+ }
45
+ response.body = {}
46
+ response
47
+ end
48
+ end # mock
49
+ end # Aliyun
50
+ end # compute
51
+ end #fog