Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion fog-aliyun.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require 'fog/aliyun/version'
Gem::Specification.new do |spec|
spec.name = 'fog-aliyun'
spec.version = Fog::Aliyun::VERSION
spec.authors = ['Qinsi Deng, Jianxun Li, Jane Han']
spec.authors = ['Qinsi Deng, Jianxun Li, Jane Han, Ricky Smith']
spec.email = ['[email protected]']

spec.summary = 'Fog provider for Aliyun Web Services.'
Expand Down
17 changes: 11 additions & 6 deletions lib/fog/aliyun/compute.rb
Original file line number Diff line number Diff line change
Expand Up @@ -303,13 +303,18 @@ def reload

def request(params)
begin
response = @connection.request(params.merge(headers: {
headers = {
'Content-Type' => 'application/json',
'Accept' => 'application/json',
'X-Auth-Token' => @auth_token
}.merge!(params[:headers] || {}),
path: "#{@path}/#{params[:path]}",
query: params[:query]))
}.merge!(params[:headers] || {})

request_params = params.merge(
headers: headers,
path: "#{@path}/#{params[:path]}",
query: params[:query])

response = @connection.request(request_params)
rescue Excon::Errors::HTTPStatusError => error
raise case error
when Excon::Errors::NotFound
Expand All @@ -319,7 +324,7 @@ def request(params)
end
end

response.body = Fog::JSON.decode(response.body) if !response.body.empty? && response.get_header('Content-Type') == 'application/json'
response.body = Fog::JSON.decode(response.body) if !response.body.empty? && response.get_header('Content-Type').start_with?('application/json')

response
end
Expand All @@ -342,7 +347,7 @@ def VPCrequest(params)
end
end

response.body = Fog::JSON.decode(response.body) if !response.body.empty? && response.get_header('Content-Type') == 'application/json'
response.body = Fog::JSON.decode(response.body) if !response.body.empty? && response.get_header('Content-Type').start_with?('application/json')

response
end
Expand Down
2 changes: 1 addition & 1 deletion lib/fog/aliyun/models/compute/eip_address.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def save(options = {})
options[:bandwidth] = bandwidth if bandwidth
options[:internet_charge_type] = charge_type if charge_type

data = Fog::JSON.decode(service.allocate_eip_address(options).body)
data = service.allocate_eip_address(options).body
merge_attributes(data)
true
end
Expand Down
2 changes: 1 addition & 1 deletion lib/fog/aliyun/models/compute/eip_addresses.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ 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']
data = service.list_eip_addresses(filters_arg).body['EipAddresses']['EipAddress']
load(data)
# load(data['volumeSet'])
# if server
Expand Down
2 changes: 1 addition & 1 deletion lib/fog/aliyun/models/compute/image.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def save(options = {})
requires :snapshot_id
options[:name] = name if name
options[:description] = description if description
data = Fog::JSON.decode(service.create_image(snapshot_id, options).body)
data = service.create_image(snapshot_id, options).body
merge_attributes(data)
true
end
Expand Down
2 changes: 1 addition & 1 deletion lib/fog/aliyun/models/compute/images.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def all(filters_arg = {})
Fog::Logger.deprecation("all with #{filters_arg.class} param is deprecated, use all('diskIds' => []) instead [light_black](#{caller.first})[/]")
filters_arg = { imageId: filters_arg }
end
data = Fog::JSON.decode(service.list_images(filters_arg).body)['Images']['Image']
data = service.list_images(filters_arg).body['Images']['Image']
load(data)
end

Expand Down
2 changes: 1 addition & 1 deletion lib/fog/aliyun/models/compute/route_entrys.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class RouteEntrys < Fog::Collection
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']
data = service.list_route_tables(route_table.v_router_id, options).body['RouteTables']['RouteTable'][0]['RouteEntrys']['RouteEntry']
load(data)
end

Expand Down
2 changes: 1 addition & 1 deletion lib/fog/aliyun/models/compute/route_tables.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class RouteTables < Fog::Collection

def all(options = {})
requires :v_router
data = Fog::JSON.decode(service.list_route_tables(v_router.id, options).body)['RouteTables']['RouteTable']
data = service.list_route_tables(v_router.id, options).body['RouteTables']['RouteTable']
load(data)
end

Expand Down
2 changes: 1 addition & 1 deletion lib/fog/aliyun/models/compute/security_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def save(options = {})
options[:vpcId] = vpc_id if vpc_id
options[:name] = name if name
options[:description] = description if description
Fog::JSON.decode(service.create_security_group(options).body)
service.create_security_group(options).body
true
end

Expand Down
2 changes: 1 addition & 1 deletion lib/fog/aliyun/models/compute/security_group_rules.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class SecurityGroupRules < Fog::Collection
attribute :security_group_id

