morpheus-cli 4.2.2 → 4.2.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 44226a558c2f02d9ca3aea75025930a2adb9c8b63e41fa6437d14ad55f34211b
4
- data.tar.gz: debee18e47a2930a5da5cf2085d6463ce23171a70e875bbe81dc33d68ec1b640
3
+ metadata.gz: 55a52bf8952a3690771d35f8914b7d0d6e38df15722637675195d5cf11aefa28
4
+ data.tar.gz: f20e90f2a385cc4d1bb3e8dec5d6237e8849d0e8aee1dfe0a55dbb30a895b15a
5
5
  SHA512:
6
- metadata.gz: b3d6087cb623b08e6adabe1bf9e8f214b38c9eef2a627a47442b30c3f9523c7a5487fdff61c63f4fef885176695fc595cd0d751287a3e42b8edbebbf984b06f8
7
- data.tar.gz: ab8829f3d013e6ef4345447f90cd2defb13e2d91491f5b860ad44fe06ac022b3e2bf8baa3c12e525ab7e33f527e7b51b35043538ab82a52e79c5d628fff3dd0f
6
+ metadata.gz: '099de15a241b8b7fa06d637a44416fe2d485c986aa203bc5b937206f7901f5459e767b5395c7c5f6987e3e4885902af4de480f85973f69fa1f292ced4cbb9415'
7
+ data.tar.gz: c11981e1aba213f0447379a4f30ace695b51af37a7626360acac64954e2bef8199839393953f27252f7ba92b8d04310789917509e182952c7906d9c246908572
data/Dockerfile CHANGED
@@ -1,5 +1,5 @@
1
1
  FROM ruby:2.5.1
2
2
 
3
- RUN gem install morpheus-cli -v 4.2.2
3
+ RUN gem install morpheus-cli -v 4.2.3
4
4
 
5
5
  ENTRYPOINT ["morpheus"]
@@ -8,10 +8,10 @@ class Morpheus::InvoicesInterface < Morpheus::APIClient
8
8
  @expires_at = expires_at
9
9
  end
10
10
 
11
- def get(id)
11
+ def get(id, params={})
12
12
  raise "#{self.class}.get() passed a blank id!" if id.to_s == ''
13
13
  url = "#{@base_url}/api/invoices/#{id}"
14
- headers = { params: {}, authorization: "Bearer #{@access_token}" }
14
+ headers = { params: params, authorization: "Bearer #{@access_token}" }
15
15
  execute(method: :get, url: url, headers: headers)
16
16
  end
17
17
 
@@ -183,11 +183,21 @@ module Morpheus
183
183
  value_label = 'on|off' # or.. true|false
184
184
  elsif option_type['type'] == 'number'
185
185
  value_label = 'NUMBER'
186
+ elsif option_type['type'] == 'multiSelect'
187
+ value_label = 'LIST'
186
188
  # elsif option_type['type'] == 'select'
187
189
  # value_label = 'SELECT'
188
190
  # elsif option['type'] == 'select'
189
191
  end
190
192
  opts.on("--#{full_field_name} #{value_label}", String, description) do |val|
193
+ # attempt to parse JSON, this allows blank arrays for multiSelect like --tenants []
194
+ if (val.to_s[0] == '{' && val.to_s[-1] == '}') || (val.to_s[0] == '[' && val.to_s[-1] == ']')
195
+ begin
196
+ val = JSON.parse(val)
197
+ rescue
198
+ Morpheus::Logging::DarkPrinter.puts "Failed to parse option value '#{val}' as JSON" if Morpheus::Logging.debug?
199
+ end
200
+ end
191
201
  cur_namespace = custom_options
192
202
  field_namespace.each do |ns|
193
203
  next if ns.empty?
@@ -4,11 +4,13 @@ require 'rest_client'
4
4
  require 'optparse'
5
5
  require 'morpheus/cli/cli_command'
6
6
  require 'morpheus/cli/mixins/infrastructure_helper'
7
+ require 'morpheus/cli/mixins/provisioning_helper'
7
8
  require 'morpheus/cli/option_types'
