Class: Fog::Compute::Aliyun::Real

Inherits:
Object
  • Object
show all
Defined in:
lib/fog/aliyun/compute.rb,
lib/fog/aliyun/requests/compute/list_vpcs.rb,
lib/fog/aliyun/requests/compute/create_vpc.rb,
lib/fog/aliyun/requests/compute/delete_vpc.rb,
lib/fog/aliyun/requests/compute/list_disks.rb,
lib/fog/aliyun/requests/compute/list_zones.rb,
lib/fog/aliyun/requests/compute/modify_vpc.rb,
lib/fog/aliyun/requests/compute/attach_disk.rb,
lib/fog/aliyun/requests/compute/create_disk.rb,
lib/fog/aliyun/requests/compute/delete_disk.rb,
lib/fog/aliyun/requests/compute/detach_disk.rb,
lib/fog/aliyun/requests/compute/list_images.rb,
lib/fog/aliyun/requests/compute/stop_server.rb,
lib/fog/aliyun/requests/compute/create_image.rb,
lib/fog/aliyun/requests/compute/delete_image.rb,
lib/fog/aliyun/requests/compute/list_servers.rb,
lib/fog/aliyun/requests/compute/start_server.rb,
lib/fog/aliyun/requests/compute/create_server.rb,
lib/fog/aliyun/requests/compute/delete_server.rb,
lib/fog/aliyun/requests/compute/list_vrouters.rb,
lib/fog/aliyun/requests/compute/list_vswitchs.rb,
lib/fog/aliyun/requests/compute/reboot_server.rb,
lib/fog/aliyun/requests/compute/create_vswitch.rb,
lib/fog/aliyun/requests/compute/delete_vswitch.rb,
lib/fog/aliyun/requests/compute/list_snapshots.rb,
lib/fog/aliyun/requests/compute/modify_vswitch.rb,
lib/fog/aliyun/requests/compute/create_snapshot.rb,
lib/fog/aliyun/requests/compute/delete_snapshot.rb,
lib/fog/aliyun/requests/compute/list_route_tables.rb,
lib/fog/aliyun/requests/compute/list_server_types.rb,
lib/fog/aliyun/requests/compute/list_eip_addresses.rb,
lib/fog/aliyun/requests/compute/join_security_group.rb,
lib/fog/aliyun/requests/compute/release_eip_address.rb,
lib/fog/aliyun/requests/compute/allocate_eip_address.rb,
lib/fog/aliyun/requests/compute/leave_security_group.rb,
lib/fog/aliyun/requests/compute/list_security_groups.rb,
lib/fog/aliyun/requests/compute/associate_eip_address.rb,
lib/fog/aliyun/requests/compute/create_security_group.rb,
lib/fog/aliyun/requests/compute/delete_security_group.rb,
lib/fog/aliyun/requests/compute/unassociate_eip_address.rb,
lib/fog/aliyun/requests/compute/list_security_group_rules.rb,
lib/fog/aliyun/requests/compute/allocate_public_ip_address.rb,
lib/fog/aliyun/requests/compute/create_security_group_ip_rule.rb,
lib/fog/aliyun/requests/compute/create_security_group_sg_rule.rb,
lib/fog/aliyun/requests/compute/delete_security_group_ip_rule.rb,
lib/fog/aliyun/requests/compute/delete_security_group_sg_rule.rb,
lib/fog/aliyun/requests/compute/create_security_group_egress_ip_rule.rb,
lib/fog/aliyun/requests/compute/create_security_group_egress_sg_rule.rb,
lib/fog/aliyun/requests/compute/delete_security_group_egress_ip_rule.rb,
lib/fog/aliyun/requests/compute/delete_security_group_egress_sg_rule.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Real

Returns a new instance of Real.

Raises:

  • (ArgumentError)


261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
# File 'lib/fog/aliyun/compute.rb', line 261

def initialize(options={})

  #initialize the parameters
  @aliyun_url              = options[:aliyun_url]
  @aliyun_accesskey_id     = options[:aliyun_accesskey_id]
  @aliyun_accesskey_secret = options[:aliyun_accesskey_secret]
  @aliyun_region_id        = options[:aliyun_region_id]
  @aliyun_zone_id          = options[:aliyun_zone_id]

  #check for the parameters
  missing_credentials = Array.new
  missing_credentials << :aliyun_accesskey_id  unless @aliyun_accesskey_id
  missing_credentials << :aliyun_accesskey_secret unless @aliyun_accesskey_secret
  missing_credentials << :aliyun_region_id unless @aliyun_region_id
  missing_credentials << :aliyun_url unless @aliyun_url
  missing_credentials << :aliyun_zone_id unless @aliyun_zone_id
  raise ArgumentError, "Missing required arguments: #{missing_credentials.join(', ')}" unless missing_credentials.empty?

  @connection_options = options[:connection_options] || {}
  
  uri = URI.parse(@aliyun_url)
  @host   = uri.host
  @path   = uri.path
  @port   = uri.port
  @scheme = uri.scheme

  @persistent = options[:persistent] || false
  @connection = Fog::Core::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options)

end

Instance Attribute Details

#aliyun_accesskey_idObject (readonly)

Initialize connection to ECS

Notes

options parameter must include values for :aliyun_url, :aliyun_accesskey_id, :aliyun_secret_access_key, :aliyun_region_id and :aliyun_zone_id in order to create a connection. if you haven’t set these values in the configuration file.

Examples

sdb = Fog::Compute.new(:provider=>'aliyun',
 :aliyun_accesskey_id => your_:aliyun_accesskey_id,
 :aliyun_secret_access_key => your_aliyun_secret_access_key
)

Parameters

  • options<~Hash> - config arguments for connection. Defaults to {}.

Returns

  • ECS object with connection to aliyun.



255
256
257
# File 'lib/fog/aliyun/compute.rb', line 255

def aliyun_accesskey_id
  @aliyun_accesskey_id
end

#aliyun_accesskey_secretObject (readonly)

Returns the value of attribute aliyun_accesskey_secret.



256
257
258
# File 'lib/fog/aliyun/compute.rb', line 256

def aliyun_accesskey_secret
  @aliyun_accesskey_secret
end

#aliyun_region_idObject (readonly)

Returns the value of attribute aliyun_region_id.



257
258
259
# File 'lib/fog/aliyun/compute.rb', line 257

def aliyun_region_id
  @aliyun_region_id
end

#aliyun_urlObject (readonly)

Returns the value of attribute aliyun_url.



258
259
260
# File 'lib/fog/aliyun/compute.rb', line 258

def aliyun_url
  @aliyun_url
end

#aliyun_zone_idObject (readonly)

Returns the value of attribute aliyun_zone_id.



259
260
261
# File 'lib/fog/aliyun/compute.rb', line 259

def aliyun_zone_id
  @aliyun_zone_id
end

Instance Method Details

#allocate_eip_address(options = {}) ⇒ Object

Allocate an eip IP address.

Notes

The new eip Ip address would be avalable The allocated eip Ip address can only associate to the instance of the vpc in the same region Now the eip can support ICMP,TCP,UDP

Parameters

  • server_id<~String> - id of the instance

  • allocationId<~String> - id of the EIP

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • ‘EipAddress’<~String> - the allocated eip address

      • ‘AllocationId’<~String> - the instance id on the public ip

      • ‘RequestId’<~String> - Id of the request

Aliyun API Reference



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/fog/aliyun/requests/compute/allocate_eip_address.rb', line 22

def allocate_eip_address(options={})
  
  _action = 'AllocateEipAddress'
  _sigNonce = randonStr()
  _time = Time.new.utc

  _parameters = defalutParameters(_action, _sigNonce, _time)
  _pathURL  = defaultAliyunUri(_action, _sigNonce, _time)
  
  #optional parameters
  _Bandwidth = options[:bandwidth]
  if _Bandwidth
    _parameters['Bandwidth']=_Bandwidth
    _pathURL += '&Bandwidth='+_Bandwidth
  end
  
  _InternetChargeType = options[:internet_charge_type]
  unless _InternetChargeType
    _InternetChargeType = 'PayByTraffic'
  end
  _parameters['InternetChargeType']=_InternetChargeType
  _pathURL += '&InternetChargeType='+_InternetChargeType
  
  _signature = sign(@aliyun_accesskey_secret, _parameters)
  _pathURL += '&Signature='+_signature
  
  request(
    :expects => [200, 204],
    :method => 'GET',
    :path   => _pathURL
  )
end

#allocate_public_ip_address(server_id) ⇒ Object

Allocate an avalable public IP address to the given instance.

Parameters

  • server_id<~String> - id of the instance

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • ‘IpAddress’<~String> - The allocated ip address

      • ‘RequestId’<~String> - Id of the request

Aliyun API Reference



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/fog/aliyun/requests/compute/allocate_public_ip_address.rb', line 16

def allocate_public_ip_address(server_id)
  
  _action = 'AllocatePublicIpAddress'
  _sigNonce = randonStr()
  _time = Time.new.utc

  _parameters = defalutParameters(_action, _sigNonce, _time)
  _pathURL  = defaultAliyunUri(_action, _sigNonce, _time)
  
  _parameters['InstanceId']=server_id
    _pathURL += '&InstanceId='+server_id
    
  _signature = sign(@aliyun_accesskey_secret, _parameters)
  _pathURL += '&Signature='+_signature
  
  request(
    :expects => [200, 204],
    :method => 'GET',
    :path   => _pathURL
  )
end

#associate_eip_address(server_id, allocationId, options = {}) ⇒ Object

