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,135 @@
1
+ module Fog
2
+ module Compute
3
+ class Aliyun
4
+ class Real
5
+ # Create a disk.
6
+ #
7
+ # ==== Parameters
8
+ # * size<~String> - the size of the disk (GB).
9
+ # * options<~hash>
10
+ # * :name - The name of the disk,default nil. If not nil, it must start with english or chinise character.
11
+ # The length should be within [2,128]. It can contain digits,'.','_'or'-'.It shouldn't start with 'http://' or 'https://'
12
+ # * :description - The name of the disk,default nil. If not nil, the length should be within [2,255].It shouldn't start with 'http://' or 'https://'
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&createdisk]
19
+ def create_disk(size, options={})
20
+
21
+ action = 'CreateDisk'
22
+ sigNonce = randonStr()
23
+ time = Time.new.utc
24
+
25
+ parameters = defalutParameters(action, sigNonce, time)
26
+ pathUrl = defaultAliyunUri(action, sigNonce, time)
27
+
28
+ parameters["ZoneId"] = @aliyun_zone_id
29
+ pathUrl += '&ZoneId='
30
+ pathUrl += @aliyun_zone_id
31
+
32
+ parameters["Size"] = size
33
+ pathUrl += '&Size='
34
+ pathUrl += size
35
+
36
+ name = options[:name]
37
+ desc = options[:description]
38
+
39
+ if name
40
+ parameters["DiskName"] = name
41
+ pathUrl += '&DiskName='
42
+ pathUrl += name
43
+ end
44
+
45
+ if desc
46
+ parameters["Description"] = desc
47
+ pathUrl += '&Description='
48
+ pathUrl += desc
49
+ end
50
+
51
+ signature = sign(@aliyun_accesskey_secret, parameters)
52
+ pathUrl += '&Signature='
53
+ pathUrl += signature
54
+
55
+ request(
56
+ :expects => [200, 203],
57
+ :method => 'GET',
58
+ :path => pathUrl
59
+ )
60
+ end
61
+
62
+ def create_disk_by_snapshot(snapshotId, options={})
63
+
64
+ action = 'CreateDisk'
65
+ sigNonce = randonStr()
66
+ time = Time.new.utc
67
+
68
+ parameters = defalutParameters(action, sigNonce, time)
69
+ pathUrl = defaultAliyunUri(action, sigNonce, time)
70
+
71
+ parameters["ZoneId"] = @aliyun_zone_id
72
+ pathUrl += '&ZoneId='
73
+ pathUrl += @aliyun_zone_id
74
+
75
+ parameters["SnapshotId"] = snapshotId
76
+ pathUrl += '&SnapshotId='
77
+ pathUrl += snapshotId
78
+
79
+ name = options[:name]
80
+ desc = options[:description]
81
+
82
+ if name
83
+ parameters["DiskName"] = name
84
+ pathUrl += '&DiskName='
85
+ pathUrl += name
86
+ end
87
+
88
+ if desc
89
+ parameters["Description"] = desc
90
+ pathUrl += '&Description='
91
+ pathUrl += desc
92
+ end
93
+
94
+ signature = sign(@aliyun_accesskey_secret, parameters)
95
+ pathUrl += '&Signature='
96
+ pathUrl += signature
97
+
98
+ request(
99
+ :expects => [200, 203],
100
+ :method => 'GET',
101
+ :path => pathUrl
102
+ )
103
+ end
104
+
105
+ end
106
+
107
+ class Mock
108
+ def create_security_group(name, description)
109
+ Fog::Identity::OpenStack.new(:openstack_auth_url => credentials[:openstack_auth_url])
110
+ tenant_id = Fog::Identity::OpenStack::V2::Mock.data[current_tenant][:tenants].keys.first
111
+ security_group_id = Fog::Mock.random_numbers(2).to_i + 1
112
+ self.data[:security_groups][security_group_id.to_s] = {
113
+ 'tenant_id' => tenant_id,
114
+ 'rules' => [],
115
+ 'id' => security_group_id,
116
+ 'name' => name,
117
+ 'description' => description
118
+ }
119
+
120
+ response = Excon::Response.new
121
+ response.status = 200
122
+ response.headers = {
123
+ 'X-Compute-Request-Id' => "req-#{Fog::Mock.random_hex(32)}",
124
+ 'Content-Type' => 'application/json',
125
+ 'Content-Length' => Fog::Mock.random_numbers(3).to_s,
126
+ 'Date' => Date.new}
127
+ response.body = {
128
+ 'security_group' => self.data[:security_groups][security_group_id.to_s]
129
+ }
130
+ response
131
+ end
132
+ end # mock
133
+ end # Aliyun
134
+ end # compute
135
+ end # fog
@@ -0,0 +1,79 @@
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&createimage]
6
+ def create_image(snapshotId, options={})
7
+ action = 'CreateImage'
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
+ name = options[:name]
19
+ if name
20
+ parameters["ImageName"] = name
21
+ pathUrl += '&ImageName='
22
+ pathUrl += name
23
+ end
24
+
25
+ desc = options[:description]
26
+ if desc
27
+ parameters["Description"] = desc
28
+ pathUrl += '&Description='
29
+ pathUrl += desc
30
+ end
31
+
32
+ version = options[:version]
33
+ if version
34
+ parameters["ImageVersion"] = version
35
+ pathUrl += '&ImageVersion='
36
+ pathUrl += version
37
+ end
38
+
39
+ signature = sign(@aliyun_accesskey_secret, parameters)
40
+ pathUrl += '&Signature='
41
+ pathUrl += signature
42
+
43
+ request(
44
+ :expects => [200, 203],
45
+ :method => 'GET',
46
+ :path => pathUrl
47
+ )
48
+ end
49
+ end
50
+
51
+ class Mock
52
+ def create_image(server_id, name, metadata={})
53
+ response = Excon::Response.new
54
+ response.status = 202
55
+
56
+ img_id=Fog::Mock.random_numbers(6).to_s
57
+
58
+ data = {
59
+ 'id' => img_id,
60
+ 'server' => {"id"=>"3", "links"=>[{"href"=>"http://nova1:8774/admin/servers/#{server_id}", "rel"=>"bookmark"}]},
61
+ 'links' => [{"href"=>"http://nova1:8774/v1.1/admin/images/#{img_id}", "rel"=>"self"}, {"href"=>"http://nova1:8774/admin/images/#{img_id}", "rel"=>"bookmark"}],
62
+ 'metadata' => metadata || {},
63
+ 'name' => name || "server_#{rand(999)}",
64
+ 'progress' => 0,
65
+ 'status' => 'SAVING',
66
+ 'minDisk' => 0,
67
+ 'minRam' => 0,
68
+ 'updated' => "",
69
+ 'created' => ""
70
+ }
71
+ self.data[:last_modified][:images][data['id']] = Time.now
72
+ self.data[:images][data['id']] = data
73
+ response.body = { 'image' => data }
74
+ response
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,77 @@
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/securitygroup&createsecuritygroup]
6
+ def create_security_group(options={})
7
+
8
+ action = 'CreateSecurityGroup'
9
+ sigNonce = randonStr()
10
+ time = Time.new.utc
11
+
12
+ parameters = defalutParameters(action, sigNonce, time)
13
+ pathUrl = defaultAliyunUri(action, sigNonce, time)
14
+
15
+ name = options[:name]
16
+ desc = options[:description]
17
+ vpcid = options[:vpcid]
18
+
19
+ if name
20
+ parameters["SecurityGroupName"] = name
21
+ pathUrl += '&SecurityGroupName='
22
+ pathUrl += name
23
+ end
24
+
25
+ if desc
26
+ parameters["Description"] = desc
27
+ pathUrl += '&Description='
28
+ pathUrl += desc
29
+ end
30
+
31
+ if vpcid
32
+ parameters["VpcId"] = vpcid
33
+ pathUrl += '&VpcId='
34
+ pathUrl += vpcid
35
+ end
36
+
37
+ signature = sign(@aliyun_accesskey_secret, parameters)
38
+ pathUrl += '&Signature='
39
+ pathUrl += signature
40
+
41
+ request(
42
+ :expects => [200, 203],
43
+ :method => 'GET',
44
+ :path => pathUrl
45
+ )
46
+ end
47
+ end
48
+
49
+ class Mock
50
+ def create_security_group(name, description)
51
+ Fog::Identity::OpenStack.new(:openstack_auth_url => credentials[:openstack_auth_url])
52
+ tenant_id = Fog::Identity::OpenStack::V2::Mock.data[current_tenant][:tenants].keys.first
53
+ security_group_id = Fog::Mock.random_numbers(2).to_i + 1
54
+ self.data[:security_groups][security_group_id.to_s] = {
55
+ 'tenant_id' => tenant_id,
56
+ 'rules' => [],
57
+ 'id' => security_group_id,
58
+ 'name' => name,
59
+ 'description' => description
60
+ }
61
+
62
+ response = Excon::Response.new
63
+ response.status = 200
64
+ response.headers = {
65
+ 'X-Compute-Request-Id' => "req-#{Fog::Mock.random_hex(32)}",
66
+ 'Content-Type' => 'application/json',
67
+ 'Content-Length' => Fog::Mock.random_numbers(3).to_s,
68
+ 'Date' => Date.new}
69
+ response.body = {
70
+ 'security_group' => self.data[:security_groups][security_group_id.to_s]
71
+ }
72
+ response
73
+ end
74
+ end # mock
75
+ end # Aliyun
76
+ end # compute
77
+ end # fog
@@ -0,0 +1,86 @@
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/securitygroup&authorizesecuritygroup]
6
+ def create_security_group_ip_rule(securitygroup_id,sourceCidrIp, nicType, option={})
7
+
8
+ action = 'AuthorizeSecurityGroup'
9
+ sigNonce = randonStr()
10
+ time = Time.new.utc
11
+
12
+ parameters = defalutParameters(action, sigNonce, time)
13
+ pathUrl = defaultAliyunUri(action, sigNonce, time)
14
+
15
+ parameters["SecurityGroupId"] = securitygroup_id
16
+ pathUrl += '&SecurityGroupId='
17
+ pathUrl += securitygroup_id
18
+
19
+ parameters["SourceCidrIp"] = sourceCidrIp
20
+ pathUrl += '&SourceCidrIp='
21
+ pathUrl += URI.encode(sourceCidrIp,'/[^!*\'()\;?:@#&%=+$,{}[]<>`" ')
22
+
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,86 @@
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/securitygroup&authorizesecuritygroup]
6
+ def create_security_group_sg_rule(securitygroup_id, source_securyitgroup_id, option={})
7
+ action = 'AuthorizeSecurityGroup'
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