def get(security_group_id, options = {})
data = Fog::JSON.decode(service.list_security_group_rules(security_group_id, options).body)
data = service.list_security_group_rules(security_group_id, options).body
self.security_group_id = data['SecurityGroupId']
permissions = data['Permissions']['Permission']
permissions.each do |permission|
Expand Down
2 changes: 1 addition & 1 deletion lib/fog/aliyun/models/compute/security_groups.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class SecurityGroups < Fog::Collection
model Fog::Compute::Aliyun::SecurityGroup

def all(options = {})
data = Fog::JSON.decode(service.list_security_groups(options).body)['SecurityGroups']['SecurityGroup']
data = service.list_security_groups(options).body['SecurityGroups']['SecurityGroup']
load(data)
# ['Images']['Image']
end
Expand Down
4 changes: 4 additions & 0 deletions lib/fog/aliyun/models/compute/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ class Server < Fog::Compute::Server
attribute :charge_type, aliases: 'InstanceChargeType'
attribute :operation_locks, aliases: 'OperationLocks'
attribute :expired_at, aliases: 'ExpiredTime'
attribute :spot_strategy, aliases: 'SpotStrategy'
attribute :spot_price_limit, aliases: 'SpotPriceLimit'
attribute :spot_duration, aliases: 'SpotDuration'
attribute :spot_interruption_behavior, aliases: 'SpotInterruptionBehavior'

def image
requires :image_id
Expand Down
4 changes: 2 additions & 2 deletions lib/fog/aliyun/models/compute/servers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ class Servers < Fog::Collection
model Fog::Compute::Aliyun::Server

def all(options = {})
data = Fog::JSON.decode(service.list_servers(options).body)['Instances']['Instance']
load(data)
response = service.list_servers(options).body
load(response['Instances']['Instance'])
end

# Creates a new server and populates ssh keys
Expand Down
2 changes: 1 addition & 1 deletion lib/fog/aliyun/models/compute/snapshot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def save(options = {})
requires :volume_id
options[:name] = name if name
options[:description] = description if description
data = Fog::JSON.decode(service.create_snapshot(volume_id, options).body)
data = service.create_snapshot(volume_id, options).body
merge_attributes(data)
true
end
Expand Down
2 changes: 1 addition & 1 deletion lib/fog/aliyun/models/compute/snapshots.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def all(filters_arg = {})
volume_type = filters_arg[:volume_type]
filters_arg[:diskId] = volume_id if volume_id
filters_arg[:sourseDiskType] = volume_type if volume_type
data = Fog::JSON.decode(service.list_snapshots(filters_arg).body)['Snapshots']['Snapshot']
data = service.list_snapshots(filters_arg).body['Snapshots']['Snapshot']
load(data)
end

Expand Down
4 changes: 2 additions & 2 deletions lib/fog/aliyun/models/compute/volume.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ def save(options = {})
options[:name] = name if name
options[:description] = description if description
if snapshot_id
data = Fog::JSON.decode(service.create_disk_by_snapshot(snapshot_id, options).body)
data = service.create_disk_by_snapshot(snapshot_id, options).body
merge_attributes(data)
elsif size
data = Fog::JSON.decode(service.create_disk(size, options).body)
data = service.create_disk(size, options).body
merge_attributes(data)
end

Expand Down
2 changes: 1 addition & 1 deletion lib/fog/aliyun/models/compute/volumes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def all(filters_arg = {})
Fog::Logger.deprecation("all with #{filters_arg.class} param is deprecated, use all('diskIds' => []) instead [light_black](#{caller.first})[/]")
filters_arg = { 'diskIds' => [*filters_arg] }
end
data = Fog::JSON.decode(service.list_disks(filters_arg).body)['Disks']['Disk']
data = service.list_disks(filters_arg).body['Disks']['Disk']
load(data)
# load(data['volumeSet'])
# if server
Expand Down
2 changes: 1 addition & 1 deletion lib/fog/aliyun/models/compute/vpc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def save(options = {})
requires :cidr_block
options[:name] = name if name
options[:description] = description if description
Fog::JSON.decode(service.create_vpc(cidr_block, options).body)
service.create_vpc(cidr_block, options).body
true
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/fog/aliyun/models/compute/vpcs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def all(filters_arg = {})
Fog::Logger.warning("all with #{filters_arg.class} param is deprecated, use all('vpcId' => []) instead [light_black](#{caller.first})[/]")
filters_arg = { 'vpcId' => [*filters_arg] }
end
data = Fog::JSON.decode(service.list_vpcs(filters_arg).body)['Vpcs']['Vpc']
data = service.list_vpcs(filters_arg).body['Vpcs']['Vpc']
load(data)
end

Expand Down
2 changes: 1 addition & 1 deletion lib/fog/aliyun/models/compute/vrouters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def all(filters_arg = {})
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']
data = service.list_vrouters(filters_arg).body['VRouters']['VRouter']
load(data)
end

