Sha256: f2eb0f71c8da8865d3422a5551ab438ee417a71408ef39f31614ed62f15c4507

Contents?: true

Size: 1.75 KB

Versions: 5

Compression:

Stored size: 1.75 KB

Contents

# frozen_string_literal: true

module Fog
  module Compute
    class Aliyun
      class Real
        # {Aliyun API Reference}[https://docs.aliyun.com/?spm=5176.100054.3.1.DGkmH7#/pub/ecs/open-api/other&describeinstancetypes]
        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

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

        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 |instance_type|
            next unless (instance_type['CpuCoreCount'] == cpuCount) && (instance_type['MemorySize'] == memorySize)
            _InstanceTypeId = instance_type['InstanceTypeId']
            puts '_instanceTypeId: ' + _InstanceTypeId
            break
          end
          _InstanceTypeId
        end
      end
    end
  end
end

Version data entries

5 entries across 3 versions & 2 rubygems

Version Path
fog-aliyun-0.3.3 lib/fog/aliyun/requests/compute/list_server_types.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.3.0/gems/fog-aliyun-0.3.2/lib/fog/aliyun/requests/compute/list_server_types.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.4.0/gems/fog-aliyun-0.3.2/lib/fog/aliyun/requests/compute/list_server_types.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.5.0/gems/fog-aliyun-0.3.2/lib/fog/aliyun/requests/compute/list_server_types.rb
fog-aliyun-0.3.2 lib/fog/aliyun/requests/compute/list_server_types.rb