morpheus-cli 7.0.7 → 8.0.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/Dockerfile +1 -1
- data/lib/morpheus/api/api_client.rb +11 -0
- data/lib/morpheus/api/appliance_settings_interface.rb +7 -0
- data/lib/morpheus/api/clusters_interface.rb +25 -0
- data/lib/morpheus/api/datastores_interface.rb +6 -0
- data/lib/morpheus/api/library_operating_systems_interface.rb +63 -0
- data/lib/morpheus/api/processes_interface.rb +17 -5
- data/lib/morpheus/api/virtual_images_interface.rb +6 -0
- data/lib/morpheus/cli/commands/appliance_settings_command.rb +21 -2
- data/lib/morpheus/cli/commands/apps.rb +1 -1
- data/lib/morpheus/cli/commands/backup_jobs_command.rb +50 -17
- data/lib/morpheus/cli/commands/backups_command.rb +36 -9
- data/lib/morpheus/cli/commands/clouds.rb +1 -1
- data/lib/morpheus/cli/commands/clusters.rb +380 -6
- data/lib/morpheus/cli/commands/hosts.rb +3 -0
- data/lib/morpheus/cli/commands/instances.rb +33 -4
- data/lib/morpheus/cli/commands/library_container_types_command.rb +6 -0
- data/lib/morpheus/cli/commands/library_operating_systems_command.rb +671 -0
- data/lib/morpheus/cli/commands/license.rb +11 -1
- data/lib/morpheus/cli/commands/processes_command.rb +71 -1
- data/lib/morpheus/cli/commands/setup.rb +32 -18
- data/lib/morpheus/cli/commands/virtual_images.rb +66 -8
- data/lib/morpheus/cli/mixins/print_helper.rb +4 -2
- data/lib/morpheus/cli/mixins/provisioning_helper.rb +35 -8
- data/lib/morpheus/cli/option_types.rb +3 -0
- data/lib/morpheus/cli/version.rb +1 -1
- data/lib/morpheus/formatters.rb +12 -0
- metadata +5 -3
| @@ -0,0 +1,671 @@ | |
| 1 | 
            +
            require 'morpheus/cli/cli_command'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            class Morpheus::Cli::LibraryOperatingSystemsCommand
         | 
| 4 | 
            +
              include Morpheus::Cli::CliCommand
         | 
| 5 | 
            +
              include Morpheus::Cli::LibraryHelper
         | 
| 6 | 
            +
              include Morpheus::Cli::WhoamiHelper
         | 
| 7 | 
            +
             | 
| 8 | 
            +
              set_command_name :'library-operating-systems'
         | 
| 9 | 
            +
             | 
| 10 | 
            +
              register_subcommands :list, :get, :add, :update, :remove, :add_image, :remove_image, :get_image
         | 
| 11 | 
            +
             | 
| 12 | 
            +
              def initialize()
         | 
| 13 | 
            +
              end
         | 
| 14 | 
            +
             | 
| 15 | 
            +
              def connect(opts)
         | 
| 16 | 
            +
                @api_client = establish_remote_appliance_connection(opts)
         | 
| 17 | 
            +
                @library_operating_systems_interface = @api_client.library_operating_systems
         | 
| 18 | 
            +
              end
         | 
| 19 | 
            +
             | 
| 20 | 
            +
              def handle(args)
         | 
| 21 | 
            +
                handle_subcommand(args)
         | 
| 22 | 
            +
              end
         | 
| 23 | 
            +
             | 
| 24 | 
            +
              def list(args)
         | 
| 25 | 
            +
                options = {}
         | 
| 26 | 
            +
                params = {}
         | 
| 27 | 
            +
                optparse = Morpheus::Cli::OptionParser.new do |opts|
         | 
| 28 | 
            +
                  opts.banner = subcommand_usage()
         | 
| 29 | 
            +
                  build_common_options(opts, options, [:list, :query, :json, :yaml, :csv, :fields, :dry_run, :remote])
         | 
| 30 | 
            +
                  opts.footer = "List os types."
         | 
| 31 | 
            +
                end
         | 
| 32 | 
            +
                optparse.parse!(args)
         | 
| 33 | 
            +
                # verify_args!(args:args, optparse:optparse, count:0)
         | 
| 34 | 
            +
                if args.count > 0
         | 
| 35 | 
            +
                  options[:phrase] = args.join(" ")
         | 
| 36 | 
            +
                end
         | 
| 37 | 
            +
                connect(options)
         | 
| 38 | 
            +
                begin
         | 
| 39 | 
            +
                  # construct payload
         | 
| 40 | 
            +
                  params.merge!(parse_list_options(options))
         | 
| 41 | 
            +
                  @library_operating_systems_interface.setopts(options)
         | 
| 42 | 
            +
                  if options[:dry_run]
         | 
| 43 | 
            +
                    print_dry_run @library_operating_systems_interface.dry.list_os_types(params)
         | 
| 44 | 
            +
                    return
         | 
| 45 | 
            +
                  end
         | 
| 46 | 
            +
                  # do it
         | 
| 47 | 
            +
                  json_response = @library_operating_systems_interface.list_os_types(params)
         | 
| 48 | 
            +
                  # print and/or return result
         | 
| 49 | 
            +
                  # return 0 if options[:quiet]
         | 
| 50 | 
            +
                  if options[:json]
         | 
| 51 | 
            +
                    puts as_json(json_response, options, "osTypes")
         | 
| 52 | 
            +
                    return 0
         | 
| 53 | 
            +
                  elsif options[:csv]
         | 
| 54 | 
            +
                    puts records_as_csv(json_response['osTypes'], options)
         | 
| 55 | 
            +
                    return 0
         | 
| 56 | 
            +
                  elsif options[:yaml]
         | 
| 57 | 
            +
                    puts as_yaml(json_response, options, "osTypes")
         | 
| 58 | 
            +
                    return 0
         | 
| 59 | 
            +
                  end
         | 
| 60 | 
            +
                  os_types = json_response['osTypes']
         | 
| 61 | 
            +
                  title = "Morpheus Library - OS Types"
         | 
