Class: Bosh::Registry::InstanceManager::Openstack
- Inherits:
-
Bosh::Registry::InstanceManager
- Object
- Bosh::Registry::InstanceManager
- Bosh::Registry::InstanceManager::Openstack
- Defined in:
- lib/bosh/registry/instance_manager/openstack.rb
Instance Method Summary collapse
-
#initialize(cloud_config) ⇒ Openstack
constructor
A new instance of Openstack.
-
#instance_ips(instance_id) ⇒ Object
Get the list of IPs belonging to this instance.
- #openstack ⇒ Object
- #validate_options(cloud_config) ⇒ Object
Methods inherited from Bosh::Registry::InstanceManager
#delete_settings, #read_settings, #update_settings
Constructor Details
#initialize(cloud_config) ⇒ Openstack
Returns a new instance of Openstack.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/bosh/registry/instance_manager/openstack.rb', line 9 def initialize(cloud_config) (cloud_config) @logger = Bosh::Registry.logger @openstack_properties = cloud_config['openstack'] unless @openstack_properties['auth_url'].match(/\/tokens$/) if is_v3? @openstack_properties['auth_url'] @openstack_properties['auth_url'] = @openstack_properties['auth_url'] + '/auth/tokens' else @openstack_properties['auth_url'] = @openstack_properties['auth_url'] + '/tokens' end end @openstack_options = { :provider => 'OpenStack', :openstack_auth_url => @openstack_properties['auth_url'], :openstack_username => @openstack_properties['username'], :openstack_api_key => @openstack_properties['api_key'], :openstack_tenant => @openstack_properties['tenant'], :openstack_project_name => @openstack_properties['project'], :openstack_domain_name => @openstack_properties['domain'], :openstack_region => @openstack_properties['region'], :openstack_endpoint_type => @openstack_properties['endpoint_type'], :connection_options => @openstack_properties['connection_options'] } end |
Instance Method Details
#instance_ips(instance_id) ⇒ Object
Get the list of IPs belonging to this instance
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/bosh/registry/instance_manager/openstack.rb', line 64 def instance_ips(instance_id) # If we get an Unauthorized error, it could mean that the OpenStack auth token has expired, so we are # going renew the fog connection one time to make sure that we get a new non-expired token. retried = false begin instance = openstack.servers.find { |s| s.name == instance_id } rescue Excon::Errors::Unauthorized => e unless retried retried = true @openstack = nil retry end raise ConnectionError, "Unable to connect to OpenStack API: #{e.}" end raise InstanceNotFound, "Instance '#{instance_id}' not found" unless instance return (instance.private_ip_addresses + instance.floating_ip_addresses).compact end |
#openstack ⇒ Object
38 39 40 |
# File 'lib/bosh/registry/instance_manager/openstack.rb', line 38 def openstack @openstack ||= Fog::Compute.new(@openstack_options) end |
#validate_options(cloud_config) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/bosh/registry/instance_manager/openstack.rb', line 42 def (cloud_config) unless cloud_config.has_key?('openstack') && cloud_config['openstack'].is_a?(Hash) && cloud_config['openstack']['auth_url'] && cloud_config['openstack']['username'] && cloud_config['openstack']['api_key'] raise ConfigError, 'Invalid OpenStack configuration parameters' end if cloud_config['openstack']['auth_url'].match(/v2(\.\d+)?/) unless cloud_config['openstack']['tenant'] raise ConfigError, 'Invalid OpenStack configuration parameters' end elsif is_v3? cloud_config['openstack']['auth_url'] unless cloud_config['openstack']['domain'] && cloud_config['openstack']['project'] raise ConfigError, 'Invalid OpenStack configuration parameters' end end end |