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



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/mb/cli_gateway/sub_commands/environment.rb', line 13

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])

  CliClient.new(job).display
end

#create(environment) ⇒ Object



109
110
111
112
113
114
115
116
117
118
# File 'lib/mb/cli_gateway/sub_commands/environment.rb', line 109

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



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/mb/cli_gateway/sub_commands/environment.rb', line 50

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

#from(environment_file) ⇒ Object



97
98
99
100
101
102
103
104
105
106
# File 'lib/mb/cli_gateway/sub_commands/environment.rb', line 97

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



72
73
74
75
76
77
78
79
80
# File 'lib/mb/cli_gateway/sub_commands/environment.rb', line 72

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



83
84
85
86
87
# File 'lib/mb/cli_gateway/sub_commands/environment.rb', line 83

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

  CliClient.new(job).display
end

#unlock(environment) ⇒ Object



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

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

  CliClient.new(job).display
end