| 62 | 
            +
                  subtitles = parse_list_subtitles(options)
         | 
| 63 | 
            +
                  print_h1 title, subtitles
         | 
| 64 | 
            +
                  if os_types.empty?
         | 
| 65 | 
            +
                    print cyan,"No os types found.",reset,"\n"
         | 
| 66 | 
            +
                  else
         | 
| 67 | 
            +
                    rows = os_types.collect do |os_type|
         | 
| 68 | 
            +
                      {
         | 
| 69 | 
            +
                          id: os_type['id'],
         | 
| 70 | 
            +
                          name: os_type['name'],
         | 
| 71 | 
            +
                          code: os_type['code'],
         | 
| 72 | 
            +
                          platform: os_type['platform'],
         | 
| 73 | 
            +
                          vendor: os_type['vendor'],
         | 
| 74 | 
            +
                          category: os_type['category'],
         | 
| 75 | 
            +
                          family: os_type['osFamily'],
         | 
| 76 | 
            +
                          owner: os_type['owner']['name'] ? os_type['owner']['name'] : 'System'
         | 
| 77 | 
            +
                      }
         | 
| 78 | 
            +
                    end
         | 
| 79 | 
            +
                    print as_pretty_table(rows, [:id, :name, :code, :platform, :vendor, :category, :family, :owner], options)
         | 
| 80 | 
            +
                    print_results_pagination(json_response, {})
         | 
| 81 | 
            +
                  end
         | 
| 82 | 
            +
                  print reset,"\n"
         | 
| 83 | 
            +
                rescue RestClient::Exception => e
         | 
| 84 | 
            +
                  print_rest_exception(e, options)
         | 
| 85 | 
            +
                  return 1
         | 
| 86 | 
            +
                end
         | 
| 87 | 
            +
              end
         | 
| 88 | 
            +
             | 
| 89 | 
            +
              def get(args)
         | 
| 90 | 
            +
                options = {}
         | 
| 91 | 
            +
                optparse = Morpheus::Cli::OptionParser.new do |opts|
         | 
| 92 | 
            +
                  opts.banner = subcommand_usage("[osType]")
         | 
| 93 | 
            +
                  build_common_options(opts, options, [:json, :yaml, :csv, :fields, :dry_run, :remote])
         | 
| 94 | 
            +
                  opts.footer = "Display osType details." + "\n" +
         | 
| 95 | 
            +
                                "[osType] is required. This is the id of an osType."
         | 
| 96 | 
            +
                end
         | 
| 97 | 
            +
                optparse.parse!(args)
         | 
| 98 | 
            +
                if args.count < 1
         | 
| 99 | 
            +
                  puts optparse
         | 
| 100 | 
            +
                  return 1
         | 
| 101 | 
            +
                end
         | 
| 102 | 
            +
                connect(options)
         | 
| 103 | 
            +
                id_list = parse_id_list(args)
         | 
| 104 | 
            +
                id_list.each do |id|
         | 
| 105 | 
            +
             | 
| 106 | 
            +
                end
         | 
| 107 | 
            +
                return run_command_for_each_arg(id_list) do |arg|
         | 
| 108 | 
            +
                  _get(arg, options)
         | 
| 109 | 
            +
                end
         | 
| 110 | 
            +
              end
         | 
| 111 | 
            +
             | 
| 112 | 
            +
              def _get(id, options)
         | 
| 113 | 
            +
                begin
         | 
| 114 | 
            +
                  @library_operating_systems_interface.setopts(options)
         | 
| 115 | 
            +
             | 
| 116 | 
            +
                  if options[:dry_run]
         | 
| 117 | 
            +
                      print_dry_run @library_operating_systems_interface.dry.get(id)
         | 
| 118 | 
            +
                    return
         | 
| 119 | 
            +
                  end
         | 
| 120 | 
            +
                  os_type = find_os_type_by_id(id)
         | 
| 121 | 
            +
                  if os_type.nil?
         | 
| 122 | 
            +
                    return 1
         | 
| 123 | 
            +
                  end
         | 
| 124 | 
            +
             | 
| 125 | 
            +
                  json_response = {'osType' => os_type}
         | 
| 126 | 
            +
             | 
| 127 | 
            +
                  if options[:json]
         | 
| 128 | 
            +
                    puts as_json(json_response, options, "osType")
         | 
| 129 | 
            +
                    return 0
         | 
| 130 | 
            +
                  elsif options[:yaml]
         | 
| 131 | 
            +
                    puts as_yaml(json_response, options, "osType")
         | 
| 132 | 
            +
                    return 0
         | 
| 133 | 
            +
                  elsif options[:csv]
         | 
| 134 | 
            +
                    puts records_as_csv([json_response['osType']], options)
         | 
| 135 | 
            +
                    return 0
         | 
| 136 | 
            +
                  end
         | 
| 137 | 
            +
             | 
| 138 | 
            +
                  print_h1 "OsType Details"
         | 
| 139 | 
            +
                  print cyan
         | 
| 140 | 
            +
                  description_cols = {
         | 
| 141 | 
            +
                    "ID" => lambda {|it| it['id'] },
         | 
| 142 | 
            +
                    "Name" => lambda {|it| it['name'] },
         | 
| 143 | 
            +
                    "Code" => lambda {|it| it['code']},
         | 
| 144 | 
            +
                    "Platform" => lambda {|it| it['platform']},
         | 
| 145 | 
            +
                    "Category" => lambda {|it|it['category']},
         | 
| 146 | 
            +
                    "Vendor" => lambda {|it| it['vendor']},
         | 
| 147 | 
            +
                    "Family" => lambda {|it| it['osFamily']},
         | 
| 148 | 
            +
                    "Os Name" => lambda {|it| it['osName'] },
         | 
| 149 | 
            +
                    "Install Agent" => lambda {|it| format_boolean(it['installAgent'])},
         | 
| 150 | 
            +
                    "Bit Count" => lambda {|it| it['bitCount'] },
         | 
| 151 | 
            +
                    "Owner" => lambda { |it| it['owner']}
         | 
| 152 | 
            +
                  }
         | 
