Class: Bosh::Providers::Cli::OpenStackProviderCli

Inherits:
ProviderCli
  • Object
show all
Defined in:
lib/bosh/providers/cli/openstack_provider_cli.rb

Overview

Interactively prompt user for region & credential information for OpenStack

Primary use within inception is to pass settings.provider hash run #perform to gather credentials, then export the credentials/attributes.

settings["provider"] = {}
provider = OpenStackProviderCli.new(settings.provider)
provider_client.perform
settings.provider = provider_cli.export_attributes

Instance Attribute Summary

Attributes inherited from ProviderCli

#attributes, #provider_client

Instance Method Summary collapse

Methods inherited from ProviderCli

#initialize

Methods included from Inception::CliHelpers::Interactions

#bold, #clear, #cyan, #green, #hl, #red, #yellow

Constructor Details

This class inherits a constructor from Bosh::Providers::Cli::ProviderCli

Instance Method Details

#choose_regionObject



30
31
32
33
34
# File 'lib/bosh/providers/cli/openstack_provider_cli.rb', line 30

def choose_region
  attributes.region = hl.ask("OpenStack Region (optional): ") do |q|
    q.default = openstack_constants.no_region_code
  end
end

#export_attributesObject

helper to export the complete nested attributes as a pure Hash



26
27
28
# File 'lib/bosh/providers/cli/openstack_provider_cli.rb', line 26

def export_attributes
  attributes.to_nested_hash
end

#openstack_constantsObject



44
45
46
# File 'lib/bosh/providers/cli/openstack_provider_cli.rb', line 44

def openstack_constants
  Bosh::Providers::Constants::OpenStackConstants
end

#performObject



19
20
21
22
23
# File 'lib/bosh/providers/cli/openstack_provider_cli.rb', line 19

def perform
  attributes.set("name", "openstack") # ensure this property is correct
  choose_region unless attributes.exists?("region")
  setup_credentials unless attributes.exists?("credentials.openstack_api_key")
end

#setup_credentialsObject



36
37
38
39
40
41
42
# File 'lib/bosh/providers/cli/openstack_provider_cli.rb', line 36

def setup_credentials
  attributes.set_default("credentials", {})
  attributes.credentials["openstack_username"] = hl.ask("Username: ")
  attributes.credentials["openstack_api_key"] = hl.ask("Password: ")
  attributes.credentials["openstack_tenant"] = hl.ask("Tenant: ")
  attributes.credentials["openstack_auth_url"] = hl.ask("Authorization Token URL: ")
end