Class: VagrantPlugins::ArubaCloud::Command::Servers

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-arubacloud/command/servers.rb

Instance Method Summary collapse

Instance Method Details

#executeObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/vagrant-arubacloud/command/servers.rb', line 7

def execute
  options = {}
  opts = OptionParser.new do |o|
    o.banner = 'Usage: vagrant arubacloud servers [options]'
  end
  argv = parse_options(opts)
  return unless argv

  vm_count = 1
  vm_list = Array.new
  vm_size = 0

  with_target_vms(argv,  :provider => :arubacloud ,  :plist => '1' ) do |machine|
    if vm_count == 1
      ll = machine.name.length
      ui_ext = Vagrant::UI::Prefixed.new(  Vagrant::UI::Colored.new, " "*ll )
      ui_ext.opts = { :color => :white, :bold => true  }
      ui_ext.detail ('%-6s %-20s %-8s %-12s %-14s %s' % ['DC', 'Server Name', ' Id ', 'State Code', 'State meaning', 'IPv4 address'])
      ui_ext.detail ("-" * 80)
      # vm_size : how many vm are in .vagrant directory (is default)
      # status  : 'owned'  all VM defined in my '.vagrant' directory
      machine.provider_config.reserved_status = "owned"
      vm_size = machine.config.vm.defined_vm_keys.length
    end
    if (vm_count == vm_size)
        # if last element change 'status' to 'other' to output list of all external VM in current DC
        # and send  list all  VM's ( server.name) founds  in '.vagrant' directory
        machine.provider_config.reserved_status = "other"
        machine.provider_config.reserved_list_owned = vm_list
    end

    machine.action('list_servers')
    vm_count += 1
    # accum in append current server-name returned by list_server only if exist
    if machine.provider_config.reserved_list_owned
      vm_list <<  machine.provider_config.reserved_list_owned
    end
  end
end