| 153 | 
            +
                  if is_master_account
         | 
| 154 | 
            +
                    description_cols["Visibility"] = lambda {|it| it['visibility']}
         | 
| 155 | 
            +
                  end
         | 
| 156 | 
            +
             | 
| 157 | 
            +
                  print_description_list(description_cols, os_type)
         | 
| 158 | 
            +
                  title = "OsType - Images"
         | 
| 159 | 
            +
                  print_h2 title
         | 
| 160 | 
            +
                    if os_type['images'].empty?
         | 
| 161 | 
            +
                      print cyan,"No images found.",reset,"\n"
         | 
| 162 | 
            +
                    else
         | 
| 163 | 
            +
                      rows = os_type['images'].collect do |image|
         | 
| 164 | 
            +
                        {
         | 
| 165 | 
            +
                            id: image['id'],
         | 
| 166 | 
            +
                            virtual_image_id: image['virtualImageId'],
         | 
| 167 | 
            +
                            virtual_image_name: image['virtualImageName'],
         | 
| 168 | 
            +
                            account: image['account'],
         | 
| 169 | 
            +
                            cloud: image['zone']
         | 
| 170 | 
            +
                        }
         | 
| 171 | 
            +
                      end
         | 
| 172 | 
            +
                      print as_pretty_table(rows, [:id, :virtual_image_id, :virtual_image_name, :account, :cloud], options)
         | 
| 173 | 
            +
                    end
         | 
| 174 | 
            +
             | 
| 175 | 
            +
                  print reset,"\n"
         | 
| 176 | 
            +
                rescue RestClient::Exception => e
         | 
| 177 | 
            +
                  print_rest_exception(e, options)
         | 
| 178 | 
            +
                  return 1
         | 
| 179 | 
            +
                end
         | 
| 180 | 
            +
              end
         | 
| 181 | 
            +
             | 
| 182 | 
            +
              def get_image(args)
         | 
| 183 | 
            +
                options = {}
         | 
| 184 | 
            +
                optparse = Morpheus::Cli::OptionParser.new do |opts|
         | 
| 185 | 
            +
                  opts.banner = subcommand_usage("[osTypeImage]")
         | 
| 186 | 
            +
                  build_common_options(opts, options, [:json, :yaml, :csv, :fields, :dry_run, :remote])
         | 
| 187 | 
            +
                  opts.footer = "Display osTypeImage details." + "\n" +
         | 
| 188 | 
            +
                                "[osTypeImage] is required. This is the id of an osTypeImage."
         | 
| 189 | 
            +
                end
         | 
| 190 | 
            +
                optparse.parse!(args)
         | 
| 191 | 
            +
                if args.count < 1
         | 
| 192 | 
            +
                  puts optparse
         | 
| 193 | 
            +
                  return 1
         | 
| 194 | 
            +
                end
         | 
| 195 | 
            +
                connect(options)
         | 
| 196 | 
            +
                id_list = parse_id_list(args)
         | 
| 197 | 
            +
                id_list.each do |id|
         | 
| 198 | 
            +
             | 
| 199 | 
            +
                end
         | 
| 200 | 
            +
                return run_command_for_each_arg(id_list) do |arg|
         | 
| 201 | 
            +
                  _get_image(arg)
         | 
| 202 | 
            +
                end
         | 
| 203 | 
            +
              end
         | 
| 204 | 
            +
             | 
| 205 | 
            +
              def _get_image(id)
         | 
| 206 | 
            +
                begin
         | 
| 207 | 
            +
                  image = find_os_type_image_by_id(id)
         | 
| 208 | 
            +
             | 
| 209 | 
            +
                  if image.nil?
         | 
| 210 | 
            +
                    return 1
         | 
| 211 | 
            +
                  end
         | 
| 212 | 
            +
             | 
| 213 | 
            +
                  json_response = {'osTypeImage' => image}
         | 
| 214 | 
            +
                
         | 
| 215 | 
            +
                  
         | 
| 216 | 
            +
                  print_h1 "OsTypeImage Details"
         | 
| 217 | 
            +
                  print cyan
         | 
| 218 | 
            +
                  description_cols = {
         | 
| 219 | 
            +
                    "ID" => lambda {|it| it['id'] },
         | 
| 220 | 
            +
                    "VirtualImage ID" => lambda {|it| it['virtualImageId'] },
         | 
| 221 | 
            +
                    "VirtualImage Name" => lambda {|it| it['virtualImageName'] },
         | 
| 222 | 
            +
                    "Account" => lambda {|it| it['account']},
         | 
| 223 | 
            +
                    "Provision Type" => lambda {|it| it['provisionType']},
         | 
| 224 | 
            +
                    "Cloud" => lambda {|it|it['zone']}
         | 
| 225 | 
            +
                  }
         | 
| 226 | 
            +
             | 
| 227 | 
            +
                  print_description_list(description_cols, image)
         | 
| 228 | 
            +
             | 
| 229 | 
            +
                  print reset,"\n"
         | 
| 230 | 
            +
                rescue RestClient::Exception => e
         | 
| 231 | 
            +
                  print_rest_exception(e, options)
         | 
| 232 | 
            +
                  return 1
         | 
| 233 | 
            +
                end
         | 
| 234 | 
            +
              end
         | 
| 235 | 
            +
             | 
| 236 | 
            +
             | 
| 237 | 
            +
              def add(args)
         | 
| 238 | 
            +
                options = {}
         | 
| 239 | 
            +
                params = {}
         | 
| 240 | 
            +
                optparse = Morpheus::Cli::OptionParser.new do|opts|
         | 
| 241 | 
            +
                  opts.banner = subcommand_usage("[name] [options]")
         | 
| 242 | 
            +
                  opts.on('-n', '--name VALUE', String, "Name of OsType") do |val|
         | 
| 243 | 
            +
                    params['name'] = val
         | 
| 244 | 
            +
                  end
         | 
| 245 | 
            +
                  opts.on('-c', '--code VALUE', String, "Code of OsType") do |val|
         | 
| 246 | 
            +
                    params['code'] = val
         | 
