1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

Merge branch 'master' of https://github.com/fog/fog into storm

This commit is contained in:
Eric Wong 2013-05-25 17:29:44 +08:00
commit de6e6c6c6d
8 changed files with 114 additions and 96 deletions

View file

@ -8,46 +8,52 @@ module Fog
extend Fog::Deprecation
deprecate :ip_address, :public_ip_address
identity :id, :aliases => 'instanceId'
identity :id, :aliases => 'instanceId'
attr_accessor :architecture
attribute :ami_launch_index, :aliases => 'amiLaunchIndex'
attribute :availability_zone, :aliases => 'availabilityZone'
attribute :block_device_mapping, :aliases => 'blockDeviceMapping'
attribute :network_interfaces, :aliases => 'networkInterfaces'
attribute :client_token, :aliases => 'clientToken'
attribute :dns_name, :aliases => 'dnsName'
attribute :ebs_optimized, :aliases => 'ebsOptimized'
attribute :ami_launch_index, :aliases => 'amiLaunchIndex'
attribute :availability_zone, :aliases => 'availabilityZone'
attribute :block_device_mapping, :aliases => 'blockDeviceMapping'
attribute :network_interfaces, :aliases => 'networkInterfaces'
attribute :client_token, :aliases => 'clientToken'
attribute :dns_name, :aliases => 'dnsName'
attribute :ebs_optimized, :aliases => 'ebsOptimized'
attribute :groups
attribute :flavor_id, :aliases => 'instanceType'
attribute :iam_instance_profile, :aliases => 'iamInstanceProfile'
attribute :image_id, :aliases => 'imageId'
attribute :flavor_id, :aliases => 'instanceType'
attribute :hypervisor
attribute :iam_instance_profile, :aliases => 'iamInstanceProfile'
attribute :image_id, :aliases => 'imageId'
attr_accessor :instance_initiated_shutdown_behavior
attribute :kernel_id, :aliases => 'kernelId'
attribute :key_name, :aliases => 'keyName'
attribute :created_at, :aliases => 'launchTime'
attribute :monitoring, :squash => 'state'
attribute :placement_group, :aliases => 'groupName'
attribute :platform, :aliases => 'platform'
attribute :product_codes, :aliases => 'productCodes'
attribute :private_dns_name, :aliases => 'privateDnsName'
attribute :private_ip_address, :aliases => 'privateIpAddress'
attribute :public_ip_address, :aliases => 'ipAddress'
attribute :ramdisk_id, :aliases => 'ramdiskId'
attribute :kernel_id, :aliases => 'kernelId'
attribute :key_name, :aliases => 'keyName'
attribute :created_at, :aliases => 'launchTime'
attribute :lifecycle, :aliases => 'instanceLifecycle'
attribute :monitoring, :squash => 'state'
attribute :placement_group, :aliases => 'groupName'
attribute :platform, :aliases => 'platform'
attribute :product_codes, :aliases => 'productCodes'
attribute :private_dns_name, :aliases => 'privateDnsName'
attribute :private_ip_address, :aliases => 'privateIpAddress'
attribute :public_ip_address, :aliases => 'ipAddress'
attribute :ramdisk_id, :aliases => 'ramdiskId'
attribute :reason
attribute :root_device_name, :aliases => 'rootDeviceName'
attribute :root_device_type, :aliases => 'rootDeviceType'
attribute :security_group_ids, :aliases => 'securityGroupIds'
attribute :state, :aliases => 'instanceState', :squash => 'name'
attribute :state_reason, :aliases => 'stateReason'
attribute :subnet_id, :aliases => 'subnetId'
attribute :requester_id, :aliases => 'requesterId'
attribute :root_device_name, :aliases => 'rootDeviceName'
attribute :root_device_type, :aliases => 'rootDeviceType'
attribute :security_group_ids, :aliases => 'securityGroupIds'
attribute :source_dest_check, :aliases => 'sourceDestCheck'
attribute :spot_instance_request_id, :aliases => 'spotInstanceRequestId'
attribute :state, :aliases => 'instanceState', :squash => 'name'
attribute :state_reason, :aliases => 'stateReason'
attribute :subnet_id, :aliases => 'subnetId'
attribute :tenancy
attribute :tags, :aliases => 'tagSet'
attribute :tags, :aliases => 'tagSet'
attribute :user_data
attribute :vpc_id, :aliases => 'vpcId'
attribute :virtualization_type, :aliases => 'virtualizationType'
attribute :vpc_id, :aliases => 'vpcId'
attr_accessor :password
attr_writer :iam_instance_profile_name, :iam_instance_profile_arn
attr_accessor :password
attr_writer :iam_instance_profile_name, :iam_instance_profile_arn
def initialize(attributes={})

