Class: Cyoi::Cli::Providers::ProviderCliOpenStack
- Inherits:
-
ProviderCli
- Object
- ProviderCli
- Cyoi::Cli::Providers::ProviderCliOpenStack
show all
- Defined in:
- lib/cyoi/cli/providers/provider_cli_openstack.rb
Instance Attribute Summary
Attributes inherited from ProviderCli
#attributes, #hl
Instance Method Summary
collapse
Methods inherited from ProviderCli
#export_attributes, #initialize, #say
Instance Method Details
#display_confirmation ⇒ Object
50
51
52
53
54
55
56
57
58
|
# File 'lib/cyoi/cli/providers/provider_cli_openstack.rb', line 50
def display_confirmation
puts "\n"
region = attributes.credentials["openstack_region"]
if region.size > 0
puts "Confirming: Using OpenStack/#{region} (user: #{attributes.credentials.openstack_username})"
else
puts "Confirming: Using OpenStack (user: #{attributes.credentials.openstack_username})"
end
end
|
3
4
5
6
7
8
9
10
|
# File 'lib/cyoi/cli/providers/provider_cli_openstack.rb', line 3
def perform_and_return_attributes
unless valid_infrastructure?
puts "\nUsing provider OpenStack\n"
setup_credentials
setup_options
end
export_attributes
end
|
#setup_credentials ⇒ Object
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/cyoi/cli/providers/provider_cli_openstack.rb', line 12
def setup_credentials
attributes.set_default("credentials", {})
credentials = attributes.credentials
credentials["openstack_username"] = hl.ask("Username: ").to_s unless credentials.exists?("openstack_username")
credentials["openstack_api_key"] = hl.ask("Password: ").to_s unless credentials.exists?("openstack_api_key")
credentials["openstack_tenant"] = hl.ask("Tenant: ").to_s unless credentials.exists?("openstack_tenant")
credentials["openstack_auth_url"] = hl.ask("Authorization Token URL: ").to_s unless credentials.exists?("openstack_auth_url")
credentials["openstack_auth_url"] = credentials["openstack_auth_url"] + "/tokens" unless credentials["openstack_auth_url"].match(/\/tokens$/)
unless credentials.has_key?("openstack_region")
credentials["openstack_region"] = hl.ask("OpenStack Region (optional): ").to_s.strip
end
attributes["credentials"] = credentials end
|
#setup_options ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/cyoi/cli/providers/provider_cli_openstack.rb', line 26
def setup_options
attributes.set_default("options", {})
options = attributes.options
puts ""
unless options.has_key?("boot_from_volume")
image_type = hl.choose do ||
.prompt = "Image format to be used: "
.choice("QCOW2*") { "qcow2" }
.choice("RAW") { "raw" }
.default ="QCOW2*"
end
options["boot_from_volume"] = (image_type && image_type.to_s == "raw")
end
end
|
#valid_infrastructure? ⇒ Boolean
42
43
44
45
46
47
48
|
# File 'lib/cyoi/cli/providers/provider_cli_openstack.rb', line 42
def valid_infrastructure?
attributes.exists?("region") &&
attributes.exists?("credentials.openstack_username") &&
attributes.exists?("credentials.openstack_api_key") &&
attributes.exists?("credentials.openstack_tenant") &&
attributes.exists?("credentials.openstack_auth_url")
end
|