| 247 | 
            +
                  end
         | 
| 248 | 
            +
                  opts.on('-p', '--platform VALUE', String, "Platform of OsType") do |val|
         | 
| 249 | 
            +
                    params['platform'] = val
         | 
| 250 | 
            +
                  end
         | 
| 251 | 
            +
                  opts.on('-v', '--vendor VALUE', String, "Vendor of OsType") do |val|
         | 
| 252 | 
            +
                    params['vendor'] = val
         | 
| 253 | 
            +
                  end
         | 
| 254 | 
            +
                  opts.on('-ca', '--category VALUE', String, "Category of OsType") do |val|
         | 
| 255 | 
            +
                    params['category'] = val
         | 
| 256 | 
            +
                  end
         | 
| 257 | 
            +
                  opts.on('-o', '--osName VALUE', String, "OsName of OsType") do |val|
         | 
| 258 | 
            +
                    params['osName'] = val
         | 
| 259 | 
            +
                  end
         | 
| 260 | 
            +
                  opts.on('-ov', '--osVersion VALUE', String, "OsVersion of OsType") do |val|
         | 
| 261 | 
            +
                    params['osVersion'] = val
         | 
| 262 | 
            +
                  end
         | 
| 263 | 
            +
                  opts.on('-oc', '--osCodename VALUE', String, "OsCodename of OsType") do |val|
         | 
| 264 | 
            +
                    params['osCodename'] = val
         | 
| 265 | 
            +
                  end
         | 
| 266 | 
            +
                  opts.on('-of', '--osFamily VALUE', String, "OsFamily of OsType") do |val|
         | 
| 267 | 
            +
                    params['osFamily'] = val
         | 
| 268 | 
            +
                  end
         | 
| 269 | 
            +
                  opts.on('-b', '--bitCount VALUE', Integer, "BitCount of OsType") do |val|
         | 
| 270 | 
            +
                    params['bitCount'] = val
         | 
| 271 | 
            +
                  end
         | 
| 272 | 
            +
                  opts.on('-i', '--cloudInitVersion VALUE', Integer, "CloudInitVersion of OsType") do |val|
         | 
| 273 | 
            +
                    params['cloudInitVersion'] = val
         | 
| 274 | 
            +
                  end
         | 
| 275 | 
            +
                  opts.on('-d', '--description VALUE', String, "Description of OsType") do |val|
         | 
| 276 | 
            +
                    params['description'] = val
         | 
| 277 | 
            +
                  end
         | 
| 278 | 
            +
                  opts.on('--install-agent [on|off]', String, "Install Agent? Pass true to install agent. Default is false.") do |val|
         | 
| 279 | 
            +
                    params['installAgent'] = !['false','off','0'].include?(val.to_s)
         | 
| 280 | 
            +
                  end
         | 
| 281 | 
            +
                  build_common_options(opts, options, [:options, :payload, :json, :dry_run, :remote])
         | 
| 282 | 
            +
                  opts.footer = "Create an OsType."
         | 
| 283 | 
            +
                end
         | 
| 284 | 
            +
                optparse.parse!(args)
         | 
| 285 | 
            +
                connect(options)
         | 
| 286 | 
            +
                if args.count > 1
         | 
| 287 | 
            +
                  print_error Morpheus::Terminal.angry_prompt
         | 
| 288 | 
            +
                  puts_error  "wrong number of arguments, expected 0-1 and got (#{args.count}) #{args.inspect}\n#{optparse}"
         | 
| 289 | 
            +
                  return 1
         | 
| 290 | 
            +
                end
         | 
| 291 | 
            +
             | 
| 292 | 
            +
                begin
         | 
| 293 | 
            +
                  if options[:payload]
         | 
| 294 | 
            +
                    payload = options[:payload]
         | 
| 295 | 
            +
                  else
         | 
| 296 | 
            +
                    # support the old -O OPTION switch
         | 
| 297 | 
            +
                    params.deep_merge!(options[:options].reject {|k,v| k.is_a?(Symbol) }) if options[:options]
         | 
| 298 | 
            +
                    
         | 
| 299 | 
            +
                    # prompt for options
         | 
| 300 | 
            +
                    prompt_if_nil(params, options, 'name', 'Name', true)
         | 
| 301 | 
            +
                    prompt_if_nil(params, options, 'code', 'Code', true)
         | 
| 302 | 
            +
                    prompt_if_nil(params, options, 'description', 'Description')
         | 
| 303 | 
            +
                    prompt_if_nil(params, options, 'category', 'Category')
         | 
| 304 | 
            +
             | 
| 305 | 
            +
                    if params['platform'].nil?
         | 
| 306 | 
            +
                        v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'platform', 'fieldLabel' => 'Platform', 'type' => 'select', 'optionSource' => 'platforms', 'description' => 'Platform', 'required' => true}], options, @api_client, {})
         | 
| 307 | 
            +
                        params['platform'] = v_prompt['platform']
         | 
| 308 | 
            +
                    end
         | 
| 309 | 
            +
             | 
| 310 | 
            +
                    prompt_if_nil(params, options, 'vendor', 'Vendor')
         | 
| 311 | 
            +
                    prompt_if_nil(params, options, 'osName', 'OsName')
         | 
| 312 | 
            +
                    prompt_if_nil(params, options, 'osVersion', 'OsVersion')
         | 
| 313 | 
            +
                    prompt_if_nil(params, options, 'osCodename', 'OsCodename')
         | 
| 314 | 
            +
                    prompt_if_nil(params, options, 'osFamily', 'OsFamily')
         | 
| 315 | 
            +
             | 
| 316 | 
            +
                    if params['bitCount'].nil?
         | 
| 317 | 
            +
                      params['bitCount'] = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'bitCount', 'type' => 'number', 'fieldLabel' => 'BitCount', 'required' => true, 'description' => 'BitCount.'}],options[:options],@api_client,{})['bitCount']
         | 
| 318 | 
            +
                    end
         | 
| 319 | 
            +
             | 
| 320 | 
            +
                    if params['cloudInitVersion'].nil?
         | 