View file

@ -31,10 +31,11 @@ module Fog
@instance[@context.last][name] = value
when 'availabilityZone', 'tenancy'
@instance['placement'][name] = value
when 'architecture', 'clientToken', 'dnsName', 'imageId',
'instanceId', 'instanceType', 'ipAddress', 'kernelId',
'keyName', 'platform', 'privateDnsName', 'privateIpAddress', 'ramdiskId',
'reason', 'rootDeviceType', 'virtualizationType'
when 'architecture', 'clientToken', 'dnsName', 'hypervisor', 'imageId',
'instanceId', 'instanceType', 'ipAddress', 'kernelId', 'keyName',
'instanceLifecycle', 'platform', 'privateDnsName', 'privateIpAddress', 'ramdiskId',
'reason', 'requesterId', 'rootDeviceType',
'spotInstanceRequestId', 'virtualizationType'
@instance[name] = value
when 'attachTime'
@block_device_mapping[name] = Time.parse(value)
@ -103,6 +104,12 @@ module Fog
@instance['monitoring'][name] = (value == 'enabled')
when 'ebsOptimized'
@instance['ebsOptimized'] = (value == 'true')
when 'sourceDestCheck'
if value == 'true'
@instance[name] = true
else
@instance[name] = false
end
# Eucalyptus passes status in schema non conforming way
when 'stateCode'
@instance['instanceState']['code'] = value

View file

@ -24,10 +24,11 @@ module Fog
case name
when 'amiLaunchIndex'
@instance[name] = value.to_i
when 'architecture', 'clientToken', 'dnsName', 'imageId',
'instanceId', 'instanceType', 'ipAddress', 'kernelId',
'keyName', 'privateDnsName', 'privateIpAddress', 'ramdiskId',
'reason', 'rootDeviceType'
when 'architecture', 'clientToken', 'dnsName', 'hypervisor', 'imageId',
'instanceId', 'instanceType', 'ipAddress', 'kernelId', 'keyName',
'instanceLifecycle', 'privateDnsName', 'privateIpAddress', 'ramdiskId',
'reason', 'requesterId', 'rootDeviceType', 'sourceDestCheck',
'spotInstanceRequestId', 'virtualizationType'
@instance[name] = value
when 'availabilityZone', 'tenancy'
@instance['placement'][name] = value

View file

