morpheus-cli 2.10.0 → 2.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/bin/morpheus +27 -32
 - data/lib/morpheus/api/accounts_interface.rb +36 -47
 - data/lib/morpheus/api/api_client.rb +141 -110
 - data/lib/morpheus/api/app_templates_interface.rb +56 -72
 - data/lib/morpheus/api/apps_interface.rb +111 -132
 - data/lib/morpheus/api/auth_interface.rb +30 -0
 - data/lib/morpheus/api/clouds_interface.rb +71 -76
 - data/lib/morpheus/api/custom_instance_types_interface.rb +21 -46
 - data/lib/morpheus/api/dashboard_interface.rb +10 -17
 - data/lib/morpheus/api/deploy_interface.rb +60 -72
 - data/lib/morpheus/api/deployments_interface.rb +53 -71
 - data/lib/morpheus/api/groups_interface.rb +55 -45
 - data/lib/morpheus/api/instance_types_interface.rb +19 -23
 - data/lib/morpheus/api/instances_interface.rb +179 -177
 - data/lib/morpheus/api/key_pairs_interface.rb +11 -17
 - data/lib/morpheus/api/license_interface.rb +18 -23
 - data/lib/morpheus/api/load_balancers_interface.rb +54 -69
 - data/lib/morpheus/api/logs_interface.rb +25 -29
 - data/lib/morpheus/api/options_interface.rb +13 -17
 - data/lib/morpheus/api/provision_types_interface.rb +19 -22
 - data/lib/morpheus/api/roles_interface.rb +75 -94
 - data/lib/morpheus/api/security_group_rules_interface.rb +28 -37
 - data/lib/morpheus/api/security_groups_interface.rb +39 -51
 - data/lib/morpheus/api/servers_interface.rb +113 -115
 - data/lib/morpheus/api/setup_interface.rb +31 -0
 - data/lib/morpheus/api/task_sets_interface.rb +36 -38
 - data/lib/morpheus/api/tasks_interface.rb +56 -69
 - data/lib/morpheus/api/users_interface.rb +67 -76
 - data/lib/morpheus/api/virtual_images_interface.rb +61 -61
 - data/lib/morpheus/api/whoami_interface.rb +12 -15
 - data/lib/morpheus/cli.rb +71 -60
 - data/lib/morpheus/cli/accounts.rb +254 -315
 - data/lib/morpheus/cli/alias_command.rb +219 -0
 - data/lib/morpheus/cli/app_templates.rb +264 -272
 - data/lib/morpheus/cli/apps.rb +608 -671
 - data/lib/morpheus/cli/cli_command.rb +259 -21
 - data/lib/morpheus/cli/cli_registry.rb +99 -14
 - data/lib/morpheus/cli/clouds.rb +599 -372
 - data/lib/morpheus/cli/config_file.rb +126 -0
 - data/lib/morpheus/cli/credentials.rb +141 -117
 - data/lib/morpheus/cli/dashboard_command.rb +48 -56
 - data/lib/morpheus/cli/deployments.rb +254 -268
 - data/lib/morpheus/cli/deploys.rb +150 -142
 - data/lib/morpheus/cli/error_handler.rb +38 -0
 - data/lib/morpheus/cli/groups.rb +551 -179
 - data/lib/morpheus/cli/hosts.rb +862 -617
 - data/lib/morpheus/cli/instance_types.rb +103 -95
 - data/lib/morpheus/cli/instances.rb +1335 -1009
 - data/lib/morpheus/cli/key_pairs.rb +82 -90
 - data/lib/morpheus/cli/library.rb +498 -499
 - data/lib/morpheus/cli/license.rb +83 -101
 - data/lib/morpheus/cli/load_balancers.rb +314 -300
 - data/lib/morpheus/cli/login.rb +66 -44
 - data/lib/morpheus/cli/logout.rb +47 -46
 - data/lib/morpheus/cli/mixins/accounts_helper.rb +69 -31
 - data/lib/morpheus/cli/mixins/infrastructure_helper.rb +106 -0
 - data/lib/morpheus/cli/mixins/print_helper.rb +181 -17
 - data/lib/morpheus/cli/mixins/provisioning_helper.rb +535 -458
 - data/lib/morpheus/cli/mixins/whoami_helper.rb +2 -2
 - data/lib/morpheus/cli/option_parser.rb +35 -0
 - data/lib/morpheus/cli/option_types.rb +232 -192
 - data/lib/morpheus/cli/recent_activity_command.rb +61 -65
 - data/lib/morpheus/cli/remote.rb +446 -199
 - data/lib/morpheus/cli/roles.rb +884 -906
 - data/lib/morpheus/cli/security_group_rules.rb +213 -203
 - data/lib/morpheus/cli/security_groups.rb +237 -192
 - data/lib/morpheus/cli/shell.rb +338 -231
 - data/lib/morpheus/cli/tasks.rb +326 -308
 - data/lib/morpheus/cli/users.rb +457 -462
 - data/lib/morpheus/cli/version.rb +1 -1
 - data/lib/morpheus/cli/version_command.rb +16 -18
 - data/lib/morpheus/cli/virtual_images.rb +526 -345
 - data/lib/morpheus/cli/whoami.rb +125 -111
 - data/lib/morpheus/cli/workflows.rb +338 -185
 - data/lib/morpheus/formatters.rb +8 -1
 - data/lib/morpheus/logging.rb +1 -1
 - data/lib/morpheus/rest_client.rb +17 -8
 - metadata +9 -3
 - data/lib/morpheus/api/custom_instance_types.rb +0 -55
 
    
        data/lib/morpheus/cli/tasks.rb
    CHANGED
    
    | 
         @@ -6,334 +6,352 @@ require 'table_print' 
     | 
|
| 
       6 
6 
     | 
    
         
             
            require 'morpheus/cli/cli_command'
         
     | 
| 
       7 
7 
     | 
    
         | 
| 
       8 
8 
     | 
    
         
             
            class Morpheus::Cli::Tasks
         
     | 
| 
       9 
     | 
    
         
            -
             
     | 
| 
      
 9 
     | 
    
         
            +
              include Morpheus::Cli::CliCommand
         
     | 
| 
       10 
10 
     | 
    
         | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
       12 
     | 
    
         
            -
             
     | 
| 
       13 
     | 
    
         
            -
             
     | 
| 
      
 11 
     | 
    
         
            +
              register_subcommands :list, :get, :add, :update, :remove, :'task-types'
         
     | 
| 
      
 12 
     | 
    
         
            +
              alias_subcommand :details, :get
         
     | 
| 
      
 13 
     | 
    
         
            +
              alias_subcommand :types, :'task-types'
         
     | 
| 
      
 14 
     | 
    
         
            +
              set_default_subcommand :list
         
     | 
| 
      
 15 
     | 
    
         
            +
              
         
     | 
| 
      
 16 
     | 
    
         
            +
              def connect(opts)
         
     | 
| 
      
 17 
     | 
    
         
            +
                @api_client = establish_remote_appliance_connection(opts)
         
     | 
| 
      
 18 
     | 
    
         
            +
                @tasks_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).tasks
         
     | 
| 
      
 19 
     | 
    
         
            +
                @task_sets_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).task_sets
         
     | 
| 
      
 20 
     | 
    
         
            +
              end
         
     | 
| 
       14 
21 
     | 
    
         | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
       16 
     | 
    
         
            -
             
     | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
       18 
     | 
    
         
            -
            			@appliance_name = opts[:remote]
         
     | 
| 
       19 
     | 
    
         
            -
            			@access_token = Morpheus::Cli::Credentials.new(@appliance_name,@appliance_url).request_credentials(opts)
         
     | 
| 
       20 
     | 
    
         
            -
            		else
         
     | 
| 
       21 
     | 
    
         
            -
            			@access_token = Morpheus::Cli::Credentials.new(@appliance_name,@appliance_url).request_credentials(opts)
         
     | 
| 
       22 
     | 
    
         
            -
            		end
         
     | 
| 
       23 
     | 
    
         
            -
            		@api_client = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url)		
         
     | 