8
9
 
9
10
  class Morpheus::Cli::Clouds
10
11
  include Morpheus::Cli::CliCommand
11
12
  include Morpheus::Cli::InfrastructureHelper
13
+ include Morpheus::Cli::ProvisioningHelper
12
14
 
13
15
  register_subcommands :list, :count, :get, :add, :update, :remove, :security_groups, :apply_security_groups, :types => :list_cloud_types
14
16
  register_subcommands :wiki, :update_wiki
@@ -267,14 +269,14 @@ class Morpheus::Cli::Clouds
267
269
 
268
270
  # Group
269
271
  group_id = nil
270
- group = params[:group] ? find_group_by_name_or_id(params[:group]) : nil
272
+ group = params[:group] ? find_group_by_name_or_id_for_provisioning(params[:group]) : nil
271
273
  if group
272
274
  group_id = group["id"]
273
275
  else
274
276
  # print_red_alert "Group not found or specified!"
275
277
  # exit 1
276
- groups_dropdown = @groups_interface.list({})['groups'].collect {|it| {'name' => it["name"], 'value' => it["id"]} }
277
- group_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'group', 'type' => 'select', 'fieldLabel' => 'Group', 'selectOptions' => groups_dropdown, 'required' => true, 'description' => 'Select Group.'}],options[:options],@api_client,{})
278
+ #groups_dropdown = @groups_interface.list({})['groups'].collect {|it| {'name' => it["name"], 'value' => it["id"]} }
279
+ group_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'group', 'type' => 'select', 'fieldLabel' => 'Group', 'optionSource' => 'groups', 'required' => true, 'description' => 'Select Group.'}],options[:options],@api_client,{})
278
280
  group_id = group_prompt['group']
279
281
  end
280
282
  cloud_payload['groupId'] = group_id
@@ -93,6 +93,10 @@ class Morpheus::Cli::InvoicesCommand
93
93
  opts.on('--tenant ID', String, "View invoices for a tenant. Default is your own account.") do |val|
94
94
  params['accountId'] = val
95
95
  end
96
+ opts.on('--raw-data', '--raw-data', "Display Raw Data, the cost data from the cloud provider's API.") do |val|
97
+ options[:show_raw_data] = true
98
+ params['rawData'] = true
99
+ end
96
100
  build_standard_list_options(opts, options)
97
101
  opts.footer = "List invoices."
98
102
  end
@@ -134,7 +138,24 @@ class Morpheus::Cli::InvoicesCommand
134
138
  if invoices.empty?
135
139
  print cyan,"No invoices found.",reset,"\n"
136
140
  else
137
- print_invoices_table(invoices, options)
141
+ columns = [
142
+ {"INVOICE ID" => lambda {|it| it['id'] } },
143
+ {"TYPE" => lambda {|it| format_invoice_ref_type(it) } },
144
+ {"REF ID" => lambda {|it| it['refId'] } },
145
+ {"REF NAME" => lambda {|it| it['refName'] } },
146
+ #{"INTERVAL" => lambda {|it| it['interval'] } },
147
+ {"ACCOUNT" => lambda {|it| it['account'] ? it['account']['name'] : '' } },
148
+ {"ACTIVE" => lambda {|it| format_boolean(it['active']) } },
149
+ {"PERIOD" => lambda {|it| format_invoice_period(it) } },
150
+ {"START" => lambda {|it| format_date(it['startDate']) } },
151
+ {"END" => lambda {|it| it['endDate'] ? format_date(it['endDate']) : '' } },
152
+ {"PRICE" => lambda {|it| format_money(it['totalPrice']) } },
153
+ {"COST" => lambda {|it| format_money(it['totalCost']) } },
154
+ ]
155
+ if options[:show_raw_data]
156
+ columns << {"RAW DATA" => lambda {|it| truncate_string(it['rawData'].to_s, 10) } }
157
+ end
158
+ print as_pretty_table(invoices, columns, options)
138
159
  print_results_pagination(json_response, {:label => "invoice", :n_label => "invoices"})
