Class: MotherBrain::CliGateway::SubCommand::Environment
- Inherits:
-
MotherBrain::Cli::Base
- Object
- Thor
- MotherBrain::Cli::Base
- MotherBrain::CliGateway::SubCommand::Environment
- Defined in:
- lib/mb/cli_gateway/sub_commands/environment.rb
Instance Method Summary collapse
- #configure(environment, attributes_file) ⇒ Object
- #create(environment) ⇒ Object
- #destroy(environment) ⇒ Object
- #from(environment_file) ⇒ Object
- #list ⇒ Object
- #lock(environment) ⇒ Object
- #unlock(environment) ⇒ Object
Methods inherited from MotherBrain::Cli::Base
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.(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: [: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. 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) [:with] = [:provisioner] # TODO: rename with to provisioner [:yes] ||= [:force] = Hash.new.merge().deep_symbolize_keys if ![: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 = [:yes] || ui.yes?(dialog) if really_destroy job = provisioner.async_destroy(environment, ) 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. exit(1) end end |
#list ⇒ Object
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 |