Class: Morpheus::Cli::InstanceTypes

Inherits:
Object
  • Object
show all
Includes:
CliCommand
Defined in:
lib/morpheus/cli/instance_types.rb

Instance Method Summary collapse

Methods included from CliCommand

#build_common_options, included

Constructor Details

#initializeInstanceTypes

Returns a new instance of InstanceTypes.



9
10
11
12
13
14
15
# File 'lib/morpheus/cli/instance_types.rb', line 9

def initialize() 
	@appliance_name, @appliance_url = Morpheus::Cli::Remote.active_appliance
	@access_token = Morpheus::Cli::Credentials.new(@appliance_name,@appliance_url).request_credentials()
	@instance_types_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).instance_types
	@groups_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).groups
	@active_groups = ::Morpheus::Cli::Groups.load_group_file
end

Instance Method Details

#details(args) ⇒ Object



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
# File 'lib/morpheus/cli/instance_types.rb', line 39

def details(args)
	options = {}
	optparse = OptionParser.new do|opts|
		opts.banner = "Usage: morpheus instance-type details [name]"
		build_common_options(opts, options, [:json])
	end
	optparse.parse(args)
	if args.count < 1
		puts "\n#{optparse.banner}\n\n"
		return
	end
	name = args[0]
	begin
		json_response = @instance_types_interface.get({name: name})

		if options[:json]
			print JSON.pretty_generate(json_response), "\n" and 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"
			instance_type['instanceTypeLayouts'].each do |layout|
				print green, "     - #{layout['name']}\n",reset
			end
			print reset,"\n\n"
		end

	rescue RestClient::Exception => e
		print_rest_exception(e, options)
		exit 1
	end
end

#handle(args) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/morpheus/cli/instance_types.rb', line 18

def handle(args) 
	if @access_token.empty?
		print_red_alert "Invalid Credentials. Unable to acquire access token. Please verify your credentials and try again."
		return 1
	end
	if args.empty?
		puts "\nUsage: morpheus instance-types [list,details] [name]\n\n"
		return
	end

	case args[0]
		when 'list'
			list(args[1..-1])
		when 'details'
			details(args[1..-1])
		else
			puts "\nUsage: morpheus instance-types [list,details] [name]\n\n"
	end
end

#list(args) ⇒ Object



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
# File 'lib/morpheus/cli/instance_types.rb', line 78

def list(args)
	options = {}
	optparse = OptionParser.new do|opts|
		build_common_options(opts, options, [:list, :json])
	end
	optparse.parse(args)
	begin
		params = {}
		[:phrase, :offset, :max, :sort, :direction].each do |k|
			params[k] = options[k] unless options[k].nil?
		end

		json_response = @instance_types_interface.get(params)

		if options[:json]
			print JSON.pretty_generate(json_response), "\n" and 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"
				instance_type['instanceTypeLayouts'].each do |layout|
					print green, "     - #{layout['name']}\n",reset
				end
			end
		end
		print reset,"\n\n"
		
	rescue RestClient::Exception => e
		print_rest_exception(e, options)
		exit 1
	end
end