lib/fog/openstack/compute.rb in fog-1.31.0 vs lib/fog/openstack/compute.rb in fog-1.32.0
- old
+ new
@@ -8,16 +8,19 @@
:persistent, :openstack_service_type, :openstack_service_name,
:openstack_tenant, :openstack_tenant_id,
:openstack_api_key, :openstack_username, :openstack_identity_endpoint,
:current_user, :current_tenant, :openstack_region,
:openstack_endpoint_type,
- :openstack_project_name,
- :openstack_project_domain, :openstack_user_domain
+ :openstack_project_name, :openstack_project_id,
+ :openstack_project_domain, :openstack_user_domain, :openstack_domain_name,
+ :openstack_project_domain_id, :openstack_user_domain_id, :openstack_domain_id
## MODELS
#
model_path 'fog/openstack/models/compute'
+ model :aggregate
+ collection :aggregates
model :server
collection :servers
model :service
collection :services
model :image
@@ -47,10 +50,21 @@
## REQUESTS
#
request_path 'fog/openstack/requests/compute'
+ # Aggregate CRUD
+ request :list_aggregates
+ request :create_aggregate
+ request :update_aggregate
+ request :get_aggregate
+ request :update_aggregate
+ request :update_aggregate_metadata
+ request :add_aggregate_host
+ request :remove_aggregate_host
+ request :delete_aggregate
+
# Server CRUD
request :list_servers
request :list_servers_detail
request :create_server
request :get_server_details
@@ -162,19 +176,22 @@
request :set_tenant
request :get_limits
# Volume
request :list_volumes
+ request :list_volumes_detail
request :create_volume
request :get_volume_details
request :delete_volume
request :attach_volume
request :detach_volume
request :get_server_volumes
+ # Snapshot
request :create_volume_snapshot
request :list_snapshots
+ request :list_snapshots_detail
request :get_snapshot_details
request :delete_snapshot
# Usage
request :list_usages
@@ -206,10 +223,19 @@
:servers => {},
:key_pairs => {},
:security_groups => {},
:addresses => {}
},
+ :aggregates => [{
+ "availability_zone" => "nova",
+ "created_at" => "2012-11-16T06:22:23.032493",
+ "deleted" => false,
+ "deleted_at" => nil,
+ "id" => 1,
+ "name" => "name",
+ "updated_at" => nil
+ }],
:images => {
"0e09fbd6-43c5-448a-83e9-0d3d05f9747e" => {
"id"=>"0e09fbd6-43c5-448a-83e9-0d3d05f9747e",
"name"=>"cirros-0.3.0-x86_64-blank",
'progress' => 100,
@@ -264,22 +290,18 @@
def self.reset
@data = nil
end
- def initialize(options={})
- @openstack_username = options[:openstack_username]
- @openstack_user_domain = options[:openstack_user_domain] || options[:openstack_domain]
- @openstack_project_domain = options[:openstack_project_domain] || options[:openstack_domain] || 'Default'
- @openstack_auth_uri = URI.parse(options[:openstack_auth_url])
+ include Fog::OpenStack::Core
- @current_tenant = options[:openstack_tenant]
- @current_tenant_id = options[:openstack_tenant_id]
-
+ def initialize(options={})
@auth_token = Fog::Mock.random_base64(64)
@auth_token_expiration = (Time.now.utc + 86400).iso8601
+ initialize_identity options
+
management_url = URI.parse(options[:openstack_auth_url])
management_url.port = 8774
management_url.path = '/v1.1/1'
@openstack_management_url = management_url.to_s
@@ -294,82 +316,33 @@
def reset_data
self.class.data.delete("#{@openstack_username}-#{@current_tenant}")
end
- def credentials
- { :provider => 'openstack',
- :openstack_auth_url => @openstack_auth_uri.to_s,
- :openstack_auth_token => @auth_token,
- :openstack_management_url => @openstack_management_url,
- :openstack_identity_endpoint => @openstack_identity_public_endpoint }
- end
end
class Real
- attr_reader :auth_token
- attr_reader :auth_token_expiration
- attr_reader :current_user
- attr_reader :current_tenant
- attr_reader :current_tenant_id
- attr_reader :openstack_user_domain
- attr_reader :openstack_project_domain
+ include Fog::OpenStack::Core
+
def initialize(options={})
- @openstack_auth_token = options[:openstack_auth_token]
- @auth_token = options[:openstack_auth_token]
- @openstack_identity_public_endpoint = options[:openstack_identity_endpoint]
+ initialize_identity options
- unless @auth_token
- missing_credentials = Array.new
- @openstack_api_key = options[:openstack_api_key]
- @openstack_username = options[:openstack_username]
- @openstack_user_domain = options[:openstack_user_domain] || options[:openstack_domain]
- @openstack_project_domain = options[:openstack_project_domain] || options[:openstack_domain] || 'Default'
-
- missing_credentials << :openstack_api_key unless @openstack_api_key
- missing_credentials << :openstack_username unless @openstack_username
- raise ArgumentError, "Missing required arguments: #{missing_credentials.join(', ')}" unless missing_credentials.empty?
- end
-
- @openstack_tenant = options[:openstack_tenant]
- @openstack_tenant_id = options[:openstack_tenant_id]
- @openstack_user_domain = options[:openstack_user_domain] || options[:openstack_domain]
- @openstack_project_domain = options[:openstack_project_domain] || options[:openstack_domain] || 'Default'
- @openstack_auth_uri = URI.parse(options[:openstack_auth_url])
- @openstack_management_url = options[:openstack_management_url]
- @openstack_must_reauthenticate = false
+ @openstack_identity_service_type = options[:openstack_identity_service_type] || 'identity'
@openstack_service_type = options[:openstack_service_type] || ['nova', 'compute']
@openstack_service_name = options[:openstack_service_name]
- @openstack_identity_service_type = options[:openstack_identity_service_type] || 'identity'
- @openstack_endpoint_type = options[:openstack_endpoint_type] || 'publicURL'
- @openstack_region = options[:openstack_region]
@connection_options = options[:connection_options] || {}
- @current_user = options[:current_user]
- @current_tenant = options[:current_tenant]
+ authenticate_compute
- authenticate
-
@persistent = options[:persistent] || false
@connection = Fog::Core::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options)
end
- def credentials
- { :provider => 'openstack',
- :openstack_user_domain => @openstack_user_domain,
- :openstack_project_domain => @openstack_project_domain,
- :openstack_auth_url => @openstack_auth_uri.to_s,
- :openstack_auth_token => @auth_token,
- :openstack_management_url => @openstack_management_url,
- :openstack_identity_endpoint => @openstack_identity_public_endpoint,
- :openstack_region => @openstack_region,
- :current_user => @current_user,
- :current_tenant => @current_tenant }
- end
+
def reload
@connection.reset
end
def request(params)
@@ -384,11 +357,11 @@
:query => params[:query]
}))
rescue Excon::Errors::Unauthorized => error
if error.response.body != 'Bad username or password' # token expiration
@openstack_must_reauthenticate = true
- authenticate
+ authenticate_compute
retry
else # Bad Credentials
raise error
end
rescue Excon::Errors::HTTPStatusError => error
@@ -407,51 +380,21 @@
response
end
private
- def authenticate
- if !@openstack_management_url || @openstack_must_reauthenticate
- options = {
- :openstack_api_key => @openstack_api_key,
- :openstack_username => @openstack_username,
- :openstack_user_domain => @openstack_user_domain,
- :openstack_project_domain => @openstack_project_domain,
- :openstack_auth_token => @openstack_must_reauthenticate ? nil : @auth_token,
- :openstack_auth_uri => @openstack_auth_uri,
- :openstack_region => @openstack_region,
- :openstack_tenant => @openstack_tenant,
- :openstack_tenant_id => @openstack_tenant_id,
- :openstack_service_type => @openstack_service_type,
- :openstack_service_name => @openstack_service_name,
- :openstack_identity_service_type => @openstack_identity_service_type,
- :openstack_endpoint_type => @openstack_endpoint_type
- }
+ def authenticate_compute
+ authenticate
- credentials = Fog::OpenStack.authenticate(options, @connection_options)
-
- @current_user = credentials[:user]
- @current_tenant = credentials[:tenant]
-
- @openstack_must_reauthenticate = false
- @auth_token = credentials[:token]
- @auth_token_expiration = credentials[:expires]
- @openstack_management_url = credentials[:server_management_url]
- @openstack_identity_public_endpoint = credentials[:identity_public_endpoint]
- end
-
uri = URI.parse(@openstack_management_url)
@host = uri.host
@path = uri.path
@path.sub!(/\/$/, '')
unless @path.match(/1\.1|v2/)
raise Fog::OpenStack::Errors::ServiceUnavailable.new(
"OpenStack compute binding only supports version 2 (a.k.a. 1.1)")
end
-
- @port = uri.port
- @scheme = uri.scheme
# Not all implementations have identity service in the catalog
if @openstack_identity_public_endpoint || @openstack_management_url
@identity_connection = Fog::Core::Connection.new(
@openstack_identity_public_endpoint || @openstack_management_url,