Class: Morpheus::Cli::LibraryClusterPackagesCommand
- Inherits:
-
Object
- Object
- Morpheus::Cli::LibraryClusterPackagesCommand
- Includes:
- CliCommand, LibraryHelper
- Defined in:
- lib/morpheus/cli/commands/library_cluster_packages_command.rb
Instance Attribute Summary
Attributes included from CliCommand
Instance Method Summary collapse
- #_get(id, options) ⇒ Object
- #add(args) ⇒ Object
- #connect(opts) ⇒ Object
- #get(args) ⇒ Object
- #handle(args) ⇒ Object
-
#initialize ⇒ LibraryClusterPackagesCommand
constructor
A new instance of LibraryClusterPackagesCommand.
- #list(args) ⇒ Object
- #remove(args) ⇒ Object
- #update(args) ⇒ Object
Methods included from LibraryHelper
#api_client, #find_container_type_by_id, #find_container_type_by_name, #find_container_type_by_name_or_id, #find_instance_type_by_id, #find_instance_type_by_name, #find_instance_type_by_name_or_id, #find_option_type_by_id, #find_option_type_by_name, #find_option_type_by_name_or_id, #find_option_type_list_by_id, #find_option_type_list_by_name, #find_option_type_list_by_name_or_id, #find_spec_template_by_id, #find_spec_template_by_name, #find_spec_template_by_name_or_id, #find_spec_template_type_by_id, #find_spec_template_type_by_name_or_code, #find_spec_template_type_by_name_or_code_id, #format_container_type_technology, #format_instance_type_technology, #get_all_spec_template_types, included, #load_balance_protocols_dropdown, #print_container_types_table, #print_instance_types_table, #print_resource_specs_table, #prompt_exposed_ports, #prompt_for_container_types, #prompt_for_option_types, #prompt_for_spec_templates
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
Constructor Details
#initialize ⇒ LibraryClusterPackagesCommand
Returns a new instance of LibraryClusterPackagesCommand.
11 12 |
# File 'lib/morpheus/cli/commands/library_cluster_packages_command.rb', line 11 def initialize() end |
Instance Method Details
#_get(id, options) ⇒ Object
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 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/morpheus/cli/commands/library_cluster_packages_command.rb', line 109 def _get(id, ) begin @library_cluster_packages_interface.setopts() if [:dry_run] print_dry_run @library_cluster_packages_interface.dry.get(id) return end package = find_package_by_id(id) if package.nil? return 1 end json_response = {'package' => package} if [:json] puts as_json(json_response, , "package") return 0 elsif [:yaml] puts as_yaml(json_response, , "package") return 0 elsif [:csv] puts records_as_csv([json_response['package']], ) return 0 end print_h1 "Cluster Package Details" print cyan description_cols = { "ID" => lambda {|it| it['id'] }, "Name" => lambda {|it| it['name'] }, "Code" => lambda {|it| it['code']}, "Enabled" => lambda {|it| format_boolean(it['enabled'])}, "Description" => lambda {|it|it['description']}, "Package Version" => lambda {|it| it['packageVersion']}, "Package Type" => lambda {|it| it['packageType']}, "Type" => lambda {|it| it['type'] }, "Repeat Install" => lambda {|it| format_boolean(it['repeatInstall'])}, "Logo" => lambda {|it| it['imagePath'] }, "Dark Logo" => lambda {|it| it['darkImagePath'] }, "Spec Templates" => lambda {|it| "(#{it['specTemplates'].count}) #{it['specTemplates'].collect {|it| it['name'] }.join(', ')}" } } print_description_list(description_cols, package) if (package['optionTypes'] || []).count > 0 rows = package['optionTypes'].collect do |opt| { label: opt['fieldLabel'], type: opt['type'] } end print_h2 "Option Types" puts as_pretty_table(rows, [:label, :type]) end print reset,"\n" rescue RestClient::Exception => e print_rest_exception(e, ) return 1 end end |
#add(args) ⇒ Object
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 |
# File 'lib/morpheus/cli/commands/library_cluster_packages_command.rb', line 174 def add(args) = {} params = {} logo_file = nil dark_logo_file = nil optparse = Morpheus::Cli::OptionParser.new do|opts| opts. = subcommand_usage("[name] [options]") opts.on('-n', '--name VALUE', String, "Name for this cluster package") do |val| params['name'] = val end opts.on('-d', '--description VALUE', String, "Description") do |val| params['description'] = val end opts.on('-c', '--code VALUE', String, "Code") do |val| params['code'] = val end opts.on('-e', '--enabled [on|off]', String, "Can be used to enable / disable package. Default is on") do |val| params['enabled'] = val.to_s == 'on' || val.to_s == 'true' || val.to_s == '1' || val.to_s == '' end opts.on('-r', '--repeatInstall [on|off]', String, "Can be used to retry install package if initial fails") do |val| params['repeatInstall'] = val.to_s == 'on' || val.to_s == 'true' || val.to_s == '1' || val.to_s == '' end opts.on('-t', '--type VALUE', String, "Type") do |val| params['type'] = val end opts.on('-p', '--packageType VALUE', String, "Package Type") do |val| params['packageType'] = val end opts.on('-v', '--packageVersion VALUE', String, "Package Version") do |val| params['packageVersion'] = val end opts.on('--spec-templates [x,y,z]', Array, "List of Spec Templates to include in this package, comma separated list of IDs.") do |list| unless list.nil? params['specTemplates'] = list.collect {|it| it.to_s.strip.empty? ? nil : it.to_s.strip }.compact.uniq end end opts.on('--logo FILE', String, "Upload a custom logo icon") do |val| filename = val logo_file = nil if filename == 'null' logo_file = 'null' # clear it else filename = File.(filename) if !File.exist?(filename) raise_command_error "File not found: #{filename}" end logo_file = File.new(filename, 'rb') end end opts.on('--dark-logo FILE', String, "Upload a custom dark logo icon") do |val| filename = val dark_logo_file = nil if filename == 'null' dark_logo_file = 'null' # clear it else filename = File.(filename) if !File.exist?(filename) raise_command_error "File not found: #{filename}" end dark_logo_file = File.new(filename, 'rb') end end (opts, , [:options, :payload, :json, :dry_run, :remote]) opts. = "Create a cluster package." end optparse.parse!(args) connect() if args.count > 1 print_error Morpheus::Terminal.angry_prompt puts_error "wrong number of arguments, expected 0-1 and got (#{args.count}) #{args.inspect}\n#{optparse}" return 1 end if args[0] params['name'] = args[0] end begin if [:payload] payload = [:payload] else # support the old -O OPTION switch params.deep_merge!([:options].reject {|k,v| k.is_a?(Symbol) }) if [:options] # prompt for options if params['name'].nil? params['name'] = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'name', 'type' => 'text', 'fieldLabel' => 'Name', 'required' => true}], [:options], @api_client,{})['name'] end # code if params['code'].nil? params['code'] = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'code', 'type' => 'text', 'fieldLabel' => 'Code', 'required' => true}], [:options], @api_client,{})['code'] end # description if params['description'].nil? params['description'] = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'description', 'type' => 'text', 'fieldLabel' => 'Description', 'required' => false}], [:options], @api_client,{})['description'] end # enabled if params['enabled'].nil? params['enabled'] = Morpheus::Cli::OptionTypes.confirm("Enabled?", {:default => true}) == true end # enabled if params['repeatInstall'].nil? params['repeatInstall'] = Morpheus::Cli::OptionTypes.confirm("Repeat Install?", {:default => true}) == true end # type if params['type'].nil? params['type'] = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'type', 'type' => 'select', 'fieldLabel' => 'Type', 'required' => true, 'optionSource' => 'clusterPackageTypes'}], [:options], @api_client,{})['type'] end # packageType if params['packageType'].nil? params['packageType'] = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'packageType', 'packageType' => 'text', 'fieldLabel' => 'Package Type', 'required' => true}], [:options], @api_client,{})['packageType'] end # packageVersion if params['packageVersion'].nil? params['packageVersion'] = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'packageVersion', 'packageVersion' => 'text', 'fieldLabel' => 'Package Version', 'required' => true}], [:options], @api_client,{})['packageVersion'] end # logo if params['iconPath'].nil? params['iconPath'] = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'iconPath', 'fieldLabel' => 'Logo', 'type' => 'select', 'optionSource' => 'iconList'}], [:options], @api_client,{})['iconPath'] end # specTemplates if params['specTemplates'].nil? spec_templates = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'specTemplates', 'fieldLabel' => 'Spec Templates', 'type' => 'multiSelect', 'required' => true, 'optionSource' => 'clusterResourceSpecTemplates'}], [:options], @api_client, {})['specTemplates'] params['specTemplates'] = spec_templates end payload = {'clusterPackage' => params} end @library_cluster_packages_interface.setopts() if [:dry_run] print_dry_run @library_cluster_packages_interface.dry.create(payload) return end json_response = @library_cluster_packages_interface.create(payload) if json_response['success'] if logo_file || dark_logo_file begin @library_cluster_packages_interface.update_logo(json_response['id'], logo_file, dark_logo_file) rescue RestClient::Exception => e print_red_alert "Failed to save logo!" print_rest_exception(e, ) end end end if [:json] print JSON.pretty_generate(json_response), "\n" return end print_green_success "Added Cluster Package #{params['name']}" get([json_response['id']]) rescue RestClient::Exception => e print_rest_exception(e, ) exit 1 end end |
#connect(opts) ⇒ Object
14 15 16 17 |
# File 'lib/morpheus/cli/commands/library_cluster_packages_command.rb', line 14 def connect(opts) @api_client = establish_remote_appliance_connection(opts) @library_cluster_packages_interface = @api_client.library_cluster_packages end |
#get(args) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/morpheus/cli/commands/library_cluster_packages_command.rb', line 86 def get(args) = {} optparse = Morpheus::Cli::OptionParser.new do |opts| opts. = subcommand_usage("[clusterPackage]") (opts, , [:json, :yaml, :csv, :fields, :dry_run, :remote]) opts. = "Display cluster package details." + "\n" + "[clusterPackage] is required. This is the id of a cluster package." end optparse.parse!(args) if args.count < 1 puts optparse return 1 end connect() id_list = parse_id_list(args) id_list.each do |id| end return run_command_for_each_arg(id_list) do |arg| _get(arg, ) end end |
#handle(args) ⇒ Object
19 20 21 |
# File 'lib/morpheus/cli/commands/library_cluster_packages_command.rb', line 19 def handle(args) handle_subcommand(args) end |
#list(args) ⇒ Object
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 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/morpheus/cli/commands/library_cluster_packages_command.rb', line 23 def list(args) = {} params = {} optparse = Morpheus::Cli::OptionParser.new do |opts| opts. = subcommand_usage() (opts, , [:list, :query, :json, :yaml, :csv, :fields, :dry_run, :remote]) opts. = "List cluster packages." end optparse.parse!(args) # verify_args!(args:args, optparse:optparse, count:0) if args.count > 0 [:phrase] = args.join(" ") end connect() begin # construct payload params.merge!(()) @library_cluster_packages_interface.setopts() if [:dry_run] print_dry_run @library_cluster_packages_interface.dry.list(params) return end # do it json_response = @library_cluster_packages_interface.list(params) # print and/or return result # return 0 if options[:quiet] if [:json] puts as_json(json_response, , "clusterPackages") return 0 elsif [:csv] puts records_as_csv(json_response['clusterPackages'], ) return 0 elsif [:yaml] puts as_yaml(json_response, , "clusterPackages") return 0 end packages = json_response['clusterPackages'] title = "Morpheus Library - Cluster Packages" subtitles = parse_list_subtitles() print_h1 title, subtitles if packages.empty? print cyan,"No cluster packages found.",reset,"\n" else rows = packages.collect do |package| { id: package['id'], name: package['name'], type: package['type'], packageType: package['packageType'], enabled: package['enabled'] } end print as_pretty_table(rows, [:id, :name, :type, :packageType, :enabled], ) print_results_pagination(json_response, {}) end print reset,"\n" rescue RestClient::Exception => e print_rest_exception(e, ) return 1 end end |
#remove(args) ⇒ Object
471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 |
# File 'lib/morpheus/cli/commands/library_cluster_packages_command.rb', line 471 def remove(args) = {} optparse = Morpheus::Cli::OptionParser.new do|opts| opts. = subcommand_usage("[clusterPackage]") (opts, , [:auto_confirm, :json, :dry_run, :remote]) opts. = "Delete a cluster package." + "\n" + "[clusterPackage] is required. This is the id of a cluster package." end optparse.parse!(args) if args.count != 1 print_error Morpheus::Terminal.angry_prompt puts_error "wrong number of arguments, expected 1 and got (#{args.count}) #{args.inspect}\n#{optparse}" return 1 end connect() begin cluster_package = find_package_by_id(args[0]) if cluster_package.nil? return 1 end unless Morpheus::Cli::OptionTypes.confirm("Are you sure you want to delete the cluster package #{cluster_package['name']}?", ) exit end @library_cluster_packages_interface.setopts() if [:dry_run] print_dry_run @library_cluster_packages_interface.dry.destroy(cluster_package['id']) return end json_response = @library_cluster_packages_interface.destroy(cluster_package['id']) if [:json] print JSON.pretty_generate(json_response) print "\n" elsif ![:quiet] if json_response['success'] print_green_success "Removed Cluster Package #{cluster_package['name']}" else print_red_alert "Error removing cluster package: #{json_response['msg'] || json_response['errors']}" end end return 0 rescue RestClient::Exception => e print_rest_exception(e, ) exit 1 end end |
#update(args) ⇒ Object
340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 |
# File 'lib/morpheus/cli/commands/library_cluster_packages_command.rb', line 340 def update(args) = {} params = {} logo_file = nil dark_logo_file = nil optparse = Morpheus::Cli::OptionParser.new do|opts| opts. = subcommand_usage("[id] [options]") opts.on('-n', '--name VALUE', String, "Name for this cluster package") do |val| params['name'] = val end opts.on('-d', '--description VALUE', String, "Description") do |val| params['description'] = val end opts.on('-c', '--code VALUE', String, "Code") do |val| params['code'] = val end opts.on('-e', '--enabled [on|off]', String, "Can be used to enable / disable package. Default is on") do |val| params['enabled'] = val.to_s == 'on' || val.to_s == 'true' || val.to_s == '1' || val.to_s == '' end opts.on('-r', '--repeatInstall [on|off]', String, "Can be used to retry install package if initial fails") do |val| params['repeatInstall'] = val.to_s == 'on' || val.to_s == 'true' || val.to_s == '1' || val.to_s == '' end opts.on('-t', '--type VALUE', String, "Type") do |val| params['type'] = val end opts.on('-p', '--packageType VALUE', String, "Package Type") do |val| params['packageType'] = val end opts.on('-v', '--packageVersion VALUE', String, "Package Version") do |val| params['packageVersion'] = val end opts.on('--spec-templates [x,y,z]', Array, "List of Spec Templates to include in this package, comma separated list of IDs.") do |list| unless list.nil? params['specTemplates'] = list.collect {|it| it.to_s.strip.empty? ? nil : it.to_s.strip }.compact.uniq end end opts.on('--logo FILE', String, "Upload a custom logo icon") do |val| filename = val logo_file = nil if filename == 'null' logo_file = 'null' # clear it else filename = File.(filename) if !File.exist?(filename) raise_command_error "File not found: #{filename}" end logo_file = File.new(filename, 'rb') end end opts.on('--dark-logo FILE', String, "Upload a custom dark logo icon") do |val| filename = val dark_logo_file = nil if filename == 'null' dark_logo_file = 'null' # clear it else filename = File.(filename) if !File.exist?(filename) raise_command_error "File not found: #{filename}" end dark_logo_file = File.new(filename, 'rb') end end (opts, , [:options, :json, :dry_run, :remote]) opts. = "Update a cluster package." + "\n" + "[id] is required. This is the id of a cluster package." end optparse.parse!(args) connect() if args.count != 1 print_error Morpheus::Terminal.angry_prompt puts_error "wrong number of arguments, expected 1 and got (#{args.count}) #{args.inspect}\n#{optparse}" return 1 end begin cluster_package = find_package_by_id(args[0]) exit 1 if cluster_package.nil? = ([:options] || {}).reject {|k,v| k.is_a?(Symbol) } payload = nil if [:payload] payload = [:payload] else # support the old -O OPTION switch params.deep_merge!([:options].reject {|k,v| k.is_a?(Symbol) }) if [:options] end if params.empty? && !logo_file && !dark_logo_file print_green_success "Nothing to update" exit 1 end payload = {'clusterPackage' => params} if [:dry_run] print_dry_run @library_cluster_packages_interface.dry.update(cluster_package['id'], payload) return 0 end if (logo_file || dark_logo_file) && params.empty? begin @library_cluster_packages_interface.update_logo(cluster_package['id'], logo_file, dark_logo_file) print_green_success "Updated Cluster Package #{params['name'] || cluster_package['name']}" rescue RestClient::Exception => e print_red_alert "Failed to save logo!" print_rest_exception(e, ) end else json_response = @library_cluster_packages_interface.update(cluster_package['id'], payload) if json_response['success'] if logo_file || dark_logo_file begin @library_cluster_packages_interface.update_logo(json_response['id'], logo_file, dark_logo_file) rescue RestClient::Exception => e print_red_alert "Failed to save logo!" print_rest_exception(e, ) end end end if [:json] print JSON.pretty_generate(json_response), "\n" return 0 end print_green_success "Updated Cluster Package #{params['name'] || cluster_package['name']}" end return 0 rescue RestClient::Exception => e print_rest_exception(e, ) return 1 end end |