Class: OpenStackRouter::Region
- Inherits:
-
Object
- Object
- OpenStackRouter::Region
- Defined in:
- lib/openstack-router/region.rb
Overview
The class abstracting a region. It aims to centralize a region state/status regarding VM spwning capacity and connectivity.
Constant Summary collapse
- STATES =
The possible states of a Region
[ # connected and fully operational STATE_OPERATING = :operating, # connected but some limits has been reached STATE_LIMITED = :limited, # some connection problems occured STATE_FAILED = :failed ].freeze
Instance Attribute Summary collapse
-
#connection_parameters ⇒ Parameter::Connection
readonly
The parameters to connect to OpenStack services.
-
#name ⇒ String
readonly
The region name.
-
#state ⇒ Symbol
readonly
The region's state.
Instance Method Summary collapse
-
#initialize(name, connection_parameters) ⇒ Region
constructor
A new instance of Region.
- #my_args(request_args, region_names) ⇒ Object
-
#request(service, request_name, *args) {|answer| ... } ⇒ NilClass | 'a | Excon::Response
This method allow to call a request on a service for this region.
Constructor Details
#initialize(name, connection_parameters) ⇒ Region
Returns a new instance of Region
27 28 29 30 31 32 33 |
# File 'lib/openstack-router/region.rb', line 27 def initialize(name, connection_parameters) @name = name @connection_parameters = Parameter::Connection.new(connection_parameters.to_h.merge(region: name)) @services = {} @state = STATE_OPERATING end |
Instance Attribute Details
#connection_parameters ⇒ Parameter::Connection (readonly)
The parameters to connect to OpenStack services.
13 14 15 |
# File 'lib/openstack-router/region.rb', line 13 def connection_parameters @connection_parameters end |
#name ⇒ String (readonly)
The region name.
13 14 15 |
# File 'lib/openstack-router/region.rb', line 13 def name @name end |
#state ⇒ Symbol (readonly)
The region's state. @see STATES descriptions
13 14 15 |
# File 'lib/openstack-router/region.rb', line 13 def state @state end |
Instance Method Details
#my_args(request_args, region_names) ⇒ Object
64 65 66 67 68 69 70 |
# File 'lib/openstack-router/region.rb', line 64 def my_args(request_args, region_names) request_args.map do |arg| next arg unless arg.class == Hash && arg.keys == region_names arg[@name] end end |
#request(service, request_name, *args) {|answer| ... } ⇒ NilClass | 'a | Excon::Response
This method allow to call a request on a service for this region. If the service hasn't been already connected it will be connected.
57 58 59 60 61 62 |
# File 'lib/openstack-router/region.rb', line 57 def request(service, request_name, *args, &block) service = service.to_s.capitalize return nil if @state == STATE_FAILED && setup(service) == STATE_FAILED do_request(service, request_name, *args, &block) end |