Associate an avalable eip IP address to the given instance.

Parameters

  • server_id<~String> - id of the instance

  • allocationId<~String> - id of the EIP

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • ‘RequestId’<~String> - Id of the request

Aliyun API Reference



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/fog/aliyun/requests/compute/associate_eip_address.rb', line 16

def associate_eip_address(server_id, allocationId,options={})
  
  _action = 'AssociateEipAddress'
  _sigNonce = randonStr()
  _time = Time.new.utc

  type=options['instance_type']

  _parameters = defalutParameters(_action, _sigNonce, _time)
  _pathURL  = defaultAliyunUri(_action, _sigNonce, _time)
  
  _parameters['InstanceId'] = server_id
  _pathURL += '&InstanceId='+server_id
  
  _parameters['AllocationId'] = allocationId
  _pathURL += '&AllocationId='+allocationId

  if type
    _parameters['InstanceType'] = type
    _pathURL += 'InstanceType='+type
  end
  
  _signature = sign(@aliyun_accesskey_secret, _parameters)
  _pathURL += '&Signature='+_signature
  
  request(
    :expects => [200, 204],
    :method => 'GET',
    :path   => _pathURL
  )
end

#attach_disk(instanceId, diskId, options = {}) ⇒ Object

Mount a disk.

Parameters

  • instanceId<~String> - id of the instance

  • diskId<~String> - id of the disk

  • options<~hash>

    * :deleteWithInstance - if 'true',the disk will be relese with the instance.else, won't
    * :device - if nil, the system will default allocate from /dev/xvdb to /dev/xvdz. default nil
    

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • ‘RequestId’<~String> - Id of the request

Aliyun API Reference



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/fog/aliyun/requests/compute/attach_disk.rb', line 19

def attach_disk(instanceId, diskId, options={})
  action   = 'AttachDisk'
  sigNonce = randonStr()
  time     = Time.new.utc

  parameters = defalutParameters(action, sigNonce, time)
  pathUrl    = defaultAliyunUri(action, sigNonce, time)
  
  parameters["InstanceId"] = instanceId
  pathUrl += '&InstanceId='
  pathUrl += instanceId 

  parameters["DiskId"] = diskId
  pathUrl += '&DiskId='
  pathUrl += diskId
  
  deleteWithInstance = options[:deleteWithInstance]
  device             = options[:device]
  
  unless deleteWithInstance
    deleteWithInstance = 'true' 
  end

  parameters["DeleteWithInstance"] = deleteWithInstance
  pathUrl += '&DeleteWithInstance='
  pathUrl += deleteWithInstance


  if device
    parameters["Device"] = device
    pathUrl += '&Device='
    pathUrl += URI.encode(device,'/[^!*\'()\;?:@#&%=+$,{}[]<>`" ')
  end

  signature = sign(@aliyun_accesskey_secret, parameters)
  pathUrl += '&Signature='
  pathUrl += signature

  request(
    :expects  => [200, 203],
    :method   => 'GET',
    :path     => pathUrl
  )
end

#create_disk(size, options = {}) ⇒ Object

Create a disk with assigned size.

Parameters

  • size<~String> - the size of the disk (GB).–cloud:5~2000GB,cloud_efficiency: 20~2048GB,cloud_ssd:20~1024GB

  • options<~hash>

    * :name - The name of the disk,default nil. If not nil, it must start with english or chinise character. 
         The length should be within [2,128]. It can contain digits,'.','_' or '-'.It shouldn't start with 'http://' or 'https://'
    * :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://'
    * :category - Default 'cloud'. can be set to 'cloud','cloud_efficiency' or 'cloud_ssd'
    

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • ‘RequestId’<~String> - Id of the request

      • ‘DiskId’<~String> - Id of the created disk

Aliyun API Reference



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/fog/aliyun/requests/compute/create_disk.rb', line 21

def create_disk(size, options={})

  action   = 'CreateDisk'
  sigNonce = randonStr()
  time     = Time.new.utc

  parameters = defalutParameters(action, sigNonce, time)
  pathUrl    = defaultAliyunUri(action, sigNonce, time)

  parameters["ZoneId"] = @aliyun_zone_id
  pathUrl += '&ZoneId='
  pathUrl += @aliyun_zone_id  
  
  parameters["Size"] = size
  pathUrl += '&Size='
  pathUrl += size 

  name  = options[:name]
  desc  = options[:description]
  category = options[:category]


  if name
    parameters["DiskName"] = name
    pathUrl += '&DiskName='
    pathUrl += name 
  end

  if desc
    parameters["Description"] = desc
    pathUrl += '&Description='
    pathUrl += desc 
  end

  if category
    parameters["DiskCategory"] = category
    pathUrl += 'DiskCategory'
    pathUrl += category
  end

  signature = sign(@aliyun_accesskey_secret, parameters)
  pathUrl += '&Signature='
  pathUrl += signature

  request(
    :expects  => [200, 203],
    :method   => 'GET',
    :path     => pathUrl
  ).merge(options)
end

#create_disk_by_snapshot(snapshotId, options = {}) ⇒ Object

Create a disk By the snapshot with given snapshot_id.

Parameters

  • snapshotId<~String> - the snapshot_id

  • options<~hash>

    * :name - The name of the disk,default nil. If not nil, it must start with english or chinise character. 
         The length should be within [2,128]. It can contain digits,'.','_' or '-'.It shouldn't start with 'http://' or 'https://'
    * :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://'
    * :category - Default 'cloud'. can be set to 'cloud','cloud_efficiency' or 'cloud_ssd'
    

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • ‘RequestId’<~String> - Id of the request

      • ‘DiskId’<~String> - Id of the created disk

Aliyun API Reference



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/fog/aliyun/requests/compute/create_disk.rb', line 87

def create_disk_by_snapshot(snapshotId, options={})

  action   = 'CreateDisk'
  sigNonce = randonStr()
  time     = Time.new.utc

  parameters = defalutParameters(action, sigNonce, time)
  pathUrl    = defaultAliyunUri(action, sigNonce, time)

  parameters["ZoneId"] = @aliyun_zone_id
  pathUrl += '&ZoneId='
  pathUrl += @aliyun_zone_id  
  
  parameters["SnapshotId"] = snapshotId
  pathUrl += '&SnapshotId='
  pathUrl += snapshotId 

  name  = options[:name]
  desc  = options[:description]
  category = options[:category]

  if name
    parameters["DiskName"] = name
    pathUrl += '&DiskName='
    pathUrl += name 
  end

  if desc
    parameters["Description"] = desc
    pathUrl += '&Description='
    pathUrl += desc 
  end

  if category
    parameters["DiskCategory"] = category
    pathUrl += 'DiskCategory'
    pathUrl += category
  end

  signature = sign(@aliyun_accesskey_secret, parameters)
  pathUrl += '&Signature='
  pathUrl += signature

  request(
    :expects  => [200, 203],
    :method   => 'GET',
    :path     => pathUrl
  )
end

#create_image(snapshotId, options = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/fog/aliyun/requests/compute/create_image.rb', line 6

def create_image(snapshotId, options={})
  action = 'CreateImage'
  sigNonce = randonStr()
  time = Time.new.utc

  parameters = defalutParameters(action, sigNonce, time)
  pathUrl    = defaultAliyunUri(action, sigNonce, time)

  parameters["SnapshotId"] = snapshotId
  pathUrl += '&SnapshotId='
  pathUrl += snapshotId 
 
  name = options[:name]
  if name
    parameters["ImageName"] = name
    pathUrl += '&ImageName='
    pathUrl += name 
  end
  
  desc = options[:description]
  if desc
    parameters["Description"] = desc
    pathUrl += '&Description='
    pathUrl += desc
  end
  
  version = options[:version]
  if version
    parameters["ImageVersion"] = version
    pathUrl += '&ImageVersion='
    pathUrl += version
  end

  signature = sign(@aliyun_accesskey_secret, parameters)
  pathUrl += '&Signature='
  pathUrl += signature

  request(
    :expects  => [200, 203],
    :method   => 'GET',
    :path     => pathUrl
  )
end

#create_security_group(options = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/fog/aliyun/requests/compute/create_security_group.rb', line 6

def create_security_group(options={})

  action   = 'CreateSecurityGroup'
  sigNonce = randonStr()
  time     = Time.new.utc

  parameters = defalutParameters(action, sigNonce, time)
  pathUrl    = defaultAliyunUri(action, sigNonce, time)

  name  = options[:name]
  desc  = options[:description]
  vpcid = options[:vpcId]

  if name
    parameters["SecurityGroupName"] = name
    pathUrl += '&SecurityGroupName='
    pathUrl += name 
  end

  if desc
    parameters["Description"] = desc
    pathUrl += '&Description='
    pathUrl += desc 
  end

  if vpcid
    parameters["VpcId"] = vpcid
    pathUrl += '&VpcId='
    pathUrl += vpcid  
  end

  signature = sign(@aliyun_accesskey_secret, parameters)
  pathUrl += '&Signature='
  pathUrl += signature

  request(
    :expects  => [200, 203],
    :method   => 'GET',
    :path     => pathUrl
  )
end

#create_security_group_egress_ip_rule(securitygroup_id, destCidrIp, nicType, option = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/fog/aliyun/requests/compute/create_security_group_egress_ip_rule.rb', line 6