| 
       24 
     | 
    
         
            -
            		@tasks_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).tasks
         
     | 
| 
       25 
     | 
    
         
            -
            		@task_sets_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).task_sets
         
     | 
| 
       26 
     | 
    
         
            -
            		if @access_token.empty?
         
     | 
| 
       27 
     | 
    
         
            -
            			print_red_alert "Invalid Credentials. Unable to acquire access token. Please verify your credentials and try again."
         
     | 
| 
       28 
     | 
    
         
            -
            			exit 1
         
     | 
| 
       29 
     | 
    
         
            -
            		end
         
     | 
| 
       30 
     | 
    
         
            -
            	end
         
     | 
| 
      
 22 
     | 
    
         
            +
              def handle(args)
         
     | 
| 
      
 23 
     | 
    
         
            +
                handle_subcommand(args)
         
     | 
| 
      
 24 
     | 
    
         
            +
              end
         
     | 
| 
       31 
25 
     | 
    
         | 
| 
      
 26 
     | 
    
         
            +
              def list(args)
         
     | 
| 
      
 27 
     | 
    
         
            +
                options = {}
         
     | 
| 
      
 28 
     | 
    
         
            +
                optparse = OptionParser.new do|opts|
         
     | 
| 
      
 29 
     | 
    
         
            +
                  opts.banner = subcommand_usage()
         
     | 
| 
      
 30 
     | 
    
         
            +
                  build_common_options(opts, options, [:list, :json, :dry_run, :remote])
         
     | 
| 
      
 31 
     | 
    
         
            +
                end
         
     | 
| 
      
 32 
     | 
    
         
            +
                optparse.parse!(args)
         
     | 
| 
      
 33 
     | 
    
         
            +
                connect(options)
         
     | 
| 
      
 34 
     | 
    
         
            +
                begin
         
     | 
| 
      
 35 
     | 
    
         
            +
                  params = {}
         
     | 
| 
      
 36 
     | 
    
         
            +
                  [:phrase, :offset, :max, :sort, :direction].each do |k|
         
     | 
| 
      
 37 
     | 
    
         
            +
                    params[k] = options[k] unless options[k].nil?
         
     | 
| 
      
 38 
     | 
    
         
            +
                  end
         
     | 
| 
      
 39 
     | 
    
         
            +
                  if options[:dry_run]
         
     | 
| 
      
 40 
     | 
    
         
            +
                    print_dry_run @tasks_interface.dry.get(params)
         
     | 
| 
      
 41 
     | 
    
         
            +
                    return
         
     | 
| 
      
 42 
     | 
    
         
            +
                  end
         
     | 
| 
      
 43 
     | 
    
         
            +
                  json_response = @tasks_interface.get(params)
         
     | 
| 
      
 44 
     | 
    
         
            +
                  if options[:json]
         
     | 
| 
      
 45 
     | 
    
         
            +
                    print JSON.pretty_generate(json_response)
         
     | 
| 
      
 46 
     | 
    
         
            +
                  else
         
     | 
| 
      
 47 
     | 
    
         
            +
                    tasks = json_response['tasks']
         
     | 
| 
      
 48 
     | 
    
         
            +
                    print "\n" ,cyan, bold, "Morpheus Tasks\n","==================", reset, "\n\n"
         
     | 
| 
      
 49 
     | 
    
         
            +
                    if tasks.empty?
         
     | 
| 
      
 50 
     | 
    
         
            +
                      puts yellow,"No tasks currently configured.",reset
         
     | 
| 
      
 51 
     | 
    
         
            +
                    else
         
     | 
| 
      
 52 
     | 
    
         
            +
                      print cyan
         
     | 
| 
      
 53 
     | 
    
         
            +
                      tasks_table_data = tasks.collect do |task|
         
     | 
| 
      
 54 
     | 
    
         
            +
                        {name: task['name'], id: task['id'], type: task['taskType']['name']}
         
     | 
| 
      
 55 
     | 
    
         
            +
                      end
         
     | 
| 
      
 56 
     | 
    
         
            +
                      tp tasks_table_data, :id, :name, :type
         
     | 
| 
      
 57 
     | 
    
         
            +
                      print_results_pagination(json_response)
         
     | 
| 
      
 58 
     | 
    
         
            +
                    end
         
     | 
| 
      
 59 
     | 
    
         
            +
                    print reset,"\n"
         
     | 
| 
      
 60 
     | 
    
         
            +
                  end
         
     | 
| 
      
 61 
     | 
    
         
            +
                rescue RestClient::Exception => e
         
     | 
| 
      
 62 
     | 
    
         
            +
                  print_rest_exception(e, options)
         
     | 
| 
      
 63 
     | 
    
         
            +
                  exit 1
         
     | 
| 
      
 64 
     | 
    
         
            +
                end
         
     | 
| 
      
 65 
     | 
    
         
            +
              end
         
     | 
| 
       32 
66 
     | 
    
         | 
| 
       33 
     | 
    
         
            -
             
     | 
| 
       34 
     | 
    
         
            -
             
     | 
| 
       35 
     | 
    
         
            -
             
     | 
| 
       36 
     | 
    
         
            -
             
     | 
| 
       37 
     | 
    
         
            -
             
     | 
| 
      
 67 
     | 
    
         
            +
              def get(args)
         
     | 
| 
      
 68 
     | 
    
         
            +
                options = {}
         
     | 
| 
      
 69 
     | 
    
         
            +
                optparse = OptionParser.new do|opts|
         
     | 
| 
      
 70 
     | 
    
         
            +
                  opts.banner = subcommand_usage("[task]")
         
     | 
| 
      
 71 
     | 
    
         
            +
                  build_common_options(opts, options, [:json, :dry_run, :remote])
         
     | 
| 
      
 72 
     | 
    
         
            +
                end
         
     | 
| 
      
 73 
     | 
    
         
            +
                optparse.parse!(args)
         
     | 
| 
      
 74 
     | 
    
         
            +
                if args.count < 1
         
     | 
| 
      
 75 
     | 
    
         
            +
                  puts optparse
         
     | 
| 
      
 76 
     | 
    
         
            +
                  exit 1
         
     | 
| 
      
 77 
     | 
    
         
            +
                end
         
     | 
| 
      
 78 
     | 
    
         
            +
                task_name = args[0]
         
     | 
| 
      
 79 
     | 
    
         
            +
                connect(options)
         
     | 
| 
      
 80 
     | 
    
         
            +
                begin
         
     | 
| 
      
 81 
     | 
    
         
            +
                  if options[:dry_run]
         
     | 
| 
      
 82 
     | 
    
         
            +
                    if task_name.to_s =~ /\A\d{1,}\Z/
         
     | 
| 
      
 83 
     | 
    
         
            +
                      print_dry_run @tasks_interface.dry.get(task_name.to_i)
         
     | 
| 
      
 84 
     | 
    
         
            +
                    else
         
     | 
| 
      
 85 
     | 
    
         
            +
                      print_dry_run @tasks_interface.dry.get({name: task_name})
         
     | 
| 
      
 86 
     | 
    
         
            +
                    end
         
     | 
| 
      
 87 
     | 
    
         
            +
                    return
         
     | 
| 
      
 88 
     | 
    
         
            +
                  end
         
     | 
| 
      
 89 
     | 
    
         
            +
                  task = find_task_by_name_or_id(task_name)
         
     | 
| 
      
 90 
     | 
    
         
            +
                  exit 1 if task.nil?
         
     | 
| 
      
 91 
     | 
    
         
            +
                  task_type = find_task_type_by_name(task['taskType']['name'])
         
     | 
| 
      
 92 
     | 
    
         
            +
                  if options[:json]
         
     | 
| 
      
 93 
     | 
    
         
            +
                    puts JSON.pretty_generate({task:task})
         
     | 
| 
      
 94 
     | 
    
         
            +
                    print "\n"
         
     | 
| 
      
 95 
     | 
    
         
            +
                  else
         
     | 
| 
      
 96 
     | 
    
         
            +
                    #print "\n", cyan, "Task #{task['name']} - #{task['taskType']['name']}\n\n"
         
     | 