139
160
  end
140
161
  print reset,"\n"
@@ -148,6 +169,9 @@ class Morpheus::Cli::InvoicesCommand
148
169
  options = {}
149
170
  optparse = Morpheus::Cli::OptionParser.new do |opts|
150
171
  opts.banner = subcommand_usage("[id]")
172
+ opts.on('--raw-data', '--raw-data', "Display Raw Data, the cost data from the cloud provider's API.") do |val|
173
+ options[:show_raw_data] = true
174
+ end
151
175
  build_standard_get_options(opts, options)
152
176
  opts.footer = "Get details about a specific invoice."
153
177
  end
@@ -164,14 +188,17 @@ class Morpheus::Cli::InvoicesCommand
164
188
  end
165
189
 
166
190
  def _get(id, options)
167
-
191
+ params = {}
192
+ if options[:show_raw_data]
193
+ params['rawData'] = true
194
+ end
168
195
  begin
169
196
  @invoices_interface.setopts(options)
170
197
  if options[:dry_run]
171
- print_dry_run @invoices_interface.dry.get(id)
198
+ print_dry_run @invoices_interface.dry.get(id, params)
172
199
  return
173
200
  end
174
- json_response = @invoices_interface.get(id)
201
+ json_response = @invoices_interface.get(id, params)
175
202
  invoice = json_response['invoice']
176
203
  render_result = render_with_format(json_response, options, 'invoice')
177
204
  return 0 if render_result
@@ -190,17 +217,31 @@ class Morpheus::Cli::InvoicesCommand
190
217
  "Active" => lambda {|it| format_boolean(it['active']) },
191
218
  "Period" => lambda {|it| format_invoice_period(it) },
192
219
  #"Interval" => lambda {|it| it['interval'] },
193
- "Start" => lambda {|it| format_local_dt(it['startDate']) },
194
- "End" => lambda {|it| it['endDate'] ? format_local_dt(it['endDate']) : '' },
220
+ "Start" => lambda {|it| format_date(it['startDate']) },
221
+ "End" => lambda {|it| it['endDate'] ? format_date(it['endDate']) : '' },
195
222
  "Estimate" => lambda {|it| format_boolean(it['estimate']) },
196
- "Price" => lambda {|it| format_money(it['totalPrice']) },
197
- "Cost" => lambda {|it| format_money(it['totalCost']) },
223
+ "Compute Price" => lambda {|it| format_money(it['computePrice']) },
224
+ "Compute Cost" => lambda {|it| format_money(it['computeCost']) },
225
+ "Memory Price" => lambda {|it| format_money(it['memoryPrice']) },
226
+ "Memory Cost" => lambda {|it| format_money(it['memoryCost']) },
227
+ "Storage Price" => lambda {|it| format_money(it['storagePrice']) },
228
+ "Storage Cost" => lambda {|it| format_money(it['storageCost']) },
229
+ "Network Price" => lambda {|it| format_money(it['networkPrice']) },
230
+ "Network Cost" => lambda {|it| format_money(it['networkCost']) },
231
+ "License Price" => lambda {|it| format_money(it['licensePrice']) },
232
+ "License Cost" => lambda {|it| format_money(it['licenseCost']) },
233
+ "Extra Price" => lambda {|it| format_money(it['extraPrice']) },
234
+ "Extra Cost" => lambda {|it| format_money(it['extraCost']) },
235
+ "Running Price" => lambda {|it| format_money(it['runningPrice']) },
236
+ "Running Cost" => lambda {|it| format_money(it['runningCost']) },
237
+ "Total Price" => lambda {|it| format_money(it['totalPrice']) },
238
+ "Total Cost" => lambda {|it| format_money(it['totalCost']) },
198
239
  # "Created" => lambda {|it| format_local_dt(it['dateCreated']) },
199
240
  # "Updated" => lambda {|it| format_local_dt(it['lastUpdated']) }
200
241
  }
201
242
  print_description_list(description_cols, invoice)
202
243
 
203
- if invoice['rawData'] && !invoice['rawData'].empty?
244
+ if options[:show_raw_data]
204
245
  print_h2 "Raw Data"
