fog-xiaozhu 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +10 -0
  3. data/.rspec +2 -0
  4. data/.rubocop.yml +5 -0
  5. data/.rubocop_todo.yml +149 -0
  6. data/.ruby-gemset +1 -0
  7. data/.ruby-version +1 -0
  8. data/.travis.yml +4 -0
  9. data/CODE_OF_CONDUCT.md +13 -0
  10. data/Gemfile +4 -0
  11. data/LICENSE.txt +21 -0
  12. data/README.md +312 -0
  13. data/Rakefile +6 -0
  14. data/bin/console +14 -0
  15. data/bin/setup +7 -0
  16. data/fog-aliyun.gemspec +33 -0
  17. data/lib/fog/aliyun/compute.rb +424 -0
  18. data/lib/fog/aliyun/models/compute/eip_address.rb +57 -0
  19. data/lib/fog/aliyun/models/compute/eip_addresses.rb +28 -0
  20. data/lib/fog/aliyun/models/compute/image.rb +66 -0
  21. data/lib/fog/aliyun/models/compute/images.rb +25 -0
  22. data/lib/fog/aliyun/models/compute/route_entry.rb +26 -0
  23. data/lib/fog/aliyun/models/compute/route_entrys.rb +41 -0
  24. data/lib/fog/aliyun/models/compute/route_table.rb +30 -0
  25. data/lib/fog/aliyun/models/compute/route_tables.rb +27 -0
  26. data/lib/fog/aliyun/models/compute/security_group.rb +81 -0
  27. data/lib/fog/aliyun/models/compute/security_group_rule.rb +47 -0
  28. data/lib/fog/aliyun/models/compute/security_group_rules.rb +23 -0
  29. data/lib/fog/aliyun/models/compute/security_groups.rb +32 -0
  30. data/lib/fog/aliyun/models/compute/server.rb +70 -0
  31. data/lib/fog/aliyun/models/compute/servers.rb +42 -0
  32. data/lib/fog/aliyun/models/compute/snapshot.rb +52 -0
  33. data/lib/fog/aliyun/models/compute/snapshots.rb +38 -0
  34. data/lib/fog/aliyun/models/compute/volume.rb +101 -0
  35. data/lib/fog/aliyun/models/compute/volumes.rb +135 -0
  36. data/lib/fog/aliyun/models/compute/vpc.rb +77 -0
  37. data/lib/fog/aliyun/models/compute/vpcs.rb +80 -0
  38. data/lib/fog/aliyun/models/compute/vrouter.rb +35 -0
  39. data/lib/fog/aliyun/models/compute/vrouters.rb +61 -0
  40. data/lib/fog/aliyun/models/compute/vswitch.rb +70 -0
  41. data/lib/fog/aliyun/models/compute/vswitches.rb +80 -0
  42. data/lib/fog/aliyun/models/storage/directories.rb +39 -0
  43. data/lib/fog/aliyun/models/storage/directory.rb +48 -0
  44. data/lib/fog/aliyun/models/storage/file.rb +192 -0
  45. data/lib/fog/aliyun/models/storage/files.rb +193 -0
  46. data/lib/fog/aliyun/requests/compute/allocate_eip_address.rb +54 -0
  47. data/lib/fog/aliyun/requests/compute/allocate_public_ip_address.rb +39 -0
  48. data/lib/fog/aliyun/requests/compute/associate_eip_address.rb +49 -0
  49. data/lib/fog/aliyun/requests/compute/attach_disk.rb +79 -0
  50. data/lib/fog/aliyun/requests/compute/create_disk.rb +137 -0
  51. data/lib/fog/aliyun/requests/compute/create_image.rb +79 -0
  52. data/lib/fog/aliyun/requests/compute/create_security_group.rb +77 -0
  53. data/lib/fog/aliyun/requests/compute/create_security_group_egress_ip_rule.rb +63 -0
  54. data/lib/fog/aliyun/requests/compute/create_security_group_egress_sg_rule.rb +71 -0
  55. data/lib/fog/aliyun/requests/compute/create_security_group_ip_rule.rb +63 -0
  56. data/lib/fog/aliyun/requests/compute/create_security_group_sg_rule.rb +71 -0
  57. data/lib/fog/aliyun/requests/compute/create_server.rb +186 -0
  58. data/lib/fog/aliyun/requests/compute/create_snapshot.rb +46 -0
  59. data/lib/fog/aliyun/requests/compute/create_vpc.rb +46 -0
  60. data/lib/fog/aliyun/requests/compute/create_vpn_connection.rb +58 -0
  61. data/lib/fog/aliyun/requests/compute/create_vpn_customergateway.rb +48 -0
  62. data/lib/fog/aliyun/requests/compute/create_vswitch.rb +54 -0
  63. data/lib/fog/aliyun/requests/compute/delete_disk.rb +41 -0
  64. data/lib/fog/aliyun/requests/compute/delete_image.rb +31 -0
  65. data/lib/fog/aliyun/requests/compute/delete_security_group.rb +51 -0
  66. data/lib/fog/aliyun/requests/compute/delete_security_group_egress_ip_rule.rb +63 -0
  67. data/lib/fog/aliyun/requests/compute/delete_security_group_egress_sg_rule.rb +71 -0
  68. data/lib/fog/aliyun/requests/compute/delete_security_group_ip_rule.rb +63 -0
  69. data/lib/fog/aliyun/requests/compute/delete_security_group_sg_rule.rb +71 -0
  70. data/lib/fog/aliyun/requests/compute/delete_server.rb +48 -0
  71. data/lib/fog/aliyun/requests/compute/delete_snapshot.rb +31 -0
  72. data/lib/fog/aliyun/requests/compute/delete_vpc.rb +35 -0
  73. data/lib/fog/aliyun/requests/compute/delete_vpn_connection.rb +35 -0
  74. data/lib/fog/aliyun/requests/compute/delete_vpn_customergateway.rb +35 -0
  75. data/lib/fog/aliyun/requests/compute/delete_vswitch.rb +35 -0
  76. data/lib/fog/aliyun/requests/compute/detach_disk.rb +41 -0
  77. data/lib/fog/aliyun/requests/compute/join_security_group.rb +40 -0
  78. data/lib/fog/aliyun/requests/compute/leave_security_group.rb +40 -0
  79. data/lib/fog/aliyun/requests/compute/list_disks.rb +150 -0
  80. data/lib/fog/aliyun/requests/compute/list_eip_addresses.rb +55 -0
  81. data/lib/fog/aliyun/requests/compute/list_images.rb +82 -0
  82. data/lib/fog/aliyun/requests/compute/list_route_tables.rb +64 -0
  83. data/lib/fog/aliyun/requests/compute/list_security_group_rules.rb +73 -0
  84. data/lib/fog/aliyun/requests/compute/list_security_groups.rb +78 -0
  85. data/lib/fog/aliyun/requests/compute/list_server_types.rb +77 -0
  86. data/lib/fog/aliyun/requests/compute/list_servers.rb +71 -0
  87. data/lib/fog/aliyun/requests/compute/list_snapshots.rb +97 -0
  88. data/lib/fog/aliyun/requests/compute/list_vpcs.rb +47 -0
  89. data/lib/fog/aliyun/requests/compute/list_vpn_connections.rb +49 -0
  90. data/lib/fog/aliyun/requests/compute/list_vpn_customergateways.rb +43 -0
  91. data/lib/fog/aliyun/requests/compute/list_vpn_gateways.rb +49 -0
  92. data/lib/fog/aliyun/requests/compute/list_vrouters.rb +61 -0
  93. data/lib/fog/aliyun/requests/compute/list_vswitchs.rb +50 -0
  94. data/lib/fog/aliyun/requests/compute/list_zones.rb +44 -0
  95. data/lib/fog/aliyun/requests/compute/modify_vpc.rb +73 -0
  96. data/lib/fog/aliyun/requests/compute/modify_vswitch.rb +45 -0
  97. data/lib/fog/aliyun/requests/compute/reboot_server.rb +43 -0
  98. data/lib/fog/aliyun/requests/compute/release_eip_address.rb +29 -0
  99. data/lib/fog/aliyun/requests/compute/start_server.rb +41 -0
  100. data/lib/fog/aliyun/requests/compute/stop_server.rb +41 -0
  101. data/lib/fog/aliyun/requests/compute/unassociate_eip_address.rb +49 -0
  102. data/lib/fog/aliyun/requests/storage/copy_object.rb +39 -0
  103. data/lib/fog/aliyun/requests/storage/delete_bucket.rb +30 -0
  104. data/lib/fog/aliyun/requests/storage/delete_container.rb +35 -0
  105. data/lib/fog/aliyun/requests/storage/delete_object.rb +51 -0
  106. data/lib/fog/aliyun/requests/storage/get_bucket.rb +141 -0
  107. data/lib/fog/aliyun/requests/storage/get_container.rb +60 -0
  108. data/lib/fog/aliyun/requests/storage/get_containers.rb +64 -0
  109. data/lib/fog/aliyun/requests/storage/get_object.rb +45 -0
  110. data/lib/fog/aliyun/requests/storage/get_object_http_url.rb +43 -0
  111. data/lib/fog/aliyun/requests/storage/get_object_https_url.rb +43 -0
  112. data/lib/fog/aliyun/requests/storage/head_object.rb +34 -0
  113. data/lib/fog/aliyun/requests/storage/list_buckets.rb +40 -0
  114. data/lib/fog/aliyun/requests/storage/list_objects.rb +91 -0
  115. data/lib/fog/aliyun/requests/storage/put_bucket.rb +22 -0
  116. data/lib/fog/aliyun/requests/storage/put_container.rb +35 -0
  117. data/lib/fog/aliyun/requests/storage/put_object.rb +189 -0
  118. data/lib/fog/aliyun/storage.rb +233 -0
  119. data/lib/fog/aliyun/version.rb +5 -0
  120. data/lib/fog/aliyun.rb +19 -0
  121. data/lib/fog/bin/aliyun.rb +31 -0
  122. metadata +311 -0
