Class: Cyoi::Cli::Blobstore

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/cyoi/cli/blobstore.rb,
lib/cyoi/cli/provider_blobstore/blobstore_cli_base.rb

Defined Under Namespace

Classes: BlobstoreCliAws, BlobstoreCliBase, BlobstoreCliOpenStack

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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) ⇒ Blobstore

Returns a new instance of Blobstore.



9
10
11
12
13
14
15
16
# File 'lib/cyoi/cli/blobstore.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 @blobstore_name = @argv.shift
    raise "Please provide blobstore name as first argument"
  end
  @settings_dir = @argv.shift || "/tmp/provider_settings"
  @settings_dir = File.expand_path(@settings_dir)
end

Instance Attribute Details

#blobstore_nameObject (readonly)

Returns the value of attribute blobstore_name.



7
8
9
# File 'lib/cyoi/cli/blobstore.rb', line 7

def blobstore_name
  @blobstore_name
end

Class Method Details

.blobstore_cli(name) ⇒ Object



61
62
63
# File 'lib/cyoi/cli/blobstore.rb', line 61

def self.blobstore_cli(name)
  @blobstore_clis[name]
end

.register_cli(name, klass) ⇒ Object



56
57
58
59
# File 'lib/cyoi/cli/blobstore.rb', line 56

def self.register_cli(name, klass)
  @blobstore_clis ||= {}
  @blobstore_clis[name] = klass
end

Instance Method Details

#blobstore_cliObject

Continue the interactive session with the user specific to the infrastructure they have chosen.

The returned object is a class from cyoi/cli/provider_blobstore/provier_cli_INFRASTRUCTURE.rb The class loads itself into ‘@blobstore_clis` via `register_blobstore_cli`

Returns nil if settings.key_pair.name not set



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/cyoi/cli/blobstore.rb', line 38

def blobstore_cli
  @blobstore_cli ||= begin
    provider_name = settings.exists?("provider.name")
    return nil unless provider_name
    require "cyoi/cli/provider_blobstore/blobstore_cli_#{settings.provider.name}"

    settings["blobstore"] ||= {}
    settings.blobstore["name"] = blobstore_name

    klass = self.class.blobstore_cli(settings.provider.name)
    klass.new(provider_client, settings.blobstore, hl)
  end
end

#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/blobstore.rb', line 19

def execute!
  unless settings.exists?("provider.name") && settings.exists?("provider.credentials")
    $stderr.puts("Please run 'cyoi provider' first")
    exit 1
  end

  settings["blobstore"] = perform_and_return_attributes
  save_settings!

  blobstore_cli.display_confirmation
end

#perform_and_return_attributesObject



52
53
54
# File 'lib/cyoi/cli/blobstore.rb', line 52

def perform_and_return_attributes
  blobstore_cli.perform_and_return_attributes
end