Class: Morpheus::Cli::License
- Inherits:
-
Object
- Object
- Morpheus::Cli::License
show all
- Includes:
- CliCommand
- Defined in:
- lib/morpheus/cli/license.rb
Instance Attribute Summary
Attributes included from CliCommand
#no_prompt
Instance Method Summary
collapse
Methods included from CliCommand
#build_common_options, #build_option_type_options, #command_name, #default_subcommand, #establish_remote_appliance_connection, #full_command_usage, #handle_subcommand, included, #interactive?, #my_help_command, #my_terminal, #my_terminal=, #parse_id_list, #parse_list_options, #parse_list_subtitles, #print, #print_error, #puts, #puts_error, #raise_command_error, #run_command_for_each_arg, #subcommand_aliases, #subcommand_usage, #subcommands, #usage, #verify_access_token!
Constructor Details
Returns a new instance of License.
13
14
15
|
# File 'lib/morpheus/cli/license.rb', line 13
def initialize()
end
|
Instance Method Details
#apply(args) ⇒ Object
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
# File 'lib/morpheus/cli/license.rb', line 78
def apply(args)
options = {}
account_name = nil
optparse = Morpheus::Cli::OptionParser.new do |opts|
opts.banner = subcommand_usage("[key]")
build_common_options(opts, options, [:json, :dry_run, :remote])
end
optparse.parse!(args)
connect(options)
begin
if args[0]
key = args[0]
else
v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'licenseKey', 'fieldLabel' => 'License Key', 'type' => 'text', 'required' => true}], options[:options])
key = v_prompt['licenseKey'] || ''
end
if options[:dry_run]
print_dry_run @license_interface.dry.apply(key)
return 0
end
json_result = @license_interface.apply(key)
license = json_result['license']
if options[:json]
puts JSON.pretty_generate(json_result)
else
print_green_success "License applied successfully!"
end
return 0
rescue RestClient::Exception => e
print_rest_exception(e, options)
return false
end
end
|
#connect(opts) ⇒ Object
17
18
19
20
21
|
# File 'lib/morpheus/cli/license.rb', line 17
def connect(opts)
@api_client = establish_remote_appliance_connection(opts)
@api_client = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url)
@license_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).license
end
|
#decode(args) ⇒ Object
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
|
# File 'lib/morpheus/cli/license.rb', line 113
def decode(args)
options = {}
optparse = Morpheus::Cli::OptionParser.new do |opts|
opts.banner = subcommand_usage("[key]")
build_common_options(opts, options, [:json, :dry_run, :remote])
opts. = "Decode a license key."
end
optparse.parse!(args)
connect(options)
key = nil
if args[0]
key = args[0]
else
v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'licenseKey', 'fieldLabel' => 'License Key', 'type' => 'text', 'required' => true}], options[:options])
key = v_prompt['licenseKey'] || ''
end
begin
if options[:dry_run]
print_dry_run @license_interface.dry.decode(key)
return
end
json_result = @license_interface.decode(key)
license = json_result['license']
if options[:json]
puts JSON.pretty_generate(json_result)
else
if license.nil?
puts_error "Unable to decode license."
puts_error json_results['msg'] if json_results['msg']
return 1
else
print_h1 "License"
max_memory = "Unlimited"
max_storage = "Unlimited"
max_memory = Filesize.from("#{license['maxMemory']} B").pretty if license['maxMemory'].to_i != 0
max_storage = Filesize.from("#{license['maxStorage']} B").pretty if license['maxStorage'].to_i != 0
print cyan
description_cols = {
"Account" => 'accountName',
"Product Tier" => lambda {|it| format_product_tier(it) },
"Start Date" => lambda {|it| format_local_dt(it['startDate']) },
"End Date" => lambda {|it| format_local_dt(it['endDate']) },
"Max Memory" => lambda {|it| max_memory },
"Max Storage" => lambda {|it| max_storage },
"Max Instances" => lambda {|it| it["maxInstances"].to_i == 0 ? 'Unlimited' : it["maxInstances"] },
"Hard Limit" => lambda {|it| it[""] == false ? 'Yes' : 'No' },
}
print_description_list(description_cols, license)
print reset,"\n"
end
end
return 0
rescue RestClient::Exception => e
print_rest_exception(e, options)
return false
end
end
|
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
|
# File 'lib/morpheus/cli/license.rb', line 171
def format_product_tier(license)
product_tier = license['productTier'] || 'capacity'
if product_tier == 'capacity'
'Capacity'
elsif product_tier == 'essentials'
'Essentials'
elsif product_tier == 'pro'
'Pro'
elsif product_tier == 'enterprise'
'Enterprise'
elsif product_tier == 'msp'
'Service Provider'
else
product_tier.to_s.capitalize
end
end
|
#get(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
|
# File 'lib/morpheus/cli/license.rb', line 27
def get(args)
options = {}
optparse = Morpheus::Cli::OptionParser.new do |opts|
opts.banner = subcommand_usage()
build_common_options(opts, options, [:json, :dry_run, :remote])
end
optparse.parse!(args)
connect(options)
begin
if options[:dry_run]
print_dry_run @license_interface.dry.get()
return
end
json_result = @license_interface.get()
license = json_result['license']
used_memory = json_result['licenseUsedMemory']
if options[:json]
puts JSON.pretty_generate(json_result)
else
if license.nil?
puts_error "No license currently applied to the appliance."
return 1
else
print_h1 "License"
max_memory = "Unlimited"
max_storage = "Unlimited"
max_memory = Filesize.from("#{license['maxMemory']} B").pretty if license['maxMemory'].to_i != 0
max_storage = Filesize.from("#{license['maxStorage']} B").pretty if license['maxStorage'].to_i != 0
used_memory = Filesize.from("#{used_memory} B").pretty if used_memory.to_i != 0
print cyan
description_cols = {
"Account" => 'accountName',
"Product Tier" => lambda {|it| format_product_tier(it) },
"Start Date" => lambda {|it| format_local_dt(it['startDate']) },
"End Date" => lambda {|it| format_local_dt(it['endDate']) },
"Memory" => lambda {|it| "#{used_memory} / #{max_memory}" },
"Max Storage" => lambda {|it| "#{max_storage}" },
"Max Instances" => lambda {|it| it["maxInstances"].to_i == 0 ? 'Unlimited' : it["maxInstances"] },
"Hard Limit" => lambda {|it| it[""] == false ? 'Yes' : 'No' },
}
print_description_list(description_cols, license)
print reset,"\n"
end
end
return 0
rescue RestClient::Exception => e
print_rest_exception(e, options)
return false
end
end
|
#handle(args) ⇒ Object
23
24
25
|
# File 'lib/morpheus/cli/license.rb', line 23
def handle(args)
handle_subcommand(args)
end
|