Module: Bebox::PrepareCommands

Defined in:
lib/bebox/commands/prepare_commands.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object



5
6
7
# File 'lib/bebox/commands/prepare_commands.rb', line 5

def self.extended(base)
  base.load_commands
end

Instance Method Details

#load_commandsObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/bebox/commands/prepare_commands.rb', line 9

def load_commands
  # Prepare nodes phase commands
  desc 'Prepare the nodes for the environment.'
  command :prepare do |prepare_command|
    prepare_command.flag :environment, :desc => 'Set the environment of node', default_value: default_environment
    prepare_command.action do |global_options,options,args|
      environment = get_environment(options)
      # Check if vagrant is installed
      return error('Vagrant is not installed in the system. No changes were made.') unless Bebox::CommandsHelper.vagrant_installed?
      title "Environment: #{environment}"
      Bebox::NodeWizard.new.prepare(project_root, environment)
    end
  end
  # These commands are available if there are at least one node in the vagrant environment
  (Bebox::Node.list(project_root, 'vagrant', 'prepared_nodes').count > 0) ? load_vagrant_commands : return
end

#load_vagrant_commandsObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/bebox/commands/prepare_commands.rb', line 26

def load_vagrant_commands
  desc 'Halt the nodes for vagrant environment.'
  command :vagrant_halt do |vagrant_halt_command|
    vagrant_halt_command.action do |global_options,options,args|
      vagrant_command(:halt_vagrant_nodes, 'Halting nodes:')
    end
  end
  desc 'Up the nodes for vagrant environment.'
  command :vagrant_up do |vagrant_up_command|
    vagrant_up_command.action do |global_options,options,args|
      vagrant_command(:up_vagrant_nodes, 'Running up nodes:')
    end
  end
end

#vagrant_command(command, message) ⇒ Object



41
42
43
44
45
46
47
48
49
50
# File 'lib/bebox/commands/prepare_commands.rb', line 41

def vagrant_command(command, message)
  # Check if vagrant is installed
  return error('Vagrant is not installed in the system. No changes were made.') unless Bebox::CommandsHelper.vagrant_installed?
  nodes = Bebox::Node.nodes_in_environment(project_root, 'vagrant', 'nodes')
  environment = 'vagrant'
  title "Environment: #{environment}\n#{message}"
  nodes.each{|node| msg(node.hostname)}
  linebreak
  Bebox::VagrantHelper.send(command, project_root)
end