Skip to content

Instantly share code, notes, and snippets.

@Lax
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Lax/3a2037a11c49df1aa1e7 to your computer and use it in GitHub Desktop.
Save Lax/3a2037a11c49df1aa1e7 to your computer and use it in GitHub Desktop.
aliyun_cli
aliyun.yml
*.csv
:access_key_id: _YOUR_KEY_HERE
:access_key_secret: _YOUR_KEY_SECRET_HERE
:endpoint_url: https://ecs.aliyuncs.com/
#!/usr/bin/env ruby
# encoding: utf-8
require 'rubygems'
require 'aliyun'
require 'yaml'
$stdout.sync = true
config_yml = "./aliyun.yml"
$service = Aliyun::ECS::Service.new YAML.load_file(config_yml)
$types = Hash.new nil
aliyun_types_yml = "./aliyun_types.yml"
YAML.load_file(aliyun_types_yml)['InstanceTypes']['InstanceType'].each do |type|
$types[type['InstanceTypeId']] = "%s[CPU:%s|Memory:%sGB]" % [type['InstanceTypeId'], type['CpuCoreCount'], type['MemorySize']]
end
regions = $service.DescribeRegions({})['Regions']['Region']
regions.each do |region|
zones = $service.DescribeZones(:RegionId => region['RegionId'])['Zones']['Zone']
zones.each do |zone|
reach_last = false
page = 1
while ! reach_last
instances_r = $service.DescribeInstanceStatus(:RegionId => region['RegionId'], :ZoneId => zone['ZoneId'], :PageNumber => page, :PageSize => 50)
pageNumber = instances_r['PageNumber']
pageSize = instances_r['PageSize']
totalCount = instances_r['TotalCount']
instances = instances_r['InstanceStatuses']['InstanceStatus']
instances.each do |instance|
instance_attr = $service.DescribeInstanceAttribute :InstanceId => instance['InstanceId']
instance_disks = $service.DescribeDisks(:RegionId => region['RegionId'], :InstanceId => instance['InstanceId'])['Disks']['Disk'].map {|disk|
"Device:%s;Type:%s;Size:%sGB" % [disk['Device'], disk['Type'], disk['Size']]
}.join('|')
peer_info = [
instance_attr['SerialNumber'],
instance_attr['InstanceName'], instance_attr['CreationTime'],
instance['InstanceId'], instance['Status'],
instance_attr['InnerIpAddress']['IpAddress'].join('|'), instance_attr['PublicIpAddress']['IpAddress'].join('|'),
instance_attr['InternetMaxBandwidthIn'], instance_attr['InternetMaxBandwidthOut'],
$types[instance_attr['InstanceType']],
instance_disks,
region['LocalName'], region['RegionId'],
zone['LocalName'], zone['ZoneId']
]
puts (['%s']*peer_info.size).join(',') % peer_info
end
reach_last = true if pageNumber * pageNumber >= totalCount
page += 1
end
end
end
---
InstanceTypes:
InstanceType:
- CpuCoreCount: 1
InstanceTypeId: ecs.t1.xsmall
MemorySize: 0.5
- CpuCoreCount: 1
InstanceTypeId: ecs.t1.small
MemorySize: 1.0
- CpuCoreCount: 1
InstanceTypeId: ecs.s1.small
MemorySize: 2.0
- CpuCoreCount: 1
InstanceTypeId: ecs.s1.medium
MemorySize: 4.0
- CpuCoreCount: 2
InstanceTypeId: ecs.s2.small
MemorySize: 2.0
- CpuCoreCount: 2
InstanceTypeId: ecs.s2.large
MemorySize: 4.0
- CpuCoreCount: 2
InstanceTypeId: ecs.s2.xlarge
MemorySize: 8.0
- CpuCoreCount: 4
InstanceTypeId: ecs.s3.medium
MemorySize: 4.0
- CpuCoreCount: 4
InstanceTypeId: ecs.s3.large
MemorySize: 8.0
- CpuCoreCount: 4
InstanceTypeId: ecs.m1.medium
MemorySize: 16.0
- CpuCoreCount: 8
InstanceTypeId: ecs.m1.xlarge
MemorySize: 32.0
- CpuCoreCount: 8
InstanceTypeId: ecs.c1.small
MemorySize: 8.0
- CpuCoreCount: 8
InstanceTypeId: ecs.c1.large
MemorySize: 16.0
- CpuCoreCount: 16
InstanceTypeId: ecs.c2.xlarge
MemorySize: 64.0
- CpuCoreCount: 1
InstanceTypeId: ecs.s1.large
MemorySize: 8.0
- CpuCoreCount: 2
InstanceTypeId: ecs.s2.2xlarge
MemorySize: 16.0
- CpuCoreCount: 4
InstanceTypeId: ecs.m2.medium
MemorySize: 32.0
source 'http://ruby.taobao.org'
gem 'aliyun'
GEM
remote: http://ruby.taobao.org/
specs:
aliyun (0.1.0)
ruby-hmac
ruby-hmac (0.4.0)
PLATFORMS
ruby
DEPENDENCIES
aliyun
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment