Module: NexClient::Commands::Racks

Extended by:
Helpers
Defined in:
lib/nex_client/commands/racks.rb

Constant Summary collapse

COMPUTE_RACKS_TITLE =
"Compute Racks".colorize(:cyan)
STORAGE_RACKS_TITLE =
"Storage Racks".colorize(:blue)
ROUTING_RACKS_TITLE =
"Routing Racks".colorize(:green)
GATEWAY_RACKS_TITLE =
"Gateway Racks".colorize(:yellow)
RACKS_HEADERS =
['type','id','region','stack','status','iip','eip','capacity'].map(&:upcase)

Constants included from Helpers

Helpers::LOG_COLORS

Class Method Summary collapse

Methods included from Helpers

display_logs, display_record_errors, error, success

Class Method Details

.display_compute_racks(list) ⇒ Object



81
82
83
84
85
86
87
88
89
# File 'lib/nex_client/commands/racks.rb', line 81

def self.display_compute_racks(list)
  table = Terminal::Table.new title: COMPUTE_RACKS_TITLE, headings: RACKS_HEADERS do |t|
    [list].flatten.compact.each do |e|
      t.add_row(['compute',e.id,e.vpc_region,e.stack,e.status,e.private_ip_address,'-',"#{e.used_pu}/#{e.total_pu}"])
    end
  end
  puts table
  puts "\n"
end

.display_gateway_racks(list) ⇒ Object



111
112
113
114
115
116
117
118
119
# File 'lib/nex_client/commands/racks.rb', line 111

def self.display_gateway_racks(list)
  table = Terminal::Table.new title: GATEWAY_RACKS_TITLE, headings: RACKS_HEADERS do |t|
    [list].flatten.compact.each do |e|
      t.add_row(['gateway',e.id,e.vpc_region,'-',e.status,e.private_ip_address,e.ip_address,'-'])
    end
  end
  puts table
  puts "\n"
end

.display_routing_racks(list) ⇒ Object



101
102
103
104
105
106
107
108
109
# File 'lib/nex_client/commands/racks.rb', line 101

def self.display_routing_racks(list)
  table = Terminal::Table.new title: ROUTING_RACKS_TITLE, headings: RACKS_HEADERS do |t|
    [list].flatten.compact.each do |e|
      t.add_row(['routing',e.id,e.vpc_region,'-',e.status,e.private_ip_address,'-','-'])
    end
  end
  puts table
  puts "\n"
end

.display_storage_racks(list) ⇒ Object



91
92
93
94
95
96
97
98
99
# File 'lib/nex_client/commands/racks.rb', line 91

def self.display_storage_racks(list)
  table = Terminal::Table.new title: STORAGE_RACKS_TITLE, headings: RACKS_HEADERS do |t|
    [list].flatten.compact.each do |e|
      t.add_row(['storage',e.id,e.vpc_region,'-',e.status,e.private_ip_address,'-',"#{e.used_su}/#{e.total_su}"])
    end
  end
  puts table
  puts "\n"
end

.list(args, opts) ⇒ Object



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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/nex_client/commands/racks.rb', line 13

def self.list(args,opts)
  filters = {}

  # Type filter
  only_type = opts.type
  only_type = 'compute' if opts.stack.present?

  # Status filter
  filters[:status] = opts.status || 'running'

  # Stack filter
  if opts.stack.present?
    filters[:stack] = opts.stack
  end

  # All option
  filters = {} if opts.all

  # Create table
  if !only_type || only_type == 'compute'
    list = NexClient::ComputeRack.where(filters).order('vpc_region,status')
    self.display_compute_racks(list)

    # Loop through results
    while (list.pages.links||{})['next']
      ask("Press enter for next page")
      list = list.pages.next
      self.display_compute_racks(list)
    end
  end

  if !only_type || only_type == 'storage'
    list = NexClient::StorageRack.where(filters).order('vpc_region,status')
    self.display_storage_racks(list)

    # Loop through results
    while (list.pages.links||{})['next']
      ask("Press enter for next page")
      list = list.pages.next
      self.display_storage_racks(list)
    end
  end

  if !only_type || only_type == 'routing'
    list = NexClient::RoutingRack.where(filters).order('vpc_region,status')
    self.display_routing_racks(list)

    # Loop through results
    while (list.pages.links||{})['next']
      ask("Press enter for next page")
      list = list.pages.next
      self.display_routing_racks(list)
    end
  end

  if !only_type || only_type == 'gateway'
    list = NexClient::GatewayRack.where(filters).order('vpc_region,status')
    self.display_gateway_racks(list)

    # Loop through results
    while (list.pages.links||{})['next']
      ask("Press enter for next page")
      list = list.pages.next
      self.display_gateway_racks(list)
    end
  end
end