def create_security_group_egress_ip_rule(securitygroup_id,destCidrIp, nicType, option={})

  action   = 'AuthorizeSecurityGroupEgress'
  sigNonce = randonStr()
  time     = Time.new.utc

  parameters = defalutParameters(action, sigNonce, time)
  pathUrl    = defaultAliyunUri(action, sigNonce, time)
  
  parameters["SecurityGroupId"] = securitygroup_id
  pathUrl += '&SecurityGroupId='
  pathUrl += securitygroup_id

  parameters["DestCidrIp"] = destCidrIp
  pathUrl += '&DestCidrIp='
  pathUrl += URI.encode(destCidrIp,'/[^!*\'()\;?:@#&%=+$,{}[]<>`" ')  
  unless nicType
    nicType='intranet'
  end
  parameters["NicType"] = nicType
  pathUrl += '&NicType='
  pathUrl += nicType
  
  portRange = option[:portRange]
  unless portRange
    portRange = '-1/-1'
  end
  parameters["PortRange"] = portRange
  pathUrl += '&PortRange='
  pathUrl += URI.encode(portRange,'/[^!*\'()\;?:@#&%=+$,{}[]<>`" ')
  
  protocol = option[:protocol]
  unless protocol
    protocol = 'all'
  end
  parameters["IpProtocol"] = protocol
  pathUrl += '&IpProtocol='
  pathUrl += protocol

  policy = option[:policy]
  unless policy
    policy = 'accept'
  end
  parameters["Policy"] = policy
  pathUrl += '&Policy='
  pathUrl += policy

  priority = option[:priority]
  unless priority
    priority = '1'
  end
  parameters["Priority"] = priority
  pathUrl += '&Priority='
  pathUrl += priority

  signature = sign(@aliyun_accesskey_secret, parameters)
  pathUrl += '&Signature='
  pathUrl += signature

  request(
    :expects  => [200, 203],
    :method   => 'GET',
    :path     => pathUrl
  )
end

#create_security_group_egress_sg_rule(securitygroup_id, dest_group_id, option = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/fog/aliyun/requests/compute/create_security_group_egress_sg_rule.rb', line 6

def create_security_group_egress_sg_rule(securitygroup_id, dest_group_id, option={})
  action   = 'AuthorizeSecurityGroupEgress'
  sigNonce = randonStr()
  time     = Time.new.utc

  parameters = defalutParameters(action, sigNonce, time)
  pathUrl    = defaultAliyunUri(action, sigNonce, time)
  
  parameters["SecurityGroupId"] = securitygroup_id
  pathUrl += '&SecurityGroupId='
  pathUrl += securitygroup_id

  parameters["DestGroupId"] = dest_group_id
  pathUrl += '&DestGroupId='
  pathUrl += dest_group_id

  nicType = 'intranet'
  parameters["NicType"] = nicType
  pathUrl += '&NicType='
  pathUrl += nicType
  
  portRange = option[:portRange]
  unless portRange
    portRange = '-1/-1'
  end
  parameters["PortRange"] = portRange
  pathUrl += '&PortRange='
  pathUrl += URI.encode(portRange,'/[^!*\'()\;?:@#&%=+$,{}[]<>`" ')
  
  protocol = option[:protocol]
  unless protocol
    protocol = 'all'
  end
  parameters["IpProtocol"] = protocol
  pathUrl += '&IpProtocol='
  pathUrl += protocol

  destGOAccount = option[:destGroupOwnerAccount]
  if sourceGOAccount
   parameters["DestGroupOwnerAccount"]=destGOAccount
   pathUrl += '&DestGroupOwnerAccount='
   pathUrl += destGOAccount
  end

  policy = option[:policy]
  unless policy
    policy = 'accept'
  end
  parameters["Policy"] = policy
  pathUrl += '&Policy='
  pathUrl += policy

  priority = option[:priority]
  unless priority
    priority = '1'
  end
  parameters["Priority"] = priority
  pathUrl += '&Priority='
  pathUrl += priority

  signature = sign(@aliyun_accesskey_secret, parameters)
  pathUrl += '&Signature='
  pathUrl += signature

  request(
    :expects  => [200, 203],
    :method   => 'GET',
    :path     => pathUrl
  )
end

#create_security_group_ip_rule(securitygroup_id, sourceCidrIp, nicType, option = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/fog/aliyun/requests/compute/create_security_group_ip_rule.rb', line 6

def create_security_group_ip_rule(securitygroup_id,sourceCidrIp, nicType, option={})

  action   = 'AuthorizeSecurityGroup'
  sigNonce = randonStr()
  time     = Time.new.utc

  parameters = defalutParameters(action, sigNonce, time)
  pathUrl    = defaultAliyunUri(action, sigNonce, time)
  
  parameters["SecurityGroupId"] = securitygroup_id
  pathUrl += '&SecurityGroupId='
  pathUrl += securitygroup_id

  parameters["SourceCidrIp"] = sourceCidrIp
  pathUrl += '&SourceCidrIp='
  pathUrl += URI.encode(sourceCidrIp,'/[^!*\'()\;?:@#&%=+$,{}[]<>`" ')  
  unless nicType
    nicType='intranet'
  end
  parameters["NicType"] = nicType
  pathUrl += '&NicType='
  pathUrl += nicType
  
  portRange = option[:portRange]
  unless portRange
    portRange = '-1/-1'
  end
  parameters["PortRange"] = portRange
  pathUrl += '&PortRange='
  pathUrl += URI.encode(portRange,'/[^!*\'()\;?:@#&%=+$,{}[]<>`" ')
  
  protocol = option[:protocol]
  unless protocol
    protocol = 'all'
  end
  parameters["IpProtocol"] = protocol
  pathUrl += '&IpProtocol='
  pathUrl += protocol

  policy = option[:policy]
  unless policy
    policy = 'accept'
  end
  parameters["Policy"] = policy
  pathUrl += '&Policy='
  pathUrl += policy

  priority = option[:priority]
  unless priority
    priority = '1'
  end
  parameters["Priority"] = priority
  pathUrl += '&Priority='
  pathUrl += priority

  signature = sign(@aliyun_accesskey_secret, parameters)
  pathUrl += '&Signature='
  pathUrl += signature

  request(
    :expects  => [200, 203],
    :method   => 'GET',
    :path     => pathUrl
  )
end

#create_security_group_sg_rule(securitygroup_id, source_securitygroup_id, option = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/fog/aliyun/requests/compute/create_security_group_sg_rule.rb', line 6

def create_security_group_sg_rule(securitygroup_id, source_securitygroup_id, option={})
  action   = 'AuthorizeSecurityGroup'
  sigNonce = randonStr()
  time     = Time.new.utc

  parameters = defalutParameters(action, sigNonce, time)
  pathUrl    = defaultAliyunUri(action, sigNonce, time)
  
  parameters["SecurityGroupId"] = securitygroup_id
  pathUrl += '&SecurityGroupId='
  pathUrl += securitygroup_id

  parameters["SourceGroupId"] = source_securitygroup_id
  pathUrl += '&SourceGroupId='
  pathUrl += source_securitygroup_id

  nicType = 'intranet'
  parameters["NicType"] = nicType
  pathUrl += '&NicType='
  pathUrl += nicType
  
  portRange = option[:portRange]
  unless portRange
    portRange = '-1/-1'
  end
  parameters["PortRange"] = portRange
  pathUrl += '&PortRange='
  pathUrl += URI.encode(portRange,'/[^!*\'()\;?:@#&%=+$,{}[]<>`" ')
  
  protocol = option[:protocol]
  unless protocol
    protocol = 'all'
  end
  parameters["IpProtocol"] = protocol
  pathUrl += '&IpProtocol='
  pathUrl += protocol

  sourceGOAccount = option[:sourceGroupOwnerAccount]
  if sourceGOAccount
   parameters["SourceGroupOwnerAccount"]=sourceGOAccount
   pathUrl += '&SourceGroupOwnerAccount='
   pathUrl += sourceGOAccount
  end

  policy = option[:policy]
  unless policy
    policy = 'accept'
  end
  parameters["Policy"] = policy
  pathUrl += '&Policy='
  pathUrl += policy

  priority = option[:priority]
  unless priority
    priority = '1'
  end
  parameters["Priority"] = priority
  pathUrl += '&Priority='
  pathUrl += priority

  signature = sign(@aliyun_accesskey_secret, parameters)
  pathUrl += '&Signature='
  pathUrl += signature

  request(
    :expects  => [200, 203],
    :method   => 'GET',
    :path     => pathUrl
  )
end

#create_server(imageId, securityGroupId, instanceType, options = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/fog/aliyun/requests/compute/create_server.rb', line 6

def create_server(imageId, securityGroupId, instanceType, options = {})
  
  _action = 'CreateInstance'
  _sigNonce = randonStr()
  _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
  
  _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

  request(
    :expects  => [200, 203],
    :method   => 'GET',
    :path     => _pathURL
  )
  
end

#create_snapshot(diskId, options = {}) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/fog/aliyun/requests/compute/create_snapshot.rb', line 5

def create_snapshot(diskId, options={})
# {Aliyun API Reference}[https://docs.aliyun.com/?spm=5176.100054.3.1.DGkmH7#/pub/ecs/open-api/snapshot&createsnapshot]          
  action = 'CreateSnapshot'
  sigNonce = randonStr()
  time = Time.new.utc

  parameters = defalutParameters(action, sigNonce, time)
  pathUrl    = defaultAliyunUri(action, sigNonce, time)
  
  parameters["DiskId"] = diskId
  pathUrl += '&DiskId='
  pathUrl += diskId

  name = options[:name]
  desc = options[:description]
  
  if name
    parameters["SnapshotName"] = name
    pathUrl += '&SnapshotName='
    pathUrl += name
  end

  if desc
    parameters["Description"] = desc
    pathUrl += '&Description='
    pathUrl += desc
  end          

  signature = sign(@aliyun_accesskey_secret, parameters)
  pathUrl += '&Signature='
  pathUrl += signature

  request(
    :expects  => [200, 203],
    :method   => 'GET',
    :path     => pathUrl
  )
