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
- #examine(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
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.(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], node_filter: [: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. 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) [: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 |
#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. exit(1) end end |
#list ⇒ Object
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 |