@ -212,7 +212,7 @@ module Fog
'ownerId' => instance['ownerId'],
'reservationId' => instance['reservationId']
}
reservation_set[instance['reservationId']]['instancesSet'] << instance.reject{|key,value| !['amiLaunchIndex', 'architecture', 'blockDeviceMapping', 'clientToken', 'dnsName', 'ebsOptimized', 'iamInstanceProfile', 'imageId', 'instanceId', 'instanceState', 'instanceType', 'ipAddress', 'kernelId', 'keyName', 'launchTime', 'monitoring', 'networkInterfaces', 'ownerId', 'placement', 'platform', 'privateDnsName', 'privateIpAddress', 'productCodes', 'ramdiskId', 'reason', 'rootDeviceType', 'stateReason'].include?(key)}.merge('tagSet' => self.data[:tag_sets][instance['instanceId']])
reservation_set[instance['reservationId']]['instancesSet'] << instance.reject{|key,value| !['amiLaunchIndex', 'architecture', 'blockDeviceMapping', 'clientToken', 'dnsName', 'ebsOptimized', 'hypervisor', 'iamInstanceProfile', 'imageId', 'instanceId', 'instanceState', 'instanceType', 'ipAddress', 'kernelId', 'keyName', 'launchTime', 'monitoring', 'networkInterfaces', 'ownerId', 'placement', 'platform', 'privateDnsName', 'privateIpAddress', 'productCodes', 'ramdiskId', 'reason', 'rootDeviceType', 'stateReason', 'virtualizationType'].include?(key)}.merge('tagSet' => self.data[:tag_sets][instance['instanceId']])
end
end

View file