| 
      
 97 
     | 
    
         
            +
                    print "\n" ,cyan, bold, "Task Details\n","==================", reset, "\n\n"
         
     | 
| 
      
 98 
     | 
    
         
            +
                    print cyan
         
     | 
| 
      
 99 
     | 
    
         
            +
                    puts "ID: #{task['id']}"
         
     | 
| 
      
 100 
     | 
    
         
            +
                    puts "Name: #{task['name']}"
         
     | 
| 
      
 101 
     | 
    
         
            +
                    puts "Type: #{task['taskType']['name']}"
         
     | 
| 
      
 102 
     | 
    
         
            +
                    #puts "Description: #{workflow['description']}"
         
     | 
| 
      
 103 
     | 
    
         
            +
                    # print "\n", cyan, "Config:\n"
         
     | 
| 
      
 104 
     | 
    
         
            +
                    task_type['optionTypes'].sort { |x,y| x['displayOrder'].to_i <=> y['displayOrder'].to_i }.each do |optionType|
         
     | 
| 
      
 105 
     | 
    
         
            +
                      if optionType['fieldLabel'].to_s.downcase == 'script'
         
     | 
| 
      
 106 
     | 
    
         
            +
                        print cyan,bold,"Script:","\n",reset,bright_black,"#{task['taskOptions'][optionType['fieldName']]}","\n",reset
         
     | 
| 
      
 107 
     | 
    
         
            +
                      else
         
     | 
| 
      
 108 
     | 
    
         
            +
                        print cyan,("#{optionType['fieldLabel']} : " + (optionType['type'] == 'password' ? "#{task['taskOptions'][optionType['fieldName']] ? '************' : ''}" : "#{task['taskOptions'][optionType['fieldName']] || optionType['defaultValue']}")),"\n"
         
     | 
| 
      
 109 
     | 
    
         
            +
                      end
         
     | 
| 
      
 110 
     | 
    
         
            +
                    end
         
     | 
| 
      
 111 
     | 
    
         
            +
                    print reset,"\n"
         
     | 
| 
      
 112 
     | 
    
         
            +
                  end
         
     | 
| 
      
 113 
     | 
    
         
            +
                rescue RestClient::Exception => e
         
     | 
| 
      
 114 
     | 
    
         
            +
                  print_rest_exception(e, options)
         
     | 
| 
      
 115 
     | 
    
         
            +
                  exit 1
         
     | 
| 
      
 116 
     | 
    
         
            +
                end
         
     | 
| 
      
 117 
     | 
    
         
            +
              end
         
     | 
| 
       38 
118 
     | 
    
         | 
| 
       39 
     | 
    
         
            -
             
     | 
| 
       40 
     | 
    
         
            -
             
     | 
| 
       41 
     | 
    
         
            -
             
     | 
| 
       42 
     | 
    
         
            -
             
     | 
| 
       43 
     | 
    
         
            -
             
     | 
| 
       44 
     | 
    
         
            -
             
     | 
| 
       45 
     | 
    
         
            -
             
     | 
| 
       46 
     | 
    
         
            -
             
     | 
| 
       47 
     | 
    
         
            -
             
     | 
| 
       48 
     | 
    
         
            -
             
     | 
| 
       49 
     | 
    
         
            -
             
     | 
| 
       50 
     | 
    
         
            -
             
     | 
| 
       51 
     | 
    
         
            -
             
     | 
| 
       52 
     | 
    
         
            -
             
     | 
| 
       53 
     | 
    
         
            -
             
     | 
| 
       54 
     | 
    
         
            -
            				exit 127
         
     | 
| 
       55 
     | 
    
         
            -
            		end
         
     | 
| 
       56 
     | 
    
         
            -
            	end
         
     | 
| 
      
 119 
     | 
    
         
            +
              def update(args)
         
     | 
| 
      
 120 
     | 
    
         
            +
                options = {}
         
     | 
| 
      
 121 
     | 
    
         
            +
                account_name = nil
         
     | 
| 
      
 122 
     | 
    
         
            +
                optparse = OptionParser.new do|opts|
         
     | 
| 
      
 123 
     | 
    
         
            +
                  opts.banner = subcommand_usage("[task] [options]")
         
     | 
| 
      
 124 
     | 
    
         
            +
                  build_common_options(opts, options, [:options, :json, :dry_run, :remote])
         
     | 
| 
      
 125 
     | 
    
         
            +
                end
         
     | 
| 
      
 126 
     | 
    
         
            +
                optparse.parse!(args)
         
     | 
| 
      
 127 
     | 
    
         
            +
                if args.count < 1
         
     | 
| 
      
 128 
     | 
    
         
            +
                  puts optparse
         
     | 
| 
      
 129 
     | 
    
         
            +
                  exit 1
         
     | 
| 
      
 130 
     | 
    
         
            +
                end
         
     | 
| 
      
 131 
     | 
    
         
            +
                task_name = args[0]
         
     | 
| 
      
 132 
     | 
    
         
            +
                connect(options)
         
     | 
| 
      
 133 
     | 
    
         
            +
                begin
         
     | 
| 
       57 
134 
     | 
    
         | 
| 
       58 
     | 
    
         
            -
            	def list(args)
         
     | 
| 
       59 
     | 
    
         
            -
            		options = {}
         
     | 
| 
       60 
     | 
    
         
            -
            		optparse = OptionParser.new do|opts|
         
     | 
| 
       61 
     | 
    
         
            -
            			opts.banner = "Usage: morpheus tasks list [-s] [-o] [-m]"
         
     | 
| 
       62 
     | 
    
         
            -
            			build_common_options(opts, options, [:list, :json, :remote])
         
     | 
| 
       63 
     | 
    
         
            -
            		end
         
     | 
| 
       64 
     | 
    
         
            -
            		optparse.parse(args)
         
     | 
| 
       65 
     | 
    
         
            -
            		connect(options)
         
     | 
| 
       66 
     | 
    
         
            -
            		begin
         
     | 
| 
       67 
     | 
    
         
            -
            			params = {}
         
     | 
| 
       68 
     | 
    
         
            -
            			[:phrase, :offset, :max, :sort, :direction].each do |k|
         
     | 
| 
       69 
     | 
    
         
            -
            				params[k] = options[k] unless options[k].nil?
         
     | 
| 
       70 
     | 
    
         
            -
            			end
         
     | 
| 
       71 
     | 
    
         
            -
            			json_response = @tasks_interface.get(params)
         
     | 
| 
       72 
     | 
    
         
            -
            			if options[:json]
         
     | 
| 
       73 
     | 
    
         
            -
            					print JSON.pretty_generate(json_response)
         
     | 
| 
       74 
     | 
    
         
            -
            			else
         
     | 
| 
       75 
     | 
    
         
            -
            				tasks = json_response['tasks']
         
     | 
| 
       76 
     | 
    
         
            -
            				print "\n" ,cyan, bold, "Morpheus Tasks\n","==================", reset, "\n\n"
         
     | 
| 
       77 
     | 
    
         
            -
            				if tasks.empty?
         
     | 
| 
       78 
     | 
    
         
            -
            					puts yellow,"No tasks currently configured.",reset
         
     | 
| 
       79 
     | 
    
         
            -
            				else
         
     | 
| 
       80 
     | 
    
         
            -
            					print cyan
         
     | 
| 
       81 
     | 
    
         
            -
            					tasks_table_data = tasks.collect do |task|
         
     | 
| 
       82 
     | 
    
         
            -
            						{name: task['name'], id: task['id'], type: task['taskType']['name']}
         
     | 
| 
       83 
     | 
    
         
            -
            					end
         
     | 
| 
       84 
     | 
    
         
            -
            					tp tasks_table_data, :id, :name, :type
         
     | 
| 
       85 
     | 
    
         
            -
            				end
         
     | 
| 
       86 
     | 
    
         
            -
            				print reset,"\n\n"
         
     | 
| 
       87 
     | 
    
         
            -
            			end
         
     | 
| 
       88 
     | 
    
         
            -
            			
         
     | 
