Class: Cyoi::Cli::KeyPair
- Inherits:
-
Object
- Object
- Cyoi::Cli::KeyPair
- Includes:
- Helpers
- Defined in:
- lib/cyoi/cli/key_pair.rb,
lib/cyoi/cli/provider_key_pair/key_pair_aws.rb,
lib/cyoi/cli/provider_key_pair/key_pair_vsphere.rb,
lib/cyoi/cli/provider_key_pair/key_pair_openstack.rb
Defined Under Namespace
Classes: KeyPairCliAws, KeyPairCliOpenstack, KeyPairCliVsphere
Instance Attribute Summary collapse
-
#key_pair_name ⇒ Object
readonly
Returns the value of attribute key_pair_name.
Class Method Summary collapse
Instance Method Summary collapse
-
#execute! ⇒ Object
TODO run Cyoi::Cli::Provider first if settings.provider.name missing.
-
#initialize(argv, stdin = STDIN, stdout = STDOUT, stderr = STDERR, kernel = Kernel) ⇒ KeyPair
constructor
A new instance of KeyPair.
-
#key_pair_cli ⇒ Object
Continue the interactive session with the user specific to the key_pair/infrastructure they have chosen.
Methods included from Helpers::Settings
#migrate_old_settings, #reload_settings!, #save_settings!, #settings, #settings_dir, #settings_path, #settings_ssh_dir, #show_settings
Methods included from Helpers::Provider
#fog_compute, #provider_client
Methods included from Helpers::Interactions
#bold, #clear, #cyan, #green, #hl, #red, #yellow
Constructor Details
#initialize(argv, stdin = STDIN, stdout = STDOUT, stderr = STDERR, kernel = Kernel) ⇒ KeyPair
Returns a new instance of KeyPair.
9 10 11 12 13 14 15 16 |
# File 'lib/cyoi/cli/key_pair.rb', line 9 def initialize(argv, stdin=STDIN, stdout=STDOUT, stderr=STDERR, kernel=Kernel) @argv, @stdin, @stdout, @stderr, @kernel = argv, stdin, stdout, stderr, kernel unless @key_pair_name = @argv.shift raise "Please provide key pair name as first argument" end @settings_dir = @argv.shift || "/tmp/provider_settings" @settings_dir = File.(@settings_dir) end |
Instance Attribute Details
#key_pair_name ⇒ Object (readonly)
Returns the value of attribute key_pair_name.
7 8 9 |
# File 'lib/cyoi/cli/key_pair.rb', line 7 def key_pair_name @key_pair_name end |
Class Method Details
.key_pair_cli(name) ⇒ Object
58 59 60 |
# File 'lib/cyoi/cli/key_pair.rb', line 58 def self.key_pair_cli(name) @key_pair_clis[name] end |
.register_key_pair_cli(name, klass) ⇒ Object
53 54 55 56 |
# File 'lib/cyoi/cli/key_pair.rb', line 53 def self.register_key_pair_cli(name, klass) @key_pair_clis ||= {} @key_pair_clis[name] = klass end |
Instance Method Details
#execute! ⇒ Object
TODO run Cyoi::Cli::Provider first if settings.provider.name missing
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/cyoi/cli/key_pair.rb', line 19 def execute! unless settings.exists?("provider.name") $stderr.puts("Please run 'cyoi provider' first") exit 1 end unless valid? settings["key_pair"] = key_pair_cli.perform_and_return_attributes end save_settings! key_pair_cli.display_confirmation end |
#key_pair_cli ⇒ Object
Continue the interactive session with the user specific to the key_pair/infrastructure they have chosen.
The returned object is a class from cyoi/cli/key_pairs/provier_cli_NAME.rb The class loads itself into ‘@key_pair_clis` via `register_key_pair_cli`
Returns nil if settings.key_pair.name not set
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/cyoi/cli/key_pair.rb', line 39 def key_pair_cli @key_pair_cli ||= begin provider_name = settings.exists?("provider.name") return nil unless provider_name require "cyoi/cli/provider_key_pair/key_pair_#{settings.provider.name}" settings["key_pair"] ||= {} settings.key_pair["name"] = key_pair_name klass = self.class.key_pair_cli(settings.provider.name) klass.new(provider_client, settings.key_pair, hl) end end |