end

#create_vpc(cidrBlock, options = {}) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/fog/aliyun/requests/compute/create_vpc.rb', line 5

def create_vpc(cidrBlock, options={})
  # {Aliyun API Reference}[https://docs.aliyun.com/?spm=5176.100054.3.1.DGkmH7#/pub/ecs/open-api/vpc&createvpc]
  action = 'CreateVpc'
  sigNonce = randonStr()
  time = Time.new.utc

  parameters = defalutParameters(action, sigNonce, time)
  pathUrl    = defaultAliyunUri(action, sigNonce, time)

  parameters["CidrBlock"] = cidrBlock
  pathUrl += '&CidrBlock='
  pathUrl += URI.encode(cidrBlock,'/[^!*\'()\;?:@#&%=+$,{}[]<>`" ') 

  name = options[:name]
  desc = options[:description]

  if name
    parameters["VpcName"] = name
    pathUrl += '&VpcName='
    pathUrl += name 
  end

  if desc
    parameters["Description"] = desc
    pathUrl += '&Description='
    pathUrl += desc 
  end

  signature = sign(@aliyun_accesskey_secret, parameters)
  pathUrl += '&Signature='
  pathUrl += signature

  request(
    :expects  => [200, 203],
    :method   => 'GET',
    :path     => pathUrl
  )
end

#create_vswitch(vpcId, cidrBlock, options = {}) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/fog/aliyun/requests/compute/create_vswitch.rb', line 5

def create_vswitch(vpcId, cidrBlock, options={})
  # {Aliyun API Reference}[https://docs.aliyun.com/?spm=5176.100054.3.1.DGkmH7#/pub/ecs/open-api/vswitch&createvswitch]
  action = 'CreateVSwitch'
  sigNonce = randonStr()
  time = Time.new.utc

  parameters = defalutParameters(action, sigNonce, time)
  pathUrl    = defaultAliyunUri(action, sigNonce, time)

  parameters["VpcId"] = vpcId
  pathUrl += '&VpcId='
  pathUrl += vpcId

  parameters["CidrBlock"] = cidrBlock
  pathUrl += '&CidrBlock='
  pathUrl += URI.encode(cidrBlock,'/[^!*\'()\;?:@#&%=+$,{}[]<>`" ')

  parameters["ZoneId"] = @aliyun_zone_id
  pathUrl += '&ZoneId='
  pathUrl += @aliyun_zone_id

  name = options[:name]
  desc = options[:description]

  if name
    parameters["VSwitchName"] = name
    pathUrl += '&VSwitchName='
    pathUrl += name 
  end

  if desc
    parameters["Description"] = desc
    pathUrl += '&Description='
    pathUrl += desc 
  end

  signature = sign(@aliyun_accesskey_secret, parameters)
  pathUrl += '&Signature='
  pathUrl += signature

  request(
    :expects  => [200, 203],
    :method   => 'GET',
    :path     => pathUrl
  )
end

#defalutParameters(action, sigNonce, time) ⇒ Object

operation compute–collection of default parameters



339
340
341
342
343
344
345
346
347
348
349
350
351
352
# File 'lib/fog/aliyun/compute.rb', line 339

def defalutParameters(action, sigNonce, time)
  parTimeFormat = time.strftime("%Y-%m-%dT%H:%M:%SZ")
  para = {
    'Format'=>'JSON',
    'Version'=>'2014-05-26',
    'Action'=>action,
    'AccessKeyId'=>@aliyun_accesskey_id, 
    'SignatureVersion'=>'1.0',
    'SignatureMethod'=>'HMAC-SHA1',
    'SignatureNonce'=>sigNonce,
    'RegionId'=>@aliyun_region_id,
    'Timestamp'=>parTimeFormat};
  return para
end

#defaultAliyunUri(action, sigNonce, time) ⇒ Object

operation compute– default URL



324
325
326
327
328
# File 'lib/fog/aliyun/compute.rb', line 324

def defaultAliyunUri(action, sigNonce, time)
  parTimeFormat = time.strftime("%Y-%m-%dT%H:%M:%SZ")
  urlTimeFormat = URI.encode(parTimeFormat,':')
  return '?Format=JSON&AccessKeyId='+@aliyun_accesskey_id+'&Action='+action+'&SignatureMethod=HMAC-SHA1&RegionId='+@aliyun_region_id+'&SignatureNonce='+sigNonce+'&SignatureVersion=1.0&Version=2014-05-26&Timestamp='+urlTimeFormat
end

#delete_disk(diskId) ⇒ Object

Delete a disk By the given id.

Parameters

  • diskId<~String> - the disk_id

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • ‘RequestId’<~String> - Id of the request

Aliyun API Reference



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/fog/aliyun/requests/compute/delete_disk.rb', line 16

def delete_disk(diskId)
  action   = 'DeleteDisk'
  sigNonce = randonStr()
  time     = Time.new.utc

  parameters = defalutParameters(action, sigNonce, time)
  pathUrl    = defaultAliyunUri(action, sigNonce, time)
  
  parameters["DiskId"] = diskId
  pathUrl += '&DiskId='
  pathUrl += diskId 

  signature = sign(@aliyun_accesskey_secret, parameters)
  pathUrl += '&Signature='
  pathUrl += signature

  request(
    :expects  => [200, 203],
    :method   => 'GET',
    :path     => pathUrl
  )
end

#delete_image(imageId) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/fog/aliyun/requests/compute/delete_image.rb', line 6

def delete_image(imageId)
  action = 'DeleteImage'
  sigNonce = randonStr()
  time = Time.new.utc

  parameters = defalutParameters(action, sigNonce, time)
  pathUrl    = defaultAliyunUri(action, sigNonce, time)

  parameters["ImageId"] = imageId
  pathUrl += '&ImageId='
  pathUrl += imageId  

  signature = sign(@aliyun_accesskey_secret, parameters)
  pathUrl += '&Signature='
  pathUrl += signature

  request(
    :expects  => [200, 203],
    :method   => 'GET',
    :path     => pathUrl
  )
end

#delete_security_group(security_group_id) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/fog/aliyun/requests/compute/delete_security_group.rb', line 5

def delete_security_group(security_group_id)
  # {Aliyun API Reference}[https://docs.aliyun.com/?spm=5176.100054.3.1.DGkmH7#/pub/ecs/open-api/securitygroup&deletesecuritygroup]
  action = 'DeleteSecurityGroup'
  sigNonce = randonStr()
  time = Time.new.utc

  parameters = defalutParameters(action, sigNonce, time)
  pathUrl    = defaultAliyunUri(action, sigNonce, time)

  if security_group_id
    parameters["SecurityGroupId"] = security_group_id
    pathUrl += '&SecurityGroupId='
    pathUrl += security_group_id  
  else
    raise ArgumentError, "Missing required securyti id "
  end

  signature = sign(@aliyun_accesskey_secret, parameters)
  pathUrl += '&Signature='
  pathUrl += signature
  
  request(
    :expects  => [200, 203],
    :method   => 'GET',
    :path     => pathUrl
  )
end

#delete_security_group_egress_ip_rule(securitygroup_id, destCidrIp, nicType, option = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/fog/aliyun/requests/compute/delete_security_group_egress_ip_rule.rb', line 6

def delete_security_group_egress_ip_rule(securitygroup_id,destCidrIp, nicType, option={})

  action   = 'RevokeSecurityGroupEgress'
  sigNonce = randonStr()
  time     = Time.new.utc

  parameters = defalutParameters(action, sigNonce, time)
  pathUrl    = defaultAliyunUri(action, sigNonce, time)
  
  parameters["SecurityGroupId"] = securitygroup_id
  pathUrl += '&SecurityGroupId='
  pathUrl += securitygroup_id

  parameters["DestCidrIp"] = destCidrIp
  pathUrl += '&DestCidrIp='
  pathUrl += URI.encode(destCidrIp,'/[^!*\'()\;?:@#&%=+$,{}[]<>`" ')  
  unless nicType
    nicType='intranet'
  end
  parameters["NicType"] = nicType
  pathUrl += '&NicType='
  pathUrl += nicType
  
  portRange = option[:portRange]
  unless portRange
    portRange = '-1/-1'
  end
  parameters["PortRange"] = portRange
  pathUrl += '&PortRange='
  pathUrl += URI.encode(portRange,'/[^!*\'()\;?:@#&%=+$,{}[]<>`" ')
  
  protocol = option[:protocol]
  unless protocol
    protocol = 'all'
  end
  parameters["IpProtocol"] = protocol
  pathUrl += '&IpProtocol='
  pathUrl += protocol

  policy = option[:policy]
  unless policy
    policy = 'accept'
  end
  parameters["Policy"] = policy
  pathUrl += '&Policy='
  pathUrl += policy

  priority = option[:priority]
  unless priority
    priority = '1'
  end
  parameters["Priority"] = priority
  pathUrl += '&Priority='
  pathUrl += priority

  signature = sign(@aliyun_accesskey_secret, parameters)
  pathUrl += '&Signature='
  pathUrl += signature

  request(
    :expects  => [200, 203],
    :method   => 'GET',
    :path     => pathUrl
  )