| 
       89 
     | 
    
         
            -
            			
         
     | 
| 
       90 
     | 
    
         
            -
            		rescue RestClient::Exception => e
         
     | 
| 
       91 
     | 
    
         
            -
            			print_rest_exception(e, options)
         
     | 
| 
       92 
     | 
    
         
            -
            			exit 1
         
     | 
| 
       93 
     | 
    
         
            -
            		end
         
     | 
| 
       94 
     | 
    
         
            -
            	end
         
     | 
| 
       95 
135 
     | 
    
         | 
| 
       96 
     | 
    
         
            -
             
     | 
| 
       97 
     | 
    
         
            -
             
     | 
| 
       98 
     | 
    
         
            -
             
     | 
| 
       99 
     | 
    
         
            -
            		optparse = OptionParser.new do|opts|
         
     | 
| 
       100 
     | 
    
         
            -
            			opts.banner = "Usage: morpheus tasks details [task]"
         
     | 
| 
       101 
     | 
    
         
            -
            			build_common_options(opts, options, [:json, :remote])
         
     | 
| 
       102 
     | 
    
         
            -
            		end
         
     | 
| 
       103 
     | 
    
         
            -
            		if args.count < 1
         
     | 
| 
       104 
     | 
    
         
            -
            			puts "\n#{optparse.banner}\n\n"
         
     | 
| 
       105 
     | 
    
         
            -
            			exit 1
         
     | 
| 
       106 
     | 
    
         
            -
            		end
         
     | 
| 
       107 
     | 
    
         
            -
            		optparse.parse(args)
         
     | 
| 
       108 
     | 
    
         
            -
            		connect(options)
         
     | 
| 
       109 
     | 
    
         
            -
            		begin
         
     | 
| 
       110 
     | 
    
         
            -
            			task = find_task_by_name_or_code_or_id(task_name)
         
     | 
| 
      
 136 
     | 
    
         
            +
                  task = find_task_by_name_or_id(task_name)
         
     | 
| 
      
 137 
     | 
    
         
            +
                  exit 1 if task.nil?
         
     | 
| 
      
 138 
     | 
    
         
            +
                  task_type = find_task_type_by_name(task['taskType']['name'])
         
     | 
| 
       111 
139 
     | 
    
         | 
| 
       112 
     | 
    
         
            -
             
     | 
| 
       113 
     | 
    
         
            -
             
     | 
| 
       114 
     | 
    
         
            -
            			if options[:json]
         
     | 
| 
       115 
     | 
    
         
            -
            					puts JSON.pretty_generate({task:task})
         
     | 
| 
       116 
     | 
    
         
            -
            			else
         
     | 
| 
       117 
     | 
    
         
            -
            				print "\n", cyan, "Task #{task['name']} - #{task['taskType']['name']}\n\n"
         
     | 
| 
       118 
     | 
    
         
            -
            				task_type['optionTypes'].sort { |x,y| x['displayOrder'].to_i <=> y['displayOrder'].to_i }.each do |optionType|
         
     | 
| 
       119 
     | 
    
         
            -
            					puts "  #{optionType['fieldLabel']} : " + (optionType['type'] == 'password' ? "#{task['taskOptions'][optionType['fieldName']] ? '************' : ''}" : "#{task['taskOptions'][optionType['fieldName']] || optionType['defaultValue']}")
         
     | 
| 
       120 
     | 
    
         
            -
            				end
         
     | 
| 
       121 
     | 
    
         
            -
            				print reset,"\n\n"
         
     | 
| 
       122 
     | 
    
         
            -
            			end
         
     | 
| 
       123 
     | 
    
         
            -
            		rescue RestClient::Exception => e
         
     | 
| 
       124 
     | 
    
         
            -
            			print_rest_exception(e, options)
         
     | 
| 
       125 
     | 
    
         
            -
            			exit 1
         
     | 
| 
       126 
     | 
    
         
            -
            		end
         
     | 
| 
       127 
     | 
    
         
            -
            	end
         
     | 
| 
      
 140 
     | 
    
         
            +
                  #params = Morpheus::Cli::OptionTypes.prompt(add_user_option_types, options[:options], @api_client, options[:params]) # options[:params] is mysterious
         
     | 
| 
      
 141 
     | 
    
         
            +
                  params = options[:options] || {}
         
     | 
| 
       128 
142 
     | 
    
         | 
| 
       129 
     | 
    
         
            -
             
     | 
| 
       130 
     | 
    
         
            -
             
     | 
| 
       131 
     | 
    
         
            -
             
     | 
| 
       132 
     | 
    
         
            -
             
     | 
| 
       133 
     | 
    
         
            -
             
     | 
| 
       134 
     | 
    
         
            -
             
     | 
| 
       135 
     | 
    
         
            -
            			build_common_options(opts, options, [:options, :json, :remote])
         
     | 
| 
       136 
     | 
    
         
            -
            		end
         
     | 
| 
       137 
     | 
    
         
            -
            		if args.count < 1
         
     | 
| 
       138 
     | 
    
         
            -
            			puts "\n#{optparse.banner}\n\n"
         
     | 
| 
       139 
     | 
    
         
            -
            			exit 1
         
     | 
| 
       140 
     | 
    
         
            -
            		end
         
     | 
| 
       141 
     | 
    
         
            -
            		optparse.parse(args)
         
     | 
| 
      
 143 
     | 
    
         
            +
                  if params.empty?
         
     | 
| 
      
 144 
     | 
    
         
            +
                    puts optparse.banner
         
     | 
| 
      
 145 
     | 
    
         
            +
                    option_lines = update_task_option_types(task_type).collect {|it| "\t-O #{it['fieldContext'] ? (it['fieldContext'] + '.') : ''}#{it['fieldName']}=\"value\"" }.join("\n")
         
     | 
| 
      
 146 
     | 
    
         
            +
                    puts "\nAvailable Options:\n#{option_lines}\n\n"
         
     | 
| 
      
 147 
     | 
    
         
            +
                    exit 1
         
     | 
| 
      
 148 
     | 
    
         
            +
                  end
         
     | 
| 
       142 
149 
     | 
    
         | 
| 
       143 
     | 
    
         
            -
             
     | 
| 
       144 
     | 
    
         
            -
             
     | 
| 
       145 
     | 
    
         
            -
             
     | 
| 
      
 150 
     | 
    
         
            +
                  #puts "parsed params is : #{params.inspect}"
         
     | 
| 
      
 151 
     | 
    
         
            +
                  task_keys = ['name']
         
     | 
| 
      
 152 
     | 
    
         
            +
                  changes_payload = (params.select {|k,v| task_keys.include?(k) })
         
     | 
| 
      
 153 
     | 
    
         
            +
                  task_payload = task
         
     | 
| 
      
 154 
     | 
    
         
            +
                  if changes_payload
         
     | 
| 
      
 155 
     | 
    
         
            +
                    task_payload.merge!(changes_payload)
         
     | 
| 
      
 156 
     | 
    
         
            +
                  end
         
     | 
| 
      
 157 
     | 
    
         
            +
                  if params['taskOptions']
         
     | 
| 
      
 158 
     | 
    
         
            +
                    task_payload['taskOptions'].merge!(params['taskOptions'])
         
     | 
| 
      
 159 
     | 
    
         
            +
                  end
         
     | 
| 
       146 
160 
     | 
    
         | 
| 
      
 161 
     | 
    
         
            +
                  payload = {task: task_payload}
         
     | 
| 
      
 162 
     | 
    
         
            +
                  if options[:dry_run]
         
     | 
| 
      
 163 
     | 
    
         
            +
                    print_dry_run @tasks_interface.dry.update(task['id'], payload)
         
     | 
| 
      
 164 
     | 
    
         
            +
                    return
         
     | 
| 
      
 165 
     | 
    
         
            +
                  end
         
     | 
| 
      
 166 
     | 
    
         
            +
                  response = @tasks_interface.update(task['id'], payload)
         
     | 
| 
      
 167 
     | 
    
         
            +
                  if options[:json]
         
     | 
