Class: Morpheus::Cli::InstanceTypes
- Inherits:
-
Object
- Object
- Morpheus::Cli::InstanceTypes
- Includes:
- CliCommand
- Defined in:
- lib/morpheus/cli/instance_types.rb
Instance Attribute Summary
Attributes included from CliCommand
Instance Method Summary collapse
- #connect(opts) ⇒ Object
- #get(args) ⇒ Object
- #handle(args) ⇒ Object
-
#initialize ⇒ InstanceTypes
constructor
A new instance of InstanceTypes.
- #list(args) ⇒ Object
Methods included from CliCommand
#build_common_options, #build_option_type_options, #command_name, #default_subcommand, #establish_remote_appliance_connection, #handle_subcommand, included, #interactive?, #noninteractive, #print_usage, #subcommand_aliases, #subcommand_usage, #subcommands, #usage, #verify_access_token!
Constructor Details
#initialize ⇒ InstanceTypes
Returns a new instance of InstanceTypes.
12 13 14 |
# File 'lib/morpheus/cli/instance_types.rb', line 12 def initialize() # @appliance_name, @appliance_url = Morpheus::Cli::Remote.active_appliance 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) = {} optparse = OptionParser.new do|opts| opts. = subcommand_usage("[name]") (opts, , [:json, :dry_run]) end optparse.parse!(args) if args.count < 1 puts optparse exit end name = args[0] connect() begin if [:dry_run] print_dry_run @instance_types_interface.dry.get({name: name}) return end json_response = @instance_types_interface.get({name: name}) if [: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 "\n" ,cyan, bold, "Instance Type Details\n","==================", reset, "\n\n" 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 # instance_type['instanceTypeLayouts'].each do |layout| # print green, " - #{layout['name']}\n",reset # end print reset,"\n" end rescue RestClient::Exception => e print_rest_exception(e, ) 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 |
# File 'lib/morpheus/cli/instance_types.rb', line 74 def list(args) = {} optparse = OptionParser.new do|opts| opts. = subcommand_usage() (opts, , [:list, :json, :dry_run]) end optparse.parse!(args) connect() begin params = {} [:phrase, :offset, :max, :sort, :direction].each do |k| params[k] = [k] unless [k].nil? end if [:dry_run] print_dry_run @instance_types_interface.dry.get(params) return end json_response = @instance_types_interface.get(params) if [:json] print JSON.pretty_generate(json_response), "\n" return end instance_types = json_response['instanceTypes'] print "\n" ,cyan, bold, "Morpheus Instance Types\n","==================", reset, "\n\n" if instance_types.empty? puts yellow,"No instance types currently configured.",reset 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 # instance_type['instanceTypeLayouts'].each do |layout| # print green, " - #{layout['name']}\n",reset # end #print JSON.pretty_generate(instance_type['instanceTypeLayouts'].first), "\n" end end print reset,"\n" rescue RestClient::Exception => e print_rest_exception(e, ) exit 1 end end |