diff --git a/fog-aliyun.gemspec b/fog-aliyun.gemspec index 210f340..45152f9 100644 --- a/fog-aliyun.gemspec +++ b/fog-aliyun.gemspec @@ -11,7 +11,7 @@ Gem::Specification.new do |spec| spec.summary = %q{Fog provider for Aliyun Web Services.} spec.description = %q{As a FOG provider, fog-aliyun support aliyun OSS/ECS. It will support more aliyun services later.} - spec.homepage = "https://github.com/dtdream/fog-aliyun.git" + spec.homepage = "https://github.com/fog/fog-aliyun.git" spec.license = "MIT" spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } diff --git a/lib/fog/aliyun/compute.rb b/lib/fog/aliyun/compute.rb index c75af7e..4da37be 100644 --- a/lib/fog/aliyun/compute.rb +++ b/lib/fog/aliyun/compute.rb @@ -10,8 +10,16 @@ class Aliyun < Fog::Service ## MODELS # model_path 'fog/aliyun/models/compute' + model :server + collection :servers model :image collection :images + model :eip_address + collection :eip_addresses + model :security_group + collection :security_groups + model :security_group_rule + collection :security_group_rules model :volume collection :volumes model :snapshot @@ -20,6 +28,12 @@ class Aliyun < Fog::Service collection :vpcs model :vswitch collection :vswitches + model :vrouter + collection :vrouters + model :route_table + collection :route_tables + model :route_entry + collection :route_entrys ## REQUESTS # @@ -86,6 +100,12 @@ class Aliyun < Fog::Service request :modify_vpc request :modify_vswitch + #VRouter + request :list_vrouters + + #RouteTable + request :list_route_tables + #clouddisk request :list_disks diff --git a/lib/fog/aliyun/models/compute/eip_address.rb b/lib/fog/aliyun/models/compute/eip_address.rb new file mode 100644 index 0000000..00f2672 --- /dev/null +++ b/lib/fog/aliyun/models/compute/eip_address.rb @@ -0,0 +1,54 @@ +require 'fog/core/model' +module Fog + module Compute + class Aliyun + class EipAddress < Fog::Model + + identity :id, :aliases => 'AllocationId' + + attribute :allocated_at, :aliases => 'AllocationTime' + attribute :bandwidth, :aliases => 'Bandwidth' + attribute :server_id, :aliases => 'InstanceId' + attribute :charge_type, :aliases => 'InternetChargeType' + attribute :ip_address, :aliases => ['IpAddress','EipAddress'] + attribute :opertion_locks,:aliases => 'OperationLocks' + attribute :region_id, :aliases => 'RegionId' + attribute :state, :aliases => 'Status' + + def destroy + requires :id + service.release_eip_address(id) + true + end + + def ready? + requires :state + state == 'Available' + end + + def save(options={}) + # raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted? + # requires :availability_zone + options[:bandwidth] = bandwidth if bandwidth + options[:internet_charge_type]=charge_type if charge_type + + data = Fog::JSON.decode(service.allocate_eip_address(options).body) + merge_attributes(data) + true + end + + + # def associate(new_server) + # unless persisted? + # @server = new_server + # else + # @server = nil + # self.server_id = new_server.id + # service.associate_address(server_id, public_ip, network_interface_id, allocation_id) + # end + # end + + end + end + end +end \ No newline at end of file diff --git a/lib/fog/aliyun/models/compute/eip_addresses.rb b/lib/fog/aliyun/models/compute/eip_addresses.rb new file mode 100644 index 0000000..f2dbe6b --- /dev/null +++ b/lib/fog/aliyun/models/compute/eip_addresses.rb @@ -0,0 +1,30 @@ +require 'fog/core/collection' +require 'fog/aliyun/models/compute/eip_address' + +module Fog + module Compute + class Aliyun + class EipAddresses < Fog::Collection + + model Fog::Compute::Aliyun::EipAddress + + def all(filters_arg = {}) + data = Fog::JSON.decode(service.list_eip_addresses(filters_arg).body)['EipAddresses']['EipAddress'] + load(data) + # load(data['volumeSet']) + # if server + # self.replace(self.select {|volume| volume.server_id == server.id}) + # end + # self + end + + def get(allocation_id) + if allocation_id + self.class.new(:service => service).all(:allocation_id => allocation_)[0] + end + end + + end + end + end +end \ No newline at end of file diff --git a/lib/fog/aliyun/models/compute/route_entry.rb b/lib/fog/aliyun/models/compute/route_entry.rb new file mode 100644 index 0000000..5b61904 --- /dev/null +++ b/lib/fog/aliyun/models/compute/route_entry.rb @@ -0,0 +1,28 @@ +require 'fog/core/model' +module Fog + module Compute + class Aliyun + class RouteEntry < Fog::Model + # "RouteTables"=>{"RouteTable"=>[ + # {"CreationTime"=>"2015-08-03T11:23:35Z", "RouteEntrys"=>{"RouteEntry"=>[ + # {"Status"=>"Available", "Type"=>"System", "InstanceId"=>"", "RouteTableId"=>"vtb-2504onoxh", "DestinationCidrBlock"=>"172.16.0.0/24"}, + # {"Status"=>"Available", "Type"=>"System", "InstanceId"=>"", "RouteTableId"=>"vtb-2504onoxh", "DestinationCidrBlock"=>"172.16.1.0/24"}, + # {"Status"=>"Available", "Type"=>"System", "InstanceId"=>"", "RouteTableId"=>"vtb-2504onoxh", "DestinationCidrBlock"=>"172.16.2.0/24"}, + # {"Status"=>"Available", "Type"=>"System", "InstanceId"=>"", "RouteTableId"=>"vtb-2504onoxh", "DestinationCidrBlock"=>"100.64.0.0/10"}, + # {"Status"=>"Available", "Type"=>"System", "InstanceId"=>"", "RouteTableId"=>"vtb-2504onoxh", "DestinationCidrBlock"=>"10.0.0.0/8"}]}, + # "RouteTableId"=>"vtb-2504onoxh", "RouteTableType"=>"System", "VRouterId"=>"vrt-25azmd2wm"}]} + identity :cidr_block, :aliases => 'DestinationCidrBlock' + attribute :state, :aliases => 'Status' + attribute :server_id, :aliases => 'InstanceId' + attribute :type, :aliases => 'Type' + attribute :route_table_id, :aliases => 'RouteTableId' + + # def save + # requires :cidr_block,:route_table_id + # if(cidr_block) + + + end + end + end +end \ No newline at end of file diff --git a/lib/fog/aliyun/models/compute/route_entrys.rb b/lib/fog/aliyun/models/compute/route_entrys.rb new file mode 100644 index 0000000..9fe3789 --- /dev/null +++ b/lib/fog/aliyun/models/compute/route_entrys.rb @@ -0,0 +1,41 @@ +require 'fog/core/collection' +require 'fog/aliyun/models/compute/route_entry' + +module Fog + module Compute + class Aliyun + class RouteEntrys < Fog::Collection + attribute :route_table + + model Fog::Compute::Aliyun::RouteEntry + + def all(options={}) + requires :route_table + options[:routeTableId]=route_table.id + data = Fog::JSON.decode(service.list_route_tables(route_table.v_router_id, options).body)['RouteTables']['RouteTable'][0]["RouteEntrys"]["RouteEntry"] + load(data) + end + + def get(cidr_block) + requires :route_table + data=self.class.new(:service=>service,:route_table=>route_table).all() + result=nil + data.each do |i| + if i.cidr_block==cidr_block + result=i + break + end + end + result + end + + # def get(routeTableId) + # requires :v_router + # if routeTableId + # self.class.new(:service => service,:v_router=>v_router).all(:routeTableId=>routeTableId)[0] + # end + # end + end + end + end +end diff --git a/lib/fog/aliyun/models/compute/route_table.rb b/lib/fog/aliyun/models/compute/route_table.rb new file mode 100644 index 0000000..d45aff9 --- /dev/null +++ b/lib/fog/aliyun/models/compute/route_table.rb @@ -0,0 +1,32 @@ +require 'fog/core/model' +module Fog + module Compute + class Aliyun + class RouteTable < Fog::Model + # "RouteTables"=>{"RouteTable"=>[ + # {"CreationTime"=>"2015-08-03T11:23:35Z", "RouteEntrys"=>{"RouteEntry"=>[ + # {"Status"=>"Available", "Type"=>"System", "InstanceId"=>"", "RouteTableId"=>"vtb-2504onoxh", "DestinationCidrBlock"=>"172.16.0.0/24"}, + # {"Status"=>"Available", "Type"=>"System", "InstanceId"=>"", "RouteTableId"=>"vtb-2504onoxh", "DestinationCidrBlock"=>"172.16.1.0/24"}, + # {"Status"=>"Available", "Type"=>"System", "InstanceId"=>"", "RouteTableId"=>"vtb-2504onoxh", "DestinationCidrBlock"=>"172.16.2.0/24"}, + # {"Status"=>"Available", "Type"=>"System", "InstanceId"=>"", "RouteTableId"=>"vtb-2504onoxh", "DestinationCidrBlock"=>"100.64.0.0/10"}, + # {"Status"=>"Available", "Type"=>"System", "InstanceId"=>"", "RouteTableId"=>"vtb-2504onoxh", "DestinationCidrBlock"=>"10.0.0.0/8"}]}, + # "RouteTableId"=>"vtb-2504onoxh", "RouteTableType"=>"System", "VRouterId"=>"vrt-25azmd2wm"}]} + identity :id, :aliases => 'RouteTableId' + attribute :created_at, :aliases => 'CreationTime' + attribute :type, :aliases => 'RouteTableType' + attribute :v_router_id, :aliases => 'VRouterId' + # collection Fog::Compute::Aliyun::RouteEntrys + def route_entrys + @route_entrys ||= begin + Fog::Compute::Aliyun::RouteEntrys.new( + :route_table => self, + :service => service + ) + end + end + + + end + end + end +end \ No newline at end of file diff --git a/lib/fog/aliyun/models/compute/route_tables.rb b/lib/fog/aliyun/models/compute/route_tables.rb new file mode 100644 index 0000000..43064db --- /dev/null +++ b/lib/fog/aliyun/models/compute/route_tables.rb @@ -0,0 +1,43 @@ +require 'fog/core/collection' +require 'fog/aliyun/models/compute/route_table' + +module Fog + module Compute + class Aliyun + class RouteTables < Fog::Collection + attribute :v_router + + model Fog::Compute::Aliyun::RouteTable + + + def all(options={}) + requires :v_router + data = Fog::JSON.decode(service.list_route_tables(v_router.id, options).body)['RouteTables']['RouteTable'] + load(data) + end + + # Used to retrieve a VPC + # vpc_id is required to get the associated VPC information. + # + # You can run the following command to get the details: + # Aliyun.vpcs.get("vpc-12345678") + # + # ==== Returns + # + #>> Aliyun.vpcs.get("vpc-12345678") + # + # + + def get(routeTableId) + requires :v_router + if routeTableId + self.class.new(:service => service,:v_router=>v_router).all(:routeTableId=>routeTableId)[0] + end + end + end + end + end +end diff --git a/lib/fog/aliyun/models/compute/security_group.rb b/lib/fog/aliyun/models/compute/security_group.rb new file mode 100644 index 0000000..83a0783 --- /dev/null +++ b/lib/fog/aliyun/models/compute/security_group.rb @@ -0,0 +1,86 @@ +require 'fog/core/model' + +module Fog + module Compute + class Aliyun + class SecurityGroup < Fog::Model + # {"SecurityGroup"=>[{"CreationTime"=>"2015-08-10T03:21:02Z", + # "SecurityGroupId"=>"sg-25mexinlu", "Description"=>"", "SecurityGroupName"=>"bosh", + # "VpcId"=>"vpc-25mj6mguq"}} + + identity :id, :aliases =>"SecurityGroupId" + + attribute :name, :aliases => "SecurityGroupName" + attribute :description, :aliases => "Description" + attribute :created_at, :aliases => "CreationTime" + attribute :vpc_id, :aliases => "VpcId" + + def vpc + requires :vpc_id + $vpc=Fog::Compute::Aliyun::Vpcs.new(:service=>service).all('vpcId'=>vpc_id)[0] + end + + def security_group_rules + requires :id + Fog::Compute::Aliyun::SecurityGroupRules.new(:service=>service).get(id) + end + + def save(options={}) + options[:vpcId] = vpc_id if vpc_id + options[:name] = name if name + options[:description] = description if description + data = Fog::JSON.decode(service.create_security_group(options).body) + true + end + + + def destroy + requires :id + service.delete_security_group(id) + true + end + + # def security_group_rules + # Fog::Compute::OpenStack::SecurityGroupRules.new(:service => service).load(attributes[:security_group_rules]) + # end + + # def rules + # Fog::Logger.deprecation('#rules is deprecated. Use #security_group_rules instead') + # attributes[:security_group_rules] + # end + + # # no one should be calling this because it doesn't do anything + # # useful but we deprecated the rules attribute and need to maintain the API + # def rules=(new_rules) + # Fog::Logger.deprecation('#rules= is deprecated. Use the Fog::Compute::Openstack::SecurityGroupRules collection to create new rules.') + # attributes[:security_group_rules] = new_rules + # end + + # def save + # requires :name, :description + # data = service.create_security_group(name, description) + # merge_attributes(data.body['security_group']) + # true + # end + + # def destroy + # requires :id + # service.delete_security_group(id) + # true + # end + + # def create_security_group_rule(min, max, ip_protocol = "tcp", cidr = "0.0.0.0/0", group_id = nil) + # Fog::Logger.deprecation('#create_security_group_rule is deprecated. Use the Fog::Compute::Openstack::SecurityGroupRules collection to create new rules.') + # requires :id + # service.create_security_group_rule(id, ip_protocol, min, max, cidr, group_id) + # end + + # def delete_security_group_rule(rule_id) + # Fog::Logger.deprecation('#create_security_group_rule is deprecated. Use the Fog::Compute::Openstack::SecurityGroupRule objects to destroy rules.') + # service.delete_security_group_rule(rule_id) + # true + # end + end + end + end +end diff --git a/lib/fog/aliyun/models/compute/security_group_rule.rb b/lib/fog/aliyun/models/compute/security_group_rule.rb new file mode 100644 index 0000000..398421c --- /dev/null +++ b/lib/fog/aliyun/models/compute/security_group_rule.rb @@ -0,0 +1,41 @@ +require 'fog/core/model' + +module Fog + module Compute + class Aliyun + class SecurityGroupRule < Fog::Model + + attribute :source_cidr_ip, :aliases => 'SourceCidrIp' + attribute :source_owner, :aliases => 'SourceGroupOwnerAccount' + attribute :source_group_id, :aliases => 'SourceGroupId' + attribute :ip_protocol, :aliases => 'IpProtocol' + attribute :dest_cidr_ip, :aliases => 'DestCidrIp' + attribute :dest_owner, :aliases => 'DestGroupOwnerAccount' + attribute :dest_group_id, :aliases => 'DestGroupId' + attribute :nic_type, :aliases => 'NicType' + attribute :policy, :aliases => 'Policy' + attribute :port_range, :aliases => 'PortRange' + attribute :direction, :aliases => 'Direction' + attribute :priority, :aliases => 'Priority' + + def save + requires :ip_protocol, :from_port, :to_port, :parent_group_id + cidr = ip_range && ip_range["cidr"] + if rule = service.create_security_group_rule(parent_group_id, ip_protocol, from_port, to_port, cidr, group).data[:body] + merge_attributes(rule["security_group_rule"]) + end + end + + def destroy + requires :id + service.delete_security_group_rule(id) + true + end + + def authorize_security_group + + end + end + end + end +end diff --git a/lib/fog/aliyun/models/compute/security_group_rules.rb b/lib/fog/aliyun/models/compute/security_group_rules.rb new file mode 100644 index 0000000..e3eb1bf --- /dev/null +++ b/lib/fog/aliyun/models/compute/security_group_rules.rb @@ -0,0 +1,25 @@ +require 'fog/core/collection' +require 'fog/aliyun/models/compute/security_group_rule' + +module Fog + module Compute + class Aliyun + class SecurityGroupRules < Fog::Collection + model Fog::Compute::Aliyun::SecurityGroupRule + attribute :security_group_id + + def get(security_group_id,options={}) + data = Fog::JSON.decode(service.list_security_group_rules(security_group_id, options).body) + self.security_group_id = data["SecurityGroupId"] + data = data["Permissions"]["Permission"] + load(data) + end + + # def get(security_group_id, options={}) + + # end + + end + end + end +end diff --git a/lib/fog/aliyun/models/compute/security_groups.rb b/lib/fog/aliyun/models/compute/security_groups.rb new file mode 100644 index 0000000..72f7d8a --- /dev/null +++ b/lib/fog/aliyun/models/compute/security_groups.rb @@ -0,0 +1,33 @@ +require 'fog/core/collection' +require 'fog/aliyun/models/compute/security_group' + +module Fog + module Compute + class Aliyun + class SecurityGroups < Fog::Collection + model Fog::Compute::Aliyun::SecurityGroup + + def all(options={}) + data = Fog::JSON.decode(service.list_security_groups(options).body)['SecurityGroups']['SecurityGroup'] + load(data) + #['Images']['Image'] + end + + def get(security_group_id) + if security_group_id + data=self.class.new(:service=>service).all() + result=nil + data.each do |i| + if(i.id==security_group_id) + result=i + break + end + end + result + end + end + + end + end + end +end diff --git a/lib/fog/aliyun/models/compute/server.rb b/lib/fog/aliyun/models/compute/server.rb new file mode 100644 index 0000000..4913a4f --- /dev/null +++ b/lib/fog/aliyun/models/compute/server.rb @@ -0,0 +1,71 @@ +require 'fog/compute/models/server' + +module Fog + module Compute + class Aliyun + class Server < Fog::Compute::Server + identity :id, :aliases=>'InstanceId' + attribute :image_id, :aliases => 'ImageId' + attribute :inner_ip, :aliases => 'InnerIpAddress' + attribute :vlan_id, :aliases => 'VlanId' + attribute :eip, :aliases => 'EipAddress' + attribute :max_bandwidth_in, :aliases => 'InternetMaxBandwidthIn' + attribute :zone_id, :aliases => 'ZoneId' + attribute :internet_charge_type, :aliases => 'InternetChargeType' + attribute :serial_number, :aliases => 'SerialNumber' + attribute :io_optimized, :aliases => 'IoOptimized' + attribute :max_bandwidth_out, :aliases => 'InternetMaxBandwidthOut' + attribute :vpc_attributes, :aliases => 'VpcAttributes' + attribute :device_available, :aliases => 'DeviceAvailable' + attribute :private_ip, :aliases => 'PrivateIpAddress' + attribute :security_group_ids,:aliases => 'SecurityGroupIds' + attribute :name, :aliases => 'InstanceName' + attribute :description, :aliases => 'Description' + attribute :network_type, :aliases => 'InstanceNetworkType' + attribute :public_ip, :aliases => 'PublicIpAddress' + attribute :host_name, :aliases => 'HostName' + attribute :type, :aliases => 'InstanceType' + attribute :created_at, :aliases => 'CreationTime' + attribute :state, :aliases => 'Status' + attribute :cluster_id, :aliases => 'ClusterId' + attribute :region_id, :aliases => 'RegionId' + attribute :charge_type, :aliases => 'InstanceChargeType' + attribute :operation_locks, :aliases => 'OperationLocks' + attribute :expired_at, :aliases => 'ExpiredTime' + + def image + requires image_id + Fog::Compute::Aliyun::Image.new(:service=>service).all(:imageId => image_id)[0] + end + + def vpc + requires :vpc_id + $vpc=Fog::Compute::Aliyun::Vpcs.new(:service=>service).all('vpcId'=>vpc_id)[0] + end + + # {"ImageId"=>"ubuntu1404_32_20G_aliaegis_20150325.vhd", "InnerIpAddress"=>{"IpAddress"=>["10.171.90.171"]}, + # "VlanId"=>"", "InstanceId"=>"i-25d1ry3jz", + # "EipAddress"=>{"IpAddress"=>"", "AllocationId"=>"", "InternetChargeType"=>""}, + # "InternetMaxBandwidthIn"=>-1, "ZoneId"=>"cn-beijing-a", "InternetChargeType"=>"PayByTraffic", + # "SerialNumber"=>"9b332890-35e8-45c9-8e52-14e1156a4f58", "IoOptimized"=>false, "InternetMaxBandwidthOut"=>1, + # "VpcAttributes"=>{"NatIpAddress"=>"", "PrivateIpAddress"=>{"IpAddress"=>[]}, "VSwitchId"=>"", "VpcId"=>""}, + # "DeviceAvailable"=>true, "SecurityGroupIds"=>{"SecurityGroupId"=>["sg-25rgacf5p"]}, "InstanceName"=>"iZ25d1ry3jzZ", + # "Description"=>"", "InstanceNetworkType"=>"classic", "PublicIpAddress"=>{"IpAddress"=>["123.57.73.19"]}, + # "HostName"=>"iZ25d1ry3jzZ", "InstanceType"=>"ecs.t1.small", "CreationTime"=>"2015-10-13T14:57Z", "Status"=>"Stopped", + # "ClusterId"=>"", "RegionId"=>"cn-beijing", "InstanceChargeType"=>"PostPaid", "OperationLocks"=>{ + # "LockReason"=>[{"LockReason"=>"financial"}]}, "ExpiredTime"=>"2015-10-14T20:53Z"} + + # @!attribute [rw] personality + # @note This attribute is only used for server creation. This field will be nil on subsequent retrievals. + # @return [Hash] Hash containing data to inject into the file system of the cloud server instance during server creation. + # @example To inject fog.txt into file system + # :personality => [{ :path => '/root/fog.txt', + # :contents => Base64.encode64('Fog was here!') + # }] + # @see #create + # @see http://docs.openstack.org/api/openstack-compute/2/content/Server_Personality-d1e2543.html + + end + end + end +end diff --git a/lib/fog/aliyun/models/compute/servers.rb b/lib/fog/aliyun/models/compute/servers.rb new file mode 100644 index 0000000..96c21b0 --- /dev/null +++ b/lib/fog/aliyun/models/compute/servers.rb @@ -0,0 +1,44 @@ +require 'fog/core/collection' +require 'fog/aliyun/models/compute/server' + +module Fog + module Compute + class Aliyun + class Servers < Fog::Collection + + model Fog::Compute::Aliyun::Server + + def all(options = {}) + data = Fog::JSON.decode(service.list_servers(options).body)['Instances']['Instance'] + end + + # Creates a new server and populates ssh keys + # @return [Fog::Compute::OpenStack::Server] + # @raise [Fog::Compute::OpenStack::NotFound] - HTTP 404 + # @raise [Fog::Compute::OpenStack::BadRequest] - HTTP 400 + # @raise [Fog::Compute::OpenStack::InternalServerError] - HTTP 500 + # @raise [Fog::Compute::OpenStack::ServiceError] + # @example + # service.servers.bootstrap :name => 'bootstrap-server', + # :flavor_ref => service.flavors.first.id, + # :image_ref => service.images.find {|img| img.name =~ /Ubuntu/}.id, + # :public_key_path => '~/.ssh/fog_rsa.pub', + # :private_key_path => '~/.ssh/fog_rsa' + # +# def bootstrap(new_attributes = {}) +# server = create(new_attributes) +# server.wait_for { ready? } +# server.setup(:password => server.password) +# server +# end + + def get(server_id) + if(server_id) + self.class.new(:service=>service).all(:instanceId=>server_id)[0] + end + end + + end + end + end +end diff --git a/lib/fog/aliyun/models/compute/vpc.rb b/lib/fog/aliyun/models/compute/vpc.rb index 4bb3393..c1a89b9 100644 --- a/lib/fog/aliyun/models/compute/vpc.rb +++ b/lib/fog/aliyun/models/compute/vpc.rb @@ -45,6 +45,15 @@ def vswitches end end + def vrouter + requires :v_router_id + Fog::Compute::Aliyun::Vrouters.new(:service=>service).all('vRouterId'=>v_router_id)[0] + end + + def security_groups + requires :id + Fog::Compute::Aliyun::SecurityGroups.new(:service=>service).all(:vpcId=>id) + end # Create a vpc # # >> g = Aliyun.vpcs.new(:cidr_block => "10.1.2.0/24") diff --git a/lib/fog/aliyun/models/compute/vrouter.rb b/lib/fog/aliyun/models/compute/vrouter.rb new file mode 100644 index 0000000..5de29be --- /dev/null +++ b/lib/fog/aliyun/models/compute/vrouter.rb @@ -0,0 +1,35 @@ +require 'fog/core/model' +module Fog + module Compute + class Aliyun + class VRouter < Fog::Model + identity :id, :aliases => 'VRouterId' + + attribute :name, :aliases => 'VRouterName' + attribute :route_table_ids, :aliases => 'RouteTableIds' + attribute :created_at, :aliases => 'CreationTime' + attribute :description, :aliases => 'Description' + attribute :region_id, :aliases => 'RegionId' + attribute :vpc_id, :aliases => 'VpcId' + + def vpc + requires :vpc_id + $vpc=Fog::Compute::Aliyun::Vpcs.new(:service=>service).all('vpcId'=>vpc_id)[0] + end + + def route_tables + @route_tables ||= begin + Fog::Compute::Aliyun::RouteTables.new( + :v_router => self, + :service => service + ) + end + end + end + end + end +end + +# "VRouters"=>{"VRouter"=>[{"VRouterName"=>"", "RouteTableIds"=>{"RouteTableId"=>["vtb-2504onoxh"]}, +# "CreationTime"=>"2015-08-03T11:23:35Z", "Description"=>"", "RegionId"=>"cn-beijing", +# "VRouterId"=>"vrt-25azmd2wm", "VpcId"=>"vpc-25mj6mguq"}]} \ No newline at end of file diff --git a/lib/fog/aliyun/models/compute/vrouters.rb b/lib/fog/aliyun/models/compute/vrouters.rb new file mode 100644 index 0000000..c53a87d --- /dev/null +++ b/lib/fog/aliyun/models/compute/vrouters.rb @@ -0,0 +1,62 @@ +require 'fog/core/collection' +require 'fog/aliyun/models/compute/vrouter' + +module Fog + module Compute + class Aliyun + class Vrouters < Fog::Collection + + model Fog::Compute::Aliyun::VRouter + + # Returns an array of all VPCs that have been created + # + # Aliyun.vrouters.all + # + # ==== Returns + # + # Returns an array of all VPCs + # + #>> Aliyun.vrouters.all + # + # ] + # > + # + + def all(filters_arg = {}) + unless filters_arg.is_a?(Hash) + Fog::Logger.warning("all with #{filters_arg.class} param is deprecated, use all('vRouterId' => "") instead [light_black](#{caller.first})[/]") + filters_arg = {'vRouterId' => filters_arg} + end + data = Fog::JSON.decode(service.list_vrouters(filters_arg).body)['VRouters']['VRouter'] + load(data) + end + + # Used to retrieve a VPC + # vpc_id is required to get the associated VPC information. + # + # You can run the following command to get the details: + # Aliyun.vpcs.get("vpc-12345678") + # + # ==== Returns + # + #>> Aliyun.vpcs.get("vpc-12345678") + # + # + + def get(vRouterId) + if vRouterId + self.class.new(:service => service).all('vRouterId' => vRouterId)[0] + end + end + end + end + end +end diff --git a/lib/fog/aliyun/models/compute/vswitches.rb b/lib/fog/aliyun/models/compute/vswitches.rb index 01609ef..7789dfb 100644 --- a/lib/fog/aliyun/models/compute/vswitches.rb +++ b/lib/fog/aliyun/models/compute/vswitches.rb @@ -6,7 +6,6 @@ module Compute class Aliyun class Vswitches < Fog::Collection attribute :vpc - attribute :filters model Fog::Compute::Aliyun::Vswitch @@ -27,13 +26,7 @@ class Vswitches < Fog::Collection # tags=nil # tenancy=nil # > - # - - def initialize(attributes) - self.filters ||={} - super - end - + # Returns an array of all VPCs that have been created # # Aliyun.vpcs.all diff --git a/lib/fog/aliyun/requests/compute/allocate_eip_address.rb b/lib/fog/aliyun/requests/compute/allocate_eip_address.rb index 7068f02..80a4a7e 100644 --- a/lib/fog/aliyun/requests/compute/allocate_eip_address.rb +++ b/lib/fog/aliyun/requests/compute/allocate_eip_address.rb @@ -29,13 +29,13 @@ def allocate_eip_address(options={}) _pathURL = defaultAliyunUri(_action, _sigNonce, _time) #optional parameters - _Bandwidth = options[:aliyun_Bandwidth] + _Bandwidth = options[:bandwidth] if _Bandwidth _parameters['Bandwidth']=_Bandwidth _pathURL += '&Bandwidth='+_Bandwidth end - _InternetChargeType = options[:aliyun_InternetChargeType] + _InternetChargeType = options[:internet_charge_type] if _InternetChargeType _parameters['InternetChargeType']=_InternetChargeType _pathURL += '&InternetChargeType='+_InternetChargeType diff --git a/lib/fog/aliyun/requests/compute/create_security_group.rb b/lib/fog/aliyun/requests/compute/create_security_group.rb index 71c7cdf..1dd6664 100644 --- a/lib/fog/aliyun/requests/compute/create_security_group.rb +++ b/lib/fog/aliyun/requests/compute/create_security_group.rb @@ -14,7 +14,7 @@ def create_security_group(options={}) name = options[:name] desc = options[:description] - vpcid = options[:vpcid] + vpcid = options[:vpcId] if name parameters["SecurityGroupName"] = name diff --git a/lib/fog/aliyun/requests/compute/detach_disk.rb b/lib/fog/aliyun/requests/compute/detach_disk.rb index 8356fc4..1143f4c 100644 --- a/lib/fog/aliyun/requests/compute/detach_disk.rb +++ b/lib/fog/aliyun/requests/compute/detach_disk.rb @@ -3,7 +3,7 @@ module Compute class Aliyun class Real # {Aliyun API Reference}[https://docs.aliyun.com/?spm=5176.100054.3.1.DGkmH7#/pub/ecs/open-api/disk&detachdisk] - def detach_disk(instanceId, diskId) + def detach_disk(instanceId, diskId,options={}) action = 'DetachDisk' sigNonce = randonStr() time = Time.new.utc @@ -19,6 +19,11 @@ def detach_disk(instanceId, diskId) pathUrl += '&DiskId=' pathUrl += diskId + if device + parameters["Device"] = device + pathUrl += '&Device=' + pathUrl += URI.encode(device,'/[^!*\'()\;?:@#&%=+$,{}[]<>`" ') + end signature = sign(@aliyun_accesskey_secret, parameters) pathUrl += '&Signature=' pathUrl += signature diff --git a/lib/fog/aliyun/requests/compute/list_eip_addresses.rb b/lib/fog/aliyun/requests/compute/list_eip_addresses.rb index 3ca3d40..3f1a9bf 100644 --- a/lib/fog/aliyun/requests/compute/list_eip_addresses.rb +++ b/lib/fog/aliyun/requests/compute/list_eip_addresses.rb @@ -12,31 +12,31 @@ def list_eip_addresses(options={}) _parameters = defalutParameters(_action, _sigNonce, _time) _pathURL = defaultAliyunUri(_action, _sigNonce, _time) - _Status = options[:aliyun_Status] + _Status = options[:state] if _Status _parameters['Status']=_Status _pathURL += '&Status='+_Status end - _EipAddress = options[:aliyun_EipAddress] + _EipAddress = options[:ip_address] if _EipAddress _parameters['EipAddress']=_EipAddress _pathURL += '&EipAddress='+_EipAddress end - _AllocationId = options[:aliyun_AllocationId] + _AllocationId = options[:allocation_id] if _AllocationId _parameters['AllocationId']=_AllocationId _pathURL += '&AllocationId='+_AllocationId end - _PageNumber = options[:aliyun_PageNumber] + _PageNumber = options[:page_number] if _PageNumber _parameters['PageNumber']=_PageNumber _pathURL += '&PageNumber='+_PageNumber end - _PageSize = options[:pageSize] + _PageSize = options[:page_size] unless _PageSize _PageSize = '50' end diff --git a/lib/fog/aliyun/requests/compute/list_route_tables.rb b/lib/fog/aliyun/requests/compute/list_route_tables.rb new file mode 100644 index 0000000..9d521a8 --- /dev/null +++ b/lib/fog/aliyun/requests/compute/list_route_tables.rb @@ -0,0 +1,67 @@ +module Fog + module Compute + class Aliyun + class Real + # {Aliyun API Reference}[https://docs.aliyun.com/?spm=5176.100054.3.1.DGkmH7#/pub/ecs/open-api/vswitch&describevswitches] + def list_route_tables(vrouterid, options={}) + + action = 'DescribeRouteTables' + sigNonce = randonStr() + time = Time.new.utc + + parameters = defalutParameters(action, sigNonce, time) + pathUrl = defaultAliyunUri(action, sigNonce, time) + + parameters["VRouterId"] = vrouterid + pathUrl += '&VRouterId=' + pathUrl += vrouterid + + pageNumber = options[:pageNumber] + pageSize = options[:pageSize] + routeTableId = options[:routeTableId] + if routeTableId + parameters["RouteTableId"] = routeTableId + pathUrl +='&RouteTableId=' + pathUrl += routeTableId + end + if pageNumber + parameters["PageNumber"] = pageNumber + pathUrl += '&PageNumber=' + pathUrl += pageNumber + end + + unless pageSize + pageSize = '50' + end + parameters["PageSize"] = pageSize + pathUrl += '&PageSize=' + pathUrl += pageSize + + signature = sign(@aliyun_accesskey_secret, parameters) + pathUrl += '&Signature=' + pathUrl += signature + + request( + :expects => [200, 203], + :method => 'GET', + :path => pathUrl + ) + end + end + + class Mock + def list_route_tables(vrouterid, options={}) + response = Excon::Response.new + data = list_images_detail.body['images'] + images = [] + for image in data + images << image.reject { |key, value| !['id', 'name', 'links'].include?(key) } + end + response.status = [200, 203][rand(1)] + response.body = { 'images' => images } + response + end + end + end + end +end diff --git a/lib/fog/aliyun/requests/compute/list_security_groups.rb b/lib/fog/aliyun/requests/compute/list_security_groups.rb index b36e115..33eac71 100644 --- a/lib/fog/aliyun/requests/compute/list_security_groups.rb +++ b/lib/fog/aliyun/requests/compute/list_security_groups.rb @@ -14,7 +14,7 @@ def list_security_groups(options={}) pageNumber = options[:pageNumber] pageSize = options[:pageSize] - vpcId = options[:vpcid] + vpcId = options[:vpcId] if vpcId parameters["VpcId"] = vpcId diff --git a/lib/fog/aliyun/requests/compute/list_servers.rb b/lib/fog/aliyun/requests/compute/list_servers.rb index 5992cc3..e704f5b 100644 --- a/lib/fog/aliyun/requests/compute/list_servers.rb +++ b/lib/fog/aliyun/requests/compute/list_servers.rb @@ -12,11 +12,11 @@ def list_servers(options={}) _parameters = defalutParameters(_action, _sigNonce, _time) _pathURL = defaultAliyunUri(_action, _sigNonce, _time) - _InstanceId = options[:aliyun_InstanceId] - _VpcId = options[:aliyun_VpcId] - _SecurityGroupId = options[:aliyun_SecurityGroupId] - _PageNumber = options[:aliyun_PageNumber] - _PageSize = options[:aliyun_PageSize] + _InstanceId = options[:instanceId] + _VpcId = options[:vpcId] + _SecurityGroupId = options[:securityGroupId] + _PageNumber = options[:pageNumber] + _PageSize = options[:pageSize] if _InstanceId != nil _InstanceStr = "[\"#{_InstanceId}\"]" diff --git a/lib/fog/aliyun/requests/compute/list_vrouters.rb b/lib/fog/aliyun/requests/compute/list_vrouters.rb new file mode 100644 index 0000000..eef9b7c --- /dev/null +++ b/lib/fog/aliyun/requests/compute/list_vrouters.rb @@ -0,0 +1,64 @@ +module Fog + module Compute + class Aliyun + class Real + # {Aliyun API Reference}[https://docs.aliyun.com/?spm=5176.100054.3.1.DGkmH7#/pub/ecs/open-api/vpc&describevpcs] + def list_vrouters(options={}) + + action = 'DescribeVrouters' + sigNonce = randonStr() + time = Time.new.utc + + parameters = defalutParameters(action, sigNonce, time) + pathUrl = defaultAliyunUri(action, sigNonce, time) + + _VRouterId = options[:vRouterId] + if _VRouterId + parameters["VRouterId"] = _VRouterId + pathUrl += '&VRouterId=' + pathUrl += _VRouterId + end + + pageNumber = options[:pageNumber] + pageSize = options[:pageSize] + if pageNumber + parameters["PageNumber"] = pageNumber + pathUrl += '&PageNumber=' + pathUrl += pageNumber + end + + unless pageSize + pageSize = '50' + end + parameters["PageSize"] = pageSize + pathUrl += '&PageSize=' + pathUrl += pageSize + + signature = sign(@aliyun_accesskey_secret, parameters) + pathUrl += '&Signature=' + pathUrl += signature + + request( + :expects => [200, 203], + :method => 'GET', + :path => pathUrl + ) + end + end + + class Mock + def list_vrouters + response = Excon::Response.new + data = list_images_detail.body['VRouters'] + images = [] + for image in data + images << image.reject { |key, value| !['id', 'name', 'links'].include?(key) } + end + response.status = [200, 203][rand(1)] + response.body = { 'VRouter' => images } + response + end + end + end + end +end diff --git a/lib/fog/aliyun/version.rb b/lib/fog/aliyun/version.rb index 0cbffb9..80e9f49 100644 --- a/lib/fog/aliyun/version.rb +++ b/lib/fog/aliyun/version.rb @@ -1,5 +1,5 @@ module Fog module Aliyun - VERSION = "0.0.7" + VERSION = "0.0.10" end end