mirror of
https://github.com/fog/fog-aws.git
synced 2022-11-09 13:50:52 -05:00
Merge pull request #433 from fog/lanej/fog-dep-pins
fog-core 2.x, fog-json 1.x
This commit is contained in:
commit
e8856b7588
8 changed files with 79 additions and 74 deletions
|
@ -23,11 +23,11 @@ Gem::Specification.new do |spec|
|
|||
|
||||
spec.add_development_dependency 'bundler', '~> 1.15'
|
||||
spec.add_development_dependency 'rake', '~> 10.0'
|
||||
spec.add_development_dependency 'shindo', '~> 0.3'
|
||||
spec.add_development_dependency 'rubyzip', '~> 1.2.1'
|
||||
spec.add_development_dependency 'shindo', '~> 0.3'
|
||||
|
||||
spec.add_dependency 'fog-core', '~> 1.38'
|
||||
spec.add_dependency 'fog-json', '~> 1.0'
|
||||
spec.add_dependency 'fog-core', '~> 2.1'
|
||||
spec.add_dependency 'fog-json', '~> 1.1'
|
||||
spec.add_dependency 'fog-xml', '~> 0.1'
|
||||
spec.add_dependency 'ipaddress', '~> 0.8'
|
||||
end
|
||||
|
|
|
@ -59,25 +59,19 @@ module Fog
|
|||
requires :availability_zone
|
||||
requires_one :size, :snapshot_id
|
||||
|
||||
if type == 'io1'
|
||||
requires :iops
|
||||
end
|
||||
requires :iops if type == 'io1'
|
||||
|
||||
data = service.create_volume(availability_zone, size, create_params).body
|
||||
merge_attributes(data)
|
||||
|
||||
if tags = self.tags
|
||||
# expect eventual consistency
|
||||
Fog.wait_for { self.reload rescue nil }
|
||||
service.create_tags(
|
||||
self.identity,
|
||||
tags
|
||||
)
|
||||
Fog.wait_for { service.volumes.get(identity) }
|
||||
service.create_tags(identity, tags)
|
||||
end
|
||||
|
||||
if @server
|
||||
self.server = @server
|
||||
end
|
||||
attach(@service, device) if @server
|
||||
|
||||
true
|
||||
end
|
||||
end
|
||||
|
@ -87,13 +81,7 @@ module Fog
|
|||
service.servers.get(server_id)
|
||||
end
|
||||
|
||||
def server=(new_server)
|
||||
if new_server
|
||||
attach(new_server)
|
||||
else
|
||||
detach
|
||||
end
|
||||
end
|
||||
attr_writer :server
|
||||
|
||||
def snapshots
|
||||
requires :id
|
||||
|
@ -109,22 +97,15 @@ module Fog
|
|||
detach(true)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def attachmentSet=(new_attachment_set)
|
||||
merge_attributes(new_attachment_set.first || {})
|
||||
end
|
||||
|
||||
def attach(new_server)
|
||||
def attach(new_server, new_device)
|
||||
if !persisted?
|
||||
@server = new_server
|
||||
self.availability_zone = new_server.availability_zone
|
||||
elsif new_server
|
||||
requires :device
|
||||
wait_for { ready? }
|
||||
@server = nil
|
||||
self.server_id = new_server.id
|
||||
service.attach_volume(server_id, id, device)
|
||||
service.attach_volume(server_id, id, new_device)
|
||||
reload
|
||||
end
|
||||
end
|
||||
|
@ -138,6 +119,12 @@ module Fog
|
|||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def attachmentSet=(new_attachment_set)
|
||||
merge_attributes(new_attachment_set.first || {})
|
||||
end
|
||||
|
||||
def create_params
|
||||
{
|
||||
'Encrypted' => encrypted,
|
||||
|
|
|
@ -12,7 +12,7 @@ module Fog
|
|||
end
|
||||
|
||||
def get(instance_port)
|
||||
all.find{|e| e.instance_port == instance_port}
|
||||
all.find { |e| e.instance_port == instance_port }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -12,17 +12,16 @@ module Fog
|
|||
end
|
||||
|
||||
def get(lb_port)
|
||||
all.find{|listener| listener.lb_port == lb_port}
|
||||
all.find { |listener| listener.lb_port == lb_port }
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Munge an array of ListenerDescription hashes like:
|
||||
# {'Listener' => listener, 'PolicyNames' => []}
|
||||
# to an array of listeners with a PolicyNames key
|
||||
def munged_data
|
||||
data.map {|description|
|
||||
description['Listener'].merge('PolicyNames' => description['PolicyNames'])
|
||||
}
|
||||
data.map { |description| description['Listener'].merge('PolicyNames' => description['PolicyNames']) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -223,16 +223,24 @@ module Fog
|
|||
end
|
||||
|
||||
def reload
|
||||
super
|
||||
@instance_health = nil
|
||||
@policy_descriptions = nil
|
||||
self
|
||||
super
|
||||
end
|
||||
|
||||
def destroy
|
||||
requires :id
|
||||
service.delete_load_balancer(id)
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def all_associations_and_attributes
|
||||
super.merge(
|
||||
'ListenerDescriptions' => attributes['ListenerDescriptions'],
|
||||
'BackendServerDescriptions' => attributes['BackendServerDescriptions'],
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -6,7 +6,7 @@ module Fog
|
|||
model Fog::AWS::ELB::LoadBalancer
|
||||
|
||||
# Creates a new load balancer
|
||||
def initialize(attributes={})
|
||||
def initialize(attributes = {})
|
||||
super
|
||||
end
|
||||
|
||||
|
@ -14,7 +14,7 @@ module Fog
|
|||
result = []
|
||||
marker = nil
|
||||
finished = false
|
||||
while !finished
|
||||
until finished
|
||||
data = service.describe_load_balancers('Marker' => marker).body
|
||||
result.concat(data['DescribeLoadBalancersResult']['LoadBalancerDescriptions'])
|
||||
marker = data['DescribeLoadBalancersResult']['NextMarker']
|
||||
|
@ -24,10 +24,9 @@ module Fog
|
|||
end
|
||||
|
||||
def get(identity)
|
||||
if identity
|
||||
data = service.describe_load_balancers('LoadBalancerNames' => identity).body['DescribeLoadBalancersResult']['LoadBalancerDescriptions'].first
|
||||
new(data)
|
||||
end
|
||||
return unless identity
|
||||
data = service.describe_load_balancers('LoadBalancerNames' => identity).body['DescribeLoadBalancersResult']['LoadBalancerDescriptions'].first
|
||||
new(data)
|
||||
rescue Fog::AWS::ELB::NotFound
|
||||
nil
|
||||
end
|
||||
|
|
|
@ -51,34 +51,37 @@ module Fog
|
|||
|
||||
class Mock
|
||||
def create_load_balancer_listeners(lb_name, listeners)
|
||||
if load_balancer = self.data[:load_balancers][lb_name]
|
||||
response = Excon::Response.new
|
||||
load_balancer = data[:load_balancers][lb_name]
|
||||
raise Fog::AWS::ELB::NotFound unless load_balancer
|
||||
response = Excon::Response.new
|
||||
|
||||
certificate_ids = Fog::AWS::IAM::Mock.data[@aws_access_key_id][:server_certificates].map {|n, c| c['Arn'] }
|
||||
certificate_ids = Fog::AWS::IAM::Mock.data[@aws_access_key_id][:server_certificates].map { |_n, c| c['Arn'] }
|
||||
|
||||
listeners.each do |listener|
|
||||
if listener['SSLCertificateId'] and !certificate_ids.include? listener['SSLCertificateId']
|
||||
raise Fog::AWS::IAM::NotFound.new('CertificateNotFound')
|
||||
end
|
||||
|
||||
if (%w( HTTP HTTPS).include?(listener['Protocol']) && !%w( HTTP HTTPS ).include?(listener['InstanceProtocol'])) ||
|
||||
(%w( TCP SSL).include?(listener['Protocol']) && !%w( TCP SSL ).include?(listener['InstanceProtocol']))
|
||||
raise Fog::AWS::ELB::ValidationError
|
||||
end if listener['Protocol'] && listener['InstanceProtocol']
|
||||
load_balancer['ListenerDescriptions'] << {'Listener' => listener, 'PolicyNames' => []}
|
||||
listeners.each do |listener|
|
||||
if listener['SSLCertificateId'] && !certificate_ids.include?(listener['SSLCertificateId'])
|
||||
raise Fog::AWS::IAM::NotFound, 'CertificateNotFound'
|
||||
end
|
||||
|
||||
response.status = 200
|
||||
response.body = {
|
||||
'ResponseMetadata' => {
|
||||
'RequestId' => Fog::AWS::Mock.request_id
|
||||
}
|
||||
}
|
||||
|
||||
response
|
||||
else
|
||||
raise Fog::AWS::ELB::NotFound
|
||||
if listener['Protocol'] && listener['InstanceProtocol']
|
||||
if (
|
||||
%w[HTTP HTTPS].include?(listener['Protocol']) && !%w[HTTP HTTPS].include?(listener['InstanceProtocol'])
|
||||
) || (
|
||||
%w[TCP SSL].include?(listener['Protocol']) && !%w[TCP SSL].include?(listener['InstanceProtocol'])
|
||||
)
|
||||
raise Fog::AWS::ELB::ValidationError
|
||||
end
|
||||
end
|
||||
load_balancer['ListenerDescriptions'] << { 'Listener' => listener, 'PolicyNames' => [] }
|
||||
end
|
||||
|
||||
response.status = 200
|
||||
response.body = {
|
||||
'ResponseMetadata' => {
|
||||
'RequestId' => Fog::AWS::Mock.request_id
|
||||
}
|
||||
}
|
||||
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,14 +1,22 @@
|
|||
Shindo.tests("Fog::Compute[:aws] | volume", ['aws']) do
|
||||
|
||||
Shindo.tests('Fog::Compute[:aws] | volume', ['aws']) do
|
||||
@server = Fog::Compute[:aws].servers.create
|
||||
@server.wait_for { ready? }
|
||||
|
||||
model_tests(Fog::Compute[:aws].volumes, {:availability_zone => @server.availability_zone, :size => 1, :device => '/dev/sdz1', :tags => {"key" => "value"}, :type => 'gp2'}, true) do
|
||||
model_tests(
|
||||
Fog::Compute[:aws].volumes,
|
||||
{
|
||||
availability_zone: @server.availability_zone,
|
||||
size: 1,
|
||||
tags: { 'key' => 'value' },
|
||||
type: 'gp2'
|
||||
},
|
||||
true
|
||||
) do
|
||||
|
||||
@instance.wait_for { ready? }
|
||||
|
||||
tests('#server = @server').succeeds do
|
||||
@instance.server = @server
|
||||
tests('#attach(server, device)').succeeds do
|
||||
@instance.attach(@server, '/dev/sdz1')
|
||||
end
|
||||
|
||||
@instance.wait_for { state == 'in-use' }
|
||||
|
@ -17,13 +25,14 @@ Shindo.tests("Fog::Compute[:aws] | volume", ['aws']) do
|
|||
@instance.server.id == @server.id
|
||||
end
|
||||
|
||||
tests('#server = nil').succeeds do
|
||||
(@instance.server = nil).nil?
|
||||
tests('#detach').succeeds do
|
||||
@instance.detach
|
||||
@instance.server.nil?
|
||||
end
|
||||
|
||||
@instance.wait_for { ready? }
|
||||
|
||||
@instance.server = @server
|
||||
@instance.attach(@server, '/dev/sdz1')
|
||||
@instance.wait_for { state == 'in-use' }
|
||||
|
||||
tests('#force_detach').succeeds do
|
||||
|
|
Loading…
Reference in a new issue