| 
      
 168 
     | 
    
         
            +
                    print JSON.pretty_generate(json_response)
         
     | 
| 
      
 169 
     | 
    
         
            +
                    if !response['success']
         
     | 
| 
      
 170 
     | 
    
         
            +
                      exit 1
         
     | 
| 
      
 171 
     | 
    
         
            +
                    end
         
     | 
| 
      
 172 
     | 
    
         
            +
                  else
         
     | 
| 
      
 173 
     | 
    
         
            +
                    print "\n", cyan, "Task #{response['task']['name']} updated", reset, "\n\n"
         
     | 
| 
      
 174 
     | 
    
         
            +
                    get([task['id']])
         
     | 
| 
      
 175 
     | 
    
         
            +
                  end
         
     | 
| 
      
 176 
     | 
    
         
            +
                rescue RestClient::Exception => e
         
     | 
| 
      
 177 
     | 
    
         
            +
                  print_rest_exception(e, options)
         
     | 
| 
      
 178 
     | 
    
         
            +
                  exit 1
         
     | 
| 
      
 179 
     | 
    
         
            +
                end
         
     | 
| 
      
 180 
     | 
    
         
            +
              end
         
     | 
| 
       147 
181 
     | 
    
         | 
| 
       148 
     | 
    
         
            -
            			task = find_task_by_name_or_code_or_id(task_name)
         
     | 
| 
       149 
     | 
    
         
            -
            			exit 1 if task.nil?
         
     | 
| 
       150 
     | 
    
         
            -
            			task_type = find_task_type_by_name(task['taskType']['name'])
         
     | 
| 
       151 
182 
     | 
    
         | 
| 
       152 
     | 
    
         
            -
             
     | 
| 
       153 
     | 
    
         
            -
             
     | 
| 
      
 183 
     | 
    
         
            +
              def task_types(args)
         
     | 
| 
      
 184 
     | 
    
         
            +
                options = {}
         
     | 
| 
      
 185 
     | 
    
         
            +
                optparse = OptionParser.new do|opts|
         
     | 
| 
      
 186 
     | 
    
         
            +
                  opts.banner = subcommand_usage()
         
     | 
| 
      
 187 
     | 
    
         
            +
                  build_common_options(opts, options, [:json, :dry_run, :remote])
         
     | 
| 
      
 188 
     | 
    
         
            +
                end
         
     | 
| 
      
 189 
     | 
    
         
            +
                optparse.parse!(args)
         
     | 
| 
      
 190 
     | 
    
         
            +
                connect(options)
         
     | 
| 
      
 191 
     | 
    
         
            +
                begin
         
     | 
| 
      
 192 
     | 
    
         
            +
                  if options[:dry_run]
         
     | 
| 
      
 193 
     | 
    
         
            +
                    print_dry_run @tasks_interface.dry.task_types()
         
     | 
| 
      
 194 
     | 
    
         
            +
                    return
         
     | 
| 
      
 195 
     | 
    
         
            +
                  end
         
     | 
| 
      
 196 
     | 
    
         
            +
                  json_response = @tasks_interface.task_types()
         
     | 
| 
      
 197 
     | 
    
         
            +
                  if options[:json]
         
     | 
| 
      
 198 
     | 
    
         
            +
                    print JSON.pretty_generate(json_response)
         
     | 
| 
      
 199 
     | 
    
         
            +
                  else
         
     | 
| 
      
 200 
     | 
    
         
            +
                    task_types = json_response['taskTypes']
         
     | 
| 
      
 201 
     | 
    
         
            +
                    print "\n" ,cyan, bold, "Morpheus Task Types\n","==================", reset, "\n\n"
         
     | 
| 
      
 202 
     | 
    
         
            +
                    if task_types.nil? || task_types.empty?
         
     | 
| 
      
 203 
     | 
    
         
            +
                      puts yellow,"No task types currently exist on this appliance. This could be a seed issue.",reset
         
     | 
| 
      
 204 
     | 
    
         
            +
                    else
         
     | 
| 
      
 205 
     | 
    
         
            +
                      print cyan
         
     | 
| 
      
 206 
     | 
    
         
            +
                      tasks_table_data = task_types.collect do |task_type|
         
     | 
| 
      
 207 
     | 
    
         
            +
                        {name: task_type['name'], id: task_type['id'], code: task_type['code'], description: task_type['description']}
         
     | 
| 
      
 208 
     | 
    
         
            +
                      end
         
     | 
| 
      
 209 
     | 
    
         
            +
                      tp tasks_table_data, :id, :name, :code, :description
         
     | 
| 
      
 210 
     | 
    
         
            +
                    end
         
     | 
| 
       154 
211 
     | 
    
         | 
| 
       155 
     | 
    
         
            -
             
     | 
| 
       156 
     | 
    
         
            -
             
     | 
| 
       157 
     | 
    
         
            -
             
     | 
| 
       158 
     | 
    
         
            -
             
     | 
| 
       159 
     | 
    
         
            -
             
     | 
| 
       160 
     | 
    
         
            -
             
     | 
| 
      
 212 
     | 
    
         
            +
                    print reset,"\n"
         
     | 
| 
      
 213 
     | 
    
         
            +
                  end
         
     | 
| 
      
 214 
     | 
    
         
            +
                rescue RestClient::Exception => e
         
     | 
| 
      
 215 
     | 
    
         
            +
                  print_rest_exception(e, options)
         
     | 
| 
      
 216 
     | 
    
         
            +
                  exit 1
         
     | 
| 
      
 217 
     | 
    
         
            +
                end
         
     | 
| 
      
 218 
     | 
    
         
            +
              end
         
     | 
| 
       161 
219 
     | 
    
         | 
| 
       162 
     | 
    
         
            -
             
     | 
| 
       163 
     | 
    
         
            -
             
     | 
| 
       164 
     | 
    
         
            -
             
     | 
| 
       165 
     | 
    
         
            -
             
     | 
| 
       166 
     | 
    
         
            -
             
     | 
| 
       167 
     | 
    
         
            -
             
     | 
| 
       168 
     | 
    
         
            -
             
     | 
| 
       169 
     | 
    
         
            -
             
     | 
| 
       170 
     | 
    
         
            -
             
     | 
| 
       171 
     | 
    
         
            -
             
     | 
| 
      
 220 
     | 
    
         
            +
              def add(args)
         
     | 
| 
      
 221 
     | 
    
         
            +
                options = {}
         
     | 
| 
      
 222 
     | 
    
         
            +
                task_type_name = nil
         
     | 
| 
      
 223 
     | 
    
         
            +
                optparse = OptionParser.new do|opts|
         
     | 
| 
      
 224 
     | 
    
         
            +
                  opts.banner = subcommand_usage("[name] -t TASK_TYPE")
         
     | 
| 
      
 225 
     | 
    
         
            +
                  opts.on( '-t', '--type TASK_TYPE', "Task Type" ) do |val|
         
     | 
| 
      
 226 
     | 
    
         
            +
                    task_type_name = val
         
     | 
| 
      
 227 
     | 
    
         
            +
                  end
         
     | 
| 
      
 228 
     | 
    
         
            +
                  build_common_options(opts, options, [:options, :json, :dry_run, :quiet, :remote])
         
     | 
| 
      
 229 
     | 
    
         
            +
                end
         
     | 
| 
      
 230 
     | 
    
         
            +
                optparse.parse!(args)
         
     | 
| 
      
 231 
     | 
    
         
            +
                task_name = args[0]
         
     | 
| 
      
 232 
     | 
    
         
            +
                if args.count < 1 || task_type_name.nil?
         
     | 
| 
      
 233 
     | 
    
         
            +
                  puts optparse
         
     | 
| 
      
 234 
     | 
    
         
            +
                  exit 1
         
     | 
| 
      
 235 
     | 
    
         
            +
                end
         
     | 
| 
      
 236 
     | 
    
         
            +
                connect(options)
         
     | 
| 
      
 237 
     | 
    
         
            +
                begin
         
     | 
| 
      
 238 
     | 
    
         
            +
                  task_type = find_task_type_by_name(task_type_name)
         
     | 
