opennebula-cli 6.0.0.2 → 6.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -16,176 +16,174 @@
16
16
  require 'one_helper'
17
17
  require 'one_helper/onevm_helper'
18
18
 
19
- # OneVnet Command Helper
20
19
  class OneVNetHelper < OpenNebulaHelper::OneHelper
21
-
22
20
  AR = {
23
- :name => 'address_range',
24
- :short => '-a ar_id',
25
- :large => '--address_range ar_id',
21
+ :name => "address_range",
22
+ :short => "-a ar_id",
23
+ :large => "--address_range ar_id",
26
24
  :format => Integer,
27
- :description => 'ID of the address range'
25
+ :description => "ID of the address range"
28
26
  }
29
27
 
30
28
  SHOW_AR = {
31
- :name => 'show_ar',
32
- :large => '--show-ar',
33
- :description => 'Show also AR templates'
29
+ :name => "show_ar",
30
+ :large => "--show-ar",
31
+ :description => "Show also AR templates"
34
32
  }
35
33
 
36
34
  MAC = {
37
- :name => 'mac',
38
- :short => '-m mac',
39
- :large => '--mac mac',
35
+ :name => "mac",
36
+ :short => "-m mac",
37
+ :large => "--mac mac",
40
38
  :format => String,
41
- :description => 'First MAC address in : notation'
39
+ :description => "First MAC address in : notation"
42
40
  }
43
41
 
44
42
  IP = {
45
- :name => 'ip',
46
- :short => '-i ip',
47
- :large => '--ip ip',
43
+ :name => "ip",
44
+ :short => "-i ip",
45
+ :large => "--ip ip",
48
46
  :format => String,
49
- :description => 'First IP address in . notation'
47
+ :description => "First IP address in . notation"
50
48
  }
51
49
 
52
50
  IP6 = {
53
- :name => 'ip6',
54
- :short => '-6 ip6',
55
- :large => '--ip6 ip6',
51
+ :name => "ip6",
52
+ :short => "-6 ip6",
53
+ :large => "--ip6 ip6",
56
54
  :format => String,
57
- :description => 'First IPv6 address, in CIDR notation e.g. 2001::1/48'
55
+ :description => "First IPv6 address, in CIDR notation e.g. 2001::1/48"
58
56
  }
59
57
 
60
58
  SIZE = {
61
- :name => 'size',
62
- :short => '-s size',
63
- :large => '--size size',
59
+ :name => "size",
60
+ :short => "-s size",
61
+ :large => "--size size",
64
62
  :format => String,
65
- :description => 'Number of addresses'
63
+ :description => "Number of addresses"
66
64
  }
67
65
 
68
66
  IP6_GLOBAL = {
69
- :name => 'ip6_global',
70
- :short => '-g ip6_pref',
71
- :large => '--ip6_global ip6_pref',
67
+ :name => "ip6_global",
68
+ :short => "-g ip6_pref",
69
+ :large => "--ip6_global ip6_pref",
72
70
  :format => String,
73
- :description => 'IP6 global prefix'
71
+ :description => "IP6 global prefix"
74
72
  }
75
73
 
76
74
  IP6_ULA = {
77
- :name => 'ip6_ula',
78
- :short => '-u ip6_pref',
79
- :large => '--ip6_ula ip6_pref',
75
+ :name => "ip6_ula",
76
+ :short => "-u ip6_pref",
77
+ :large => "--ip6_ula ip6_pref",
80
78
  :format => String,
81
- :description => 'IP6 ula prefix'
79
+ :description => "IP6 ula prefix"
82
80
  }
83
81
 
84
82
  NAME = {
85
- :name => 'name',
86
- :short => '-n reservation name',
87
- :large => '--name reservation name',
83
+ :name => "name",
84
+ :short => "-n reservation name",
85
+ :large => "--name reservation name",
88
86
  :format => String,
89
- :description => 'Name of the address reservation'
87
+ :description => "Name of the address reservation"
90
88
  }
91
89
 
92
- # R_SIZE = {
93
- # :name => "rsize",
94
- # :short => "-s reservation size",
95
- # :large => "--size reservation size",
96
- # :format => String,
97
- # :description => "Number of addresses to reserve"
98
- # }
90
+ # R_SIZE = {
91
+ # :name => "rsize",
92
+ # :short => "-s reservation size",
93
+ # :large => "--size reservation size",
94
+ # :format => String,
95
+ # :description => "Number of addresses to reserve"
96
+ # }
99
97
 