end

#delete_security_group_egress_sg_rule(securitygroup_id, dest_group_id, option = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/fog/aliyun/requests/compute/delete_security_group_egress_sg_rule.rb', line 6

def delete_security_group_egress_sg_rule(securitygroup_id, dest_group_id, option={})
  action   = 'RevokeSecurityGroupEgress'
  sigNonce = randonStr()
  time     = Time.new.utc

  parameters = defalutParameters(action, sigNonce, time)
  pathUrl    = defaultAliyunUri(action, sigNonce, time)
  
  parameters["SecurityGroupId"] = securitygroup_id
  pathUrl += '&SecurityGroupId='
  pathUrl += securitygroup_id

  parameters["DestGroupId"] = dest_group_id
  pathUrl += '&DestGroupId='
  pathUrl += dest_group_id

  nicType = 'intranet'
  parameters["NicType"] = nicType
  pathUrl += '&NicType='
  pathUrl += nicType
  
  portRange = option[:portRange]
  unless portRange
    portRange = '-1/-1'
  end
  parameters["PortRange"] = portRange
  pathUrl += '&PortRange='
  pathUrl += URI.encode(portRange,'/[^!*\'()\;?:@#&%=+$,{}[]<>`" ')
  
  protocol = option[:protocol]
  unless protocol
    protocol = 'all'
  end
  parameters["IpProtocol"] = protocol
  pathUrl += '&IpProtocol='
  pathUrl += protocol

  destGOAccount = option[:destGroupOwnerAccount]
  if sourceGOAccount
   parameters["DestGroupOwnerAccount"]=destGOAccount
   pathUrl += '&DestGroupOwnerAccount='
   pathUrl += destGOAccount
  end

  policy = option[:policy]
  unless policy
    policy = 'accept'
  end
  parameters["Policy"] = policy
  pathUrl += '&Policy='
  pathUrl += policy

  priority = option[:priority]
  unless priority
    priority = '1'
  end
  parameters["Priority"] = priority
  pathUrl += '&Priority='
  pathUrl += priority

  signature = sign(@aliyun_accesskey_secret, parameters)
  pathUrl += '&Signature='
  pathUrl += signature

  request(
    :expects  => [200, 203],
    :method   => 'GET',
    :path     => pathUrl
  )
end

#delete_security_group_ip_rule(securitygroup_id, sourceCidrIp, nicType, option = {}) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/fog/aliyun/requests/compute/delete_security_group_ip_rule.rb', line 5

def delete_security_group_ip_rule(securitygroup_id,sourceCidrIp, nicType, option={})
  # {Aliyun API Reference}[https://docs.aliyun.com/?spm=5176.100054.3.1.DGkmH7#/pub/ecs/open-api/securitygroup&revokesecuritygroup]
  action   = 'RevokeSecurityGroup'
  sigNonce = randonStr()
  time     = Time.new.utc

  parameters = defalutParameters(action, sigNonce, time)
  pathUrl    = defaultAliyunUri(action, sigNonce, time)
  
  parameters["SecurityGroupId"] = securitygroup_id
  pathUrl += '&SecurityGroupId='
  pathUrl += securitygroup_id

  parameters["SourceCidrIp"] = sourceCidrIp
  pathUrl += '&SourceCidrIp='
  pathUrl += URI.encode(sourceCidrIp,'/[^!*\'()\;?:@#&%=+$,{}[]<>`" ')  
  unless nicType
    nicType='intranet'
  end
  parameters["NicType"] = nicType
  pathUrl += '&NicType='
  pathUrl += nicType
  
  portRange = option[:portRange]
  unless portRange
    portRange = '-1/-1'
  end
  parameters["PortRange"] = portRange
  pathUrl += '&PortRange='
  pathUrl += URI.encode(portRange,'/[^!*\'()\;?:@#&%=+$,{}[]<>`" ')
  
  protocol = option[:protocol]
  unless protocol
    protocol = 'all'
  end
  parameters["IpProtocol"] = protocol
  pathUrl += '&IpProtocol='
  pathUrl += protocol

  policy = option[:policy]
  unless policy
    policy = 'accept'
  end
  parameters["Policy"] = policy
  pathUrl += '&Policy='
  pathUrl += policy

  priority = option[:priority]
  unless priority
    priority = '1'
  end
  parameters["Priority"] = priority
  pathUrl += '&Priority='
  pathUrl += priority

  signature = sign(@aliyun_accesskey_secret, parameters)
  pathUrl += '&Signature='
  pathUrl += signature

  request(
    :expects  => [200, 203],
    :method   => 'GET',
    :path     => pathUrl
  )
end

#delete_security_group_sg_rule(securitygroup_id, source_securitygroup_id, option = {}) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/fog/aliyun/requests/compute/delete_security_group_sg_rule.rb', line 5

def delete_security_group_sg_rule(securitygroup_id, source_securitygroup_id, option={})
  # {Aliyun API Reference}[https://docs.aliyun.com/?spm=5176.100054.3.1.DGkmH7#/pub/ecs/open-api/securitygroup&revokesecuritygroup]
  action   = 'RevokeSecurityGroup'
  sigNonce = randonStr()
  time     = Time.new.utc

  parameters = defalutParameters(action, sigNonce, time)
  pathUrl    = defaultAliyunUri(action, sigNonce, time)
  
  parameters["SecurityGroupId"] = securitygroup_id
  pathUrl += '&SecurityGroupId='
  pathUrl += securitygroup_id

  parameters["SourceGroupId"] = source_securitygroup_id
  pathUrl += '&SourceGroupId='
  pathUrl += source_securitygroup_id

  nicType = 'intranet'
  parameters["NicType"] = nicType
  pathUrl += '&NicType='
  pathUrl += nicType
  
  portRange = option[:portRange]
  unless portRange
    portRange = '-1/-1'
  end
  parameters["PortRange"] = portRange
  pathUrl += '&PortRange='
  pathUrl += URI.encode(portRange,'/[^!*\'()\;?:@#&%=+$,{}[]<>`" ')
  
  protocol = option[:protocol]
  unless protocol
    protocol = 'all'
  end
  parameters["IpProtocol"] = protocol
  pathUrl += '&IpProtocol='
  pathUrl += protocol

  sourceGOAccount = option[:sourceGroupOwnerAccount]
  if sourceGOAccount
   parameters["SourceGroupOwnerAccount"]=sourceGOAccount
   pathUrl += '&SourceGroupOwnerAccount='
   pathUrl += sourceGOAccount
  end

  policy = option[:policy]
  unless policy
    policy = 'accept'
  end
  parameters["Policy"] = policy
  pathUrl += '&Policy='
  pathUrl += policy

  priority = option[:priority]
  unless priority
    priority = '1'
  end
  parameters["Priority"] = priority
  pathUrl += '&Priority='
  pathUrl += priority

  signature = sign(@aliyun_accesskey_secret, parameters)
  pathUrl += '&Signature='
  pathUrl += signature

  request(
    :expects  => [200, 203],
    :method   => 'GET',
    :path     => pathUrl
  )
end

#delete_server(server_id) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/fog/aliyun/requests/compute/delete_server.rb', line 5

def delete_server(server_id)
  # {Aliyun API Reference}[https://docs.aliyun.com/?spm=5176.100054.3.1.DGkmH7#/pub/ecs/open-api/instance&deleteinstance]
  _action = 'DeleteInstance'
  _sigNonce = randonStr()
  _time = Time.new.utc

  _parameters = defalutParameters(_action, _sigNonce, _time)
  _pathURL  = defaultAliyunUri(_action, _sigNonce, _time)
  
  _parameters['InstanceId']=server_id
    _pathURL += '&InstanceId='+server_id
    
  _signature = sign(@aliyun_accesskey_secret, _parameters)
  _pathURL += '&Signature='+_signature
  
  request(
    :expects => [200, 204],
    :method => 'GET',
    :path   => _pathURL
  )
end

#delete_snapshot(snapshotId) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/fog/aliyun/requests/compute/delete_snapshot.rb', line 5

def delete_snapshot(snapshotId)
  # {Aliyun API Reference}[https://docs.aliyun.com/?spm=5176.100054.3.1.DGkmH7#/pub/ecs/open-api/snapshot&deletesnapshot]
  action = 'DeleteSnapshot'
  sigNonce = randonStr()
  time = Time.new.utc

  parameters = defalutParameters(action, sigNonce, time)
  pathUrl    = defaultAliyunUri(action, sigNonce, time)
  
  parameters["SnapshotId"] = snapshotId
  pathUrl += '&SnapshotId='
  pathUrl += snapshotId

  signature = sign(@aliyun_accesskey_secret, parameters)
  pathUrl += '&Signature='
  pathUrl += signature

  request(
    :expects  => [200, 203],
    :method   => 'GET',
    :path     => pathUrl
  )
end

#delete_vpc(vpc_id) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/fog/aliyun/requests/compute/delete_vpc.rb', line 6

def delete_vpc(vpc_id)
  
  action = 'DeleteVpc'
  sigNonce = randonStr()
  time = Time.new.utc

  parameters = defalutParameters(action, sigNonce, time)
  pathUrl    = defaultAliyunUri(action, sigNonce, time)

  if vpc_id
    parameters["VpcId"] = vpc_id
    pathUrl += '&VpcId='
    pathUrl += vpc_id 
  else
    raise ArgumentError, "Missing required vpc_id"
  end

  signature = sign(@aliyun_accesskey_secret, parameters)
  pathUrl += '&Signature='
  pathUrl += signature
  
  request(
    :expects  => [200, 203],
    :method   => 'GET',
    :path     => pathUrl
  )