| 321 | 
            +
                      params['cloudInitVersion'] = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'cloudInitVersion', 'type' => 'number', 'fieldLabel' => 'CloudInitVersion', 'required' => false, 'description' => 'CloudInitVersion.'}],options[:options],@api_client,{})['cloudInitVersion']
         | 
| 322 | 
            +
                    end
         | 
| 323 | 
            +
             | 
| 324 | 
            +
                    if params['installAgent'].nil?
         | 
| 325 | 
            +
                       params['installAgent'] = Morpheus::Cli::OptionTypes.confirm("Install Agent?", {:default => false})
         | 
| 326 | 
            +
                    end
         | 
| 327 | 
            +
             | 
| 328 | 
            +
                    payload = {'osType' => params}
         | 
| 329 | 
            +
                  end
         | 
| 330 | 
            +
             | 
| 331 | 
            +
                  @library_operating_systems_interface.setopts(options)
         | 
| 332 | 
            +
                  if options[:dry_run]
         | 
| 333 | 
            +
                    print_dry_run @library_operating_systems_interface.dry.create(payload)
         | 
| 334 | 
            +
                    return
         | 
| 335 | 
            +
                  end
         | 
| 336 | 
            +
             | 
| 337 | 
            +
                  json_response = @library_operating_systems_interface.create(payload)
         | 
| 338 | 
            +
             | 
| 339 | 
            +
                  if options[:json]
         | 
| 340 | 
            +
                    print JSON.pretty_generate(json_response), "\n"
         | 
| 341 | 
            +
                    return
         | 
| 342 | 
            +
                  end
         | 
| 343 | 
            +
                  print_green_success "Added Os Type"
         | 
| 344 | 
            +
                  _get(json_response['id'], {})
         | 
| 345 | 
            +
                rescue RestClient::Exception => e
         | 
| 346 | 
            +
                  print_rest_exception(e, options)
         | 
| 347 | 
            +
                  exit 1
         | 
| 348 | 
            +
                end
         | 
| 349 | 
            +
              end
         | 
| 350 | 
            +
             | 
| 351 | 
            +
             | 
| 352 | 
            +
              def update(args)
         | 
| 353 | 
            +
                options = {}
         | 
| 354 | 
            +
                params = {}
         | 
| 355 | 
            +
                optparse = Morpheus::Cli::OptionParser.new do |opts|
         | 
| 356 | 
            +
                  opts.banner = subcommand_usage("[osType] [options]")
         | 
| 357 | 
            +
                  opts.on('-n', '--name VALUE', String, "Name of OsType") do |val|
         | 
| 358 | 
            +
                    params['name'] = val
         | 
| 359 | 
            +
                  end
         | 
| 360 | 
            +
                  opts.on('-c', '--code VALUE', String, "Code of OsType") do |val|
         | 
| 361 | 
            +
                    params['code'] = val
         | 
| 362 | 
            +
                  end
         | 
| 363 | 
            +
                  opts.on('-p', '--platform VALUE', String, "Platform of OsType") do |val|
         | 
| 364 | 
            +
                    params['platform'] = val
         | 
| 365 | 
            +
                  end
         | 
| 366 | 
            +
                  opts.on('-v', '--vendor VALUE', String, "Vendor of OsType") do |val|
         | 
| 367 | 
            +
                    params['vendor'] = val
         | 
| 368 | 
            +
                  end
         | 
| 369 | 
            +
                  opts.on('-ca', '--category VALUE', String, "Category of OsType") do |val|
         | 
| 370 | 
            +
                    params['category'] = val
         | 
| 371 | 
            +
                  end
         | 
| 372 | 
            +
                  opts.on('-o', '--osName VALUE', String, "OsName of OsType") do |val|
         | 
| 373 | 
            +
                    params['osName'] = val
         | 
| 374 | 
            +
                  end
         | 
| 375 | 
            +
                  opts.on('-ov', '--osVersion VALUE', String, "OsVersion of OsType") do |val|
         | 
| 376 | 
            +
                    params['osVersion'] = val
         | 
| 377 | 
            +
                  end
         | 
| 378 | 
            +
                  opts.on('-oc', '--osCodename VALUE', String, "OsCodename of OsType") do |val|
         | 
| 379 | 
            +
                    params['osCodename'] = val
         | 
| 380 | 
            +
                  end
         | 
| 381 | 
            +
                  opts.on('-of', '--osFamily VALUE', String, "OsFamily of OsType") do |val|
         | 
| 382 | 
            +
                    params['osFamily'] = val
         | 
| 383 | 
            +
                  end
         | 
| 384 | 
            +
                  opts.on('-b', '--bitCount VALUE', Integer, "BitCount of OsType") do |val|
         | 
| 385 | 
            +
                    params['bitCount'] = val
         | 
| 386 | 
            +
                  end
         | 
| 387 | 
            +
                  opts.on('-i', '--cloudInitVersion VALUE', Integer, "CloudInitVersion of OsType") do |val|
         | 
| 388 | 
            +
                    params['cloudInitVersion'] = val
         | 
| 389 | 
            +
                  end
         | 
| 390 | 
            +
                  opts.on('-d', '--description VALUE', String, "Description of OsType") do |val|
         | 
| 391 | 
            +
                    params['description'] = val
         | 
| 392 | 
            +
                  end
         | 
| 393 | 
            +
                  opts.on('--install-agent [on|off]', String, "Install Agent? Pass true to install agent. Default is false.") do |val|
         | 
| 394 | 
            +
                    params['installAgent'] = !['false','off','0'].include?(val.to_s)
         | 
| 395 | 
            +
                  end
         | 
| 396 | 
            +
             | 
| 397 | 
            +
                  build_common_options(opts, options, [:options, :json, :dry_run, :remote])
         | 
| 398 | 
            +
                  opts.footer = "Update an osType." + "\n" +
         | 
| 399 | 
            +
                                "[osType] is required. This is the id of an osType."
         | 
| 400 | 
            +
                end
         | 
| 401 | 
            +
                optparse.parse!(args)
         | 
| 402 | 
            +
                if args.count != 1
         | 