@@ -0,0 +1,135 @@
1
+ require 'fog/core/collection'
2
+ require 'fog/aliyun/models/compute/volume'
3
+
4
+ module Fog
5
+ module Compute
6
+ class Aliyun
7
+ class Volumes < Fog::Collection
8
+ model Fog::Compute::Aliyun::Volume
9
+
10
+ # Used to create a volume. There are 3 arguments and availability_zone and size are required. You can generate a new key_pair as follows:
11
+ # Aliyun.volumes.create(:size => 10)
12
+ #
13
+ # ==== Returns
14
+ #
15
+ # <Fog::AWS::Compute::Volume
16
+ # id="vol-1e2028b9",
17
+ # attached_at=nil,
18
+ # availability_zone="us-east-1a",
19
+ # created_at=Tue Nov 23 23:30:29 -0500 2010,
20
+ # delete_on_termination=nil,
21
+ # device=nil,
22
+ # server_id=nil,
23
+ # size=10,
24
+ # snapshot_id=nil,
25
+ # state="creating",
26
+ # tags=nil
27
+ # >
28
+ #
29
+ # The volume can be retrieved by running Aliyun.volumes.get("d-25ohde62o"). See get method below.
30
+ #
31
+
32
+ # Used to return all volumes.
33
+ # Aliyun.volumes.all
34
+ #
35
+ # ==== Returns
36
+ #
37
+ # >>Aliyun.volumes.all
38
+ # <Fog::Compute::Aliyun::Volumes
39
+ # [
40
+ # <Fog::Compute::Aliyun::Volume
41
+ # id="d-25ohde62o",
42
+ # region_id="cn-beijing",
43
+ # zone_id="cn-beijing-a",
44
+ # name="",
45
+ # description="",
46
+ # type="data",
47
+ # category="cloud",
48
+ # size=10,
49
+ # image_id="",
50
+ # snapshot_id="",
51
+ # product_code="",
52
+ # portable=true,
53
+ # state="In_use",
54
+ # operation_locks={"OperationLock"=>[{"LockReason"=>"financial"}]},
55
+ # server_id="i-25l758pg4",
56
+ # device="/dev/xvdc",
57
+ # delete_with_instance=false,
58
+ # delete_auto_snapshot=true,
59
+ # enable_auto_snapshot=true,
60
+ # created_at="2015-08-03T11:35:10Z",
61
+ # attached_at="2015-08-03T11:35:15Z",
62
+ # detached_at="",
63
+ # expired_at="2015-09-29T15:45Z",
64
+ # charge_type="PostPaid",
65
+ # tags={"Tag"=>[]}
66
+ # >
67
+ # ]
68
+ # >
69
+
70
+ #
71
+ # The volume can be retrieved by running Aliyun.volumes.get('d-25x03nah9'). See get method below.
72
+ #
73
+
74
+ def all(filters_arg = {})
75
+ unless filters_arg.is_a?(Hash)
76
+ Fog::Logger.deprecation("all with #{filters_arg.class} param is deprecated, use all('diskIds' => []) instead [light_black](#{caller.first})[/]")
77
+ filters_arg = { 'diskIds' => [*filters_arg] }
78
+ end
79
+ data = Fog::JSON.decode(service.list_disks(filters_arg).body)['Disks']['Disk']
80
+ load(data)
81
+ # load(data['volumeSet'])
82
+ # if server
83
+ # self.replace(self.select {|volume| volume.server_id == server.id})
84
+ # end
85
+ # self
86
+ end
87
+
88
+ # Used to retrieve a volume
89
+ # volume_id is required to get the associated volume information.
90
+ #
91
+ # You can run the following command to get the details:
92
+ # Aliyun.volumes.get('d-25x03nah9')
93
+ #
94
+ # ==== Returns
95
+ #
96
+ # >> Aliyun.volumes.get('d-25ohde62o')
97
+ # <Fog::Compute::Aliyun::Volume
98
+ # id="d-25ohde62o",
99
+ # region_id="cn-beijing",
100
+ # zone_id="cn-beijing-a",
101
+ # name="",
102
+ # description="",
103
+ # type="data",
104
+ # category="cloud",
105
+ # size=10,
106
+ # image_id="",
107
+ # snapshot_id="",
108
+ # product_code="",
109
+ # portable=true,
110
+ # state="In_use",
111
+ # operation_locks={"OperationLock"=>[{"LockReason"=>"financial"}]},
112
+ # server_id="i-25l758pg4",
113
+ # device="/dev/xvdc",
114
+ # delete_with_instance=false,
115
+ # delete_auto_snapshot=true,
116
+ # enable_auto_snapshot=true,
117
+ # created_at="2015-08-03T11:35:10Z",
118
+ # attached_at="2015-08-03T11:35:15Z",
119
+ # detached_at="",
120
+ # expired_at="2015-09-29T15:45Z",
121
+ # charge_type="PostPaid",
122
+ # tags={"Tag"=>[]}
123
+ # >
124
+ #
125
+
126
+ def get(volume_id)
127
+ if volume_id
128
+ diskIds = Array.new(1, volume_id)
129
+ self.class.new(service: service).all(diskIds: diskIds)[0]
130
+ end
131
+ end
132
+ end
133
+ end
134
+ end
135
+ end
@@ -0,0 +1,77 @@
1
+ require 'fog/core/model'
2
+ module Fog
3
+ module Compute
4
+ class Aliyun
5
+ class VPC < Fog::Model
6
+ identity :id, aliases: 'VpcId'
7
+ attribute :name, aliases: 'VpcName'
8
+ attribute :state, aliases: 'Status'
9
+ attribute :cidr_block, aliases: 'CidrBlock'
10
+ attribute :v_switch_ids, aliases: 'VSwitchIds'
11
+ attribute :description, aliases: 'Description'
12
+ attribute :user_cidrs, aliases: 'UserCidrs'
13
+ attribute :region_id, aliases: 'RegionId'
14
+ attribute :v_router_id, aliases: 'VRouterId'
15
+ attribute :create_at, aliases: 'CreationTime'
16
+
17
+ def ready?
18
+ requires :state
19
+ state == 'Available'
20
+ end
21
+
22
+ # Removes an existing vpc
23
+ #
24
+ # vpc.destroy
25
+ #
26
+ # ==== Returns
27
+ #
28
+ # True or false depending on the result
29
+ #
30
+
31
+ def destroy
32
+ requires :id
33
+
34
+ service.delete_vpc(id)
35
+ true
36
+ end
37
+
38
+ def vswitches
39
+ @vswitches ||= begin
40
+ Fog::Compute::Aliyun::Vswitches.new(
41
+ vpc: self,
42
+ service: service
43
+ )
44
+ end
45
+ end
46
+
47
+ def vrouter
48
+ requires :v_router_id
49
+ Fog::Compute::Aliyun::Vrouters.new(service: service).all('vRouterId' => v_router_id)[0]
50
+ end
51
+
52
+ def security_groups
53
+ requires :id
54
+ Fog::Compute::Aliyun::SecurityGroups.new(service: service).all(vpcId: id)
55
+ end
56
+ # Create a vpc
57
+ #
58
+ # >> g = Aliyun.vpcs.new(:cidr_block => "10.1.2.0/24")
59
+ # >> g.save
60
+ #
61
+ # == Returns:
62
+ #
63
+ # True or an exception depending on the result. Keep in mind that this *creates* a new vpc.
64
+ # As such, it yields an InvalidGroup.Duplicate exception if you attempt to save an existing vpc.
65
+ #
66
+
67
+ def save(options = {})
68
+ requires :cidr_block
69
+ options[:name] = name if name
70
+ options[:description] = description if description
71
+ Fog::JSON.decode(service.create_vpc(cidr_block, options).body)
72
+ true
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,80 @@
1
+ require 'fog/core/collection'
2
+ require 'fog/aliyun/models/compute/vpc'
3
+
4
+ module Fog
5
+ module Compute
6
+ class Aliyun
7
+ class Vpcs < Fog::Collection
8
+ model Fog::Compute::Aliyun::VPC
9
+
10
+ # Creates a new VPC
11
+ #
12
+ # Aliyun.vpcs.new
13
+ #
14
+ # ==== Returns
15
+ #
16
+ # Returns the details of the new VPC
17
+ #
18
+ # >> Aliyun.vpcs.new
19
+ # <Fog::Aliyun::VPC::VPC
20
+ # id=nil,
21
+ # state=nil,
22
+ # cidr_block=nil,
23
+ # dhcp_options_id=nil
24
+ # tags=nil
25
+ # tenancy=nil
26
+ # >
27
+ #
28
+
29
+ # Returns an array of all VPCs that have been created
30
+ #
31
+ # Aliyun.vpcs.all
32
+ #
33
+ # ==== Returns
34
+ #
35
+ # Returns an array of all VPCs
36
+ #
37
+ # >> Aliyun.vpcs.all
38
+ # <Fog::Aliyun::VPC::VPCs
39
+ # [
40
+ # <Fog::Aliyun::VPC::VPC
41
+ # id="vpc-12345678",
42
+ # TODO
43
+ # >
44
+ # ]
45
+ # >
46
+ #
47
+
48
+ def all(filters_arg = {})
49
+ unless filters_arg.is_a?(Hash)
50
+ Fog::Logger.warning("all with #{filters_arg.class} param is deprecated, use all('vpcId' => []) instead [light_black](#{caller.first})[/]")
51
+ filters_arg = { 'vpcId' => [*filters_arg] }
52
+ end
53
+ data = Fog::JSON.decode(service.list_vpcs(filters_arg).body)['Vpcs']['Vpc']
54
+ load(data)
55
+ end
56
+
57
+ # Used to retrieve a VPC
58
+ # vpc_id is required to get the associated VPC information.
59
+ #
60
+ # You can run the following command to get the details:
61
+ # Aliyun.vpcs.get("vpc-12345678")
62
+ #
63
+ # ==== Returns
64
+ #
65
+ # >> Aliyun.vpcs.get("vpc-12345678")
66
+ # <Fog::Aliyun::Compute::VPC
67
+ # id="vpc-12345678",
68
+ # TODO
69
+ # >
70
+ #
71
+
72
+ def get(vpcId)
73
+ if vpcId
74
+ $vpc = self.class.new(service: service).all('vpcId' => vpcId)[0]
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,35 @@
1
+ require 'fog/core/model'
2
+ module Fog
3
+ module Compute
4
+ class Aliyun
5
+ class VRouter < Fog::Model
6
+ identity :id, aliases: 'VRouterId'
7
+
8
+ attribute :name, aliases: 'VRouterName'
9
+ attribute :route_table_ids, aliases: 'RouteTableIds'
10
+ attribute :created_at, aliases: 'CreationTime'
11
+ attribute :description, aliases: 'Description'
12
+ attribute :region_id, aliases: 'RegionId'
13
+ attribute :vpc_id, aliases: 'VpcId'
14
+
15
+ def vpc
16
+ requires :vpc_id
17
+ $vpc = Fog::Compute::Aliyun::Vpcs.new(service: service).all('vpcId' => vpc_id)[0]
18
+ end
19
+
20
+ def route_tables
21
+ @route_tables ||= begin
22
+ Fog::Compute::Aliyun::RouteTables.new(
23
+ v_router: self,
24
+ service: service
25
+ )
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+
33
+ # "VRouters"=>{"VRouter"=>[{"VRouterName"=>"", "RouteTableIds"=>{"RouteTableId"=>["vtb-2504onoxh"]},
34
+ # "CreationTime"=>"2015-08-03T11:23:35Z", "Description"=>"", "RegionId"=>"cn-beijing",
35
+ # "VRouterId"=>"vrt-25azmd2wm", "VpcId"=>"vpc-25mj6mguq"}]}
@@ -0,0 +1,61 @@
1
+ require 'fog/core/collection'
2
+ require 'fog/aliyun/models/compute/vrouter'
3
+
4
+ module Fog
5
+ module Compute
6
+ class Aliyun
7
+ class Vrouters < Fog::Collection
8
+ model Fog::Compute::Aliyun::VRouter
9
+
10
+ # Returns an array of all VPCs that have been created
11
+ #
12
+ # Aliyun.vrouters.all
13
+ #
14
+ # ==== Returns
15
+ #
16
+ # Returns an array of all VPCs
17
+ #
18
+ # >> Aliyun.vrouters.all
19
+ # <Fog::Aliyun::Compute::VRouters
20
+ # [
21
+ # <Fog::Aliyun::Compute::VRouter
22
+ # id="vpc-12345678",
23
+ # TODO
24
+ # >
25
+ # ]
26
+ # >
27
+ #
28
+
29
+ def all(filters_arg = {})
30
+ unless filters_arg.is_a?(Hash)
31
+ Fog::Logger.warning("all with #{filters_arg.class} param is deprecated, use all('vRouterId' => "") instead [light_black](#{caller.first})[/]")
32
+ filters_arg = { 'vRouterId' => filters_arg }
33
+ end
34
+ data = Fog::JSON.decode(service.list_vrouters(filters_arg).body)['VRouters']['VRouter']
35
+ load(data)
36
+ end
37
+
38
+ # Used to retrieve a VPC
39
+ # vpc_id is required to get the associated VPC information.
40
+ #
41
+ # You can run the following command to get the details:
42
+ # Aliyun.vpcs.get("vpc-12345678")
43
+ #
44
+ # ==== Returns
45
+ #
46
+ # >> Aliyun.vpcs.get("vpc-12345678")
47
+ # <Fog::Aliyun::Compute::VPC
48
+ # id="vpc-12345678",
49
+ # TODO
50
+ # >
51
+ #
52
+
53
+ def get(vRouterId)
54
+ if vRouterId
55
+ self.class.new(service: service).all('vRouterId' => vRouterId)[0]
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -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 :create_at, 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
+ options[:name] = name if name
55
+ options[:description] = description if description
56
+ Fog::JSON.decode(service.create_vswitch(vpc.id, cidr_block, options).body)
57
+ true
58
+ end
59
+
60
+ def vpc
61
+ $vpc
62
+ end
63
+
64
+ def all
65
+ Fog::JSON.decode(service.list_vswitchs(vpc_id).body)['VSwitches']['VSwitch']
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,80 @@
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
+
10
+ model Fog::Compute::Aliyun::Vswitch
11
+
12
+ # Creates a new VPC
13
+ #
14
+ # Aliyun.vpcs.new
15
+ #
16
+ # ==== Returns
17
+ #
18
+ # Returns the details of the new VPC
19
+ #
20
+ # >> Aliyun.vpcs.new
21
+ # <Fog::Aliyun::VPC::VPC
22
+ # id=nil,
23
+ # state=nil,
24
+ # cidr_block=nil,
25
+ # dhcp_options_id=nil
26
+ # tags=nil
27
+ # tenancy=nil
28
+ # >
29
+
30
+ # Returns an array of all VPCs that have been created
31
+ #
32
+ # Aliyun.vpcs.all
33
+ #
34
+ # ==== Returns
35
+ #
36
+ # Returns an array of all VPCs
37
+ #
38
+ # >> Aliyun.vpcs.all
39
+ # <Fog::Aliyun::VPC::VPCs
40
+ # filters={}
41
+ # [
42
+ # <Fog::Aliyun::VPC::VPC
43
+ # id="vpc-12345678",
44
+ # TODO
45
+ # >
46
+ # ]
47
+ # >
48
+ #
49
+
50
+ def all(options = {})
51
+ requires :vpc
52
+ data = Fog::JSON.decode(service.list_vswitchs(vpc.id, options).body)['VSwitches']['VSwitch']
53
+ load(data)
54
+ end
55
+
56
+ # Used to retrieve a VPC
57
+ # vpc_id is required to get the associated VPC information.
58
+ #
59
+ # You can run the following command to get the details:
60
+ # Aliyun.vpcs.get("vpc-12345678")
61
+ #
62
+ # ==== Returns
63
+ #
64
+ # >> Aliyun.vpcs.get("vpc-12345678")
65
+ # <Fog::Aliyun::Compute::VPC
66
+ # id="vpc-12345678",
67
+ # TODO
68
+ # >
69
+ #
70
+
71
+ def get(vswitchId)
72
+ requires :vpc
73
+ if vswitchId
74
+ self.class.new(service: service, vpc: vpc).all(vSwitchId: vswitchId)[0]
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,39 @@
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
+ return nil if nil == containers
13
+ data = []
14
+ i = 0
15
+ containers.each do |entry|
16
+ key = entry['Prefix'][0]
17
+ key[-1] = ''
18
+ data[i] = { key: key }
19
+ i += 1
20
+ end
21
+
22
+ load(data)
23
+ end
24
+
25
+ def get(key, options = {})
26
+ if !key.nil? && key != '' && key != '.'
27
+ dir = key + '/'
28
+ ret = service.head_object(dir, options)
29
+ new(key: key) if ret.data[:status] == 200
30
+ else
31
+ new(key: '')
32
+ end
33
+ rescue Fog::Storage::Aliyun::NotFound
34
+ nil
35
+ end
36
+ end
37
+ end
38
+ end
39
+ 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