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

Merge pull request #2631 from radekg/master

[openstack] Add more observable states for openstack models.
This commit is contained in:
Wesley Beary 2014-02-18 10:55:32 -06:00
commit 43fd1a9092
7 changed files with 63 additions and 4 deletions

View file

@ -163,6 +163,7 @@ module Fog
class Mock
include Fog::AWS::CredentialFetcher::ConnectionMethods
include Fog::AWS::RegionMethods
def self.data
@data ||= Hash.new do |hash, region|
@ -278,10 +279,7 @@ module Fog
@aws_credentials_expire_at = Time::now + 20
setup_credentials(options)
@region = options[:region] || 'us-east-1'
unless ['ap-northeast-1', 'ap-southeast-1', 'ap-southeast-2', 'eu-west-1', 'us-east-1', 'us-west-1', 'us-west-2', 'sa-east-1'].include?(@region)
raise ArgumentError, "Unknown region: #{@region.inspect}"
end
validate_aws_region @region
end
def region_data
@ -351,6 +349,7 @@ module Fog
class Real
include Fog::AWS::CredentialFetcher::ConnectionMethods
include Fog::AWS::RegionMethods
# Initialize connection to EC2
#
# ==== Notes
@ -385,6 +384,8 @@ module Fog
@instrumentor_name = options[:instrumentor_name] || 'fog.aws.compute'
@version = options[:version] || '2013-10-01'
validate_aws_region @region
if @endpoint = options[:endpoint]
endpoint = URI.parse(@endpoint)
@host = endpoint.host

View file

@ -1,5 +1,6 @@
require 'fog/core'
require 'fog/aws/credential_fetcher'
require 'fog/aws/region_methods'
require 'fog/aws/signaturev4'
module Fog

View file

@ -0,0 +1,13 @@
module Fog
module AWS
module RegionMethods
def validate_aws_region region
unless ['ap-northeast-1', 'ap-southeast-1', 'ap-southeast-2', 'eu-west-1', 'us-east-1', 'us-west-1', 'us-west-2', 'sa-east-1'].include?(region)
raise ArgumentError, "Unknown region: #{region.inspect}"
end
end
end
end
end

View file

@ -157,6 +157,10 @@ module Fog
self.state == 'ACTIVE'
end
def failed?
self.state == 'ERROR'
end
def change_password(admin_password)
requires :id
service.change_server_password(id, admin_password)

View file

@ -51,6 +51,11 @@ module Fog
service.detach_volume(server_id, attachment_id)
true
end
def ready?
self.status == "available"
end
end
end

View file

@ -18,6 +18,17 @@ Shindo.tests('Fog::Compute[:aws] | region requests', ['aws']) do
Fog::Compute[:aws].describe_regions('region-name' => 'us-east-1').body
end
tests("#incorrect_region") do
raises(ArgumentError, "Unknown region: world-antarctica-1") do
Fog::Compute::AWS.new({:aws_access_key_id => 'dummykey',
:aws_secret_access_key => 'dummysecret',
:aws_session_token => 'dummytoken',
:region => "world-antarctica-1"})
end
end
end
end

View file

@ -41,6 +41,30 @@ Shindo.tests("Fog::Compute[:openstack] | server", ['openstack']) do
end
end
tests('#failed') do
fog = Fog::Compute[:openstack]
flavor = fog.flavors.first.id
image = fog.images.first.id
tests('successful server').returns(false) do
server = fog.servers.new( :name => 'test server',
:flavor_ref => flavor,
:image_ref => image,
:state => 'success' )
server.failed?
end
tests('failed server').returns(true) do
server = fog.servers.new( :name => 'test server',
:flavor_ref => flavor,
:image_ref => image,
:state => 'ERROR' )
server.failed?
end
end
tests('#metadata').succeeds do
fog = Fog::Compute[:openstack]