Class: MotherBrain::CliGateway::SubCommand::Environment

Inherits:
MotherBrain::Cli::Base show all
Defined in:
lib/mb/cli_gateway/sub_commands/environment.rb

Instance Method Summary collapse

Methods inherited from MotherBrain::Cli::Base

register_subcommand, ui

Instance Method Details

#configure(environment, attributes_file) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/mb/cli_gateway/sub_commands/environment.rb', line 19

def configure(environment, attributes_file)
  attributes_file = File.expand_path(attributes_file)

  begin
    content = File.read(attributes_file)
  rescue Errno::ENOENT
    ui.say "No attributes file found at: '#{attributes_file}'"
    exit(1)
  end

  begin
    attributes = MultiJson.decode(content)
  rescue MultiJson::DecodeError => ex
    ui.say "Error decoding JSON from: '#{attributes_file}'"
    ui.say ex
    exit(1)
  end

  job = environment_manager.async_configure(environment, attributes: attributes, force: options[:force], node_filter: options[:only])

  CliClient.new(job).display
end

#create(environment) ⇒ Object



115
116
117
118
119
120
121
122
123
124
# File 'lib/mb/cli_gateway/sub_commands/environment.rb', line 115

def create(environment)
  ui.say "Creating empty environment #{environment}"

  begin
    environment_manager.create(environment)
  rescue => e
    ui.error e.message
    exit(1)
  end
end

#destroy(environment) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/mb/cli_gateway/sub_commands/environment.rb', line 56

def destroy(environment)
  options[:with] = options[:provisioner] # TODO: rename with to provisioner
  options[:yes] ||= options[:force]
  destroy_options = Hash.new.merge(options).deep_symbolize_keys

  if !options[:force] && ChefMutex.new(chef_environment: environment).locked?
    raise MB::ResourceLocked,
      "The environment \"#{environment}\" is locked. You may use --force to override this safeguard."
  end

  dialog = "This will destroy the '#{environment}' environment.\nAre you sure? (yes|no): "
  really_destroy = options[:yes] || ui.yes?(dialog)

  if really_destroy
    job = provisioner.async_destroy(environment, destroy_options)
    CliClient.new(job).display
  else
    ui.say("Aborting destruction of '#{environment}'")
  end
end

#examine(environment) ⇒ Object



127
128
129
130
131
# File 'lib/mb/cli_gateway/sub_commands/environment.rb', line 127

def examine(environment)
  job = environment_manager.async_examine_nodes(environment)

  CliClient.new(job).display
end

#from(environment_file) ⇒ Object



103
104
105
106
107
108
109
110
111
112
# File 'lib/mb/cli_gateway/sub_commands/environment.rb', line 103

def from(environment_file)
  ui.say "Creating environment from #{environment_file}"

  begin
    environment_manager.create_from_file(environment_file)
  rescue => e
    ui.error e.message
    exit(1)
  end
end

#listObject



78
79
80
81
82
83
84
85
86
# File 'lib/mb/cli_gateway/sub_commands/environment.rb', line 78

def list
  ui.say "\n"
  ui.say "** listing environments"
  ui.say "\n"

  environment_manager.list.each do |env|
    ui.say env.name
  end
end

#lock(environment) ⇒ Object



89
90
91
92
93
# File 'lib/mb/cli_gateway/sub_commands/environment.rb', line 89

def lock(environment)
  job = lock_manager.async_lock(environment)

  CliClient.new(job).display
end

#unlock(environment) ⇒ Object



96
97
98
99
100
# File 'lib/mb/cli_gateway/sub_commands/environment.rb', line 96

def unlock(environment)
  job = lock_manager.async_unlock(environment)

  CliClient.new(job).display
end