mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[compute|aws] cluster compute placement group implementation
closes #372
This commit is contained in:
parent
c413037d11
commit
c8244b4930
10 changed files with 230 additions and 22 deletions
|
@ -32,12 +32,14 @@ module Fog
|
|||
request :authorize_security_group_ingress
|
||||
request :create_image
|
||||
request :create_key_pair
|
||||
request :create_placement_group
|
||||
request :create_security_group
|
||||
request :create_snapshot
|
||||
request :create_tags
|
||||
request :create_volume
|
||||
request :delete_key_pair
|
||||
request :delete_security_group
|
||||
request :delete_placement_group
|
||||
request :delete_snapshot
|
||||
request :delete_tags
|
||||
request :delete_volume
|
||||
|
@ -48,6 +50,7 @@ module Fog
|
|||
request :describe_instances
|
||||
request :describe_reserved_instances
|
||||
request :describe_key_pairs
|
||||
request :describe_placement_groups
|
||||
request :describe_regions
|
||||
request :describe_reserved_instances_offerings
|
||||
request :describe_security_groups
|
||||
|
@ -266,7 +269,7 @@ module Fog
|
|||
rescue Excon::Errors::HTTPStatusError => error
|
||||
if match = error.message.match(/<Code>(.*)<\/Code><Message>(.*)<\/Message>/)
|
||||
raise case match[1].split('.').last
|
||||
when 'NotFound'
|
||||
when 'NotFound', 'Unknown'
|
||||
Fog::Compute::AWS::NotFound.slurp(error, match[2])
|
||||
else
|
||||
Fog::Compute::AWS::Error.slurp(error, "#{match[1]} => #{match[2]}")
|
||||
|
|
|
@ -12,7 +12,7 @@ module Fog
|
|||
|
||||
attr_accessor :architecture
|
||||
attribute :ami_launch_index, :aliases => 'amiLaunchIndex'
|
||||
attribute :availability_zone, :aliases => ['availabilityZone', 'placement'], :squash => 'availabilityZone'
|
||||
attribute :availability_zone, :aliases => 'availabilityZone'
|
||||
attribute :block_device_mapping, :aliases => 'blockDeviceMapping'
|
||||
attribute :client_token, :aliases => 'clientToken'
|
||||
attribute :dns_name, :aliases => 'dnsName'
|
||||
|
@ -24,6 +24,7 @@ module Fog
|
|||
attribute :key_name, :aliases => 'keyName'
|
||||
attribute :created_at, :aliases => 'launchTime'
|
||||
attribute :monitoring, :squash => 'state'
|
||||
attribute :placement_group, :aliases => 'groupName'
|
||||
attribute :product_codes, :aliases => 'productCodes'
|
||||
attribute :private_dns_name, :aliases => 'privateDnsName'
|
||||
attribute :private_ip_address, :aliases => 'privateIpAddress'
|
||||
|
@ -35,6 +36,7 @@ module Fog
|
|||
attribute :state, :aliases => 'instanceState', :squash => 'name'
|
||||
attribute :state_reason, :aliases => 'stateReason'
|
||||
attribute :subnet_id, :aliases => 'subnetId'
|
||||
attribute :tenancy
|
||||
attribute :tags, :aliases => 'tagSet'
|
||||
attribute :user_data
|
||||
|
||||
|
@ -145,6 +147,8 @@ module Fog
|
|||
'KeyName' => key_name,
|
||||
'Monitoring.Enabled' => monitoring,
|
||||
'Placement.AvailabilityZone' => availability_zone,
|
||||
'Placement.GroupName' => placement_group,
|
||||
'Placement.Tenancy' => tenancy,
|
||||
'RamdiskId' => ramdisk_id,
|
||||
'SecurityGroup' => groups,
|
||||
'SubnetId' => subnet_id,
|
||||
|
@ -249,6 +253,16 @@ module Fog
|
|||
self.monitoring = new_monitor
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def placement=(new_placement)
|
||||
if new_placement.is_a?(Hash)
|
||||
merge_attributes(new_placement)
|
||||
else
|
||||
self.attributes[:placement] = new_placement
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -8,7 +8,7 @@ module Fog
|
|||
def reset
|
||||
@block_device_mapping = {}
|
||||
@context = []
|
||||
@contexts = ['blockDeviceMapping', 'groupSet', 'instancesSet', 'instanceState', 'productCodes', 'stateReason', 'tagSet']
|
||||
@contexts = ['blockDeviceMapping', 'groupSet', 'instancesSet', 'instanceState', 'placement', 'productCodes', 'stateReason', 'tagSet']
|
||||
@instance = { 'blockDeviceMapping' => [], 'instanceState' => {}, 'monitoring' => {}, 'placement' => {}, 'productCodes' => [], 'stateReason' => {}, 'tagSet' => {} }
|
||||
@reservation = { 'groupSet' => [], 'instancesSet' => [] }
|
||||
@response = { 'reservationSet' => [] }
|
||||
|
@ -26,7 +26,7 @@ module Fog
|
|||
case name
|
||||
when 'amiLaunchIndex'
|
||||
@instance[name] = value.to_i
|
||||
when 'availabilityZone'
|
||||
when 'availabilityZone', 'tenancy'
|
||||
@instance['placement'][name] = value
|
||||
when 'architecture', 'clientToken', 'dnsName', 'imageId',
|
||||
'instanceId', 'instanceType', 'ipAddress', 'kernelId',
|
||||
|
@ -44,7 +44,12 @@ module Fog
|
|||
when 'deviceName', 'status', 'volumeId'
|
||||
@block_device_mapping[name] = value
|
||||
when 'groupName'
|
||||
@reservation['groupSet'] << value
|
||||
case @context.last
|
||||
when 'groupSet'
|
||||
@reservation['groupSet'] << value
|
||||
when 'placement'
|
||||
@instance['placement'][name] = value
|
||||
end
|
||||
when 'item'
|
||||
case @context.last
|
||||
when 'blockDeviceMapping'
|
||||
|
|
30
lib/fog/compute/parsers/aws/describe_placement_groups.rb
Normal file
30
lib/fog/compute/parsers/aws/describe_placement_groups.rb
Normal file
|
@ -0,0 +1,30 @@
|
|||
module Fog
|
||||
module Parsers
|
||||
module Compute
|
||||
module AWS
|
||||
|
||||
class DescribePlacementGroups < Fog::Parsers::Base
|
||||
|
||||
def reset
|
||||
@placement_group = {}
|
||||
@response = { 'placementGroupSet' => [] }
|
||||
end
|
||||
|
||||
def end_element(name)
|
||||
case name
|
||||
when 'item'
|
||||
@response['placementGroupSet'] << @placement_group
|
||||
@placement_group = {}
|
||||
when 'groupName', 'state', 'strategy'
|
||||
@placement_group[name] = value
|
||||
when 'requestId'
|
||||
@response[name] = value
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -7,19 +7,16 @@ module Fog
|
|||
|
||||
def reset
|
||||
@block_device_mapping = {}
|
||||
@context = []
|
||||
@contexts = ['blockDeviceMapping', 'groupSet', 'placement', 'productCodes']
|
||||
@instance = { 'blockDeviceMapping' => [], 'instanceState' => {}, 'monitoring' => {}, 'placement' => {}, 'productCodes' => [] }
|
||||
@response = { 'groupSet' => [], 'instancesSet' => [] }
|
||||
end
|
||||
|
||||
def start_element(name, attrs = [])
|
||||
super
|
||||
case name
|
||||
when 'blockDeviceMapping'
|
||||
@in_block_device_mapping = true
|
||||
when 'groupSet'
|
||||
@in_group_set = true
|
||||
when 'productCodes'
|
||||
@in_product_codes = true
|
||||
if @contexts.include?(name)
|
||||
@context.push(name)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -32,12 +29,12 @@ module Fog
|
|||
'keyName', 'privateDnsName', 'privateIpAddress', 'ramdiskId',
|
||||
'reason', 'rootDeviceType'
|
||||
@instance[name] = value
|
||||
when 'availabilityZone'
|
||||
when 'availabilityZone', 'tenancy'
|
||||
@instance['placement'][name] = value
|
||||
when 'attachTime'
|
||||
@block_device_mapping[name] = Time.parse(value)
|
||||
when 'blockDeviceMapping'
|
||||
@in_block_device_mapping = false
|
||||
when *@contexts
|
||||
@context.pop
|
||||
when 'code'
|
||||
@instance['instanceState'][name] = value.to_i
|
||||
when 'deleteOnTermination'
|
||||
|
@ -46,13 +43,19 @@ module Fog
|
|||
@block_device_mapping[name] = value
|
||||
when 'groupId'
|
||||
@response['groupSet'] << value
|
||||
when 'groupSet'
|
||||
@in_group_set = false
|
||||
when 'groupName'
|
||||
case @context.last
|
||||
when 'groupSet'
|
||||
@response['groupSet'] << value
|
||||
when 'placement'
|
||||
@instance['placement'][name] = value
|
||||
end
|
||||
when 'item'
|
||||
if @in_block_device_mapping
|
||||
case @context.last
|
||||
when 'blockDeviceMapping'
|
||||
@instance['blockDeviceMapping'] << @block_device_mapping
|
||||
@block_device_mapping = {}
|
||||
elsif !@in_group_set && !@in_product_codes
|
||||
when nil
|
||||
@response['instancesSet'] << @instance
|
||||
@instance = { 'blockDeviceMapping' => [], 'instanceState' => {}, 'monitoring' => {}, 'placement' => {}, 'productCodes' => [] }
|
||||
end
|
||||
|
@ -64,8 +67,6 @@ module Fog
|
|||
@response[name] = value
|
||||
when 'product_code'
|
||||
@instance['productCodes'] << value
|
||||
when 'productCodes'
|
||||
@in_product_codes = false
|
||||
when 'state'
|
||||
@instance['monitoring'][name] = (value == 'true')
|
||||
when 'subnetId'
|
||||
|
|
34
lib/fog/compute/requests/aws/create_placement_group.rb
Normal file
34
lib/fog/compute/requests/aws/create_placement_group.rb
Normal file
|
@ -0,0 +1,34 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class AWS
|
||||
class Real
|
||||
|
||||
require 'fog/compute/parsers/aws/basic'
|
||||
|
||||
# Create a new placement group
|
||||
#
|
||||
# ==== Parameters
|
||||
# * group_name<~String> - Name of the placement group.
|
||||
# * strategy<~String> - Placement group strategy. Valid options in ['cluster']
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * 'requestId'<~String> - Id of request
|
||||
# * 'return'<~Boolean> - success?
|
||||
#
|
||||
# {Amazon API Reference}[http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-CreatePlacementGroup.html]
|
||||
def create_placement_group(name, strategy)
|
||||
request(
|
||||
'Action' => 'CreatePlacementGroup',
|
||||
'GroupName' => name,
|
||||
'Strategy' => strategy,
|
||||
:parser => Fog::Parsers::Compute::AWS::Basic.new
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
32
lib/fog/compute/requests/aws/delete_placement_group.rb
Normal file
32
lib/fog/compute/requests/aws/delete_placement_group.rb
Normal file
|
@ -0,0 +1,32 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class AWS
|
||||
class Real
|
||||
|
||||
require 'fog/compute/parsers/aws/basic'
|
||||
|
||||
# Delete a placement group that you own
|
||||
#
|
||||
# ==== Parameters
|
||||
# * group_name<~String> - Name of the placement group.
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * 'requestId'<~String> - Id of request
|
||||
# * 'return'<~Boolean> - success?
|
||||
#
|
||||
# {Amazon API Reference}[http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-DeletePlacementGroup.html]
|
||||
def delete_placement_group(name)
|
||||
request(
|
||||
'Action' => 'DeletePlacementGroup',
|
||||
'GroupName' => name,
|
||||
:idempotent => true,
|
||||
:parser => Fog::Parsers::Compute::AWS::Basic.new
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
35
lib/fog/compute/requests/aws/describe_placement_groups.rb
Normal file
35
lib/fog/compute/requests/aws/describe_placement_groups.rb
Normal file
|
@ -0,0 +1,35 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class AWS
|
||||
class Real
|
||||
|
||||
require 'fog/compute/parsers/aws/describe_placement_groups'
|
||||
|
||||
# Describe all or specified placement groups
|
||||
#
|
||||
# ==== Parameters
|
||||
# * filters<~Hash> - List of filters to limit results with
|
||||
#
|
||||
# === Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * 'requestId'<~String> - Id of request
|
||||
# * 'placementGroupSet'<~Array>:
|
||||
# * 'groupName'<~String> - Name of placement group
|
||||
# * 'strategy'<~String> - Strategy of placement group
|
||||
# * 'state'<~String> - State of placement group
|
||||
#
|
||||
# {Amazon API Reference}[http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-DescribePlacementGroups.html]
|
||||
def describe_placement_groups(filters = {})
|
||||
params = Fog::AWS.indexed_filters(filters)
|
||||
request({
|
||||
'Action' => 'DescribePlacementGroups',
|
||||
:idempotent => true,
|
||||
:parser => Fog::Parsers::Compute::AWS::DescribePlacementGroups.new
|
||||
}.merge!(params))
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -30,7 +30,7 @@ module Fog
|
|||
# * 'SecurityGroup'<~Array> or <~String> - Name of security group(s) for instances (you must omit this parameter if using Virtual Private Clouds)
|
||||
# * 'InstanceInitiatedShutdownBehaviour'<~String> - specifies whether volumes are stopped or terminated when instance is shutdown, in [stop, terminate]
|
||||
# * 'InstanceType'<~String> - Type of instance to boot. Valid options
|
||||
# in ['m1.small', 'm1.large', 'm1.xlarge', 'c1.medium', 'c1.xlarge', 'm2.2xlarge', 'm2.4xlarge']
|
||||
# in ['t1.micro', 'm1.small', 'm1.large', 'm1.xlarge', 'c1.medium', 'c1.xlarge', 'm2.xlarge', m2.2xlarge', 'm2.4xlarge', 'cc1.4xlarge', 'cg1.4xlarge']
|
||||
# default is 'm1.small'
|
||||
# * 'KernelId'<~String> - Id of kernel with which to launch
|
||||
# * 'KeyName'<~String> - Name of a keypair to add to booting instances
|
||||
|
|
54
tests/compute/requests/aws/placement_group_tests.rb
Normal file
54
tests/compute/requests/aws/placement_group_tests.rb
Normal file
|
@ -0,0 +1,54 @@
|
|||
Shindo.tests('Fog::Compute[:aws] | placement group requests', ['aws']) do
|
||||
|
||||
@placement_group_format = {
|
||||
'requestId' => String,
|
||||
'placementGroupSet' => [{
|
||||
'groupName' => String,
|
||||
'state' => String,
|
||||
'strategy' => String
|
||||
}]
|
||||
}
|
||||
|
||||
tests('success') do
|
||||
|
||||
tests("#create_placement_group('fog_placement_group', 'cluster')").formats(AWS::Compute::Formats::BASIC) do
|
||||
pending if Fog.mocking?
|
||||
Fog::Compute[:aws].create_placement_group('fog_placement_group', 'cluster').body
|
||||
end
|
||||
|
||||
tests("#describe_placement_groups").formats(@placement_group_format) do
|
||||
pending if Fog.mocking?
|
||||
Fog::Compute[:aws].describe_placement_groups.body
|
||||
end
|
||||
|
||||
tests("#describe_placement_groups('group-name' => 'fog_placement_group)").formats(@placement_group_format) do
|
||||
pending if Fog.mocking?
|
||||
Fog::Compute[:aws].describe_placement_groups('group-name' => 'fog_security_group').body
|
||||
end
|
||||
|
||||
tests("#delete_placement_group('fog_placement_group')").formats(AWS::Compute::Formats::BASIC) do
|
||||
pending if Fog.mocking?
|
||||
Fog::Compute[:aws].delete_placement_group('fog_placement_group').body
|
||||
end
|
||||
|
||||
end
|
||||
tests('failure') do
|
||||
|
||||
unless Fog.mocking?
|
||||
Fog::Compute[:aws].create_placement_group('fog_placement_group', 'cluster')
|
||||
end
|
||||
|
||||
tests("duplicate #create_placement_group('fog_placement_group', 'cluster')").raises(Fog::Compute::AWS::Error) do
|
||||
Fog::Compute[:aws].create_placement_group('fog_placement_group', 'cluster')
|
||||
end
|
||||
|
||||
tests("#delete_placement_group('not_a_group_name')").raises(Fog::Compute::AWS::NotFound) do
|
||||
Fog::Compute[:aws].delete_placement_group('not_a_group_name')
|
||||
end
|
||||
|
||||
unless Fog.mocking?
|
||||
Fog::Compute[:aws].delete_placement_group('fog_placement_group')
|
||||
end
|
||||
|
||||
end
|
||||
end
|
Loading…
Add table
Reference in a new issue