100
98
  GATEWAY = {
101
- :name => 'gateway',
102
- :large => '--gateway ip',
99
+ :name => "gateway",
100
+ :large => "--gateway ip",
103
101
  :format => String,
104
- :description=> 'IP of the gateway'
102
+ :description=> "IP of the gateway"
105
103
  }
106
104
 
107
105
  NETMASK = {
108
- :name => 'netmask',
109
- :large => '--netmask mask',
106
+ :name => "netmask",
107
+ :large => "--netmask mask",
110
108
  :format => String,
111
- :description=> 'Netmask in dot notation'
109
+ :description=> "Netmask in dot notation"
112
110
  }
113
111
 
114
112
  VN_MAD = {
115
- :name => 'vn_mad',
116
- :large => '--vn_mad mad',
113
+ :name => "vn_mad",
114
+ :large => "--vn_mad mad",
117
115
  :format => String,
118
- :description=> 'Use this driver for the network'
116
+ :description=> "Use this driver for the network"
119
117
  }
120
118
 
121
119
  VLAN_ID = {
122
- :name => 'vlanid',
123
- :large => '--vlanid id',
120
+ :name => "vlanid",
121
+ :large => "--vlanid id",
124
122
  :format => String,
125
- :description=> 'VLAN ID assigned'
123
+ :description=> "VLAN ID assigned"
126
124
  }
127
125
 
128
126
  ADDAR_OPTIONS = [
129
127
  SIZE, MAC, IP, IP6, IP6_GLOBAL, IP6_ULA, GATEWAY, NETMASK, VN_MAD,
130
- VLAN_ID
131
- ]
128
+ VLAN_ID ]
132
129
 
133
130
  def self.rname
134
- 'VNET'
131
+ "VNET"
135
132
  end
136
133
 
137
134
  def self.conf_file
138
- 'onevnet.yaml'
135
+ "onevnet.yaml"
139
136
  end
140
137
 
141
138
  def format_pool(options)
142
139
  config_file = self.class.table_conf
143
140
 
144
- CLIHelper::ShowTable.new(config_file, self) do
145
- column :ID, 'ONE identifier for Virtual Network', :size=>4 do |d|
146
- d['ID']
141
+ table = CLIHelper::ShowTable.new(config_file, self) do
142
+ column :ID, "ONE identifier for Virtual Network", :size=>4 do |d|
143
+ d["ID"]
147
144
  end
148
145
 
149
- column :USER, 'Username of the Virtual Network owner', :left,
150
- :size=>15 do |d|
146
+ column :USER, "Username of the Virtual Network owner", :left,
147
+ :size=>15 do |d|
151
148
  helper.user_name(d, options)
152
149
  end
153
150
 
154
- column :GROUP, 'Group of the Virtual Network', :left,
155
- :size=>12 do |d|
151
+ column :GROUP, "Group of the Virtual Network", :left,
152
+ :size=>12 do |d|
156
153
  helper.group_name(d, options)
157
154
  end
158
155
 
159
- column :NAME, 'Name of the Virtual Network', :left,
160
- :size=>19 do |d|
161
- d['NAME']
156
+ column :NAME, "Name of the Virtual Network", :left,
157
+ :size=>19 do |d|
158
+ d["NAME"]
162
159
  end
163
160
 
164
- column :CLUSTERS, 'Cluster IDs', :left, :size=>10 do |d|
165
- OpenNebulaHelper.clusters_str(d['CLUSTERS']['ID']) rescue '-'
161
+ column :CLUSTERS, "Cluster IDs", :left, :size=>10 do |d|
162
+ OpenNebulaHelper.clusters_str(d["CLUSTERS"]["ID"]) rescue "-"
166
163
  end
167
164
 
168
- column :BRIDGE, 'Bridge associated to the Virtual Network', :left,
169
- :size=>8 do |d|
170
- d['BRIDGE']
165
+ column :BRIDGE, "Bridge associated to the Virtual Network", :left,
166
+ :size=>8 do |d|
167
+ d["BRIDGE"]
171
168
  end
172
169
 
173
170
  column :LEASES, "Number of this Virtual Network's given leases",
174
- :size=>6 do |d|
175
- d['USED_LEASES']
171
+ :size=>6 do |d|
172
+ d["USED_LEASES"]
176
173
  end
177
174
 
178
175
  default :ID, :USER, :GROUP, :NAME, :CLUSTERS, :BRIDGE, :LEASES
179
176
  end
177
+
178
+ table
180
179
  end
181
180
 
182
181
  def show_ar(vn, ar_id)
183
- CLIHelper.print_header(format('%-80s', "TEMPLATE FOR AR #{ar_id}"),
184
- false)
182
+ CLIHelper.print_header("%-80s" % ["TEMPLATE FOR AR #{ar_id}"], false)
185
183
 