Expand Down
4 changes: 2 additions & 2 deletions lib/fog/aliyun/models/compute/vswitch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def save(options = {})
requires :vpc, :cidr_block
options[:name] = name if name
options[:description] = description if description
Fog::JSON.decode(service.create_vswitch(vpc.id, cidr_block, options).body)
service.create_vswitch(vpc.id, cidr_block, options).body
true
end

Expand All @@ -64,7 +64,7 @@ def vpc
end

def all
Fog::JSON.decode(service.list_vswitchs(vpc_id).body)['VSwitches']['VSwitch']
service.list_vswitchs(vpc_id).body['VSwitches']['VSwitch']
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/fog/aliyun/models/compute/vswitches.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class Vswitches < Fog::Collection

def all(options = {})
requires :vpc
data = Fog::JSON.decode(service.list_vswitchs(vpc.id, options).body)['VSwitches']['VSwitch']
data = service.list_vswitchs(vpc.id, options).body['VSwitches']['VSwitch']
load(data)
end

Expand Down
39 changes: 21 additions & 18 deletions lib/fog/aliyun/requests/compute/create_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,80 +11,83 @@ def create_server(imageId, securityGroupId, instanceType, options = {})
_time = Time.new.utc

_parameters = defalutParameters(_action, _sigNonce, _time)
_pathURL = defaultAliyunUri(_action, _sigNonce, _time)

_parameters['ImageId'] = imageId
_pathURL += '&ImageId=' + imageId

_parameters['InstanceType'] = instanceType
_pathURL += '&InstanceType=' + instanceType

_parameters['SecurityGroupId'] = securityGroupId
_pathURL += '&SecurityGroupId=' + securityGroupId

_ZoneId = options[:ZoneId]
if _ZoneId
_parameters['ZoneId'] = _ZoneId
_pathURL += '&ZoneId=' + _ZoneId
end

_InstanceName = options[:InstanceName]
if _InstanceName
_parameters['InstanceName'] = _InstanceName
_pathURL += '&InstanceName=' + _InstanceName
end

_Description = options[:Description]
if _Description
_parameters['Description'] = _Description
_pathURL += '&Description=' + _Description
end

_InternetChargeType = options[:InternetChargeType]
if _InternetChargeType
_parameters['InternetChargeType'] = _InternetChargeType
_pathURL += '&InternetChargeType=' + _InternetChargeType
end

_HostName = options[:HostName]
if _HostName
_parameters['HostName'] = _HostName
_pathURL += '&HostName=' + _HostName
end

_Password = options[:Password]
if _Password
_parameters['Password'] = _Password
_pathURL += '&Password=' + _Password
end

_SpotStrategy = options[:SpotStrategy]
if _SpotStrategy
_parameters['SpotStrategy'] = _SpotStrategy
end

_SpotPriceLimit = options[:SpotPriceLimit]
if _SpotPriceLimit
_parameters['SpotPriceLimit'] = _SpotPriceLimit
end

_SpotDuration = options[:SpotDuration]
if _SpotDuration
_parameters['SpotDuration'] = _SpotDuration
end

_SpotInterruptionBehavior = options[:SpotInterruptionBehavior]
if _SpotInterruptionBehavior
_parameters['SpotInterruptionBehavior'] = _SpotInterruptionBehavior
end

_VSwitchId = options[:VSwitchId]
_PrivateIpAddress = options[:PrivateIpAddress]
if _VSwitchId
_parameters['VSwitchId'] = _VSwitchId
_pathURL += '&VSwitchId=' + _VSwitchId

if _PrivateIpAddress
_parameters['PrivateIpAddress'] = _PrivateIpAddress
_pathURL += '&PrivateIpAddress=' + _PrivateIpAddress
end
else

_InternetMaxBandwidthIn = options[:InternetMaxBandwidthIn]
if _InternetMaxBandwidthIn
_parameters['InternetMaxBandwidthIn'] = _InternetMaxBandwidthIn
_pathURL += '&InternetMaxBandwidthIn=' + _InternetMaxBandwidthIn
end

_InternetMaxBandwidthOut = options[:InternetMaxBandwidthOut]
if _InternetMaxBandwidthOut
_parameters['InternetMaxBandwidthOut'] = _InternetMaxBandwidthOut
_pathURL += '&InternetMaxBandwidthOut=' + _InternetMaxBandwidthOut
end
end

_signature = sign(@aliyun_accesskey_secret, _parameters)
_pathURL += '&Signature=' + _signature
_pathURL = defaultAliyunUri(_action, _sigNonce, _time) + '&' + _parameters.merge({Signature: _signature}).map{|k,v| "#{k}=#{v}" }.join('&')

request(
expects: [200, 203],
Expand Down