Class: Morpheus::Cli::CloudTypes
Instance Attribute Summary
Attributes included from CliCommand
#no_prompt
Instance Method Summary
collapse
#cloud_type_for_id, #cloud_type_for_name, #cloud_type_for_name_or_id, #clouds_interface, #find_cloud_by_id, #find_cloud_by_name, #find_cloud_by_name_or_id, #find_group_by_id, #find_group_by_name, #find_group_by_name_or_id, #find_network_by_id, #find_network_by_name, #find_network_by_name_or_id, #find_network_group_by_id, #find_network_group_by_name, #find_network_group_by_name_or_id, #find_network_server_type_by_id, #find_network_server_type_by_name, #find_network_server_type_by_name_or_code, #find_network_server_type_by_name_or_id, #find_network_type_by_id, #find_network_type_by_name, #find_network_type_by_name_or_id, #find_resource_pool_by_id, #find_resource_pool_by_name, #find_resource_pool_by_name_or_id, #find_resource_pool_group_by_id, #find_resource_pool_group_by_name, #find_resource_pool_group_by_name_or_id, #find_subnet_by_id, #find_subnet_by_name, #find_subnet_by_name_or_id, #find_subnet_type_by_id, #find_subnet_type_by_name, #find_subnet_type_by_name_or_id, #format_network_pool_server_status, #get_available_cloud_types, #groups_interface, included, #network_groups_interface, #network_pool_server_column_definitions, #network_pool_server_list_column_definitions, #network_pool_server_type_column_definitions, #network_pool_server_type_list_column_definitions, #network_server_type_column_definitions, #network_server_type_list_column_definitions, #network_types_interface, #networks_interface, #prompt_for_network, #prompt_for_networks, #prompt_for_pools, #prompt_for_subnets, #resource_pool_groups_interface, #resource_pools_interface, #subnet_types_interface, #subnets_interface
Methods included from CliCommand
#add_query_parameter, #apply_options, #build_common_options, #build_get_options, #build_list_options, #build_option_type_options, #build_standard_add_many_options, #build_standard_add_options, #build_standard_api_options, #build_standard_delete_options, #build_standard_get_options, #build_standard_list_options, #build_standard_post_options, #build_standard_put_options, #build_standard_remove_options, #build_standard_update_options, #command_description, #command_name, #confirm, #confirm!, #default_refresh_interval, #default_sigdig, #default_subcommand, #establish_remote_appliance_connection, #execute_api, #execute_api_payload, #execute_api_request, #find_all, #find_all_json, #find_by_id, #find_by_name, #find_by_name_or_id, #find_record, #find_record_json, #full_command_usage, #get_interface, #get_list_key, #get_object_key, #get_subcommand_description, #handle_each_payload, #handle_subcommand, included, #interactive?, #my_help_command, #my_terminal, #my_terminal=, #parse_array, #parse_bytes_param, #parse_get_options!, #parse_id_list, #parse_labels, #parse_list_options, #parse_list_options!, #parse_list_subtitles, #parse_options, #parse_parameter_as_resource_id!, #parse_passed_options, #parse_payload, #parse_query_options, #print, #print_error, #println, #prog_name, #puts, #puts_error, #raise_args_error, #raise_command_error, #render_response, #run_command_for_each_arg, #subcommand_aliases, #subcommand_description, #subcommand_usage, #subcommands, #usage, #validate_outfile, #verify_args!, #visible_subcommands
Instance Method Details
#connect(opts) ⇒ Object
12
13
14
15
|
# File 'lib/morpheus/cli/commands/clouds_types.rb', line 12
def connect(opts)
@api_client = establish_remote_appliance_connection(opts)
@clouds_interface = @api_client.clouds
end
|
#get(args) ⇒ Object
68
69
70
71
72
73
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
129
130
131
132
133
134
135
136
137
138
139
|
# File 'lib/morpheus/cli/commands/clouds_types.rb', line 68
def get(args)
options={}
params = {}
optparse = Morpheus::Cli::OptionParser.new do |opts|
opts.banner = subcommand_usage("[type]")
build_standard_get_options(opts, options)
opts. = <<-EOT
Get details about a cloud type.
[type] is required. This is the name or id of cloud type.
EOT
end
optparse.parse!(args)
verify_args!(args:args, optparse:optparse, count:1)
connect(options)
params.merge!(parse_query_options(options))
id = args[0]
cloud_type = nil
if id.to_s !~ /\A\d{1,}\Z/
cloud_type = cloud_type_for_name_or_id(id)
if cloud_type.nil?
raise_command_error "cloud type not found for name or code '#{id}'"
end
id = cloud_type['id']
end
@clouds_interface.setopts(options)
if options[:dry_run]
print_dry_run @clouds_interface.dry.cloud_type(id.to_i)
return 0
end
json_response = @clouds_interface.cloud_type(id.to_i)
render_response(json_response, options, 'zoneType') do
cloud_type = json_response['zoneType']
print_h1 "Cloud Type", [], options
print cyan
columns = {
"ID" => 'id',
"Name" => 'name',
"Code" => 'code',
"Enabled" => lambda {|it| format_boolean it['enabled'] },
"Provision" => lambda {|it| format_boolean it['provision'] },
"Auto Capacity" => lambda {|it| format_boolean it['autoCapacity'] },
"Datastores" => lambda {|it| format_boolean it['hasDatastores'] },
"Networks" => lambda {|it| format_boolean it['hasNetworks'] },
"Resource Pools" => lambda {|it| format_boolean it['hasResourcePools'] },
"Security Groups" => lambda {|it| format_boolean it['hasSecurityGroups'] },
"Containers" => lambda {|it| format_boolean it['hasContainers'] },
"Bare Metal" => lambda {|it| format_boolean it['hasBareMetal'] },
"Services" => lambda {|it| format_boolean it['hasServices'] },
"Functions" => lambda {|it| format_boolean it['hasFunctions'] },
"Jobs" => lambda {|it| format_boolean it['hasJobs'] },
"Discovery" => lambda {|it| format_boolean it['hasDiscovery'] },
"Cloud Init" => lambda {|it| format_boolean it['hasCloudInit'] },
"Folders" => lambda {|it| format_boolean it['hasFolders'] },
"Floating Ips" => lambda {|it| format_boolean it['hasFloatingIps'] },
"Public Cloud" => lambda {|it| format_boolean(it['cloud'] == 'public') },
}
print_description_list(columns, cloud_type, options)
option_types = cloud_type['optionTypes']
if option_types && option_types.size > 0
print_h2 "Option Types", options
print format_option_types_table(option_types, options, "zone")
end
print reset,"\n"
end
end
|
#handle(args) ⇒ Object
17
18
19
|
# File 'lib/morpheus/cli/commands/clouds_types.rb', line 17
def handle(args)
handle_subcommand(args)
end
|
#list(args) ⇒ Object
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
|
# File 'lib/morpheus/cli/commands/clouds_types.rb', line 21
def list(args)
options={}
params = {}
optparse = Morpheus::Cli::OptionParser.new do |opts|
opts.banner = subcommand_usage("[search]")
build_standard_list_options(opts, options)
opts. = <<-EOT
List cloud types.
EOT
end
optparse.parse!(args)
connect(options)
if args.count > 0
options[:phrase] = args.join(" ")
end
params.merge!(parse_list_options(options))
@clouds_interface.setopts(options)
if options[:dry_run]
print_dry_run @clouds_interface.dry.cloud_types({})
return 0
end
json_response = @clouds_interface.cloud_types(params)
render_response(json_response, options, 'zoneTypes') do
cloud_types = json_response['zoneTypes']
subtitles = []
subtitles += parse_list_subtitles(options)
print_h1 "Morpheus Cloud Types", subtitles, options
if cloud_types.empty?
print cyan,"No cloud types found.",reset,"\n"
else
print cyan
cloud_types = cloud_types.select {|it| it['enabled'] }
rows = cloud_types.collect do |cloud_type|
{id: cloud_type['id'], name: cloud_type['name'], code: cloud_type['code']}
end
columns = [:id, :name, :code]
columns = options[:include_fields] if options[:include_fields]
print as_pretty_table(rows, columns, options)
(json_response)
print reset,"\n"
end
end
end
|