end

#delete_vswitch(vswitch_id) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/fog/aliyun/requests/compute/delete_vswitch.rb', line 5

def delete_vswitch(vswitch_id)
  # {Aliyun API Reference}[https://docs.aliyun.com/?spm=5176.100054.3.1.DGkmH7#/pub/ecs/open-api/vswitch&deletevswitch]
  action = 'DeleteVSwitch'
  sigNonce = randonStr()
  time = Time.new.utc

  parameters = defalutParameters(action, sigNonce, time)
  pathUrl    = defaultAliyunUri(action, sigNonce, time)

  if vswitch_id
    parameters["VSwitchId"] = vswitch_id
    pathUrl += '&VSwitchId='
    pathUrl += vswitch_id 
  else
    raise ArgumentError, "Missing required vswitch_id"
  end

  signature = sign(@aliyun_accesskey_secret, parameters)
  pathUrl += '&Signature='
  pathUrl += signature
  
  request(
    :expects  => [200, 203],
    :method   => 'GET',
    :path     => pathUrl
  )
end

#detach_disk(instanceId, diskId, options = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/fog/aliyun/requests/compute/detach_disk.rb', line 6

def detach_disk(instanceId, diskId,options={})
  action   = 'DetachDisk'
  sigNonce = randonStr()
  time     = Time.new.utc

  parameters = defalutParameters(action, sigNonce, time)
  pathUrl    = defaultAliyunUri(action, sigNonce, time)
  
  parameters["InstanceId"] = instanceId
  pathUrl += '&InstanceId='
  pathUrl += instanceId 

  parameters["DiskId"] = 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

  request(
    :expects  => [200, 203],
    :method   => 'GET',
    :path     => pathUrl
  )
end

#get_instance_type(cpuCount, memorySize) ⇒ Object

end list_server_types



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/fog/aliyun/requests/compute/list_server_types.rb', line 31

def get_instance_type(cpuCount, memorySize)
  _action = 'DescribeInstanceTypes'
  _sigNonce = randonStr()
  _time = Time.new.utc

  _parameters = defalutParameters(_action, _sigNonce, _time)
  _pathURL  = defaultAliyunUri(_action, _sigNonce, _time)
  
  _signature = sign(@aliyun_accesskey_secret, _parameters)
  _pathURL += '&Signature='+_signature
  
  response = request(
    :expects  => [200, 203],
    :method   => 'GET',
    :path     => _pathURL
  )

  _InstanceTypeId = nil
  _InstanceTypeList =  Fog::JSON.decode(response.body)["InstanceTypes"]["InstanceType"]
  _InstanceTypeList.each do |instanceType|
    if ((instanceType["CpuCoreCount"] == cpuCount) && (instanceType["MemorySize"] == memorySize))
      _InstanceTypeId = instanceType["InstanceTypeId"]
      puts "_instanceTypeId: "+_InstanceTypeId
      break
    end #end if
  end #end each
  _InstanceTypeId
end

#join_security_group(server_id, group_id) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/fog/aliyun/requests/compute/join_security_group.rb', line 6

def join_security_group(server_id, group_id)

  _action = 'JoinSecurityGroup'
  _sigNonce = randonStr()
  _time = Time.new.utc

  _parameters = defalutParameters(_action, _sigNonce, _time)
  _pathURL  = defaultAliyunUri(_action, _sigNonce, _time)
  
  _parameters['InstanceId']=server_id
  _pathURL += '&InstanceId='+server_id
    
  _parameters['SecurityGroupId']=group_id
  _pathURL += '&SecurityGroupId='+group_id
  
  _signature = sign(@aliyun_accesskey_secret, _parameters)
  _pathURL += '&Signature='+_signature
  
  request(
    :expects => [200, 204],
    :method => 'GET',
    :path   => _pathURL
  )
end

#leave_security_group(server_id, group_id) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/fog/aliyun/requests/compute/leave_security_group.rb', line 6

def leave_security_group(server_id, group_id)

  _action = 'LeaveSecurityGroup'
  _sigNonce = randonStr()
  _time = Time.new.utc

  _parameters = defalutParameters(_action, _sigNonce, _time)
  _pathURL  = defaultAliyunUri(_action, _sigNonce, _time)
  
  _parameters['InstanceId']=server_id
  _pathURL += '&InstanceId='+server_id
    
  _parameters['SecurityGroupId']=group_id
  _pathURL += '&SecurityGroupId='+group_id
  
  _signature = sign(@aliyun_accesskey_secret, _parameters)
  _pathURL += '&Signature='+_signature
  
  request(
    :expects => [200, 204],
    :method => 'GET',
    :path   => _pathURL
  )
end

#list_disks(options = {}) ⇒ Object

Describe disks.

Parameters

  • options<~hash>

    * :diskIds - arry of diskId, the length of arry should less than or equal to 100.
    * :instanceId - id of the instance
    * :diskType - Default 'all'.Can be set to all | system | data
    * :category - Default 'all'. Can be set to all | cloud | cloud_efficiency | cloud_ssd | ephemeral | ephemeral_ssd
    * :state - status of the disk. Default 'All'. Can be set to In_use | Available | Attaching | Detaching | Creating | ReIniting | All
    * :snapshotId - id of snapshot which used to create disk.
    * :name - name of disk
    * :portable - If ture, can exist dependently,which means it can be mount or umont in available zones.
          Else, it must be created or destroyed with a instance. 
          The value for ocal disks and system disks on the cloud and cloud disks paid by month must be false.
    * :delWithIns - If ture, the disk will be released when the instance is released.
    * :delAutoSna - If ture, the auto created snapshot will be destroyed when the disk is destroyed
    * :enAutoSna - Whether the disk apply the auto snapshot strategy.
    * :diskChargeType - Prepaid | Postpaid
    

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • ‘RequestId’<~String> - Id of the request

      • ‘Disks’<~Hash> - list of Disk,and the parameter of disk refer to the Volume model

Aliyun API Reference



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/fog/aliyun/requests/compute/list_disks.rb', line 30

def list_disks(options={})
  action = 'DescribeDisks'
  sigNonce = randonStr()
  time = Time.new.utc

  parameters = defalutParameters(action, sigNonce, time)
  pathUrl    = defaultAliyunUri(action, sigNonce, time)

  pageNumber = options[:pageNumber]
  pageSize   = options[:pageSize]
  instanceId = options[:instanceId]
  diskIds = options[:diskIds]
  diskType = options[:diskType]
  category = options[:category]
  state = options[:state]
  snapshotId = options[:snapshotId]
  name = options[:name]
  portable = options[:portable]
  delWithIns = options[:deleteWithInstance]
  delAutoSna = options[:deleteAutoSnapshot]
  enAutoSna = options[:enableAutoSnapshot]
  diskChargeType = options[:diskChargeType]

  if diskChargeType
    parameters["DiskChargeType"] = diskChargeType
    pathUrl += '&DiskChargeType='
    pathUrl += diskChargeType
  end

  if enAutoSna
    parameters["EnableAutoSnapshot"] = enAutoSna
    pathUrl += '&EnableAutoSnapshot='
    pathUrl += enAutoSna
  end

  if delAutoSna
    parameters["DeleteAutoSnapshot"] = delAutoSna
    pathUrl += '&DeleteAutoSnapshot='
    pathUrl += delAutoSna
  end

  if delWithIns
    parameters["DeleteWithInstance"] = delWithIns
    pathUrl += '&DeleteWithInstance='
    pathUrl += delWithIns
  end

  if portable
    parameters["Portable"] = portable
    pathUrl += '&Portable='
    pathUrl += portable
  end

  if name
    parameters["DiskName"] = name
    pathUrl += '&DiskName='
    pathUrl += name
  end

  if snapshotId
    parameters["SnapshotId"] = snapshotId
    pathUrl += '&SnapshotId='
    pathUrl += snapshotId
  end

  if state
    parameters["Status"] = state
    pathUrl += '&Status='
    pathUrl += state
  end

  if category
    parameters["DiskType"] = diskType
    pathUrl += '&DiskType='
    pathUrl += diskType
  end

  if category
    parameters["Category"] = category
    pathUrl += '&Category='
    pathUrl += category
  end

  if instanceId
    parameters["InstanceId"] = instanceId
    pathUrl += '&InstanceId='
    pathUrl += instanceId
  end

  if diskIds
    parameters["DiskIds"] = Fog::JSON.encode(diskIds)
    pathUrl += '&DiskIds='
    pathUrl += Fog::JSON.encode(diskIds)
  end
  
  if pageNumber
    parameters["PageNumber"] = pageNumber
    pathUrl += '&PageNumber='
    pathUrl += pageNumber
  end

  pageSize   = options[:pageSize]
  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

#list_eip_addresses(options = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/fog/aliyun/requests/compute/list_eip_addresses.rb', line 6