186
184
  begin
187
185
  template = vn.template_like_str("AR_POOL/AR[AR_ID=#{ar_id}]")
188
- rescue StandardError
186
+ rescue
189
187
  STDERR.puts "Can not get template for AR #{ar_id}"
190
188
  return
191
189
  end
@@ -283,7 +281,7 @@ class OneVNetHelper < OpenNebulaHelper::OneHelper
283
281
 
284
282
  private
285
283
 
286
- def factory(id = nil)
284
+ def factory(id=nil)
287
285
  if id
288
286
  OpenNebula::VirtualNetwork.new_with_id(id, @client)
289
287
  else
@@ -292,63 +290,55 @@ class OneVNetHelper < OpenNebulaHelper::OneHelper
292
290
  end
293
291
  end
294
292
 
295
- def factory_pool(user_flag = -2)
293
+ def factory_pool(user_flag=-2)
296
294
  OpenNebula::VirtualNetworkPool.new(@client, user_flag)
297
295
  end
298
296
 
299
297
  def format_resource(vn, options = {})
300
298
  vn_hash = vn.to_hash
301
299
 
302
- str_h1='%-80s'
303
- CLIHelper.print_header(format(str_h1,
304
- "VIRTUAL NETWORK #{vn.id} INFORMATION"))
305
-
306
- str='%-25s: %-20s'
307
- puts format(str, 'ID', vn.id.to_s)
308
- puts format(str, 'NAME', vn['NAME'])
309
- puts format(str, 'USER', vn['UNAME'])
310
- puts format(str, 'GROUP', vn['GNAME'])
311
- puts format(str, 'LOCK',
312
- OpenNebulaHelper.level_lock_to_str(vn['LOCK/LOCKED']))
313
- puts format(str, 'CLUSTERS',
314
- OpenNebulaHelper.clusters_str(
315
- vn.retrieve_elements('CLUSTERS/ID')
316
- ))
317
- puts format(str, 'BRIDGE', vn['BRIDGE'])
318
- puts format(str, 'VN_MAD', vn['VN_MAD']) unless vn['VN_MAD'].empty?
319
- puts format(str, 'PHYSICAL DEVICE',
320
- vn['PHYDEV']) unless vn['PHYDEV'].empty?
321
- puts format(str, 'VLAN ID', vn['VLAN_ID']) unless vn['VLAN_ID'].empty?
322
- puts format(str, 'AUTOMATIC VLAN ID',
323
- vn['VLAN_ID_AUTOMATIC']=='1' ? 'YES' : 'NO')
324
- puts format(str, 'OUTER VLAN ID',
325
- vn['OUTER_VLAN_ID']) unless vn['OUTER_VLAN_ID']
326
- puts format(str, 'AUTOMATIC OUTER VLAN ID',
327
- vn['OUTER_VLAN_ID_AUTOMATIC']=='1' ? 'YES' : 'NO')
328
- puts format(str, 'USED LEASES', vn['USED_LEASES'])
300
+ str_h1="%-80s"
301
+ CLIHelper.print_header(str_h1 %
302
+ ["VIRTUAL NETWORK #{vn.id.to_s} INFORMATION"])
303
+
304
+ str="%-25s: %-20s"
305
+ puts str % ["ID", vn.id.to_s]
306
+ puts str % ["NAME", vn['NAME']]
307
+ puts str % ["USER", vn['UNAME']]
308
+ puts str % ["GROUP", vn['GNAME']]
309
+ puts str % ["LOCK", OpenNebulaHelper.level_lock_to_str(vn['LOCK/LOCKED'])]
310
+ puts str % ["CLUSTERS",
311
+ OpenNebulaHelper.clusters_str(vn.retrieve_elements("CLUSTERS/ID"))]
312
+ puts str % ["BRIDGE", vn["BRIDGE"]]
313
+ puts str % ["VN_MAD", vn['VN_MAD']] if !vn['VN_MAD'].empty?
314
+ puts str % ["PHYSICAL DEVICE", vn["PHYDEV"]] if !vn["PHYDEV"].empty?
315
+ puts str % ["VLAN ID", vn["VLAN_ID"]] if !vn["VLAN_ID"].empty?
316
+ puts str % ["AUTOMATIC VLAN ID", vn["VLAN_ID_AUTOMATIC"]=="1" ? "YES" : "NO"]
317
+ puts str % ["OUTER VLAN ID", vn["OUTER_VLAN_ID"]] if !vn["OUTER_VLAN_ID"]
318
+ puts str % ["AUTOMATIC OUTER VLAN ID", vn["OUTER_VLAN_ID_AUTOMATIC"]=="1" ? "YES" : "NO"]
319
+ puts str % ["USED LEASES", vn['USED_LEASES']]
329
320
  puts
