Class: Morpheus::Cli::ServerDevicesCommand
Instance Attribute Summary
Attributes included from CliCommand
#no_prompt
Instance Method Summary
collapse
#accounts_interface, #add_perms_options, #api_client, #apps_interface, #cloud_datastores_interface, #clouds_interface, #datastores_interface, #find_app_by_id, #find_app_by_name, #find_app_by_name_or_id, #find_cloud_by_id_for_provisioning, #find_cloud_by_name_for_provisioning, #find_cloud_by_name_or_id_for_provisioning, #find_cloud_resource_pool_by_name_or_id, #find_group_by_id_for_provisioning, #find_group_by_name_for_provisioning, #find_group_by_name_or_id_for_provisioning, #find_host_by_id, #find_host_by_name, #find_host_by_name_or_id, #find_instance_by_id, #find_instance_by_name, #find_instance_by_name_or_id, #find_instance_type_by_code, #find_instance_type_by_id, #find_instance_type_by_name, #find_instance_type_by_name_or_id, #find_instance_type_layout_by_id, #find_server_by_id, #find_server_by_name, #find_server_by_name_or_id, #find_workflow_by_id, #find_workflow_by_name, #find_workflow_by_name_or_id, #format_app_status, #format_blueprint_type, #format_container_connection_string, #format_container_status, #format_instance_connection_string, #format_instance_container_display_name, #format_instance_status, #format_metadata, #format_snapshot_status, #get_available_accounts, #get_available_clouds, #get_available_environments, #get_available_groups, #get_available_plans, #get_provision_type_for_zone_type, #get_static_environments, #get_volume_size, included, #instance_type_layouts_interface, #instance_types_interface, #instances_interface, #load_balance_protocols_dropdown, #load_service_plan_datastores, #options_interface, #parse_blueprint_type, #parse_host_id_list, #parse_instance_id_list, #parse_metadata, #parse_resource_id_list, #parse_server_id_list, #print_permissions, #prompt_cluster_load_balancer, #prompt_evars, #prompt_exposed_ports, #prompt_instance_load_balancer, #prompt_metadata, #prompt_network_interfaces, #prompt_new_instance, #prompt_permissions, #prompt_permissions_v2, #prompt_resize_volumes, #prompt_security_groups, #prompt_service_plan_options, #prompt_volume_controller_mount_point, #prompt_volumes, #provision_types_interface, #reject_service_plan_option_types, #servers_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
#assign(args) ⇒ Object
60
61
62
63
64
65
66
67
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
|
# File 'lib/morpheus/cli/commands/server_devices_command.rb', line 60
def assign(args)
options = {}
params = {}
optparse = Morpheus::Cli::OptionParser.new do |opts|
opts.banner = "Usage: #{prog_name} hosts assign [host] [device] [target]"
build_standard_update_options(opts, options)
opts. = <<-EOT
Assign a host device to a target server.
[host] is required. This is the id of the host.
[device] is required. This is the id of the device.
[target] is required. This is the id of the target server.
EOT
end
optparse.parse!(args)
verify_args!(args:args, optparse:optparse, min:1, max:3)
connect(options)
server_id = args[0] =~ /\A\d{1,}\Z/ ? args[0].to_i : find_server_by_name(args[0])['id']
device_id = args[1] ? args[1].to_i : nil
if device_id.nil?
avail_devices = @server_devices_interface.list(server_id)['devices'].collect {|it| {'name' => it['name'], 'value' => it['id']}}
device_id = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'deviceId', 'fieldLabel' => 'Device', 'type' => 'select', 'selectOptions' => avail_devices, 'required' => true}], options[:options], @api_client)['deviceId']
end
target_server_id = args[2] ? args[2].to_i : nil
parse_payload(options) do |payload|
if target_server_id.nil?
target_server_id = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'targetServerId', 'fieldLabel' => 'Target Server', 'type' => 'select', 'optionSource' => 'hostVms', 'required' => true}], options[:options], @api_client, {'parentId' => server_id})['targetServerId']
end
payload['targetServerId'] = target_server_id
end
execute_api(@server_devices_interface, :assign, [server_id, device_id], options) do |json_response|
print_green_success "Assigned host device to target server"
end
end
|
#attach(args) ⇒ Object
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/commands/server_devices_command.rb', line 96
def attach(args)
options = {}
params = {}
optparse = Morpheus::Cli::OptionParser.new do |opts|
opts.banner = "Usage: #{prog_name} hosts attach [host] [device]"
build_standard_update_options(opts, options)
opts. = <<-EOT
Attach a host device.
[host] is required. This is the id of the host.
[device] is required. This is the id of the device.
EOT
end
optparse.parse!(args)
verify_args!(args:args, optparse:optparse, min:1, max:3)
connect(options)
server_id = args[0] =~ /\A\d{1,}\Z/ ? args[0].to_i : find_server_by_name(args[0])['id']
device_id = args[1] ? args[1].to_i : nil
if device_id.nil?
avail_devices = @server_devices_interface.list(server_id)['devices'].collect {|it| {'name' => it['name'], 'value' => it['id']}}
device_id = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'deviceId', 'fieldLabel' => 'Device', 'type' => 'select', 'selectOptions' => avail_devices, 'required' => true}], options[:options], @api_client)['deviceId']
end
parse_payload(options) do |payload|
end
execute_api(@server_devices_interface, :attach, [server_id, device_id], options) do |json_response|
print_green_success "Attached host device"
end
end
|
#connect(opts) ⇒ Object
14
15
16
17
18
|
# File 'lib/morpheus/cli/commands/server_devices_command.rb', line 14
def connect(opts)
@api_client = establish_remote_appliance_connection(opts)
@servers_interface = @api_client.servers
@server_devices_interface = @api_client.server_devices
end
|
#detach(args) ⇒ Object
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
# File 'lib/morpheus/cli/commands/server_devices_command.rb', line 125
def detach(args)
options = {}
params = {}
optparse = Morpheus::Cli::OptionParser.new do |opts|
opts.banner = "Usage: #{prog_name} hosts detach [host] [device]"
build_standard_update_options(opts, options)
opts. = <<-EOT
Detach a host device.
[host] is required. This is the id of the host.
[device] is required. This is the id of the device.
EOT
end
optparse.parse!(args)
verify_args!(args:args, optparse:optparse, min:1, max:3)
connect(options)
server_id = args[0] =~ /\A\d{1,}\Z/ ? args[0].to_i : find_server_by_name(args[0])['id']
device_id = args[1] ? args[1].to_i : nil
if device_id.nil?
avail_devices = @server_devices_interface.list(server_id)['devices'].collect {|it| {'name' => it['name'], 'value' => it['id']}}
device_id = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'deviceId', 'fieldLabel' => 'Device', 'type' => 'select', 'selectOptions' => avail_devices, 'required' => true}], options[:options], @api_client)['deviceId']
end
parse_payload(options) do |payload|
end
execute_api(@server_devices_interface, :detach, [server_id, device_id], options) do |json_response|
print_green_success "Detached host device"
end
end
|
#handle(args) ⇒ Object
20
21
22
|
# File 'lib/morpheus/cli/commands/server_devices_command.rb', line 20
def handle(args)
handle_subcommand(args)
end
|
#list(args) ⇒ Object
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
|
# File 'lib/morpheus/cli/commands/server_devices_command.rb', line 24
def list(args)
options = {}
params = {}
ref_ids = []
optparse = Morpheus::Cli::OptionParser.new do |opts|
opts.banner = "Usage: #{prog_name} hosts [host] list-devices"
build_standard_list_options(opts, options)
opts. = <<-EOT
List host devices.
[host] is required. This is the id of the host.
EOT
end
optparse.parse!(args)
connect(options)
verify_args!(args:args, optparse:optparse, count:1)
server_id = args[0] =~ /\A\d{1,}\Z/ ? args[0].to_i : find_server_by_name(args[0])['id']
@server_devices_interface.setopts(options)
if options[:dry_run]
print_dry_run @server_devices_interface.dry.list(server_id, params)
return
end
json_response = @server_devices_interface.list(server_id, params)
render_response(json_response, options, 'devices') do
server_devices = json_response['devices']
print_h1 "Host Devices: #{server_id}", parse_list_subtitles(options), options
if server_devices.empty?
print cyan,"No host devices found.",reset,"\n"
else
print as_pretty_table(server_devices, server_device_list_column_definitions.upcase_keys!, options)
(json_response)
end
print reset,"\n"
end
end
|