opennebula-cli 6.10.2 → 6.99.85.pre
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/oneacct +5 -18
- data/bin/oneacl +2 -18
- data/bin/onebackupjob +2 -18
- data/bin/onecluster +36 -18
- data/bin/onedatastore +2 -18
- data/bin/oneflow +2 -18
- data/bin/oneflow-template +8 -24
- data/bin/onegroup +2 -18
- data/bin/onehook +2 -18
- data/bin/onehost +4 -48
- data/bin/oneimage +2 -18
- data/bin/oneirb +2 -61
- data/bin/onelog +3 -22
- data/bin/onemarket +2 -18
- data/bin/onemarketapp +2 -30
- data/bin/onesecgroup +2 -18
- data/bin/oneshowback +2 -18
- data/bin/onetemplate +2 -19
- data/bin/oneuser +2 -18
- data/bin/onevdc +2 -18
- data/bin/onevm +21 -19
- data/bin/onevmgroup +2 -18
- data/bin/onevnet +2 -18
- data/bin/onevntemplate +2 -18
- data/bin/onevrouter +13 -20
- data/bin/onezone +2 -18
- data/lib/cli_helper.rb +1 -1
- data/lib/command_parser.rb +1 -1
- data/lib/one_helper/oneacct_helper.rb +10 -2
- data/lib/one_helper/oneacl_helper.rb +1 -1
- data/lib/one_helper/onebackupjob_helper.rb +1 -1
- data/lib/one_helper/onecluster_helper.rb +49 -1
- data/lib/one_helper/onedatastore_helper.rb +1 -1
- data/lib/one_helper/oneflow_helper.rb +1 -1
- data/lib/one_helper/oneflowtemplate_helper.rb +17 -17
- data/lib/one_helper/onegroup_helper.rb +4 -55
- data/lib/one_helper/onehook_helper.rb +1 -1
- data/lib/one_helper/onehost_helper.rb +29 -87
- data/lib/one_helper/oneimage_helper.rb +2 -19
- data/lib/one_helper/onemarket_helper.rb +1 -1
- data/lib/one_helper/onemarketapp_helper.rb +13 -3
- data/lib/one_helper/onequota_helper.rb +35 -8
- data/lib/one_helper/onesecgroup_helper.rb +1 -1
- data/lib/one_helper/onetemplate_helper.rb +1 -8
- data/lib/one_helper/oneuser_helper.rb +41 -75
- data/lib/one_helper/onevdc_helper.rb +1 -1
- data/lib/one_helper/onevm_helper.rb +119 -102
- data/lib/one_helper/onevmgroup_helper.rb +1 -1
- data/lib/one_helper/onevnet_helper.rb +1 -1
- data/lib/one_helper/onevntemplate_helper.rb +1 -1
- data/lib/one_helper/onevrouter_helper.rb +1 -1
- data/lib/one_helper/onezone_helper.rb +10 -23
- data/lib/one_helper.rb +34 -156
- data/share/schemas/xsd/acct.xsd +2 -0
- data/share/schemas/xsd/cluster.xsd +21 -0
- data/share/schemas/xsd/datastore.xsd +1 -13
- data/share/schemas/xsd/group.xsd +11 -122
- data/share/schemas/xsd/group_pool.xsd +8 -120
- data/share/schemas/xsd/host.xsd +19 -21
- data/share/schemas/xsd/image.xsd +0 -1
- data/share/schemas/xsd/monitoring_data.xsd +0 -8
- data/share/schemas/xsd/opennebula_configuration.xsd +23 -1
- data/share/schemas/xsd/plan.xsd +29 -0
- data/share/schemas/xsd/requirements.xsd +45 -0
- data/share/schemas/xsd/scheduler_driver_action.xsd +24 -0
- data/share/schemas/xsd/shared.xsd +67 -0
- data/share/schemas/xsd/user.xsd +10 -122
- data/share/schemas/xsd/user_pool.xsd +8 -120
- data/share/schemas/xsd/vm.xsd +37 -28
- data/share/schemas/xsd/vm_pool.xsd +0 -12
- data/share/schemas/xsd/vm_pool_extended.xsd +12 -0
- data/share/schemas/xsd/vmtemplate.xsd +0 -3
- data/share/schemas/xsd/vnet.xsd +0 -5
- data/share/schemas/xsd/vnet_pool_extended.xsd +12 -0
- metadata +11 -9
- data/bin/onevcenter +0 -471
- data/lib/one_helper/onevcenter_helper.rb +0 -523
@@ -1,523 +0,0 @@
|
|
1
|
-
# -------------------------------------------------------------------------- #
|
2
|
-
# Copyright 2002-2024, OpenNebula Project, OpenNebula Systems #
|
3
|
-
# #
|
4
|
-
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
5
|
-
# not use this file except in compliance with the License. You may obtain #
|
6
|
-
# a copy of the License at #
|
7
|
-
# #
|
8
|
-
# http://www.apache.org/licenses/LICENSE-2.0 #
|
9
|
-
# #
|
10
|
-
# Unless required by applicable law or agreed to in writing, software #
|
11
|
-
# distributed under the License is distributed on an "AS IS" BASIS, #
|
12
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
13
|
-
# See the License for the specific language governing permissions and #
|
14
|
-
# limitations under the License. #
|
15
|
-
#--------------------------------------------------------------------------- #
|
16
|
-
|
17
|
-
require 'one_helper'
|
18
|
-
|
19
|
-
##############################################################################
|
20
|
-
# Module OneVcenterHelper
|
21
|
-
##############################################################################
|
22
|
-
class OneVcenterHelper < OpenNebulaHelper::OneHelper
|
23
|
-
|
24
|
-
#
|
25
|
-
# vCenter importer will divide rvmomi resources
|
26
|
-
# in this group, makes parsing easier.
|
27
|
-
module VOBJECT
|
28
|
-
|
29
|
-
DATASTORE = 1
|
30
|
-
TEMPLATE = 2
|
31
|
-
NETWORK = 3
|
32
|
-
IMAGE = 4
|
33
|
-
HOST = 5
|
34
|
-
|
35
|
-
end
|
36
|
-
|
37
|
-
#
|
38
|
-
# onevcenter helper main constant
|
39
|
-
# This will control everything displayed on STDOUT
|
40
|
-
# Resources (above) uses this table
|
41
|
-
#
|
42
|
-
# struct: [Array] LIST FORMAT for opennebula cli
|
43
|
-
# related methods: * cli_format
|
44
|
-
#
|
45
|
-
# columns: [Hash(column => Integer)] Will be used in the list command,
|
46
|
-
# Integer represent nbytes
|
47
|
-
# related methods: * format_list
|
48
|
-
#
|
49
|
-
# cli: [Array] with mandatory args, for example image
|
50
|
-
# listing needs a datastore
|
51
|
-
# related methods: * parse_opts
|
52
|
-
#
|
53
|
-
# dialogue: [Lambda] Used only for Vobject that require a previous
|
54
|
-
# dialogue with the user, will be triggered
|
55
|
-
# on importation process
|
56
|
-
# related methods: * network_dialogue
|
57
|
-
# * template_dialogue
|
58
|
-
#
|
59
|
-
TABLE = {
|
60
|
-
VOBJECT::DATASTORE => {
|
61
|
-
:struct => ['DATASTORE_LIST', 'DATASTORE'],
|
62
|
-
:columns =>
|
63
|
-
{ :IMID => 5, :REF => 15, :NAME => 50, :CLUSTERS => 10 },
|
64
|
-
:cli => [:host],
|
65
|
-
:dialogue => ->(arg) {}
|
66
|
-
},
|
67
|
-
VOBJECT::TEMPLATE => {
|
68
|
-
:struct => ['TEMPLATE_LIST', 'TEMPLATE'],
|
69
|
-
:columns => { :IMID => 5, :REF => 10, :NAME => 50 },
|
70
|
-
:cli => [:host],
|
71
|
-
:dialogue => ->(arg) { OneVcenterHelper.template_dialogue(arg) }
|
72
|
-
},
|
73
|
-
VOBJECT::NETWORK => {
|
74
|
-
:struct => ['NETWORK_LIST', 'NETWORK'],
|
75
|
-
:columns => {
|
76
|
-
:IMID => 5,
|
77
|
-
:REF => 15,
|
78
|
-
:NAME => 30,
|
79
|
-
:CLUSTERS => 20
|
80
|
-
},
|
81
|
-
:cli => [:host],
|
82
|
-
:dialogue => ->(arg) { OneVcenterHelper.network_dialogue(arg) }
|
83
|
-
},
|
84
|
-
VOBJECT::IMAGE => {
|
85
|
-
:struct => ['IMAGE_LIST', 'IMAGE'],
|
86
|
-
:columns => { :IMID => 5, :REF => 35, :PATH => 60 },
|
87
|
-
:cli => [:host, :datastore],
|
88
|
-
:dialogue => ->(arg) {}
|
89
|
-
},
|
90
|
-
VOBJECT::HOST => {
|
91
|
-
:struct => ['HOST_LIST', 'HOST'],
|
92
|
-
:columns => { :DATACENTER => 10, :NAME => 30, :REF => 35 },
|
93
|
-
:cli => [],
|
94
|
-
:dialogue => ->(arg) {}
|
95
|
-
}
|
96
|
-
}
|
97
|
-
|
98
|
-
################################################################
|
99
|
-
# CLI ARGS
|
100
|
-
################################################################
|
101
|
-
|
102
|
-
# these methods will be used by table :cli property
|
103
|
-
# the purpose is to inject code when -d option in this case is used
|
104
|
-
#
|
105
|
-
# @param arg [String] The parameter passed to the option:w
|
106
|
-
#
|
107
|
-
|
108
|
-
def datastore(arg)
|
109
|
-
ds = VCenterDriver::VIHelper.one_item(OpenNebula::Datastore, arg)
|
110
|
-
|
111
|
-
{
|
112
|
-
:ds_ref => ds['TEMPLATE/VCENTER_DS_REF'],
|
113
|
-
:one_item => ds
|
114
|
-
}
|
115
|
-
end
|
116
|
-
|
117
|
-
def host(arg)
|
118
|
-
arg
|
119
|
-
end
|
120
|
-
|
121
|
-
########################
|
122
|
-
|
123
|
-
# In list command you can use this method to print a header
|
124
|
-
#
|
125
|
-
# @param vcenter_host [String] this text will be displayed
|
126
|
-
#
|
127
|
-
def show_header(vcenter_host)
|
128
|
-
CLIHelper.scr_bold
|
129
|
-
CLIHelper.scr_underline
|
130
|
-
puts "# vCenter: #{vcenter_host}".ljust(50)
|
131
|
-
CLIHelper.scr_restore
|
132
|
-
puts
|
133
|
-
end
|
134
|
-
|
135
|
-
# Using for parse a String into a VOBJECT
|
136
|
-
# We will use VOBJECT instances for handle any operatiion
|
137
|
-
#
|
138
|
-
# @param type [String] String representing the vCenter resource
|
139
|
-
#
|
140
|
-
def object_update(type)
|
141
|
-
raise 'you need to use -o option!' unless type
|
142
|
-
|
143
|
-
type = type.downcase
|
144
|
-
case type
|
145
|
-
when 'datastores'
|
146
|
-
@vobject = VOBJECT::DATASTORE
|
147
|
-
when 'templates'
|
148
|
-
@vobject = VOBJECT::TEMPLATE
|
149
|
-
when 'networks'
|
150
|
-
@vobject = VOBJECT::NETWORK
|
151
|
-
when 'images'
|
152
|
-
@vobject = VOBJECT::IMAGE
|
153
|
-
when 'hosts'
|
154
|
-
@vobject = VOBJECT::HOST
|
155
|
-
else
|
156
|
-
puts "unknown #{type} type option"
|
157
|
-
puts ' -o options:'
|
158
|
-
puts ' datastores'
|
159
|
-
puts ' templates'
|
160
|
-
puts ' networks'
|
161
|
-
puts ' images'
|
162
|
-
puts ' hosts'
|
163
|
-
|
164
|
-
exit 0
|
165
|
-
end
|
166
|
-
end
|
167
|
-
|
168
|
-
# Handles connection to vCenter.
|
169
|
-
#
|
170
|
-
# @param options [Hash] options for the connection
|
171
|
-
#
|
172
|
-
def connection_options(object_name, options)
|
173
|
-
if options[:vuser].nil? || options[:vcenter].nil?
|
174
|
-
raise 'vCenter connection parameters are mandatory to import'\
|
175
|
-
" #{object_name}:\n"\
|
176
|
-
"\t --vcenter vCenter hostname\n"\
|
177
|
-
"\t --vuser username to login in vcenter"
|
178
|
-
end
|
179
|
-
|
180
|
-
password = options[:vpass] || OpenNebulaHelper::OneHelper.get_password
|
181
|
-
{
|
182
|
-
:user => options[:vuser],
|
183
|
-
:password => password,
|
184
|
-
:host => options[:vcenter],
|
185
|
-
:port => options[:port]
|
186
|
-
}
|
187
|
-
end
|
188
|
-
|
189
|
-
def cli_format(hash)
|
190
|
-
{
|
191
|
-
TABLE[@vobject][:struct].first =>
|
192
|
-
{
|
193
|
-
TABLE[@vobject][:struct].last =>
|
194
|
-
hash.values
|
195
|
-
}
|
196
|
-
}
|
197
|
-
end
|
198
|
-
|
199
|
-
# General method to list vCenter objects
|
200
|
-
#
|
201
|
-
# @param options [Hash] User CLI options
|
202
|
-
# @param args [Hash] Search arguments
|
203
|
-
def list(options, args)
|
204
|
-
if !options[:host]
|
205
|
-
# This case is to list available hosts, instead other object
|
206
|
-
list_hosts(options)
|
207
|
-
else
|
208
|
-
vi_client = VCenterDriver::VIClient.new_from_host(
|
209
|
-
options[:host]
|
210
|
-
)
|
211
|
-
importer = VCenterDriver::VcImporter.new_child(
|
212
|
-
@client,
|
213
|
-
vi_client,
|
214
|
-
options[:object]
|
215
|
-
)
|
216
|
-
|
217
|
-
list_object(options, importer.retrieve_resources(args))
|
218
|
-
end
|
219
|
-
end
|
220
|
-
|
221
|
-
# This method will print a list for a vcenter_resource.
|
222
|
-
#
|
223
|
-
def list_object(options, list)
|
224
|
-
vcenter_host = list.keys[0]
|
225
|
-
list = cli_format(list.values.first)
|
226
|
-
table = format_list
|
227
|
-
|
228
|
-
show_header(vcenter_host)
|
229
|
-
|
230
|
-
table.show(list, options)
|
231
|
-
end
|
232
|
-
|
233
|
-
# List unimported hosts
|
234
|
-
#
|
235
|
-
# @param options [Hash] User CLI options
|
236
|
-
def list_hosts(options)
|
237
|
-
con_ops = connection_options('hosts', options)
|
238
|
-
vi_client = VCenterDriver::VIClient.new(con_ops)
|
239
|
-
dc_folder = VCenterDriver::DatacenterFolder.new(vi_client)
|
240
|
-
hpool = VCenterDriver::VIHelper.one_pool(OpenNebula::HostPool,
|
241
|
-
false)
|
242
|
-
|
243
|
-
VCenterDriver::VIHelper.set_client(nil, @client)
|
244
|
-
|
245
|
-
list = []
|
246
|
-
hosts = dc_folder.get_unimported_hosts(hpool, vi_client.vim.host)
|
247
|
-
|
248
|
-
hosts.each do |key, value|
|
249
|
-
value.each do |v|
|
250
|
-
v[:datacenter] = key
|
251
|
-
list << v
|
252
|
-
end
|
253
|
-
end
|
254
|
-
|
255
|
-
format_list.show(hosts, options)
|
256
|
-
end
|
257
|
-
|
258
|
-
# handles :cli section of TABLE
|
259
|
-
# used for executing the dialogue in some VOBJECTS
|
260
|
-
#
|
261
|
-
# @param object_info [Hash] This is the object
|
262
|
-
# with all the info related to the object
|
263
|
-
# that will be imported
|
264
|
-
#
|
265
|
-
def cli_dialogue(object_info)
|
266
|
-
TABLE[@vobject][:dialogue].call(object_info)
|
267
|
-
end
|
268
|
-
|
269
|
-
# This method iterates over the possible options for certain resources
|
270
|
-
# and will raise an error in case of missing mandatory param
|
271
|
-
#
|
272
|
-
# @param opts [Hash] options object passed to the onecenter tool
|
273
|
-
#
|
274
|
-
def parse_opts(opts)
|
275
|
-
object_update(opts[:object])
|
276
|
-
|
277
|
-
res = {}
|
278
|
-
TABLE[@vobject][:cli].each do |arg|
|
279
|
-
raise "#{arg} it's mandadory for this op" if opts[arg].nil?
|
280
|
-
|
281
|
-
res[arg] = method(arg).call(opts[arg])
|
282
|
-
end
|
283
|
-
|
284
|
-
res[:config] = parse_file(opts[:configuration]) if opts[:configuration]
|
285
|
-
|
286
|
-
res
|
287
|
-
end
|
288
|
-
|
289
|
-
# This method will parse a yaml
|
290
|
-
# Only used for a feature that adds the posibility
|
291
|
-
# of import resources with custom params (bulk)
|
292
|
-
#
|
293
|
-
# @param path [String] Path of the file
|
294
|
-
#
|
295
|
-
def parse_file(path)
|
296
|
-
begin
|
297
|
-
_config = YAML.safe_load(File.read(path))
|
298
|
-
rescue StandardError => _e
|
299
|
-
str_error="Unable to read '#{path}'. Invalid YAML syntax:\n"
|
300
|
-
|
301
|
-
raise str_error
|
302
|
-
end
|
303
|
-
end
|
304
|
-
|
305
|
-
# Use the attributes provided by TABLE
|
306
|
-
# with the purpose of build a complete CLI list
|
307
|
-
# OpenNebula way
|
308
|
-
#
|
309
|
-
def format_list
|
310
|
-
config = TABLE[@vobject][:columns]
|
311
|
-
CLIHelper::ShowTable.new do
|
312
|
-
column :DATACENTER,
|
313
|
-
'Object datacenter',
|
314
|
-
:size => config[:DATACENTER] || 15 do |d|
|
315
|
-
d[:datacenter]
|
316
|
-
end
|
317
|
-
|
318
|
-
column :IMID, 'identifier for ...', :size=>config[:IMID] || 4 do |d|
|
319
|
-
d[:import_id]
|
320
|
-
end
|
321
|
-
|
322
|
-
column :REF, 'ref', :left, :adjust, :size=>config[:REF] || 15 do |d|
|
323
|
-
d[:ref] || d[:cluster_ref]
|
324
|
-
end
|
325
|
-
|
326
|
-
column :NAME, 'Name', :left, :expand,
|
327
|
-
:size=>config[:NAME] || 20 do |d|
|
328
|
-
d[:name] || d[:simple_name]
|
329
|
-
end
|
330
|
-
|
331
|
-
column :CLUSTERS, 'CLUSTERS', :left,
|
332
|
-
:size=>config[:CLUSTERS] || 10 do |d|
|
333
|
-
d = d[:clusters] if d[:clusters]
|
334
|
-
d[:one_ids] || d[:cluster].to_s
|
335
|
-
end
|
336
|
-
|
337
|
-
column :PATH, 'PATH', :left, :expand,
|
338
|
-
:size=>config[:PATH] || 10 do |d|
|
339
|
-
d[:path]
|
340
|
-
end
|
341
|
-
|
342
|
-
default(*config.keys)
|
343
|
-
end
|
344
|
-
end
|
345
|
-
|
346
|
-
################################################################
|
347
|
-
# CLI DIALOGUES
|
348
|
-
################################################################
|
349
|
-
def self.template_dialogue(t)
|
350
|
-
rps_list = lambda {
|
351
|
-
return '' if t[:rp_list].empty?
|
352
|
-
|
353
|
-
puts
|
354
|
-
t[:rp_list].each do |rp|
|
355
|
-
puts " #{rp[:name]}"
|
356
|
-
end
|
357
|
-
puts
|
358
|
-
|
359
|
-
return STDIN.gets.strip.downcase
|
360
|
-
}
|
361
|
-
|
362
|
-
# default opts
|
363
|
-
opts = {
|
364
|
-
:linked_clone => '0',
|
365
|
-
:copy => '0',
|
366
|
-
:name => '',
|
367
|
-
:folder => '',
|
368
|
-
:resourcepool => [],
|
369
|
-
:type => ''
|
370
|
-
}
|
371
|
-
|
372
|
-
STDOUT.print "\n- Template: \e[92m#{t[:template_name]}\e[39m\n\n"\
|
373
|
-
|
374
|
-
# LINKED CLONE OPTION
|
375
|
-
STDOUT.print "\n For faster deployment operations"\
|
376
|
-
' and lower disk usage, OpenNebula'\
|
377
|
-
' can create new VMs as linked clones.'\
|
378
|
-
"\n Would you like to use Linked Clones"\
|
379
|
-
' with VMs based on this template (y/[n])? '
|
380
|
-
|
381
|
-
if STDIN.gets.strip.downcase == 'y'
|
382
|
-
opts[:linked_clone] = '1'
|
383
|
-
|
384
|
-
# CREATE COPY OPTION
|
385
|
-
STDOUT.print "\n Linked clones requires that delta"\
|
386
|
-
' disks must be created for '\
|
387
|
-
'each disk in the template.'\
|
388
|
-
' This operation may change the template contents.'\
|
389
|
-
" \n Do you want OpenNebula to "\
|
390
|
-
'create a copy of the template,'\
|
391
|
-
' so the original template remains untouched ([y]/n)? '
|
392
|
-
|
393
|
-
if STDIN.gets.strip.downcase != 'n'
|
394
|
-
opts[:copy] = '1'
|
395
|
-
|
396
|
-
# NAME OPTION
|
397
|
-
STDOUT.print "\n The new template will be named"\
|
398
|
-
' adding a one- prefix to the name'\
|
399
|
-
" of the original template. \n"\
|
400
|
-
' If you prefer a different name'\
|
401
|
-
' please specify or press Enter'\
|
402
|
-
' to use defaults: '
|
403
|
-
|
404
|
-
template_name = STDIN.gets.strip.downcase
|
405
|
-
opts[:name] = template_name
|
406
|
-
|
407
|
-
STDOUT.print "\n WARNING!!! The cloning "\
|
408
|
-
'operation can take some time'\
|
409
|
-
" depending on the size of disks.\n"
|
410
|
-
end
|
411
|
-
end
|
412
|
-
|
413
|
-
sdtout_print = "\n\n Do you want to specify a folder where"\
|
414
|
-
' the deployed VMs based on this template will appear'\
|
415
|
-
" in vSphere's VM and Templates section?"\
|
416
|
-
"\n If no path is set, VMs will be placed in the same"\
|
417
|
-
' location where the template lives.'\
|
418
|
-
"\n Please specify a path using slashes to separate folders"\
|
419
|
-
' e.g /Management/VMs or press Enter to use defaults: '\
|
420
|
-
|
421
|
-
STDOUT.print sdtout_print
|
422
|
-
|
423
|
-
vcenter_vm_folder = STDIN.gets.strip
|
424
|
-
opts[:folder] = vcenter_vm_folder
|
425
|
-
|
426
|
-
STDOUT.print "\n\n This template is currently set to "\
|
427
|
-
'launch VMs in the default resource pool.'\
|
428
|
-
"\n Press y to keep this behaviour, n to select"\
|
429
|
-
' a new resource pool or d to delegate the choice'\
|
430
|
-
' to the user ([y]/n/d)? '
|
431
|
-
|
432
|
-
answer = STDIN.gets.strip.downcase
|
433
|
-
|
434
|
-
case answer.downcase
|
435
|
-
when 'd' || 'delegate'
|
436
|
-
opts[:type]='list'
|
437
|
-
puts "separate with commas ',' the list that you want to deleate:"
|
438
|
-
|
439
|
-
opts[:resourcepool] = rps_list.call.gsub(/\s+/, '').split(',')
|
440
|
-
|
441
|
-
when 'n' || 'no'
|
442
|
-
opts[:type]='fixed'
|
443
|
-
puts 'choose the proper name'
|
444
|
-
opts[:resourcepool] = rps_list.call
|
445
|
-
else
|
446
|
-
opts[:type]='default'
|
447
|
-
end
|
448
|
-
|
449
|
-
opts
|
450
|
-
end
|
451
|
-
|
452
|
-
def self.network_dialogue(n)
|
453
|
-
ask = lambda {|question, default = ''|
|
454
|
-
STDOUT.print question
|
455
|
-
answer = STDIN.gets.strip
|
456
|
-
|
457
|
-
answer = default if answer.empty?
|
458
|
-
|
459
|
-
return answer
|
460
|
-
}
|
461
|
-
|
462
|
-
STDOUT.print "\n- Network: \e[92m#{n[:name]}\e[39m\n\n"\
|
463
|
-
|
464
|
-
opts = { :size => '255', :type => 'ether' }
|
465
|
-
|
466
|
-
question = ' How many VMs are you planning'\
|
467
|
-
' to fit into this network [255]? '
|
468
|
-
opts[:size] = ask.call(question, '255')
|
469
|
-
|
470
|
-
question = ' What type of Virtual Network'\
|
471
|
-
' do you want to create (IPv[4],IPv[6], [E]thernet)? '
|
472
|
-
type_answer = ask.call(question, 'ether')
|
473
|
-
|
474
|
-
supported_types = ['4', '6', 'ether', 'e', 'ip4', 'ip6']
|
475
|
-
if !supported_types.include?(type_answer)
|
476
|
-
type_answer = 'e'
|
477
|
-
STDOUT.puts " Type [#{type_answer}] not supported,"\
|
478
|
-
' defaulting to Ethernet.'
|
479
|
-
end
|
480
|
-
question_ip =
|
481
|
-
' Please input the first IP in the range: '
|
482
|
-
question_mac =
|
483
|
-
' Please input the first MAC in the range [Enter for default]: '
|
484
|
-
|
485
|
-
case type_answer.downcase
|
486
|
-
when '4', 'ip4'
|
487
|
-
opts[:ip] = ask.call(question_ip)
|
488
|
-
opts[:mac] = ask.call(question_mac)
|
489
|
-
opts[:type] = 'ip'
|
490
|
-
when '6', 'ip6'
|
491
|
-
opts[:mac] = ask.call(question_mac)
|
492
|
-
|
493
|
-
question = ' Do you want to use SLAAC '\
|
494
|
-
'Stateless Address Autoconfiguration? ([y]/n): '
|
495
|
-
slaac_answer = ask.call(question, 'y').downcase
|
496
|
-
|
497
|
-
if slaac_answer == 'n'
|
498
|
-
question =
|
499
|
-
' Please input the IPv6 address (cannot be empty): '
|
500
|
-
opts[:ip6] = ask.call(question)
|
501
|
-
|
502
|
-
question =
|
503
|
-
' Please input the Prefix length (cannot be empty): '
|
504
|
-
opts[:prefix_length] = ask.call(question)
|
505
|
-
opts[:type] = 'ip6_static'
|
506
|
-
else
|
507
|
-
question = ' Please input the GLOBAL PREFIX '\
|
508
|
-
'[Enter for default]: '
|
509
|
-
opts[:global_prefix] = ask.call(question)
|
510
|
-
|
511
|
-
question= ' Please input the ULA PREFIX '\
|
512
|
-
'[Enter for default]: '
|
513
|
-
opts[:ula_prefix] = ask.call(question)
|
514
|
-
opts[:type] = 'ip6'
|
515
|
-
end
|
516
|
-
when 'e', 'ether'
|
517
|
-
opts[:mac] = ask.call(question_mac)
|
518
|
-
end
|
519
|
-
|
520
|
-
opts
|
521
|
-
end
|
522
|
-
|
523
|
-
end
|