330
321
 
331
- CLIHelper.print_header(str_h1 % 'PERMISSIONS', false)
322
+ CLIHelper.print_header(str_h1 % "PERMISSIONS",false)
332
323
 
333
- %w[OWNER GROUP OTHER].each do |e|
334
- mask = '---'
335
- mask[0] = 'u' if vn["PERMISSIONS/#{e}_U"] == '1'
336
- mask[1] = 'm' if vn["PERMISSIONS/#{e}_M"] == '1'
337
- mask[2] = 'a' if vn["PERMISSIONS/#{e}_A"] == '1'
324
+ ["OWNER", "GROUP", "OTHER"].each { |e|
325
+ mask = "---"
326
+ mask[0] = "u" if vn["PERMISSIONS/#{e}_U"] == "1"
327
+ mask[1] = "m" if vn["PERMISSIONS/#{e}_M"] == "1"
328
+ mask[2] = "a" if vn["PERMISSIONS/#{e}_A"] == "1"
338
329
 
339
- puts format(str, e, mask)
340
- end
330
+ puts str % [e, mask]
331
+ }
341
332
 
342
333
  puts
343
334
 
344
- CLIHelper.print_header(format(str_h1, 'VIRTUAL NETWORK TEMPLATE'),
345
- false)
335
+ CLIHelper.print_header(str_h1 % ["VIRTUAL NETWORK TEMPLATE"], false)
346
336
 
347
337
  puts vn.template_str(false)
348
338
 
349
339
  puts
350
340
 
351
- CLIHelper.print_header(format(str_h1, 'ADDRESS RANGE POOL'), false)
341
+ CLIHelper.print_header(str_h1 % ["ADDRESS RANGE POOL"], false)
352
342
 
353
343
  arlist = []
354
344
 
@@ -357,72 +347,70 @@ class OneVNetHelper < OpenNebulaHelper::OneHelper
357
347
  end
358
348
 
359
349
  arlist.each do |ar|
360
- CLIHelper.print_header(format('%-80s', "AR #{ar['AR_ID']}"))
361
350
 
362
- str='%-15s: %-20s'
363
- puts format(str, 'SIZE', ar['SIZE'])
364
- puts format(str, 'LEASES', ar['USED_LEASES'])
365
- puts format(str, 'VN_MAD', ar['VN_MAD']) if ar['VN_MAD']
366
- puts format(str, 'IPAM_MAD', ar['IPAM_MAD']) if ar['IPAM_MAD']
351
+ CLIHelper.print_header("%-80s" % "AR #{ar["AR_ID"]}")
352
+
353
+ str="%-15s: %-20s"
354
+ puts str % ["SIZE", ar["SIZE"]]
355
+ puts str % ["LEASES", ar["USED_LEASES"]]
356
+ puts str % ["VN_MAD", ar["VN_MAD"]] if ar["VN_MAD"]
357
+ puts str % ["IPAM_MAD", ar["IPAM_MAD"]] if ar["IPAM_MAD"]
367
358
  puts
368
359
 
369
- format = '%-10s %34s %34s'
370
- CLIHelper.print_header(
371
- format(format, 'RANGE', 'FIRST', 'LAST'), false
372
- )
360
+ format = "%-10s %34s %34s"
361
+ CLIHelper.print_header(format % ["RANGE", "FIRST", "LAST"], false)
373
362
 
374
- puts format(format, 'MAC', ar['MAC'], ar['MAC_END'])
363
+ puts format % ["MAC", ar["MAC"], ar["MAC_END"]]
375
364
 
376
- if !ar['IP'].nil?
377
- puts format(format, 'IP', ar['IP'], ar['IP_END'])
365
+ if !ar["IP"].nil?
366
+ puts format % ["IP", ar["IP"], ar["IP_END"]]
378
367
  end
379
368
 
380
- if !ar['IP6_GLOBAL'].nil?
381
- puts format(format, 'IP6_GLOBAL', ar['IP6_GLOBAL'],
382
- ar['IP6_GLOBAL_END'])
369
+ if !ar["IP6_GLOBAL"].nil?
370
+ puts format % ["IP6_GLOBAL", ar["IP6_GLOBAL"], ar["IP6_GLOBAL_END"]]
383
371
  end
384
372
 