| 
      
 239 
     | 
    
         
            +
                  if task_type.nil?
         
     | 
| 
      
 240 
     | 
    
         
            +
                    puts "Task Type not found!"
         
     | 
| 
      
 241 
     | 
    
         
            +
                    exit 1
         
     | 
| 
      
 242 
     | 
    
         
            +
                  end
         
     | 
| 
      
 243 
     | 
    
         
            +
                  input_options = Morpheus::Cli::OptionTypes.prompt(task_type['optionTypes'],options[:options],@api_client, options[:params])
         
     | 
| 
      
 244 
     | 
    
         
            +
                  payload = {task: {name: task_name, taskOptions: input_options['taskOptions'], taskType: {code: task_type['code'], id: task_type['id']}}}
         
     | 
| 
      
 245 
     | 
    
         
            +
                  if options[:dry_run]
         
     | 
| 
      
 246 
     | 
    
         
            +
                    print_dry_run @tasks_interface.dry.create(payload)
         
     | 
| 
      
 247 
     | 
    
         
            +
                    return
         
     | 
| 
      
 248 
     | 
    
         
            +
                  end
         
     | 
| 
      
 249 
     | 
    
         
            +
                  json_response = @tasks_interface.create(payload)
         
     | 
| 
      
 250 
     | 
    
         
            +
                  if options[:json]
         
     | 
| 
      
 251 
     | 
    
         
            +
                    print JSON.pretty_generate(json_response)
         
     | 
| 
      
 252 
     | 
    
         
            +
                  elsif !options[:quiet]
         
     | 
| 
      
 253 
     | 
    
         
            +
                    print "\n", cyan, "Task #{json_response['task']['name']} created successfully", reset, "\n\n"
         
     | 
| 
      
 254 
     | 
    
         
            +
                    list([])
         
     | 
| 
      
 255 
     | 
    
         
            +
                  end
         
     | 
| 
      
 256 
     | 
    
         
            +
                rescue RestClient::Exception => e
         
     | 
| 
      
 257 
     | 
    
         
            +
                  print_rest_exception(e, options)
         
     | 
| 
      
 258 
     | 
    
         
            +
                  exit 1
         
     | 
| 
      
 259 
     | 
    
         
            +
                end
         
     | 
| 
      
 260 
     | 
    
         
            +
              end
         
     | 
| 
       172 
261 
     | 
    
         | 
| 
       173 
     | 
    
         
            -
             
     | 
| 
       174 
     | 
    
         
            -
             
     | 
| 
       175 
     | 
    
         
            -
             
     | 
| 
       176 
     | 
    
         
            -
             
     | 
| 
       177 
     | 
    
         
            -
             
     | 
| 
       178 
     | 
    
         
            -
             
     | 
| 
       179 
     | 
    
         
            -
             
     | 
| 
       180 
     | 
    
         
            -
             
     | 
| 
       181 
     | 
    
         
            -
             
     | 
| 
       182 
     | 
    
         
            -
             
     | 
| 
       183 
     | 
    
         
            -
             
     | 
| 
       184 
     | 
    
         
            -
             
     | 
| 
       185 
     | 
    
         
            -
             
     | 
| 
       186 
     | 
    
         
            -
             
     | 
| 
       187 
     | 
    
         
            -
             
     | 
| 
      
 262 
     | 
    
         
            +
              def remove(args)
         
     | 
| 
      
 263 
     | 
    
         
            +
                task_name = args[0]
         
     | 
| 
      
 264 
     | 
    
         
            +
                options = {}
         
     | 
| 
      
 265 
     | 
    
         
            +
                optparse = OptionParser.new do|opts|
         
     | 
| 
      
 266 
     | 
    
         
            +
                  opts.banner = subcommand_usage("[task]")
         
     | 
| 
      
 267 
     | 
    
         
            +
                  build_common_options(opts, options, [:auto_confirm, :json, :dry_run, :quiet, :remote])
         
     | 
| 
      
 268 
     | 
    
         
            +
                end
         
     | 
| 
      
 269 
     | 
    
         
            +
                optparse.parse!(args)
         
     | 
| 
      
 270 
     | 
    
         
            +
                if args.count < 1
         
     | 
| 
      
 271 
     | 
    
         
            +
                  puts optparse
         
     | 
| 
      
 272 
     | 
    
         
            +
                  exit 1
         
     | 
| 
      
 273 
     | 
    
         
            +
                end
         
     | 
| 
      
 274 
     | 
    
         
            +
                connect(options)
         
     | 
| 
      
 275 
     | 
    
         
            +
                begin
         
     | 
| 
      
 276 
     | 
    
         
            +
                  task = find_task_by_name_or_id(task_name)
         
     | 
| 
      
 277 
     | 
    
         
            +
                  exit 1 if task.nil?
         
     | 
| 
      
 278 
     | 
    
         
            +
                  unless options[:yes] || Morpheus::Cli::OptionTypes.confirm("Are you sure you want to delete the task #{task['name']}?")
         
     | 
| 
      
 279 
     | 
    
         
            +
                    exit
         
     | 
| 
      
 280 
     | 
    
         
            +
                  end
         
     | 
| 
      
 281 
     | 
    
         
            +
                  if options[:dry_run]
         
     | 
| 
      
 282 
     | 
    
         
            +
                    print_dry_run @tasks_interface.dry.destroy(task['id'])
         
     | 
| 
      
 283 
     | 
    
         
            +
                    return
         
     | 
| 
      
 284 
     | 
    
         
            +
                  end
         
     | 
| 
      
 285 
     | 
    
         
            +
                  json_response = @tasks_interface.destroy(task['id'])
         
     | 
| 
      
 286 
     | 
    
         
            +
                  if options[:json]
         
     | 
| 
      
 287 
     | 
    
         
            +
                    print JSON.pretty_generate(json_response)
         
     | 
| 
      
 288 
     | 
    
         
            +
                  elsif !options[:quiet]
         
     | 
| 
      
 289 
     | 
    
         
            +
                    print "\n", cyan, "Task #{task['name']} removed", reset, "\n\n"
         
     | 
| 
      
 290 
     | 
    
         
            +
                  end
         
     | 
| 
      
 291 
     | 
    
         
            +
                rescue RestClient::Exception => e
         
     | 
| 
      
 292 
     | 
    
         
            +
                  print_rest_exception(e, options)
         
     | 
| 
      
 293 
     | 
    
         
            +
                  exit 1
         
     | 
| 
      
 294 
     | 
    
         
            +
                end
         
     | 
| 
      
 295 
     | 
    
         
            +
              end
         
     | 
| 
       188 
296 
     | 
    
         | 
| 
       189 
297 
     | 
    
         | 
| 
       190 
     | 
    
         
            -
             
     | 
| 
       191 
     | 
    
         
            -
             
     | 
| 
       192 
     | 
    
         
            -
             
     | 
| 
       193 
     | 
    
         
            -
             
     | 
| 
       194 
     | 
    
         
            -
             
     | 
| 
       195 
     | 
    
         
            -
             
     | 
| 
       196 
     | 
    
         
            -
             
     | 
| 
       197 
     | 
    
         
            -
             
     | 
| 
       198 
     | 
    
         
            -
            		begin
         
     | 
| 
       199 
     | 
    
         
            -
            			json_response = @tasks_interface.task_types()
         
     | 
| 
       200 
     | 
    
         
            -
            			if options[:json]
         
     | 
| 
       201 
     | 
    
         
            -
            					print JSON.pretty_generate(json_response)
         
     | 
| 
       202 
     | 
    
         
            -
            			else
         
     | 
| 
       203 
     | 
    
         
            -
            				task_types = json_response['taskTypes']
         
     | 
| 
       204 
     | 
    
         
            -
            				print "\n" ,cyan, bold, "Morpheus Task Types\n","==================", reset, "\n\n"
         
     | 
| 
       205 
     | 
    
         
            -
            				if task_types.nil? || task_types.empty?
         
     | 