205
246
  puts invoice['rawData']
206
247
  end
@@ -253,27 +294,6 @@ class Morpheus::Cli::InvoicesCommand
253
294
  # end
254
295
  # end
255
296
 
256
- def print_invoices_table(invoices, opts={})
257
- columns = [
258
- {"INVOICE ID" => lambda {|it| it['id'] } },
259
- {"TYPE" => lambda {|it| format_invoice_ref_type(it) } },
260
- {"REF ID" => lambda {|it| it['refId'] } },
261
- {"REF NAME" => lambda {|it| it['refName'] } },
262
- #{"INTERVAL" => lambda {|it| it['interval'] } },
263
- {"ACCOUNT" => lambda {|it| it['account'] ? it['account']['name'] : '' } },
264
- {"ACTIVE" => lambda {|it| format_boolean(it['active']) } },
265
- {"PERIOD" => lambda {|it| format_invoice_period(it) } },
266
- {"START" => lambda {|it| format_local_dt(it['startDate']) } },
267
- {"END" => lambda {|it| it['endDate'] ? format_local_dt(it['endDate']) : '' } },
268
- {"PRICE" => lambda {|it| format_money(it['totalPrice']) } },
269
- {"COST" => lambda {|it| format_money(it['totalCost']) } },
270
- ]
271
- if opts[:include_fields]
272
- columns = opts[:include_fields]
273
- end
274
- print as_pretty_table(invoices, columns, opts)
275
- end
276
-
277
297
  def format_invoice_ref_type(it)
278
298
  if it['refType'] == 'ComputeZone'
279
299
  "Cloud"
@@ -111,17 +111,15 @@ module Morpheus
111
111
  elsif option_type['type'] == 'select'
112
112
  value = select_prompt(option_type.merge({'defaultValue' => value, 'defaultInputValue' => input_value}), api_client, (api_params || {}).merge(results), true)
113
113
  elsif option_type['type'] == 'multiSelect'
114
- value_list = value.is_a?(String) ? value.parse_csv : [value].flatten
115
- input_value_list = input_value.is_a?(String) ? input_value.parse_csv : [input_value].flatten
116
- if value_list.size > 1
117
- select_value_list = []
118
- value_list.each_with_index do |v, i|
119
- select_value_list << select_prompt(option_type.merge({'defaultValue' => v, 'defaultInputValue' => input_value_list[i]}), api_client, (api_params || {}).merge(results), true)
120
- end
121
- value = select_value_list
122
- else
123
- value = select_prompt(option_type.merge({'defaultValue' => value, 'defaultInputValue' => input_value}), api_client, (api_params || {}).merge(results), true)
114
+ # support value as csv like "thing1, thing2"
115
+ value_list = value.is_a?(String) ? value.parse_csv.collect {|v| v ? v.to_s.strip : v } : [value].flatten
116
+ input_value_list = input_value.is_a?(String) ? input_value.parse_csv.collect {|v| v ? v.to_s.strip : v } : [input_value].flatten
117
+ select_value_list = []
118
+ value_list.each_with_index do |v, i|
119
+ select_value_list << select_prompt(option_type.merge({'defaultValue' => v, 'defaultInputValue' => input_value_list[i]}), api_client, (api_params || {}).merge(results), true)
124
120
  end
121
+ value = select_value_list
122
+
125
123
  end
126
124
  if options[:always_prompt] != true
127
125
  value_found = true
@@ -4,9 +4,7 @@ class Morpheus::Cli::ProvisioningLicensesCommand
4
4
  include Morpheus::Cli::CliCommand
5
5
  set_command_name :'provisioning-licenses'
6
6
  register_subcommands :list, :get, :add, :update, :remove, :reservations, :'list-types'
7
-
8
7
  set_command_hidden
9
-
10
8
  def connect(opts)
11
9
  @api_client = establish_remote_appliance_connection(opts)
12
10
  @provisioning_licenses_interface = @api_client.provisioning_licenses
