Method: OpenStack::Connection.create
- Defined in:
- lib/openstack/connection.rb
.create(options = {:retry_auth => true}) ⇒ Object
Creates and returns a new Connection object, depending on the service_type passed in the options:
e.g: os = OpenStack::Connection.create({:username => “[email protected]”, :api_key=>“password”,
:auth_url => "https://region-a.geo-1.identity.cloudsvc.com:35357/v2.0/",
:authtenant=>"[email protected]", :service_type=>"object-store")
Will return an OpenStack::Swift::Connection object.
options hash:
:username - Your OpenStack username or public key, depending on auth_method. *required*
:auth_method - Type of authentication - 'password', 'key', 'rax-kskey', 'token' - defaults to 'password'.
For auth v3.0 valid options are 'password', 'token', 'password_user_id'
:authtenant_name OR :authtenant_id - Your OpenStack tenant name or id *required*. Defaults to username.
passing :authtenant will default to using that parameter as tenant name.
:api_key - Your OpenStack API key *required* (either private key or password, depending on auth_method)
:auth_url - Configurable auth_url endpoint.
:service_name - (Optional for v2.0 auth only). The optional name of the compute service to use.
:service_type - (Optional for v2.0 auth only). Defaults to "compute"
:user_domain - (Optional for v3.0 auth only). The optional name of the user domain.
:user_domain_id - (Optional for v3.0 auth only). Defaults to "default"
:project_id - (Optional for v3.0 auth only). For authorization scoping
:project_name - (Optional for v3.0 auth only). For authorization scoping
:project_domain_name - (Optional for v3.0 auth only). For authorization scoping
:project_domain_id - (Optional for v3.0 auth only). For authorization scoping
:domain_name - (Optional for v3.0 auth only). For authorization scoping
:domain_id - (Optional for v3.0 auth only). For authorization scoping
:region - (Optional for v2.0 auth only). The specific service region to use. Defaults to first returned region.
:retry_auth - Whether to retry if your auth token expires (defaults to true)
:proxy_host - If you need to connect through a proxy, supply the hostname here
:proxy_port - If you need to connect through a proxy, supply the port here
:ca_cert - path to a CA chain in PEM format
:ssl_version - explicitly set an version (:SSLv3 etc, see OpenSSL::SSL::SSLContext::METHODS)
:is_debug - Only for development purpose for debug output
:endpoint_type - Type of endpoint. Optional. 'publicURL', 'internalURL', 'adminURL'
The options hash is used to create a new OpenStack::Connection object (private constructor) and this is passed to the constructor of OpenStack::Compute::Connection or OpenStack::Swift::Connection (depending on :service_type) where authentication is done using OpenStack::Authentication.
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/openstack/connection.rb', line 87 def self.create( = {:retry_auth => true}) #call private constructor and grab instance vars connection = new() case connection.service_type when "compute" OpenStack::Compute::Connection.new(connection) when "object-store" OpenStack::Swift::Connection.new(connection) when "volume" OpenStack::Volume::Connection.new(connection) when "image" OpenStack::Image::Connection.new(connection) when "network" OpenStack::Network::Connection.new(connection) when "metering" OpenStack::Metering::Connection.new(connection) when "identity" OpenStack::Identity::Connection.new(connection) else raise Exception::InvalidArgument, "Invalid :service_type parameter: #{@service_type}" end end |