1 2 3 4 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 76 77 78 79 80 81 82 83
|
# frozen_string_literal: true
require 'addressable'
module Fog
module Compute
class Aliyun
class Real
# 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}[https://docs.aliyun.com/?spm=5176.100054.201.106.DGkmH7#/pub/ecs/open-api/disk&attachdisk]
def attach_disk(instanceId, diskId, options = {})
action = 'AttachDisk'
sigNonce = randonStr
time = Time.new.utc
parameters = defaultParameters(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]
deleteWithInstance ||= 'true'
parameters['DeleteWithInstance'] = deleteWithInstance
pathUrl += '&DeleteWithInstance='
pathUrl += deleteWithInstance
if device
parameters['Device'] = device
pathUrl += '&Device='
pathUrl += Addressable::URI.encode_component(device, Addressable::URI::CharacterClasses::UNRESERVED + '|')
end
signature = sign(@aliyun_accesskey_secret, parameters)
pathUrl += '&Signature='
pathUrl += signature
request(
expects: [200, 203],
method: 'GET',
path: pathUrl
)
end
end
class Mock
def attach_volume(volume_id, server_id, device)
response = Excon::Response.new
response.status = 200
data = {
'id' => volume_id,
'volumeId' => volume_id,
'serverId' => server_id,
'device' => device
}
self.data[:volumes][volume_id]['attachments'] << data
response.body = { 'volumeAttachment' => data }
response
end
end
end
end
end
|