| 403 | 
            +
                  print_error Morpheus::Terminal.angry_prompt
         | 
| 404 | 
            +
                  puts_error  "wrong number of arguments, expected 1 and got #{args.count}\n#{optparse}"
         | 
| 405 | 
            +
                  return 1
         | 
| 406 | 
            +
                end
         | 
| 407 | 
            +
                connect(options)
         | 
| 408 | 
            +
             | 
| 409 | 
            +
                begin
         | 
| 410 | 
            +
                  os_type = find_os_type_by_id(args[0])
         | 
| 411 | 
            +
                  return 1 if os_type.nil?
         | 
| 412 | 
            +
                  
         | 
| 413 | 
            +
                  payload = {
         | 
| 414 | 
            +
                    'osType' => {}
         | 
| 415 | 
            +
                  }
         | 
| 416 | 
            +
             | 
| 417 | 
            +
                  # no prompting, just collect all user passed options
         | 
| 418 | 
            +
                  params.deep_merge!(options.reject {|k,v| k.is_a?(Symbol) })
         | 
| 419 | 
            +
                  params.deep_merge!(options[:options]) if options[:options]
         | 
| 420 | 
            +
             | 
| 421 | 
            +
                  if params.empty?
         | 
| 422 | 
            +
                    print_error Morpheus::Terminal.angry_prompt
         | 
| 423 | 
            +
                    puts_error  "Specify at least one option to update\n#{optparse}"
         | 
| 424 | 
            +
                    return 1
         | 
| 425 | 
            +
                  end
         | 
| 426 | 
            +
                  payload['osType'].deep_merge!(params)
         | 
| 427 | 
            +
             | 
| 428 | 
            +
             | 
| 429 | 
            +
                  @library_operating_systems_interface.setopts(options)
         | 
| 430 | 
            +
                  if options[:dry_run]
         | 
| 431 | 
            +
                      print_dry_run @library_operating_systems_interface.dry.update(os_type["id"], payload)
         | 
| 432 | 
            +
                    return
         | 
| 433 | 
            +
                  end
         | 
| 434 | 
            +
             | 
| 435 | 
            +
                  json_response = @library_operating_systems_interface.update(os_type["id"], payload)
         | 
| 436 | 
            +
             | 
| 437 | 
            +
                  if options[:json]
         | 
| 438 | 
            +
                    puts as_json(json_response)
         | 
| 439 | 
            +
                  else
         | 
| 440 | 
            +
                    print_green_success "Updated osType #{os_type['id']}"
         | 
| 441 | 
            +
                    get([os_type['id']])
         | 
| 442 | 
            +
                  end
         | 
| 443 | 
            +
                  return 0
         | 
| 444 | 
            +
                rescue RestClient::Exception => e
         | 
| 445 | 
            +
                  print_rest_exception(e, options)
         | 
| 446 | 
            +
                  return 1
         | 
| 447 | 
            +
                end
         | 
| 448 | 
            +
              end
         | 
| 449 | 
            +
                       
         | 
| 450 | 
            +
             | 
| 451 | 
            +
             | 
| 452 | 
            +
              def add_image(args)
         | 
| 453 | 
            +
                options = {}
         | 
| 454 | 
            +
                params = {}
         | 
| 455 | 
            +
                optparse = Morpheus::Cli::OptionParser.new do|opts|
         | 
| 456 | 
            +
                  opts.banner = subcommand_usage("[name] [options]")
         | 
| 457 | 
            +
                  opts.on('-o', '--osType VALUE', String, "Id of OsType") do |val|
         | 
| 458 | 
            +
                    params['osType'] = val
         | 
| 459 | 
            +
                  end
         | 
| 460 | 
            +
                  opts.on('-v', '--virtualImage VALUE', String, "Id of Virtual Image") do |val|
         | 
| 461 | 
            +
                    params['virtualImage'] = val
         | 
| 462 | 
            +
                  end
         | 
| 463 | 
            +
                  opts.on('-p', '--provisionType VALUE', String, "Provision Type") do |val|
         | 
| 464 | 
            +
                    params['provisionType'] = val
         | 
| 465 | 
            +
                  end
         | 
| 466 | 
            +
                  opts.on('-z', '--zone VALUE', String, "Zone") do |val|
         | 
| 467 | 
            +
                    params['zone'] = val
         | 
| 468 | 
            +
                  end
         | 
| 469 | 
            +
                  build_common_options(opts, options, [:options, :payload, :json, :dry_run, :remote])
         | 
| 470 | 
            +
                  opts.footer = "Create an OsType Image."
         | 
| 471 | 
            +
                end
         | 
| 472 | 
            +
                optparse.parse!(args)
         | 
| 473 | 
            +
                connect(options)
         | 
| 474 | 
            +
                if args.count > 1
         | 
| 475 | 
            +
                  print_error Morpheus::Terminal.angry_prompt
         | 
| 476 | 
            +
                  puts_error  "wrong number of arguments, expected 0-1 and got (#{args.count}) #{args.inspect}\n#{optparse}"
         | 
| 477 | 
            +
                  return 1
         | 
| 478 | 
            +
                end
         | 
| 479 | 
            +
                if args[0]
         | 
| 480 | 
            +
                  params['osType'] = args[0]
         | 
| 481 | 
            +
                end
         | 
| 482 | 
            +
                begin
         | 
| 483 | 
            +
                  if options[:payload]
         | 
| 484 | 
            +
                    payload = options[:payload]
         | 
| 485 | 
            +
                  else
         | 
| 486 | 
            +
                    # support the old -O OPTION switch
         | 
| 487 | 
            +
                    params.deep_merge!(options[:options].reject {|k,v| k.is_a?(Symbol) }) if options[:options]
         | 
| 488 | 
            +
                    
         | 
| 489 | 
            +
                    # prompt for options
         | 
| 490 | 
            +
                    if params['osType'].nil?
         | 
| 491 | 
            +
                        params['osType'] = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'osType', 'type' => 'select', 'fieldLabel' => 'Os Type', 'required' => true, 'optionSource' => 'osTypes'}], options[:options], @api_client,{})['osType']
         | 
