1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00
fog--fog/lib/fog/aws/models/compute/spot_request.rb

94 lines
4.1 KiB
Ruby
Raw Normal View History

2011-07-02 00:30:32 -04:00
require 'fog/core/model'
module Fog
module Compute
class AWS
class SpotRequest < Fog::Model
identity :id, :aliases => 'spotInstanceRequestId'
attribute :price, :aliases => 'spotPrice'
attribute :request_type, :aliases => 'type'
attribute :created_at, :aliases => 'createTime'
attribute :instance_count, :aliases => 'instanceCount'
2011-07-02 03:54:37 -04:00
attribute :instance_id, :aliases => 'instanceId'
2011-07-02 00:30:32 -04:00
attribute :state
attribute :valid_from, :aliases => 'validFrom'
attribute :valid_until, :aliases => 'validUntil'
attribute :launch_group, :aliases => 'launchGroup'
attribute :availability_zone_group, :aliases => 'availabilityZoneGroup'
attribute :product_description, :aliases => 'productDescription'
attribute :groups, :aliases => 'LaunchSpecification.SecurityGroup'
attribute :key_name, :aliases => 'LaunchSpecification.KeyName'
2011-07-02 03:54:37 -04:00
attribute :availability_zone, :aliases => 'LaunchSpecification.Placement.AvailabilityZone'
2011-07-02 00:30:32 -04:00
attribute :flavor_id, :aliases => 'LaunchSpecification.InstanceType'
attribute :image_id, :aliases => 'LaunchSpecification.ImageId'
attribute :monitoring, :aliases => 'LaunchSpecification.Monitoring'
2011-07-02 03:54:37 -04:00
attribute :block_device_mapping, :aliases => 'LaunchSpecification.BlockDeviceMapping'
attribute :tags, :aliases => 'tagSet'
attribute :fault, :squash => 'message'
attribute :user_data
2011-07-02 00:30:32 -04:00
attr_writer :username
def initialize(attributes={})
self.groups ||= ["default"]
self.flavor_id ||= 't1.micro'
self.image_id ||= begin
self.username = 'ubuntu'
case attributes[:connection].instance_variable_get(:@region) # Ubuntu 10.04 LTS 64bit (EBS)
when 'ap-northeast-1'
'ami-5e0fa45f'
when 'ap-southeast-1'
'ami-f092eca2'
when 'eu-west-1'
'ami-3d1f2b49'
when 'us-east-1'
'ami-3202f25b'
when 'us-west-1'
'ami-f5bfefb0'
end
end
super
end
def save
requires :image_id, :flavor_id, :price
options = {
2011-07-02 03:54:37 -04:00
'AvailabilityZoneGroup' => availability_zone_group,
2011-07-02 00:30:32 -04:00
'InstanceCount' => instance_count,
2011-07-02 03:54:37 -04:00
'LaunchGroup' => launch_group,
'LaunchSpecification.BlockDeviceMapping' => block_device_mapping,
2011-07-02 00:30:32 -04:00
'LaunchSpecification.KeyName' => key_name,
2011-07-02 03:54:37 -04:00
'LaunchSpecification.Monitoring.Enabled' => monitoring,
2011-07-02 00:30:32 -04:00
'LaunchSpecification.Placement.AvailabilityZone' => availability_zone,
'LaunchSpecification.SecurityGroup' => groups,
2011-07-02 03:54:37 -04:00
'LaunchSpecification.UserData' => user_data,
'Type' => request_type,
'ValidFrom' => valid_from,
'ValidUntil' => valid_until }
options.delete_if {|key, value| value.nil?}
2011-07-02 00:30:32 -04:00
2011-07-02 03:54:37 -04:00
data = connection.request_spot_instances(image_id, flavor_id, price, options).body
spot_instance_request = data['spotInstanceRequestSet'].first
spot_instance_request['launchSpecification'].each do |name,value|
spot_instance_request['LaunchSpecification.' + name[0,1].upcase + name[1..-1]] = value
end
spot_instance_request.merge(:groups => spot_instance_request['LaunchSpecification.GroupSet'])
spot_instance_request.merge(options)
merge_attributes( spot_instance_request )
2011-07-02 00:30:32 -04:00
end
def ready?
state == 'active'
end
end
end
end
end