| 
       206 
     | 
    
         
            -
            					puts yellow,"No task types currently exist on this appliance. This could be a seed issue.",reset
         
     | 
| 
       207 
     | 
    
         
            -
            				else
         
     | 
| 
       208 
     | 
    
         
            -
            					print cyan
         
     | 
| 
       209 
     | 
    
         
            -
            					tasks_table_data = task_types.collect do |task_type|
         
     | 
| 
       210 
     | 
    
         
            -
            						{name: task_type['name'], id: task_type['id'], code: task_type['code'], description: task_type['description']}
         
     | 
| 
       211 
     | 
    
         
            -
            					end
         
     | 
| 
       212 
     | 
    
         
            -
            					tp tasks_table_data, :id, :name, :code, :description
         
     | 
| 
       213 
     | 
    
         
            -
            				end
         
     | 
| 
      
 298 
     | 
    
         
            +
              private
         
     | 
| 
      
 299 
     | 
    
         
            +
              def find_task_by_name_or_id(val)
         
     | 
| 
      
 300 
     | 
    
         
            +
                if val.to_s =~ /\A\d{1,}\Z/
         
     | 
| 
      
 301 
     | 
    
         
            +
                  return find_task_by_id(val)
         
     | 
| 
      
 302 
     | 
    
         
            +
                else
         
     | 
| 
      
 303 
     | 
    
         
            +
                  return find_task_by_name(val)
         
     | 
| 
      
 304 
     | 
    
         
            +
                end
         
     | 
| 
      
 305 
     | 
    
         
            +
              end
         
     | 
| 
       214 
306 
     | 
    
         | 
| 
       215 
     | 
    
         
            -
             
     | 
| 
       216 
     | 
    
         
            -
             
     | 
| 
       217 
     | 
    
         
            -
             
     | 
| 
       218 
     | 
    
         
            -
             
     | 
| 
       219 
     | 
    
         
            -
             
     | 
| 
       220 
     | 
    
         
            -
             
     | 
| 
       221 
     | 
    
         
            -
             
     | 
| 
       222 
     | 
    
         
            -
             
     | 
| 
       223 
     | 
    
         
            -
             
     | 
| 
      
 307 
     | 
    
         
            +
              def find_task_by_id(id)
         
     | 
| 
      
 308 
     | 
    
         
            +
                begin
         
     | 
| 
      
 309 
     | 
    
         
            +
                  json_response = @tasks_interface.get(id.to_i)
         
     | 
| 
      
 310 
     | 
    
         
            +
                  return json_response['task']
         
     | 
| 
      
 311 
     | 
    
         
            +
                rescue RestClient::Exception => e
         
     | 
| 
      
 312 
     | 
    
         
            +
                  if e.response && e.response.code == 404
         
     | 
| 
      
 313 
     | 
    
         
            +
                    print_red_alert "Task not found by id #{id}"
         
     | 
| 
      
 314 
     | 
    
         
            +
                  else
         
     | 
| 
      
 315 
     | 
    
         
            +
                    raise e
         
     | 
| 
      
 316 
     | 
    
         
            +
                  end
         
     | 
| 
      
 317 
     | 
    
         
            +
                end
         
     | 
| 
      
 318 
     | 
    
         
            +
              end
         
     | 
| 
       224 
319 
     | 
    
         | 
| 
       225 
     | 
    
         
            -
             
     | 
| 
       226 
     | 
    
         
            -
             
     | 
| 
       227 
     | 
    
         
            -
             
     | 
| 
       228 
     | 
    
         
            -
             
     | 
| 
       229 
     | 
    
         
            -
             
     | 
| 
       230 
     | 
    
         
            -
             
     | 
| 
       231 
     | 
    
         
            -
             
     | 
| 
       232 
     | 
    
         
            -
             
     | 
| 
       233 
     | 
    
         
            -
             
     | 
| 
       234 
     | 
    
         
            -
             
     | 
| 
       235 
     | 
    
         
            -
             
     | 
| 
       236 
     | 
    
         
            -
             
     | 
| 
       237 
     | 
    
         
            -
             
     | 
| 
       238 
     | 
    
         
            -
             
     | 
| 
       239 
     | 
    
         
            -
            		end
         
     | 
| 
       240 
     | 
    
         
            -
            		optparse.parse(args)
         
     | 
| 
       241 
     | 
    
         
            -
            		connect(options)
         
     | 
| 
      
 320 
     | 
    
         
            +
              def find_task_by_name(name)
         
     | 
| 
      
 321 
     | 
    
         
            +
                tasks = @tasks_interface.get({name: name.to_s})['tasks']
         
     | 
| 
      
 322 
     | 
    
         
            +
                if tasks.empty?
         
     | 
| 
      
 323 
     | 
    
         
            +
                  print_red_alert "Task not found by name #{name}"
         
     | 
| 
      
 324 
     | 
    
         
            +
                  return nil
         
     | 
| 
      
 325 
     | 
    
         
            +
                elsif tasks.size > 1
         
     | 
| 
      
 326 
     | 
    
         
            +
                  print_red_alert "#{tasks.size} tasks by name #{name}"
         
     | 
| 
      
 327 
     | 
    
         
            +
                  print_tasks_table(tasks, {color: red})
         
     | 
| 
      
 328 
     | 
    
         
            +
                  print reset,"\n\n"
         
     | 
| 
      
 329 
     | 
    
         
            +
                  return nil
         
     | 
| 
      
 330 
     | 
    
         
            +
                else
         
     | 
| 
      
 331 
     | 
    
         
            +
                  return tasks[0]
         
     | 
| 
      
 332 
     | 
    
         
            +
                end
         
     | 
| 
      
 333 
     | 
    
         
            +
              end
         
     | 
| 
       242 
334 
     | 
    
         | 
| 
       243 
     | 
    
         
            -
             
     | 
| 
       244 
     | 
    
         
            -
             
     | 
| 
       245 
     | 
    
         
            -
             
     | 
| 
       246 
     | 
    
         
            -
             
     | 
| 
       247 
     | 
    
         
            -
             
     | 
| 
       248 
     | 
    
         
            -
             
     | 
| 
       249 
     | 
    
         
            -
             
     | 
| 
       250 
     | 
    
         
            -
             
     | 
| 
       251 
     | 
    
         
            -
             
     | 
| 
       252 
     | 
    
         
            -
             
     | 
| 
       253 
     | 
    
         
            -
             
     | 
| 
       254 
     | 
    
         
            -
             
     | 
| 
       255 
     | 
    
         
            -
             
     | 
| 
       256 
     | 
    
         
            -
             
     | 
| 
       257 
     | 
    
         
            -
             
     | 
| 
       258 
     | 
    
         
            -
             
     | 
| 
       259 
     | 
    
         
            -
            				print "\n", cyan, "Task #{json_response['task']['name']} created successfully", reset, "\n\n"			
         
     | 
| 
       260 
     | 
    
         
            -
            			end
         
     | 
| 
       261 
     | 
    
         
            -
            		rescue RestClient::Exception => e
         
     | 
| 
       262 
     | 
    
         
            -
            			print_rest_exception(e, options)
         
     | 
| 
       263 
     | 
    
         
            -
            			exit 1
         
     | 
| 
       264 
     | 
    
         
            -
            		end
         
     | 
| 
       265 
     | 
    
         
            -
            	end
         
     | 
| 
      
 335 
     | 
    
         
            +
              def find_task_type_by_name(val)
         
     | 
| 
      
 336 
     | 
    
         
            +
                raise "find_task_type_by_name passed a bad name: #{val.inspect}" if val.to_s == ''
         
     | 
| 
      
 337 
     | 
    
         
            +
                results = @tasks_interface.task_types(val)
         
     | 
| 
      
 338 
     | 
    
         
            +
                result = nil
         
     | 
| 
      
 339 
     | 
    
         
            +
                if !results['taskTypes'].nil? && !results['taskTypes'].empty?
         
     | 
| 
      
 340 
     | 
    
         
            +
                  result = results['taskTypes'][0]
         
     | 
| 
      
 341 
     | 
    
         
            +
                elsif val.to_i.to_s == val
         
     | 