| 492 | 
            +
                    end
         | 
| 493 | 
            +
             | 
| 494 | 
            +
                    if params['provisionType'].nil?
         | 
| 495 | 
            +
                        params['provisionType'] = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'provisionType', 'type' => 'select', 'fieldLabel' => 'Provision Type', 'required' => false, 'optionSource' => 'provisionTypes'}], options[:options], @api_client,{'cli' => true})['provisionType']
         | 
| 496 | 
            +
                    end
         | 
| 497 | 
            +
             | 
| 498 | 
            +
                    if params['zone'].nil?
         | 
| 499 | 
            +
                        params['zone'] = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'zone', 'type' => 'select', 'fieldLabel' => 'Cloud', 'required' => false, 'optionSource' => 'clouds'}], options[:options], @api_client,{'provisionTypeIds' => params['provisionType']})['zone']
         | 
| 500 | 
            +
                    end
         | 
| 501 | 
            +
             | 
| 502 | 
            +
                    if params['virtualImage'].nil?
         | 
| 503 | 
            +
                        virtual_image = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'virtualImage', 'fieldLabel' => 'Virtual Image', 'type' => 'select', 'required' => true, 'optionSource' => 'osTypeVirtualImage'}], options[:options], @api_client, {'osTypeImage' => params})['virtualImage']
         | 
| 504 | 
            +
              
         | 
| 505 | 
            +
                        params['virtualImage'] = virtual_image
         | 
| 506 | 
            +
                    end
         | 
| 507 | 
            +
             | 
| 508 | 
            +
                    payload = {'osTypeImage' => params}
         | 
| 509 | 
            +
                  end
         | 
| 510 | 
            +
             | 
| 511 | 
            +
                  @library_operating_systems_interface.setopts(options)
         | 
| 512 | 
            +
                  if options[:dry_run]
         | 
| 513 | 
            +
                    print_dry_run @library_operating_systems_interface.dry.create_image(payload)
         | 
| 514 | 
            +
                    return
         | 
| 515 | 
            +
                  end
         | 
| 516 | 
            +
             | 
| 517 | 
            +
                  json_response = @library_operating_systems_interface.create_image(payload)
         | 
| 518 | 
            +
             | 
| 519 | 
            +
                  if options[:json]
         | 
| 520 | 
            +
                    print JSON.pretty_generate(json_response), "\n"
         | 
| 521 | 
            +
                    return
         | 
| 522 | 
            +
                  end
         | 
| 523 | 
            +
                  print_green_success "Added Os Type Image"
         | 
| 524 | 
            +
                  _get_image(json_response['id'])
         | 
| 525 | 
            +
                rescue RestClient::Exception => e
         | 
| 526 | 
            +
                  print_rest_exception(e, options)
         | 
| 527 | 
            +
                  exit 1
         | 
| 528 | 
            +
                end
         | 
| 529 | 
            +
              end
         | 
| 530 | 
            +
             | 
| 531 | 
            +
              def remove(args)
         | 
| 532 | 
            +
                options = {}
         | 
| 533 | 
            +
                optparse = Morpheus::Cli::OptionParser.new do|opts|
         | 
| 534 | 
            +
                  opts.banner = subcommand_usage("[osType]")
         | 
| 535 | 
            +
                  build_common_options(opts, options, [:auto_confirm, :json, :dry_run, :remote])
         | 
| 536 | 
            +
                  opts.footer = "Delete an Os Type." + "\n" +
         | 
| 537 | 
            +
                                "[osType] is required. This is the id of an osType."
         | 
| 538 | 
            +
                end
         | 
| 539 | 
            +
                optparse.parse!(args)
         | 
| 540 | 
            +
             | 
| 541 | 
            +
                if args.count != 1
         | 
| 542 | 
            +
                  print_error Morpheus::Terminal.angry_prompt
         | 
| 543 | 
            +
                  puts_error  "wrong number of arguments, expected 1 and got (#{args.count}) #{args.inspect}\n#{optparse}"
         | 
| 544 | 
            +
                  return 1
         | 
| 545 | 
            +
                end
         | 
| 546 | 
            +
             | 
| 547 | 
            +
                connect(options)
         | 
| 548 | 
            +
             | 
| 549 | 
            +
                begin
         | 
| 550 | 
            +
                  os_type = find_os_type_by_id(args[0])
         | 
| 551 | 
            +
                  if os_type.nil?
         | 
| 552 | 
            +
                    return 1
         | 
| 553 | 
            +
                  end
         | 
| 554 | 
            +
             | 
| 555 | 
            +
                  unless Morpheus::Cli::OptionTypes.confirm("Are you sure you want to delete the OsType?", options)
         | 
| 556 | 
            +
                    exit
         | 
| 557 | 
            +
                  end
         | 
| 558 | 
            +
             | 
| 559 | 
            +
                  @library_operating_systems_interface.setopts(options)
         | 
| 560 | 
            +
                  if options[:dry_run]
         | 
| 561 | 
            +
                    print_dry_run @library_operating_systems_interface.dry.destroy(os_type['id'])
         | 
| 562 | 
            +
                    return
         | 
| 563 | 
            +
                  end
         | 
| 564 | 
            +
                  json_response = @library_operating_systems_interface.destroy(os_type['id'])
         | 
| 565 | 
            +
             | 
| 566 | 
            +
                  if options[:json]
         | 
| 567 | 
            +
                    print JSON.pretty_generate(json_response)
         | 
| 568 | 
            +
                    print "\n"
         | 
| 569 | 
            +
                  elsif !options[:quiet]
         | 
| 570 | 
            +
                    if json_response['success']
         | 
| 571 | 
            +
                      print_green_success "Removed the OsType"
         | 
| 572 | 
            +
                    else
         | 
| 573 | 
            +
                      print_red_alert "Error removing osType: #{json_response['msg'] || json_response['errors']}"
         | 
| 574 | 
            +
                    end
         | 
| 575 | 
            +
                  end
         | 
| 576 | 
            +
                  return 0
         | 
| 577 | 
            +
                rescue RestClient::Exception => e
         | 