def list_eip_addresses(options={})
  
  _action = 'DescribeEipAddresses'
  _sigNonce = randonStr()
  _time = Time.new.utc

  _parameters = defalutParameters(_action, _sigNonce, _time)
  _pathURL  = defaultAliyunUri(_action, _sigNonce, _time)
  
  _Status = options[:state]
  if _Status
    _parameters['Status']=_Status
    _pathURL += '&Status='+_Status
  end
  
  _EipAddress = options[:ip_address]
  if _EipAddress
    _parameters['EipAddress']=_EipAddress
    _pathURL += '&EipAddress='+_EipAddress
  end
  
  _AllocationId = options[:allocation_id]
  if _AllocationId
    _parameters['AllocationId']=_AllocationId
    _pathURL += '&AllocationId='+_AllocationId
  end
  
  _PageNumber = options[:page_number]
  if _PageNumber
    _parameters['PageNumber']=_PageNumber
    _pathURL += '&PageNumber='+_PageNumber
  end

  _PageSize   = options[:page_size]
  unless _PageSize
    _PageSize = '50'
  end
  _parameters['PageSize']=_PageSize
  _pathURL += '&PageSize='+_PageSize
  
  _signature = sign(@aliyun_accesskey_secret, _parameters)
  _pathURL += '&Signature='+_signature
  
  request(
    :expects => [200, 204],
    :method => 'GET',
    :path   => _pathURL
  )
end

#list_images(options = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/fog/aliyun/requests/compute/list_images.rb', line 6

def list_images(options={})
  
  action = 'DescribeImages'
  sigNonce = randonStr()
  time = Time.new.utc

  parameters = defalutParameters(action, sigNonce, time)
  pathUrl    = defaultAliyunUri(action, sigNonce, time)

  pageNumber = options[:pageNumber]
  if pageNumber
    parameters["PageNumber"] = pageNumber
    pathUrl += '&PageNumber='
    pathUrl += pageNumber
  end

  pageSize   = options[:pageSize]
  unless pageSize
    pageSize = '50'
  end
  parameters["PageSize"] = pageSize  
  pathUrl += '&PageSize='
  pathUrl += pageSize 
  
  imageId = options[:imageId]
  if imageId
    parameters["ImageId"] = imageId
    pathUrl += '&ImageId='
    pathUrl += imageId  
  end
  
  imageName = options[:imageName]
  if imageName
    parameters["ImageName"] = imageName
    pathUrl += '&ImageName='
    pathUrl += imageName
  end
  
  snapshotId = options[:snapshotId]
  if snapshotId
    parameters["SnapshotId"] = snapshotId
    pathUrl += '&SnapshotId='
    pathUrl += snapshotId
  end
  
  ownerAlias = options[:ownerAlias]
  if ownerAlias
    parameters["ImageOwnerAlias"] = ownerAlias
    pathUrl += '&ImageOwnerAlias='
    pathUrl += ownerAlias
  end

  signature = sign(@aliyun_accesskey_secret, parameters)
  pathUrl += '&Signature='
  pathUrl += signature

  request(
    :expects  => [200, 203],
    :method   => 'GET',
    :path     => pathUrl
  )
end

#list_route_tables(vrouterid, options = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/fog/aliyun/requests/compute/list_route_tables.rb', line 6

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

#list_security_group_rules(securityGroupId, options = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/fog/aliyun/requests/compute/list_security_group_rules.rb', line 6

def list_security_group_rules(securityGroupId, options = {})

  action = 'DescribeSecurityGroupAttribute'
  sigNonce = randonStr()
  time = Time.new.utc

  parameters = defalutParameters(action, sigNonce, time)
  pathUrl = defaultAliyunUri(action, sigNonce, time)
  
  parameters["SecurityGroupId"] = securityGroupId
  pathUrl += '&SecurityGroupId='
  pathUrl += securityGroupId
  
  nicType = options[:nicType]
  if nicType
    parameters["NicType"] = nicType
    pathUrl += '&NicType='
    pathUrl += nicType
  end          
  pageNumber = options[:pageNumber]
  pageSize   = options[:pageSize]       
  if pageNumber
      parameters["PageNumber"] = pageNumber
      pathUrl += '&PageNumber='
      pathUrl += pageNumber
  end

  if pageSize
      parameters["PageSize"] = pageSize
      pathUrl += '&PageSize='
      pathUrl += pageSize 
  end

  signature = sign(@aliyun_accesskey_secret, parameters)
  pathUrl += '&Signature='
  pathUrl += signature

  request(
    :expects  => [200, 203],
    :method   => 'GET',
    :path     => pathUrl
  )
end

#list_security_groups(options = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/fog/aliyun/requests/compute/list_security_groups.rb', line 6

def list_security_groups(options={})

  action = 'DescribeSecurityGroups'
  sigNonce = randonStr()
  time = Time.new.utc

  parameters = defalutParameters(action, sigNonce, time)
  pathUrl    = defaultAliyunUri(action, sigNonce, time)

  pageNumber = options[:pageNumber]
  pageSize   = options[:pageSize]
  vpcId      = options[:vpcId]
  
  if vpcId
    parameters["VpcId"] = vpcId
    pathUrl += '&VpcId='
    pathUrl += vpcId
  end

  if pageNumber
    parameters["PageNumber"] = pageNumber
    pathUrl += '&PageNumber='
    pathUrl += pageNumber
  end

  pageSize   = options[:pageSize]
  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],
    :method   => 'GET',
    :path     => pathUrl
  )
end

#list_server_typesObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/fog/aliyun/requests/compute/list_server_types.rb', line 6

def list_server_types
  _action = 'DescribeInstanceTypes'
  _sigNonce = randonStr()
  _time = Time.new.utc

  _parameters = defalutParameters(_action, _sigNonce, _time)
  _pathURL  = defaultAliyunUri(_action, _sigNonce, _time)
  
  _signature = sign(@aliyun_accesskey_secret, _parameters)
  _pathURL += '&Signature='+_signature
  
  response = request(
    :expects  => [200, 203],
    :method   => 'GET',
    :path     => _pathURL
  )

  #_InstanceType = Hash.new
  #_InstanceTypeList =  Fog::JSON.decode(response.body)["InstanceTypes"]["InstanceType"]
  #_InstanceTypeList.each do |instanceType|
  #  _InstanceType[[instanceType["CpuCoreCount"], instanceType["MemorySize"]]] = instanceType["InstanceTypeId"]
  #end
  #_InstanceType
end

#list_servers(options = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/fog/aliyun/requests/compute/list_servers.rb', line 6

def list_servers(options={})
  
  _action = 'DescribeInstances'
  _sigNonce = randonStr()
  _time = Time.new.utc

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

  _InstanceId = options[:instanceId]
  _VpcId = options[:vpcId]
  _SecurityGroupId = options[:securityGroupId]
  _PageNumber = options[:pageNumber]
  _PageSize = options[:pageSize]

  if _InstanceId != nil
    _InstanceStr = "[\"#{_InstanceId}\"]"
    _parameters['InstanceIds'] = _InstanceStr
    _pathURL += '&InstanceIds='+_InstanceStr
  end

  if _VpcId != nil
    _parameters['VpcId'] = _VpcId
    _pathURL += '&VpcId='+_VpcId
  end

  if _SecurityGroupId != nil
    _parameters['SecurityGroupId']=_SecurityGroupId
    _pathURL += '&SecurityGroupId='+_SecurityGroupId
  end
  
  if _PageNumber != nil
    _parameters['PageNumber']=_PageNumber
    _pathURL += '&PageNumber='+_PageNumber
  end
  
  unless _PageSize
    _PageSize = '50'
  end
  _parameters['PageSize']=_PageSize
  _pathURL += '&PageSize='+_PageSize

  _signature = sign(@aliyun_accesskey_secret, _parameters)
  _pathURL += '&Signature='+_signature

  request(
    :expects  => [200, 203],
    :method   => 'GET',
    :path     => _pathURL
  )
end

#list_snapshots(options = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/fog/aliyun/requests/compute/list_snapshots.rb', line 6

def list_snapshots(options={})
  
  action = 'DescribeSnapshots'
  sigNonce = randonStr()
  time = Time.new.utc

  parameters = defalutParameters(action, sigNonce, time)
  pathUrl    = defaultAliyunUri(action, sigNonce, time)

  pageNumber = options[:pageNumber]
  pageSize = options[:pageSize]
  instanceId = options[:instanceId]
  diskId = options[:diskId]
  snapshotId = options[:snapshotIds]
  sourceDiskType = options[:sourceDiskType]
  name = options[:snapshotName]
  state = options[:state]
  type = options[:snapshotType]
  usage = options[:usage]

  if usage
    parameters["Usage"] = usage
    pathUrl += '&Usage='
    pathUrl += usage
  end

  if type
    parameters["SnapshotType"] = type
    pathUrl += '&SnapshotType='
    pathUrl += type
  end

  if state
    parameters["Status"] = state
    pathUrl += '&Status='
    pathUrl += state
  end

  if name
    parameters["SnapshotName"] = name
    pathUrl += '&SnapshotName='
    pathUrl += name
  end

  if instanceId
    parameters["InstanceId"] = instanceId
    pathUrl += '&InstanceId='
    pathUrl += instanceId
  end

  if diskId
    parameters["DiskId"] = diskId
    pathUrl += '&DiskId='
    pathUrl += diskId
  end          

  if snapshotId
    parameters["SnapshotIds"] = Fog::JSON.encode(snapshotId)
    pathUrl += '&SnapshotIds='
    pathUrl += Fog::JSON.encode(snapshotId)
  end
  
  if sourceDiskType
    parameters["SourceDiskType"] = sourceDiskType
    pathUrl += '&SourceDiskType='
    pathUrl += sourceDiskType
  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

#list_vpcs(options = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/fog/aliyun/requests/compute/list_vpcs.rb', line 6

