Class: OpenStackRouter::Parameter::Connection
- Inherits:
-
Object
- Object
- OpenStackRouter::Parameter::Connection
- Defined in:
- lib/openstack-router/parameter/connection.rb
Overview
This class is used to parameter the connection to OpenStack instance and services. Its purpose is to encapsulate the connection parameters.
Constant Summary collapse
- MANDATORY_OPTIONS =
The mandatory options needed to be pass in argument at initialization of that class.
%i[auth_url username api_key tenant project_id].freeze
- OTHER_OPTIONS =
The options that are not mandatory for this object.
%i[region].freeze
- ALL_OPTIONS =
Constant containing all the available options.
(MANDATORY_OPTIONS + OTHER_OPTIONS).freeze
Instance Attribute Summary collapse
-
#api_key ⇒ String
readonly
The api key that you have been given to connect to the OpenStack services.
-
#auth_url ⇒ String
readonly
The OpenStack url of the auth system.
-
#project_id ⇒ String
readonly
The Project ID that you want to limit your actions on the OpenStack services.
-
#region ⇒ String | NilClass
readonly
The region on which to connect.
-
#tenant ⇒ String
readonly
The tenant that you have been given to connect to the OpenStack services.
-
#username ⇒ String
readonly
The username to use to connect to OpenStack.
Instance Method Summary collapse
-
#initialize(options) ⇒ Connection
constructor
A new instance of Connection.
-
#present?(key) ⇒ Boolean
checks if an option is present.
-
#to_h ⇒ Object
convert the connection parameters to hash.
-
#to_os_h ⇒ Object
get the corresponding connection parameter hash with openstack_ prefix.
-
#to_s ⇒ Object
convert to string the options (first convert to Hash, then the Hash to String).
Constructor Details
#initialize(options) ⇒ Connection
Returns a new instance of Connection.
34 35 36 37 |
# File 'lib/openstack-router/parameter/connection.rb', line 34 def initialize() () () end |
Instance Attribute Details
#api_key ⇒ String
The api key that you have been given to connect to the OpenStack services
19 20 21 |
# File 'lib/openstack-router/parameter/connection.rb', line 19 def api_key @api_key end |
#auth_url ⇒ String
The OpenStack url of the auth system
19 20 21 |
# File 'lib/openstack-router/parameter/connection.rb', line 19 def auth_url @auth_url end |
#project_id ⇒ String
The Project ID that you want to limit your actions on the OpenStack services
19 20 21 |
# File 'lib/openstack-router/parameter/connection.rb', line 19 def project_id @project_id end |
#region ⇒ String | NilClass
The region on which to connect.
19 20 21 |
# File 'lib/openstack-router/parameter/connection.rb', line 19 def region @region end |
#tenant ⇒ String
The tenant that you have been given to connect to the OpenStack services
19 20 21 |
# File 'lib/openstack-router/parameter/connection.rb', line 19 def tenant @tenant end |
#username ⇒ String
The username to use to connect to OpenStack
19 20 21 |
# File 'lib/openstack-router/parameter/connection.rb', line 19 def username @username end |
Instance Method Details
#present?(key) ⇒ Boolean
checks if an option is present. This method prevent testing nil? over the attribute.
59 60 61 62 63 |
# File 'lib/openstack-router/parameter/connection.rb', line 59 def present?(key) raise ArgumentError, "unavailable option: #{key}" unless ALL_OPTIONS.include?(key) instance_variable_defined?("@#{key}".to_sym) end |
#to_h ⇒ Object
convert the connection parameters to hash
45 46 47 |
# File 'lib/openstack-router/parameter/connection.rb', line 45 def to_h ALL_OPTIONS.map { |key| [key, send(key)] }.to_h end |
#to_os_h ⇒ Object
get the corresponding connection parameter hash with openstack_ prefix.
40 41 42 |
# File 'lib/openstack-router/parameter/connection.rb', line 40 def to_os_h to_h.map { |key, value| ["openstack_#{key}", value] }.to_h end |
#to_s ⇒ Object
convert to string the options (first convert to Hash, then the Hash to String)
50 51 52 |
# File 'lib/openstack-router/parameter/connection.rb', line 50 def to_s to_h.to_s end |