@@ -55,11 +53,12 @@ class Morpheus::Cli::ProvisioningLicensesCommand
55
53
  {"ID" => lambda {|license| license['id'] } },
56
54
  {"NAME" => lambda {|license| license['name'] } },
57
55
  {"LICENSE TYPE" => lambda {|license| license['licenseType']['name'] rescue license['licenseType'] } },
56
+ {"VERSION" => lambda {|license| license['licenseVersion'] } },
58
57
  {"COPIES" => lambda {|license|
59
58
  "#{license['reservationCount']}/#{license['copies']}"
60
59
  } },
61
- {"TENANTS" => lambda {|it| it['tenants'] ? it['tenants'].collect {|acnt| acnt['name']}.join(', ') : '' } },
62
60
  {"VIRTUAL IMAGES" => lambda {|it| it['virtualImages'] ? it['virtualImages'].collect {|v| v['name']}.join(', ') : '' } },
61
+ {"TENANTS" => lambda {|it| it['tenants'] ? it['tenants'].collect {|acnt| acnt['name']}.join(', ') : '' } },
63
62
  ]
64
63
  if options[:include_fields]
65
64
  columns = options[:include_fields]
@@ -121,11 +120,16 @@ class Morpheus::Cli::ProvisioningLicensesCommand
121
120
  {"Name" => lambda {|license| license['name'] } },
122
121
  {"License Type" => lambda {|license| license['licenseType']['name'] rescue license['licenseType'] } },
123
122
  {"License Key" => lambda {|license| license['licenseKey'] } },
123
+ {"Org Name" => lambda {|license| license['orgName'] } },
124
+ {"Full Name" => lambda {|license| license['fullName'] } },
125
+ {"Version" => lambda {|license| license['licenseVersion'] } },
126
+ {"Description" => lambda {|license| license['description'] } },
124
127
  {"Copies" => lambda {|license|
125
128
  "#{license['reservationCount']}/#{license['copies']}"
126
129
  } },
127
- {"Tenants" => lambda {|it| it['tenants'] ? it['tenants'].collect {|acnt| acnt['name']}.join(', ') : '' } },
130
+ {"Description" => lambda {|license| license['description'] } },
128
131
  {"Virtual Images" => lambda {|it| it['virtualImages'] ? it['virtualImages'].collect {|v| v['name']}.join(', ') : '' } },
132
+ {"Tenants" => lambda {|it| it['tenants'] ? it['tenants'].collect {|acnt| acnt['name']}.join(', ') : '' } },
129
133
  ]
130
134
  print_description_list(columns, license, options)
131
135
  print reset,"\n"
@@ -1,6 +1,6 @@
1
1
 
2
2
  module Morpheus
3
3
  module Cli
4
- VERSION = "4.2.2"
4
+ VERSION = "4.2.3"
5
5
  end
6
6
  end
@@ -2,6 +2,7 @@ require 'time'
2
2
  require 'filesize'
3
3
  require 'money'
4
4
 
5
+ DEFAULT_DATE_FORMAT = "%x"
5
6
  DEFAULT_TIME_FORMAT = "%x %I:%M %p"
6
7
  ALTERNATE_TIME_FORMAT = "yyyy-MM-dd'T'HH:mm:ss'Z'"
7
8
 
@@ -64,11 +65,11 @@ def format_local_dt(dt, options={})
64
65
  end
65
66
 
66
67
  def format_date(dt, options={})
67
- format_dt(dt, options.merge({local: true}))
68
+ format_dt(dt, {format: DEFAULT_DATE_FORMAT}.merge(options))
68
69
  end
69
70
 
70
71
  def format_local_date(dt, options={})
71
- format_dt(dt, {local: true, format: "%x"}.merge(options))
72
+ format_dt(dt, {local: true, format: DEFAULT_DATE_FORMAT}.merge(options))
72
73
  end
73
74
 
74
75
  def format_dt_as_param(dt)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: morpheus-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.2.2
4
+ version: 4.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Estes
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2020-03-14 00:00:00.000000000 Z
14
+ date: 2020-03-17 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: bundler