Class: Morpheus::Cli::InstanceTypes
- Inherits:
-
Object
- Object
- Morpheus::Cli::InstanceTypes
show all
- Includes:
- CliCommand
- Defined in:
- lib/morpheus/cli/instance_types.rb
Instance Attribute Summary
Attributes included from CliCommand
#no_prompt
Instance Method Summary
collapse
Methods included from CliCommand
#build_common_options, #build_option_type_options, #command_name, #default_subcommand, #establish_remote_appliance_connection, #full_command_usage, #handle_subcommand, included, #interactive?, #my_help_command, #my_terminal, #my_terminal=, #parse_id_list, #print, #print_error, #puts, #puts_error, #raise_command_error, #run_command_for_each_arg, #subcommand_aliases, #subcommand_usage, #subcommands, #usage, #verify_access_token!
Constructor Details
Returns a new instance of InstanceTypes.
12
13
14
|
# File 'lib/morpheus/cli/instance_types.rb', line 12
def initialize()
end
|
Instance Method Details
#connect(opts) ⇒ Object
16
17
18
19
|
# File 'lib/morpheus/cli/instance_types.rb', line 16
def connect(opts)
@api_client = establish_remote_appliance_connection(opts)
@instance_types_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).instance_types
end
|
#get(args) ⇒ Object
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
|
# File 'lib/morpheus/cli/instance_types.rb', line 25
def get(args)
options = {}
optparse = OptionParser.new do|opts|
opts.banner = subcommand_usage("[name]")
build_common_options(opts, options, [:json, :dry_run])
end
optparse.parse!(args)
if args.count < 1
puts optparse
exit
end
name = args[0]
connect(options)
begin
if options[:dry_run]
print_dry_run @instance_types_interface.dry.get({name: name})
return
end
json_response = @instance_types_interface.get({name: name})
if options[:json]
print JSON.pretty_generate(json_response), "\n"
return
end
instance_type = json_response['instanceTypes'][0]
if instance_type.nil?
puts yellow,"No instance type found by name #{name}.",reset
else
print_h1 "Instance Type Details"
versions = instance_type['versions'].join(', ')
print cyan, "= #{instance_type['name']} (#{instance_type['code']}) - #{versions}\n"
layout_names = instance_type['instanceTypeLayouts'].collect { |layout| layout['name'] }.uniq.sort
layout_names.each do |layout_name|
print green, " - #{layout_name}\n",reset
end
print reset,"\n"
end
rescue RestClient::Exception => e
print_rest_exception(e, options)
exit 1
end
end
|
#handle(args) ⇒ Object
21
22
23
|
# File 'lib/morpheus/cli/instance_types.rb', line 21
def handle(args)
handle_subcommand(args)
end
|
#list(args) ⇒ Object
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
# File 'lib/morpheus/cli/instance_types.rb', line 74
def list(args)
options = {}
optparse = OptionParser.new do|opts|
opts.banner = subcommand_usage()
build_common_options(opts, options, [:list, :json, :dry_run])
end
optparse.parse!(args)
connect(options)
begin
params = {}
[:phrase, :offset, :max, :sort, :direction].each do |k|
params[k] = options[k] unless options[k].nil?
end
if options[:dry_run]
print_dry_run @instance_types_interface.dry.get(params)
return
end
json_response = @instance_types_interface.get(params)
if options[:json]
print JSON.pretty_generate(json_response), "\n"
return 0
end
instance_types = json_response['instanceTypes']
title = "Morpheus Instance Types"
subtitles = []
if params[:phrase]
subtitles << "Search: #{params[:phrase]}".strip
end
print_h1 title, subtitles
if instance_types.empty?
print yellow,"No instance types found.",reset,"\n"
else
instance_types.each do |instance_type|
versions = instance_type['versions'].join(', ')
print cyan, "= #{instance_type['name']} (#{instance_type['code']}) - #{versions}\n"
layout_names = instance_type['instanceTypeLayouts'].collect { |layout| layout['name'] }.uniq.sort
layout_names.each do |layout_name|
print green, " - #{layout_name}\n",reset
end
end
end
print reset,"\n"
return 0
rescue RestClient::Exception => e
print_rest_exception(e, options)
return 1
end
end
|