| 578 | 
            +
                  print_rest_exception(e, options)
         | 
| 579 | 
            +
                  exit 1
         | 
| 580 | 
            +
                end
         | 
| 581 | 
            +
              end
         | 
| 582 | 
            +
             | 
| 583 | 
            +
             | 
| 584 | 
            +
              def remove_image(args)
         | 
| 585 | 
            +
                options = {}
         | 
| 586 | 
            +
                optparse = Morpheus::Cli::OptionParser.new do|opts|
         | 
| 587 | 
            +
                  opts.banner = subcommand_usage("[osTypeImage]")
         | 
| 588 | 
            +
                  build_common_options(opts, options, [:auto_confirm, :json, :dry_run, :remote])
         | 
| 589 | 
            +
                  opts.footer = "Delete an Os Type Image." + "\n" +
         | 
| 590 | 
            +
                                "[osTypeImage] is required. This is the id of an osTypeImage."
         | 
| 591 | 
            +
                end
         | 
| 592 | 
            +
                optparse.parse!(args)
         | 
| 593 | 
            +
             | 
| 594 | 
            +
                if args.count != 1
         | 
| 595 | 
            +
                  print_error Morpheus::Terminal.angry_prompt
         | 
| 596 | 
            +
                  puts_error  "wrong number of arguments, expected 1 and got (#{args.count}) #{args.inspect}\n#{optparse}"
         | 
| 597 | 
            +
                  return 1
         | 
| 598 | 
            +
                end
         | 
| 599 | 
            +
             | 
| 600 | 
            +
                connect(options)
         | 
| 601 | 
            +
             | 
| 602 | 
            +
                begin
         | 
| 603 | 
            +
                  os_type_image = find_os_type_image_by_id(args[0])
         | 
| 604 | 
            +
                  if os_type_image.nil?
         | 
| 605 | 
            +
                    return 1
         | 
| 606 | 
            +
                  end
         | 
| 607 | 
            +
             | 
| 608 | 
            +
                  unless Morpheus::Cli::OptionTypes.confirm("Are you sure you want to delete the OsTypeImage?", options)
         | 
| 609 | 
            +
                    exit
         | 
| 610 | 
            +
                  end
         | 
| 611 | 
            +
             | 
| 612 | 
            +
                  @library_operating_systems_interface.setopts(options)
         | 
| 613 | 
            +
                  if options[:dry_run]
         | 
| 614 | 
            +
                    print_dry_run @library_operating_systems_interface.dry.destroy_image(os_type_image['id'])
         | 
| 615 | 
            +
                    return
         | 
| 616 | 
            +
                  end
         | 
| 617 | 
            +
                  json_response = @library_operating_systems_interface.destroy_image(os_type_image['id'])
         | 
| 618 | 
            +
             | 
| 619 | 
            +
                  if options[:json]
         | 
| 620 | 
            +
                    print JSON.pretty_generate(json_response)
         | 
| 621 | 
            +
                    print "\n"
         | 
| 622 | 
            +
                  elsif !options[:quiet]
         | 
| 623 | 
            +
                    if json_response['success']
         | 
| 624 | 
            +
                      print_green_success "Removed the OsTypeImage"
         | 
| 625 | 
            +
                    else
         | 
| 626 | 
            +
                      print_red_alert "Error removing osTypeImage: #{json_response['msg'] || json_response['errors']}"
         | 
| 627 | 
            +
                    end
         | 
| 628 | 
            +
                  end
         | 
| 629 | 
            +
                  return 0
         | 
| 630 | 
            +
                rescue RestClient::Exception => e
         | 
| 631 | 
            +
                  print_rest_exception(e, options)
         | 
| 632 | 
            +
                  exit 1
         | 
| 633 | 
            +
                end
         | 
| 634 | 
            +
              end
         | 
| 635 | 
            +
             | 
| 636 | 
            +
             | 
| 637 | 
            +
              private
         | 
| 638 | 
            +
             | 
| 639 | 
            +
              def find_os_type_by_id(id)
         | 
| 640 | 
            +
                begin
         | 
| 641 | 
            +
                  json_response = @library_operating_systems_interface.get(id.to_i)
         | 
| 642 | 
            +
                  return json_response['osType']
         | 
| 643 | 
            +
                rescue RestClient::Exception => e
         | 
| 644 | 
            +
                  if e.response && e.response.code == 404
         | 
| 645 | 
            +
                    print_red_alert "OsType not found by id #{id}"
         | 
| 646 | 
            +
                  else
         | 
| 647 | 
            +
                    raise e
         | 
| 648 | 
            +
                  end
         | 
| 649 | 
            +
                end
         | 
| 650 | 
            +
              end
         | 
| 651 | 
            +
             | 
| 652 | 
            +
              def find_os_type_image_by_id(id)
         | 
| 653 | 
            +
                begin
         | 
| 654 | 
            +
                  json_response = @library_operating_systems_interface.get_image(id.to_i)
         | 
| 655 | 
            +
                  return json_response['osTypeImage']
         | 
| 656 | 
            +
                rescue RestClient::Exception => e
         | 
| 657 | 
            +
                  if e.response && e.response.code == 404
         | 
| 658 | 
            +
                    print_red_alert "OsTypeImage not found by id #{id}"
         | 
| 659 | 
            +
                  else
         | 
| 660 | 
            +
                    raise e
         | 
| 661 | 
            +
                  end
         | 
| 662 | 
            +
                end
         | 
| 663 | 
            +
              end
         | 
| 664 | 
            +
             | 
| 665 | 
            +
              def prompt_if_nil(params, options, param_key, label, required = false)
         | 
| 666 | 
            +
                params[param_key] ||= Morpheus::Cli::OptionTypes.prompt(
         | 
| 667 | 
            +
                  [{ 'fieldName' => param_key, 'fieldLabel' => label, 'type' => 'text', 'required' => required }],
         | 
| 668 | 
            +
                  options[:options], @api_client, {}
         | 
| 669 | 
            +
                )[param_key]
         | 
| 670 | 
            +
              end
         | 
| 671 | 
            +
            end
         |