@ -143,6 +143,8 @@ module Fog
'blockDeviceMapping' => [],
'clientToken' => options['clientToken'],
'dnsName' => nil,
'ebsOptimized' => options['EbsOptimized'] || false,
'hypervisor' => 'xen',
'imageId' => image_id,
'instanceId' => instance_id,
'instanceState' => { 'code' => 0, 'name' => 'pending' },
@ -156,7 +158,7 @@ module Fog
'productCodes' => [],
'reason' => nil,
'rootDeviceType' => 'instance-store',
'ebsOptimized' => options['EbsOptimized'] || false
'virtualizationType' => 'paravirtual'
}
instances_set << instance
self.data[:instances][instance_id] = instance.merge({

View file

@ -18,6 +18,7 @@ module Fog
def find_by_id(id)
self.find {|image| image.id == id}
end
alias_method :get, :find_by_id
def public
images = load(service.list_public_images_detailed.body['images'])

View file

@ -3,7 +3,8 @@ Shindo.tests('Fog::Compute[:aws] | instance requests', ['aws']) do
@instance_format = {
'architecture' => String,
'amiLaunchIndex' => Integer,
'blockDeviceMapping' => [],
'attachmentId' => Fog::Nullable::String,
'blockDeviceMapping' => [Fog::Nullable::Hash],
'clientToken' => Fog::Nullable::String,
'dnsName' => NilClass,
'ebsOptimized' => Fog::Boolean,
@ -11,24 +12,24 @@ Shindo.tests('Fog::Compute[:aws] | instance requests', ['aws']) do
'instanceId' => String,
'instanceState' => {'code' => Integer, 'name' => String},
'instanceType' => String,
# 'ipAddress' => String,
'kernelId' => Fog::Nullable::String,
'keyName' => Fog::Nullable::String,
'launchTime' => Time,
'monitoring' => {'state' => Fog::Boolean},
'networkInterfaceId' => Fog::Nullable::String,
'placement' => {
'availabilityZone' => String,
'groupName' => Fog::Nullable::String,
'tenancy' => String
'groupName' => Fog::Nullable::String,
'tenancy' => String
},
'platform' => Fog::Nullable::String,
'privateDnsName' => NilClass,
# 'privateIpAddress' => String,
'productCodes' => [],
# 'ramdiskId' => Fog::Nullable::String,
'productCodes' => Array,
'reason' => Fog::Nullable::String,
# 'rootDeviceName' => String,
'rootDeviceType' => String,
'sourceDestCheck' => Fog::Nullable::Boolean,
'subnetId' => Fog::Nullable::String,
'vpcId' => Fog::Nullable::String
}
@run_instances_format = {
@ -44,16 +45,18 @@ Shindo.tests('Fog::Compute[:aws] | instance requests', ['aws']) do
'groupSet' => [String],
'groupIds' => [String],
'instancesSet' => [@instance_format.merge(
'architecture' => String,
'dnsName' => Fog::Nullable::String,
'iamInstanceProfile' => {},
'ipAddress' => Fog::Nullable::String,
'networkInterfaces' => [],
'ownerId' => String,
'privateDnsName' => Fog::Nullable::String,
'privateIpAddress' => Fog::Nullable::String,
'stateReason' => Hash,
'tagSet' => Hash
'architecture' => String,
'dnsName' => Fog::Nullable::String,
'hypervisor' => String,
'iamInstanceProfile' => Hash,
'ipAddress' => Fog::Nullable::String,
'networkInterfaces' => Array,
'ownerId' => String,
'privateDnsName' => Fog::Nullable::String,
'privateIpAddress' => Fog::Nullable::String,
'stateReason' => Hash,
'tagSet' => Hash,
'virtualizationType' => String
)],
'ownerId' => Fog::Nullable::String,
'reservationId' => String
@ -98,7 +101,7 @@ Shindo.tests('Fog::Compute[:aws] | instance requests', ['aws']) do
'instanceTenancy' => String,
'currencyCode' => String
}],
'requestId' => String
'requestId' => String
}
@purchase_reserved_instances_offering_format = {
@ -130,43 +133,36 @@ Shindo.tests('Fog::Compute[:aws] | instance requests', ['aws']) do
}
@describe_instance_status_format = {
'requestId' => String,
'requestId' => String,
'instanceStatusSet' => [{
'instanceId' => String,
'availabilityZone' => String,
'instanceState' => {
'code' => Integer,
'name' => String
},
'systemStatus' => {
'status' => String,
'details' => [{
'name' => String,
'status' => String
}]
},
'instanceStatus' => {
'status' => String,
'details' => [{
'name' => String,
'status' => String
}]
},
'eventsSet' => [{
'code' => String,
'description' => String,
'notBefore' => Time,
'notAfter' => Time
}]
}]
'instanceId' => String,
'availabilityZone' => String,
'instanceState' => {
'code' => Integer,
'name' => String
},
'systemStatus' => {
'status' => String,
'details' => [{
'name' => String,
'status' => String
}]
},
'instanceStatus' => {
'status' => String,
'details' => [{
'name' => String,
'status' => String
}]
},
'eventsSet' => [Fog::Nullable::Hash],
}]
}
tests('success') do
@instance_id = nil
@ami = if ENV['FASTER_TEST_PLEASE']
'ami-6bbb1302' # ubuntu 12.04 daily build 20120728
'ami-79c0ae10' # ubuntu 12.04 daily build 20120728
else
# Use a MS Windows AMI to test #get_password_data
'ami-71b50018' # Amazon Public Images - Windows_Server-2008-SP2-English-64Bit-Base-2012.07.11
@ -191,14 +187,14 @@ Shindo.tests('Fog::Compute[:aws] | instance requests', ['aws']) do
server.wait_for { ready? }
tests("#describe_instances").formats(@describe_instances_format) do
Fog::Compute[:aws].describe_instances('instance-state-name' => 'running').body
Fog::Compute[:aws].describe_instances('instance-state-name' => 'running').body
end
# Launch another instance to test filters
another_server = Fog::Compute[:aws].servers.create
tests("#describe_instances('instance-id' => '#{@instance_id}')").formats(@describe_instances_format) do
body = Fog::Compute[:aws].describe_instances('instance-id' => @instance_id).body
tests("#describe_instances('instance-id' => '#{@instance_id}'").formats(@describe_instances_format) do
body = Fog::Compute[:aws].describe_instances('instance-id' => "#{@instance_id}").body
tests("returns 1 instance").returns(1) { body['reservationSet'].size }
body
end

View file

@ -7,6 +7,11 @@ Shindo.tests("Fog::Image[:openstack] | images", ['openstack']) do
image.id == @instance['image']['id']
end
tests('#get').succeeds do
image = Fog::Image[:openstack].images.get(@instance['image']['id'])
image.id == @instance['image']['id']
end
tests('#destroy').succeeds do
Fog::Image[:openstack].images.destroy(@instance['image']['id'])
end