| 
      
 342 
     | 
    
         
            +
                  results = @tasks_interface.task_types(val.to_i)
         
     | 
| 
      
 343 
     | 
    
         
            +
                  result = results['taskType']
         
     | 
| 
      
 344 
     | 
    
         
            +
                end
         
     | 
| 
      
 345 
     | 
    
         
            +
                if result.nil?
         
     | 
| 
      
 346 
     | 
    
         
            +
                  print_red_alert "Task Type not found by '#{val}'"
         
     | 
| 
      
 347 
     | 
    
         
            +
                  return nil
         
     | 
| 
      
 348 
     | 
    
         
            +
                end
         
     | 
| 
      
 349 
     | 
    
         
            +
                return result
         
     | 
| 
      
 350 
     | 
    
         
            +
              end
         
     | 
| 
       266 
351 
     | 
    
         | 
| 
       267 
     | 
    
         
            -
             
     | 
| 
       268 
     | 
    
         
            -
             
     | 
| 
       269 
     | 
    
         
            -
             
     | 
| 
       270 
     | 
    
         
            -
             
     | 
| 
       271 
     | 
    
         
            -
             
     | 
| 
       272 
     | 
    
         
            -
            			build_common_options(opts, options, [:auto_confirm, :json, :remote])
         
     | 
| 
       273 
     | 
    
         
            -
            		end
         
     | 
| 
       274 
     | 
    
         
            -
            		if args.count < 1
         
     | 
| 
       275 
     | 
    
         
            -
            			puts "\n#{optparse.banner}\n\n"
         
     | 
| 
       276 
     | 
    
         
            -
            			exit 1
         
     | 
| 
       277 
     | 
    
         
            -
            		end
         
     | 
| 
       278 
     | 
    
         
            -
            		optparse.parse(args)
         
     | 
| 
       279 
     | 
    
         
            -
            		connect(options)
         
     | 
| 
       280 
     | 
    
         
            -
            		begin
         
     | 
| 
       281 
     | 
    
         
            -
            			task = find_task_by_name_or_code_or_id(task_name)
         
     | 
| 
       282 
     | 
    
         
            -
            			exit 1 if task.nil?
         
     | 
| 
       283 
     | 
    
         
            -
            			unless options[:yes] || Morpheus::Cli::OptionTypes.confirm("Are you sure you want to delete the task #{task['name']}?")
         
     | 
| 
       284 
     | 
    
         
            -
            				exit
         
     | 
| 
       285 
     | 
    
         
            -
            			end
         
     | 
| 
       286 
     | 
    
         
            -
            			json_response = @tasks_interface.destroy(task['id'])
         
     | 
| 
       287 
     | 
    
         
            -
            			if options[:json]
         
     | 
| 
       288 
     | 
    
         
            -
            					print JSON.pretty_generate(json_response)
         
     | 
| 
       289 
     | 
    
         
            -
            			else
         
     | 
| 
       290 
     | 
    
         
            -
            				print "\n", cyan, "Task #{task['name']} removed", reset, "\n\n"
         
     | 
| 
       291 
     | 
    
         
            -
            			end
         
     | 
| 
       292 
     | 
    
         
            -
            		rescue RestClient::Exception => e
         
     | 
| 
       293 
     | 
    
         
            -
            			print_rest_exception(e, options)
         
     | 
| 
       294 
     | 
    
         
            -
            			exit 1
         
     | 
| 
       295 
     | 
    
         
            -
            		end
         
     | 
| 
       296 
     | 
    
         
            -
            	end
         
     | 
| 
       297 
     | 
    
         
            -
             
     | 
| 
       298 
     | 
    
         
            -
             
     | 
| 
       299 
     | 
    
         
            -
            private
         
     | 
| 
       300 
     | 
    
         
            -
            	def find_task_by_name_or_code_or_id(val)
         
     | 
| 
       301 
     | 
    
         
            -
            		raise "find_task_by_name_or_code_or_id passed a bad name: #{val.inspect}" if val.to_s == ''
         
     | 
| 
       302 
     | 
    
         
            -
            		results = @tasks_interface.get(val)
         
     | 
| 
       303 
     | 
    
         
            -
            		result = nil
         
     | 
| 
       304 
     | 
    
         
            -
            		if !results['tasks'].nil? && !results['tasks'].empty?
         
     | 
| 
       305 
     | 
    
         
            -
            			result = results['tasks'][0]
         
     | 
| 
       306 
     | 
    
         
            -
            		elsif val.to_i.to_s == val
         
     | 
| 
       307 
     | 
    
         
            -
            			results = @tasks_interface.get(val.to_i)
         
     | 
| 
       308 
     | 
    
         
            -
            			result = results['task']
         
     | 
| 
       309 
     | 
    
         
            -
            		end
         
     | 
| 
       310 
     | 
    
         
            -
            		if result.nil?
         
     | 
| 
       311 
     | 
    
         
            -
            			print_red_alert "Task not found by '#{val}'"
         
     | 
| 
       312 
     | 
    
         
            -
            			return nil
         
     | 
| 
       313 
     | 
    
         
            -
            		end
         
     | 
| 
       314 
     | 
    
         
            -
            		return result
         
     | 
| 
       315 
     | 
    
         
            -
            	end
         
     | 
| 
       316 
     | 
    
         
            -
             
     | 
| 
       317 
     | 
    
         
            -
            	def find_task_type_by_name(val)
         
     | 
| 
       318 
     | 
    
         
            -
            		raise "find_task_type_by_name passed a bad name: #{val.inspect}" if val.to_s == ''
         
     | 
| 
       319 
     | 
    
         
            -
            		results = @tasks_interface.task_types(val)
         
     | 
| 
       320 
     | 
    
         
            -
            		result = nil
         
     | 
| 
       321 
     | 
    
         
            -
            		if !results['taskTypes'].nil? && !results['taskTypes'].empty?
         
     | 
| 
       322 
     | 
    
         
            -
            			result = results['taskTypes'][0]
         
     | 
| 
       323 
     | 
    
         
            -
            		elsif val.to_i.to_s == val
         
     | 
| 
       324 
     | 
    
         
            -
            			results = @tasks_interface.task_types(val.to_i)
         
     | 
| 
       325 
     | 
    
         
            -
            			result = results['taskType']
         
     | 
| 
       326 
     | 
    
         
            -
            		end
         
     | 
| 
       327 
     | 
    
         
            -
            		if result.nil?
         
     | 
| 
       328 
     | 
    
         
            -
            			print_red_alert "Task Type not found by '#{val}'"
         
     | 
| 
       329 
     | 
    
         
            -
            			return nil
         
     | 
| 
       330 
     | 
    
         
            -
            		end
         
     | 
| 
       331 
     | 
    
         
            -
            		return result
         
     | 
| 
       332 
     | 
    
         
            -
            	end
         
     | 
| 
       333 
     | 
    
         
            -
             
     | 
| 
       334 
     | 
    
         
            -
            	def update_task_option_types(task_type)
         
     | 
| 
       335 
     | 
    
         
            -
            		[
         
     | 
| 
       336 
     | 
    
         
            -
            			{'fieldName' => 'name', 'fieldLabel' => 'Name', 'type' => 'text', 'required' => true, 'displayOrder' => 0}
         
     | 
| 
       337 
     | 
    
         
            -
            		] + task_type['optionTypes']
         
     | 
| 
       338 
     | 
    
         
            -
            	end
         
     | 
| 
      
 352 
     | 
    
         
            +
              def update_task_option_types(task_type)
         
     | 
| 
      
 353 
     | 
    
         
            +
                [
         
     | 
| 
      
 354 
     | 
    
         
            +
                  {'fieldName' => 'name', 'fieldLabel' => 'Name', 'type' => 'text', 'required' => true, 'displayOrder' => 0}
         
     | 
| 
      
 355 
     | 
    
         
            +
                ] + task_type['optionTypes']
         
     | 
| 
      
 356 
     | 
    
         
            +
              end
         
     | 
| 
       339 
357 
     | 
    
         
             
            end
         
     |