def list_vpcs(options={})
  
  action = 'DescribeVpcs'
  sigNonce = randonStr()
  time = Time.new.utc

  parameters = defalutParameters(action, sigNonce, time)
  pathUrl    = defaultAliyunUri(action, sigNonce, time)

  _VpcId   = options[:vpcId]       
  if _VpcId
    parameters["VpcId"] = _VpcId
    pathUrl += '&VpcId='
    pathUrl += _VpcId
  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

#list_vrouters(options = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/fog/aliyun/requests/compute/list_vrouters.rb', line 6

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

#list_vswitchs(vpcid, options = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/fog/aliyun/requests/compute/list_vswitchs.rb', line 6

def list_vswitchs(vpcid, options={})
  
  action = 'DescribeVSwitches'
  sigNonce = randonStr()
  time = Time.new.utc

  parameters = defalutParameters(action, sigNonce, time)
  pathUrl    = defaultAliyunUri(action, sigNonce, time)

  parameters["VpcId"] = vpcid
  pathUrl += '&VpcId='
  pathUrl += vpcid

  pageNumber = options[:pageNumber]
  pageSize   = options[:pageSize]   
  vswitchId  = options[:vSwitchId]    
  if vswitchId
    parameters["VSwitchId"] = vswitchId
    pathUrl +='&VSwitchId='
    pathUrl += vswitchId
  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

#list_zonesObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/fog/aliyun/requests/compute/list_zones.rb', line 6

def list_zones()
  action = 'DescribeZones'
  sigNonce = randonStr()
  time = Time.new.utc

  parameters = defalutParameters(action, sigNonce, time)
  pathUrl    = defaultAliyunUri(action, sigNonce, time)

  signature = sign(@aliyun_accesskey_secret, parameters)
  pathUrl += '&Signature='
  pathUrl += signature

  request(
    :expects  => [200, 203],
    :method   => 'GET',
    :path     => pathUrl
  )
end

#modify_vpc(vSwitchId, options = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/fog/aliyun/requests/compute/modify_vpc.rb', line 6

def modify_vpc(vpcId,options={})

  action = 'ModifyVpcAttribute'
  sigNonce = randonStr()
  time = Time.new.utc

  parameters = defalutParameters(action, sigNonce, time)
  pathUrl    = defaultAliyunUri(action, sigNonce, time)

  parameters["VpcId"] = vpcId
  pathUrl += '&VpcId='
  pathUrl += URI.encode(vpcId,'/[^!*\'()\;?:@#&%=+$,{}[]<>`" ') 
  name = options[:name]
  desc = options[:description]

  if name
    parameters["VpcName"] = name
    pathUrl += '&VpcName='
    pathUrl += name 
  end

  if desc
    parameters["Description"] = desc
    pathUrl += '&Description='
    pathUrl += desc 
  end

  signature = sign(@aliyun_accesskey_secret, parameters)
  pathUrl += '&Signature='
  pathUrl += signature

  request(
    :expects  => [200, 203],
    :method   => 'GET',
    :path     => pathUrl
  )
end

#randonStrObject

generate random num



331
332
333
334
335
336
# File 'lib/fog/aliyun/compute.rb', line 331

def randonStr ()
  numStr = rand(100000).to_s
  timeStr = Time.now.to_f.to_s
  ranStr = timeStr+"-"+numStr
  return ranStr
end

#reboot_server(server_id, options = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/fog/aliyun/requests/compute/reboot_server.rb', line 6

def reboot_server(server_id, options = {})

  _action = 'RebootInstance'
  _sigNonce = randonStr()
  _time = Time.new.utc

  _parameters = defalutParameters(_action, _sigNonce, _time)
  _pathURL  = defaultAliyunUri(_action, _sigNonce, _time)
  
  _parameters['InstanceId']=server_id
  _pathURL += '&InstanceId='+server_id
    
  _ForceStop = options[:aliyun_ForceStop]
  if _ForceStop
    _parameters['ForceStop']=_ForceStop
    _pathURL += '&ForceStop='+_ForceStop
  end
  
  _signature = sign(@aliyun_accesskey_secret, _parameters)
  _pathURL += '&Signature='+_signature
  
  request(
    :expects => [200, 204],
    :method => 'GET',
    :path   => _pathURL
  )
end

#release_eip_address(allocationId) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/fog/aliyun/requests/compute/release_eip_address.rb', line 6

def release_eip_address(allocationId)
  
  _action = 'ReleaseEipAddress'
  _sigNonce = randonStr()
  _time = Time.new.utc

  _parameters = defalutParameters(_action, _sigNonce, _time)
  _pathURL  = defaultAliyunUri(_action, _sigNonce, _time)
  
  _parameters['AllocationId'] = allocationId
  _pathURL += '&AllocationId='+allocationId
  
  _signature = sign(@aliyun_accesskey_secret, _parameters)
  _pathURL += '&Signature='+_signature
  
  request(
    :expects => [200, 204],
    :method => 'GET',
    :path   => _pathURL
  )
end

#reloadObject



292
293
294
# File 'lib/fog/aliyun/compute.rb', line 292

def reload
  @connection.reset
end

#request(params) ⇒ Object



296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
# File 'lib/fog/aliyun/compute.rb', line 296

def request(params)
  begin
    response = @connection.request(params.merge({
      :headers  => {
        'Content-Type' => 'application/json',
        'Accept' => 'application/json',
        'X-Auth-Token' => @auth_token
      }.merge!(params[:headers] || {}),
      :path     => "#{@path}/#{params[:path]}",
      :query    => params[:query]
    }))
  rescue Excon::Errors::HTTPStatusError => error
    raise case error
      when Excon::Errors::NotFound
        Fog::Compute::Aliyun::NotFound.slurp(error)
      else
        error
      end
  end

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

  response
end

#sign(accessKeySecret, parameters) ⇒ Object

compute signature



355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
# File 'lib/fog/aliyun/compute.rb', line 355

def sign (accessKeySecret,parameters)
  sortedParameters = parameters.sort
  canonicalizedQueryString = ''
  sortedParameters.each do | k, v |
      canonicalizedQueryString += '&' + URI.encode(k,'/[^!*\'()\;?:@#&%=+$,{}[]<>`" ') + '=' + URI.encode(v,'/[^!*\'()\;?:@#&%=+$,{}[]<>`" ')
  end

  canonicalizedQueryString[0] = ''
  stringToSign = 'GET&%2F&' + URI.encode(canonicalizedQueryString,'/[^!*\'()\;?:@#&%=+$,{}[]<>`" ')
  key = accessKeySecret + '&'

  digVer =  OpenSSL::Digest.new("sha1")
  digest =  OpenSSL::HMAC.digest(digVer, key, stringToSign)
  signature = Base64.encode64(digest)
  signature[-1] = ''
  encodedSig = URI.encode(signature,'/[^!*\'()\;?:@#&%=+$,{}[]<>`" ')

  return encodedSig
end

#start_server(server_id) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/fog/aliyun/requests/compute/start_server.rb', line 12

def start_server(server_id)
  
  _action = 'StartInstance'
  _sigNonce = randonStr()
  _time = Time.new.utc

  _parameters = defalutParameters(_action, _sigNonce, _time)
  _pathURL  = defaultAliyunUri(_action, _sigNonce, _time)
  
  _parameters['InstanceId']=server_id
  _pathURL += '&InstanceId='+server_id
    
  _signature = sign(@aliyun_accesskey_secret, _parameters)
  _pathURL += '&Signature='+_signature
  
  request(
    :expects => [200, 204],
    :method => 'GET',
    :path   => _pathURL
  )
end

#stop_server(server_id) ⇒ Object

Stop the server.

Parameters

  • server_id <~String> - The ID of the server to be stopped.

Returns

  • success <~Boolean>

Aliyun API Reference



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/fog/aliyun/requests/compute/stop_server.rb', line 12

def stop_server(server_id)

  _action = 'StopInstance'
  _sigNonce = randonStr()
  _time = Time.new.utc

  _parameters = defalutParameters(_action, _sigNonce, _time)
  _pathURL  = defaultAliyunUri(_action, _sigNonce, _time)
  
  _parameters['InstanceId']=server_id
  _pathURL += '&InstanceId='+server_id
    
  _signature = sign(@aliyun_accesskey_secret, _parameters)
  _pathURL += '&Signature='+_signature
  
  request(
    :expects => [200, 204],
    :method => 'GET',
    :path   => _pathURL
  )
end

#unassociate_eip_address(server_id, allocationId, options = {}) ⇒ Object

Disassociate an avalable eip IP address to the given instance.

Parameters

  • server_id<~String> - id of the instance

  • allocationId<~String> - id of the EIP

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • ‘RequestId’<~String> - Id of the request

Aliyun API Reference



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/fog/aliyun/requests/compute/unassociate_eip_address.rb', line 16

def unassociate_eip_address(server_id, allocationId, options={})
  
  _action = 'UnassociateEipAddress'
  _sigNonce = randonStr()
  _time = Time.new.utc

  type=options['instance_type']

  _parameters = defalutParameters(_action, _sigNonce, _time)
  _pathURL  = defaultAliyunUri(_action, _sigNonce, _time)
  
  _parameters['InstanceId'] = server_id
  _pathURL += '&InstanceId='+server_id
  
  _parameters['AllocationId'] = allocationId
  _pathURL += '&AllocationId='+allocationId

  if type
    _parameters['InstanceType'] = type
    _pathURL += 'InstanceType='+type
  end
  
  _signature = sign(@aliyun_accesskey_secret, _parameters)
  _pathURL += '&Signature='+_signature
  
  request(
    :expects => [200, 204],
    :method => 'GET',
    :path   => _pathURL
  )
end