Class: Morpheus::Cli::VdiAllocationsCommand

Inherits:
Object
  • Object
show all
Includes:
CliCommand, OptionSourceHelper, VdiHelper
Defined in:
lib/morpheus/cli/vdi_allocations_command.rb

Overview

CLI command VDI Allocation management UI is Tools: VDI Allocations API is /vdi-allocations and returns vdiAllocations

Instance Attribute Summary

Attributes included from CliCommand

#no_prompt

Instance Method Summary collapse

Methods included from OptionSourceHelper

#find_available_user_option, #find_cloud_option, #find_group_option, #find_tenant_option, #get_available_user_options, #get_cloud_options, #get_group_options, #get_tenant_options, included, #load_option_source_data, #options_interface, #parse_cloud_id_list, #parse_group_id_list, #parse_option_source_id_list, #parse_project_id_list, #parse_tenant_id_list, #parse_user_id_list

Methods included from VdiHelper

#find_vdi_allocation_by_id, #find_vdi_app_by_id, #find_vdi_app_by_name, #find_vdi_app_by_name_or_id, #find_vdi_gateway_by_id, #find_vdi_gateway_by_name, #find_vdi_gateway_by_name_or_id, #find_vdi_pool_by_id, #find_vdi_pool_by_name, #find_vdi_pool_by_name_or_id, #format_vdi_allocation_status, #format_vdi_pool_status, #get_available_vdi_apps, #get_vdi_app_by_name_or_code, included, #vdi_allocation_list_key, #vdi_allocation_object_key, #vdi_allocations_interface, #vdi_app_list_key, #vdi_app_object_key, #vdi_apps_interface, #vdi_gateway_list_key, #vdi_gateway_object_key, #vdi_gateways_interface, #vdi_pool_list_key, #vdi_pool_object_key, #vdi_pools_interface

Methods included from CliCommand

#apply_options, #build_common_options, #build_option_type_options, #build_standard_add_options, #build_standard_delete_options, #build_standard_get_options, #build_standard_list_options, #build_standard_post_options, #build_standard_put_options, #build_standard_remove_options, #build_standard_update_options, #command_description, #command_name, #default_refresh_interval, #default_sigdig, #default_subcommand, #establish_remote_appliance_connection, #full_command_usage, #get_subcommand_description, #handle_subcommand, included, #interactive?, #my_help_command, #my_terminal, #my_terminal=, #parse_bytes_param, #parse_id_list, #parse_list_options, #parse_list_subtitles, #parse_passed_options, #parse_payload, #parse_query_options, #print, #print_error, #println, #prog_name, #puts, #puts_error, #raise_args_error, #raise_command_error, #render_response, #run_command_for_each_arg, #subcommand_aliases, #subcommand_description, #subcommand_usage, #subcommands, #usage, #validate_outfile, #verify_args!, #visible_subcommands

Instance Method Details

#_get(id, params, options) ⇒ Object



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/morpheus/cli/vdi_allocations_command.rb', line 120

def _get(id, params, options)
  @vdi_allocations_interface.setopts(options)
  if options[:dry_run]
    print_dry_run @vdi_allocations_interface.dry.get(id, params)
    return
  end
  json_response = @vdi_allocations_interface.get(id, params)
  vdi_allocation = json_response[vdi_allocation_object_key]
  render_response(json_response, options, vdi_allocation_object_key) do
    print_h1 "VDI Allocation Details", [], options
    print cyan
    show_columns = vdi_allocation_column_definitions
    print_description_list(show_columns, vdi_allocation)
    print reset,"\n"
  end
  return 0, nil
end

#connect(opts) ⇒ Object



16
17
18
19
20
21
# File 'lib/morpheus/cli/vdi_allocations_command.rb', line 16

def connect(opts)
  @api_client = establish_remote_appliance_connection(opts)
  @vdi_pools_interface = @api_client.vdi_pools
  @vdi_allocations_interface = @api_client.vdi_allocations
  @option_types_interface = @api_client.option_types
end

#get(args) ⇒ Object



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/morpheus/cli/vdi_allocations_command.rb', line 99

def get(args)
  params = {}
  options = {}
  optparse = Morpheus::Cli::OptionParser.new do |opts|
    opts.banner = subcommand_usage("[allocation]")
    build_standard_get_options(opts, options)
    opts.footer = <<-EOT
Get details about a specific VDI allocation.
[allocation] is required. This is the id of a VDI allocation.
EOT
  end
  optparse.parse!(args)
  verify_args!(args:args, optparse:optparse, min:1)
  connect(options)
  params.merge!(parse_query_options(options))
  id_list = parse_id_list(args)
  return run_command_for_each_arg(id_list) do |arg|
    _get(arg, params, options)
  end
end

#handle(args) ⇒ Object



23
24
25
# File 'lib/morpheus/cli/vdi_allocations_command.rb', line 23

def handle(args)
  handle_subcommand(args)
end

#list(args) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/morpheus/cli/vdi_allocations_command.rb', line 27

def list(args)
  options = {}
  params = {}
  ref_ids = []
  optparse = Morpheus::Cli::OptionParser.new do |opts|
    opts.banner = subcommand_usage("[search]")
    build_standard_list_options(opts, options)
    opts.on('--id ID', String, "Filter by VDI Allocation ID" ) do |val|
      params['id'] = parse_id_list(val)
    end
    opts.on('--status STATUS', String, "Filter by VDI Allocation Status" ) do |val|
      params['status'] = parse_id_list(val)
    end
    opts.on('--pool POOL', String, "Filter by VDI Pool Name or ID" ) do |val|
      options[:pool] = val
    end
    opts.on('-u', '--user USER', "Filter by User Username or ID" ) do |val|
      options[:user] = val
    end
    opts.footer = "List VDI allocations."
  end
  optparse.parse!(args)
  connect(options)
  if args.count > 0
    options[:phrase] = args.join(" ")
  end
  params.merge!(parse_list_options(options))
  # --id
  if options[:pool]
    pool_ids = parse_id_list(options[:pool]).collect { |it|
      vdi_pool = find_vdi_pool_by_name_or_id(it)
      vdi_pool ? vdi_pool['id'] : nil
    }
    return 1 if pool_ids.include?(nil)
    params['poolId'] = pool_ids
  end
  # --pool
  if options[:pool]
    pool_ids = parse_id_list(options[:pool]).collect { |it|
      vdi_pool = find_vdi_pool_by_name_or_id(it)
      vdi_pool ? vdi_pool['id'] : nil
    }
    return 1 if pool_ids.include?(nil)
    params['poolId'] = pool_ids
  end
  # --user
  if options[:user]
    user_ids = parse_user_id_list(options[:user])
    return 1 if user_ids.nil?
    params['userId'] = user_ids
  end
  @vdi_allocations_interface.setopts(options)
  if options[:dry_run]
    print_dry_run @vdi_allocations_interface.dry.list(params)
    return
  end
  json_response = @vdi_allocations_interface.list(params)
  render_response(json_response, options, vdi_allocation_list_key) do
    vdi_allocations = json_response[vdi_allocation_list_key]
    print_h1 "Morpheus VDI Allocations", parse_list_subtitles(options), options
    if vdi_allocations.empty?
      print cyan,"No VDI allocations found.",reset,"\n"
    else
      list_columns = vdi_allocation_column_definitions.upcase_keys!
      print as_pretty_table(vdi_allocations, list_columns, options)
      print_results_pagination(json_response)
    end
    print reset,"\n"
  end
  return 0, nil
end