385
- if !ar['IP6_ULA'].nil?
386
- puts format(format, 'IP6_ULA', ar['IP6_ULA'], ar['IP6_ULA_END'])
373
+ if !ar["IP6_ULA"].nil?
374
+ puts format % ["IP6_ULA", ar["IP6_ULA"], ar["IP6_ULA_END"]]
387
375
  end
388
376
 
389
- if !ar['IP6'].nil?
390
- puts format(format, 'IP6', ar['IP6'], ar['IP6_END'])
377
+ if !ar["IP6"].nil?
378
+ puts format % ["IP6", ar["IP6"], ar["IP6_END"]]
391
379
  end
392
380
 
393
381
  puts
394
382
  end
395
383
 
396
384
  puts
397
- CLIHelper.print_header(format(str_h1, 'LEASES'), false)
385
+ CLIHelper.print_header(str_h1 % ["LEASES"], false)
398
386
  ar_list = []
399
387
 
400
388
  if !vn_hash['VNET']['AR_POOL']['AR'].nil?
401
389
  lease_list = [vn_hash['VNET']['AR_POOL']['AR']].flatten
402
- leases = []
390
+ leases = Array.new
403
391
 
404
392
  lease_list.each do |ar|
405
393
  id = ar['AR_ID']
406
394
  ar_list << id
407
395
 
408
- next unless ar['LEASES'] && !ar['LEASES']['LEASE'].nil?
409
-
410
- lease = [ar['LEASES']['LEASE']].flatten
411
- lease.each do |l|
412
- l['AR_ID'] = id
396
+ if ar['LEASES'] && !ar['LEASES']['LEASE'].nil?
397
+ lease = [ar['LEASES']['LEASE']].flatten
398
+ lease.each do |l|
399
+ l['AR_ID'] = id
400
+ end
401
+ leases << lease
413
402
  end
414
- leases << lease
415
403
  end
416
404
 
417
405
  leases.flatten!
418
406
  end
419
407
 
420
408
  CLIHelper::ShowTable.new(nil, self) do
421
- column :AR, '', :left, :size=>3 do |d|
409
+ column :AR, "", :left, :size=>3 do |d|
422
410
  d['AR_ID']
423
411
  end
424
412
 
425
- column :OWNER, '', :left, :size=>10 do |d|
413
+ column :OWNER, "", :left, :size=>15 do |d|
426
414
  if d['VM']
427
415
  "V:#{d['VM']}"
428
416
  elsif d['VNET']
@@ -432,40 +420,31 @@ class OneVNetHelper < OpenNebulaHelper::OneHelper
432
420
  end
433
421
  end
434
422
 
435
- column :MAC, '', :adjust do |d|
436
- d['MAC']
437
- end
438
-
439
- column :IP, '', :adjust do |d|
440
- d['IP'] || '-'
423
+ column :MAC, "", :size=>17 do |d|
424
+ d["MAC"]
441
425
  end
442
426
 
443
- column :PORT_FORWARD, '', :adjust do |d|
444
- if d['EXTERNAL_PORT_RANGE']
445
- "[#{d['EXTERNAL_PORT_RANGE']}]:" \
446
- "[#{d['INTERNAL_PORT_RANGE'].split('/')[0]}]"
447
- else
448
- '-'
449
- end
427
+ column :IP, "", :size=>15 do |d|
428
+ d["IP"]||"-"
450
429
  end
451
430
 
452
- column :IP6, '', :adjust do |d|
453
- d['IP6']||d['IP6_GLOBAL']||'-'
431
+ column :IP6, "", :adjust, :size=>26 do |d|
432
+ d["IP6"]||d["IP6_GLOBAL"]||"-"
454
433
  end
455
434
  end.show(leases, {})
456
435
 
457
436
  puts
458
437
 
459
- CLIHelper.print_header(format('%-15s', 'VIRTUAL ROUTERS'))
438
+ CLIHelper.print_header("%-15s" % "VIRTUAL ROUTERS")
460
439
  vn.vrouter_ids.each do |id|
461
- puts format('%-15s', id)
440
+ puts "%-15s" % [id]
462
441
  end
463
442
 
464
- return unless options[:show_ar]
465
-
466
- ar_list.each do |ar_id|
467
- puts
468
- show_ar(vn, ar_id)
443
+ if options[:show_ar]
444
+ ar_list.each do |ar_id|
445
+ puts
446
+ show_ar(vn, ar_id)
447
+ end
469
448
  end
470
449
  end
471
450
 
@@ -480,5 +459,4 @@ class OneVNetHelper < OpenNebulaHelper::OneHelper
480
459
  # in options hash
481
460
  (add_ar_options-options.keys)!=add_ar_options
482
461
  end
483
-
484
462
  end