Module: NexClient::Commands::CubeInstances
- Extended by:
- Helpers
- Defined in:
- lib/nex_client/commands/cube_instances.rb
Constant Summary
collapse
- CUBES_TITLE =
"Cube Instances".colorize(:blue)
['id','status','region','ssl','storage','SOA','ip','port','dns','cluster'].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_cubes(list) ⇒ Object
59
60
61
62
63
64
65
66
67
|
# File 'lib/nex_client/commands/cube_instances.rb', line 59
def self.display_cubes(list)
table = Terminal::Table.new title: CUBES_TITLE, headings: CUBES_HEADERS do |t|
[list].flatten.compact.each do |e|
t.add_row(self.format_record(e))
end
end
puts table
puts "\n"
end
|
90
91
92
93
|
# File 'lib/nex_client/commands/cube_instances.rb', line 90
def self.format_cluster(record)
return '-' unless o = record.cluster
"#{o.type.singularize}:#{o.name}"
end
|
86
87
88
|
# File 'lib/nex_client/commands/cube_instances.rb', line 86
def self.format_dns(record)
record.dns || '-'
end
|
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
# File 'lib/nex_client/commands/cube_instances.rb', line 69
def self.format_record(record)
dns = self.format_dns(record)
cluster = self.format_cluster(record)
[
record.id,
record.status,
record.region,
record.ssl_enabled,
record.persistent_storage,
record.soa_enabled,
record.ip_address || '-',
record.port || '-',
dns,
cluster
]
end
|
.list(args, opts) ⇒ Object
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
|
# File 'lib/nex_client/commands/cube_instances.rb', line 10
def self.list(args,opts)
filters = {}
filters[:status] = opts.status || 'running'
filters[:soa_enabled] = opts.soa if opts.soa.present?
filters[:ssl_enabled] = opts.ssl if opts.ssl.present?
filters[:persistent_storage] = opts.storage if opts.storage.present?
filters = {} if opts.all
filters[:dns] = opts.dns if opts.dns.present?
filters[:'app.name'] = opts.app if opts.app.present?
filters[:'addon.name'] = opts.addon if opts.addon.present?
list = NexClient::CubeInstance.includes(:cluster).where(filters).order('status')
self.display_cubes(list)
while (list.pages.links||{})['next']
ask("Press enter for next page")
list = list.pages.next
self.display_cubes(list)
end
end
|
.trigger_action(action, args, opts) ⇒ Object
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/nex_client/commands/cube_instances.rb', line 37
def self.trigger_action(action,args,opts)
name = args.first
e = NexClient::CubeInstance.find(name: name).first
unless e
error("Error! Could not find cube: #{name}")
return false
end
e.send(action)
if e.errors.any?
display_record_errors(e)
return false
end
success("Initiated #{action} for cube #{name}...")
end
|