opennebula-cli 4.10.2 → 4.11.80.beta

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.
@@ -44,7 +44,7 @@ private
44
44
  def self.resource_mask(str)
45
45
  resource_type=str.split("/")[0]
46
46
 
47
- mask = "-----------"
47
+ mask = "-------------"
48
48
 
49
49
  resource_type.split("+").each{|type|
50
50
  case type
@@ -70,6 +70,10 @@ private
70
70
  mask[9] = "O"
71
71
  when "ZONE"
72
72
  mask[10] = "Z"
73
+ when "SECGROUP"
74
+ mask[11] = "S"
75
+ when "VDC"
76
+ mask[12] = "v"
73
77
  end
74
78
  }
75
79
  mask
@@ -109,8 +113,8 @@ private
109
113
  d['STRING'].split(" ")[0]
110
114
  end
111
115
 
112
- column :RES_VHNIUTGDCOZ, "Resource to which the rule applies",
113
- :size => 15 do |d|
116
+ column :RES_VHNIUTGDCOZSv, "Resource to which the rule applies",
117
+ :size => 17 do |d|
114
118
  OneAclHelper::resource_mask d['STRING'].split(" ")[1]
115
119
  end
116
120
 
@@ -127,7 +131,7 @@ private
127
131
  OneAclHelper::right_mask d['STRING'].split(" ")[2]
128
132
  end
129
133
 
130
- default :ID, :USER, :RES_VHNIUTGDCOZ, :RID, :OPE_UMAC, :ZONE
134
+ default :ID, :USER, :RES_VHNIUTGDCOZSv, :RID, :OPE_UMAC, :ZONE
131
135
  end
132
136
 
133
137
  table
@@ -82,15 +82,21 @@ class OneDatastoreHelper < OpenNebulaHelper::OneHelper
82
82
  Datastore::SHORT_DATASTORE_TYPES[type]
83
83
  end
84
84
 
85
- column :DS, "Datastore driver", :left, :size=>8 do |d|
85
+ column :DS, "Datastore driver", :left, :size=>7 do |d|
86
86
  d["DS_MAD"]
87
87
  end
88
88
 
89
- column :TM, "Transfer driver", :left, :size=>8 do |d|
89
+ column :TM, "Transfer driver", :left, :size=>7 do |d|
90
90
  d["TM_MAD"]
91
91
  end
92
92
 
93
- default :ID, :NAME, :SIZE, :AVAIL, :CLUSTER, :IMAGES, :TYPE, :DS, :TM
93
+ column :STAT, "State of the Datastore", :left, :size=>3 do |d|
94
+ state = Datastore::DATASTORE_STATES[d["STATE"].to_i]
95
+ Datastore::SHORT_DATASTORE_STATES[state]
96
+ end
97
+
98
+ default :ID, :NAME, :SIZE, :AVAIL, :CLUSTER, :IMAGES,
99
+ :TYPE, :DS, :TM, :STAT
94
100
  end
95
101
 
96
102
  table
@@ -128,6 +134,7 @@ class OneDatastoreHelper < OpenNebulaHelper::OneHelper
128
134
  puts str % ["TM_MAD", datastore['TM_MAD']]
129
135
  puts str % ["BASE PATH",datastore['BASE_PATH']]
130
136
  puts str % ["DISK_TYPE",Image::DISK_TYPES[datastore['DISK_TYPE'].to_i]]
137
+ puts str % ["STATE", datastore.state_str]
131
138
  puts
132
139
 
133
140
  CLIHelper.print_header(str_h1 % "DATASTORE CAPACITY", false)
@@ -286,29 +286,23 @@ class OneGroupHelper < OpenNebulaHelper::OneHelper
286
286
  puts group.template_str
287
287
  puts
288
288
 
289
- CLIHelper.print_header(str_h1 % "USERS", false)
290
- CLIHelper.print_header("%-15s" % ["ID"])
291
- group.user_ids.each do |uid|
292
- puts "%-15s" % [uid]
293
- end
294
-
295
- group_hash = group.to_hash
289
+ admin_ids = group.admin_ids
296
290
 
297
- providers = group_hash['GROUP']['RESOURCE_PROVIDER']
298
- if(providers != nil)
299
- puts
300
- CLIHelper.print_header(str_h1 % "RESOURCE PROVIDERS", false)
291
+ CLIHelper::ShowTable.new(nil, self) do
292
+ column :"USER ID", "", :right, :size=>7 do |d|
293
+ d
294
+ end
301
295
 
302
- CLIHelper::ShowTable.new(nil, self) do
303
- column :"ZONE", "", :right, :size=>7 do |d|
304
- d['ZONE_ID']
296
+ column :"ADMIN", "", :left, :size=>5 do |d|
297
+ if (group.admin_ids.include?(d))
298
+ "*"
299
+ else
300
+ ""
305
301
  end
302
+ end
303
+ end.show(group.user_ids, {})
306
304
 
307
- column :"CLUSTER", "", :right, :size=>7 do |d|
308
- d['CLUSTER_ID'] == '10' ? 'ALL' : d['CLUSTER_ID']
309
- end
310
- end.show([providers].flatten, {})
311
- end
305
+ group_hash = group.to_hash
312
306
 
313
307
  default_quotas = nil
314
308
 
@@ -223,6 +223,16 @@ class OneHostHelper < OpenNebulaHelper::OneHelper
223
223
  next if host['CLUSTER_ID'].to_i != cluster_id
224
224
  end
225
225
 
226
+ vm_mad = host['VM_MAD'].downcase
227
+ remote_remotes = host['TEMPLATE/REMOTE_REMOTES']
228
+
229
+ # Skip this host from remote syncing unless:
230
+ # - the host is type "KVM"
231
+ # - the host is type "XEN"
232
+ # - the host has REMOTE_REMOTES defined in the template (useful
233
+ # for custom defined VMM types)
234
+ next unless remote_remotes || vm_mad == "kvm" || vm_mad == "xen"
235
+
226
236
  host_version=host['TEMPLATE/VERSION']
227
237
 
228
238
  begin
@@ -0,0 +1,155 @@
1
+ # -------------------------------------------------------------------------- #
2
+ # Copyright 2002-2015, OpenNebula Project (OpenNebula.org), C12G Labs #
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
+ class OneSecurityGroupHelper < OpenNebulaHelper::OneHelper
20
+ def self.rname
21
+ "SECURITY_GROUP"
22
+ end
23
+
24
+ def self.conf_file
25
+ "onesecgroup.yaml"
26
+ end
27
+
28
+ def format_pool(options)
29
+ config_file = self.class.table_conf
30
+
31
+ table = CLIHelper::ShowTable.new(config_file, self) do
32
+ column :ID, "ONE identifier for the Security Group", :size=>4 do |d|
33
+ d["ID"]
34
+ end
35
+
36
+ column :NAME, "Name of the Security Group", :left, :size=>27 do |d|
37
+ d["NAME"]
38
+ end
39
+
40
+ column :USER, "Username of the Security Group owner", :left,
41
+ :size=>15 do |d|
42
+ helper.user_name(d, options)
43
+ end
44
+
45
+ column :GROUP, "Group of the Security Group", :left, :size=>15 do |d|
46
+ helper.group_name(d, options)
47
+ end
48
+
49
+ default :ID, :USER, :GROUP, :NAME
50
+ end
51
+
52
+ table
53
+ end
54
+
55
+ private
56
+
57
+ def factory(id=nil)
58
+ if id
59
+ OpenNebula::SecurityGroup.new_with_id(id, @client)
60
+ else
61
+ xml=OpenNebula::SecurityGroup.build_xml
62
+ OpenNebula::SecurityGroup.new(xml, @client)
63
+ end
64
+ end
65
+
66
+ def factory_pool(user_flag=-2)
67
+ OpenNebula::SecurityGroupPool.new(@client, user_flag)
68
+ end
69
+
70
+ def format_resource(secgroup, options = {})
71
+ str="%-15s: %-20s"
72
+ str_h1="%-80s"
73
+
74
+ CLIHelper.print_header(
75
+ str_h1 % "SECURITY GROUP #{secgroup['ID']} INFORMATION")
76
+ puts str % ["ID", secgroup.id.to_s]
77
+ puts str % ["NAME", secgroup.name]
78
+ puts str % ["USER", secgroup['UNAME']]
79
+ puts str % ["GROUP", secgroup['GNAME']]
80
+
81
+ CLIHelper.print_header(str_h1 % "PERMISSIONS",false)
82
+
83
+ ["OWNER", "GROUP", "OTHER"].each { |e|
84
+ mask = "---"
85
+ mask[0] = "u" if secgroup["PERMISSIONS/#{e}_U"] == "1"
86
+ mask[1] = "m" if secgroup["PERMISSIONS/#{e}_M"] == "1"
87
+ mask[2] = "a" if secgroup["PERMISSIONS/#{e}_A"] == "1"
88
+
89
+ puts str % [e, mask]
90
+ }
91
+
92
+ puts
93
+
94
+ CLIHelper.print_header(str_h1 % ["RULES"], false)
95
+
96
+ if !secgroup.to_hash['SECURITY_GROUP']['TEMPLATE']['RULE'].nil?
97
+ rule_list = [secgroup.to_hash['SECURITY_GROUP']['TEMPLATE']['RULE']].flatten
98
+ end
99
+
100
+ CLIHelper::ShowTable.new(nil, self) do
101
+ column :TYPE, "", :left, :size=>8 do |d|
102
+ d["RULE_TYPE"]
103
+ end
104
+
105
+ column :PROTOCOL, "", :left, :size=>8 do |d|
106
+ d["PROTOCOL"]
107
+ end
108
+
109
+ column :ICMP_TYPE, "", :left, :size=>9 do |d|
110
+ d["ICMP_TYPE"]
111
+ end
112
+
113
+ column :NETWORK, "", :left, :donottruncate, :size=>35 do |d|
114
+ network = ""
115
+ if(!d["NETWORK_ID"].nil? && d["NETWORK_ID"] != "")
116
+ network += "VNet " + d["NETWORK_ID"]
117
+ end
118
+
119
+ if(!d["SIZE"].nil? && d["SIZE"] != "")
120
+ if(network != "")
121
+ network += ": "
122
+ end
123
+
124
+ if(!d["IP"].nil? && d["IP"] != "")
125
+ network += "Start: " + d["IP"] + ", "
126
+ elsif(!d["MAC"] != undefined && d["MAC"] != "")
127
+ network += "Start: " + d["MAC"] + ", "
128
+ end
129
+
130
+ network += "Size: " + d["SIZE"]
131
+ end
132
+
133
+ if(network == "")
134
+ network = "Any"
135
+ end
136
+
137
+ network += " "
138
+ network
139
+ end
140
+
141
+ column :RANGE, "", :left, :donottruncate, :size=>16 do |d|
142
+ d["RANGE"]
143
+ end
144
+ end.show(rule_list, {})
145
+
146
+ while secgroup.has_elements?("/SECURITY_GROUP/TEMPLATE/RULE")
147
+ secgroup.delete_element("/SECURITY_GROUP/TEMPLATE/RULE")
148
+ end
149
+
150
+ puts
151
+
152
+ CLIHelper.print_header(str_h1 % "TEMPLATE CONTENTS",false)
153
+ puts secgroup.template_str
154
+ end
155
+ end
@@ -0,0 +1,144 @@
1
+ # -------------------------------------------------------------------------- #
2
+ # Copyright 2002-2015, OpenNebula Project (OpenNebula.org), C12G Labs #
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
+ class OneVdcHelper < OpenNebulaHelper::OneHelper
20
+
21
+ def self.rname
22
+ "VDC"
23
+ end
24
+
25
+ def self.conf_file
26
+ "onevdc.yaml"
27
+ end
28
+
29
+ def id_list_size(list)
30
+ case list
31
+ when NilClass
32
+ return 0
33
+ when Array
34
+ return list.size
35
+ when Hash
36
+ return 1
37
+ end
38
+ end
39
+
40
+ def format_pool(options)
41
+ config_file = self.class.table_conf
42
+
43
+ table = CLIHelper::ShowTable.new(config_file, self) do
44
+ column :ID, "ONE identifier for the VDC", :size=>5 do |d|
45
+ d["ID"]
46
+ end
47
+
48
+ column :NAME, "Name of the VDC", :left, :size=>30 do |d|
49
+ d["NAME"]
50
+ end
51
+
52
+ column :GROUPS, "Number of Groups", :size=>6 do |d|
53
+ ids = d["GROUPS"]["ID"]
54
+ case ids
55
+ when String
56
+ 1
57
+ when Array
58
+ ids.size
59
+ when NilClass
60
+ 0
61
+ end
62
+ end
63
+
64
+ column :CLUSTERS, "Number of Clusters", :size=>8 do |d|
65
+ @ext.id_list_size(d["CLUSTERS"]["CLUSTER"])
66
+ end
67
+
68
+ column :HOSTS, "Number of Hosts", :size=>5 do |d|
69
+ @ext.id_list_size(d["HOSTS"]["HOST"])
70
+ end
71
+
72
+ column :VNETS, "Number of Networks", :size=>5 do |d|
73
+ @ext.id_list_size(d["VNETS"]["VNET"])
74
+ end
75
+
76
+ column :DATASTORES, "Number of Datastores", :size=>10 do |d|
77
+ @ext.id_list_size(d["DATASTORES"]["DATASTORE"])
78
+ end
79
+
80
+ default :ID, :NAME, :GROUPS, :CLUSTERS, :HOSTS, :VNETS, :DATASTORES
81
+ end
82
+
83
+ table
84
+ end
85
+
86
+ private
87
+
88
+ def factory(id=nil)
89
+ if id
90
+ OpenNebula::Vdc.new_with_id(id, @client)
91
+ else
92
+ xml=OpenNebula::Vdc.build_xml
93
+ OpenNebula::Vdc.new(xml, @client)
94
+ end
95
+ end
96
+
97
+ def factory_pool(user_flag=-2)
98
+ OpenNebula::VdcPool.new(@client)
99
+ end
100
+
101
+ def format_resource(vdc, options = {})
102
+ str="%-18s: %-20s"
103
+ str_h1="%-80s"
104
+
105
+ CLIHelper.print_header(str_h1 % "VDC #{vdc['ID']} INFORMATION")
106
+ puts str % ["ID", vdc.id.to_s]
107
+ puts str % ["NAME", vdc.name]
108
+
109
+ vdc_hash = vdc.to_hash
110
+
111
+ groups = vdc_hash['VDC']['GROUPS']['ID']
112
+ if(groups != nil)
113
+ puts
114
+
115
+ CLIHelper::ShowTable.new(nil, self) do
116
+ column :"GROUPS", "", :right, :size=>7 do |d|
117
+ d
118
+ end
119
+ end.show([groups].flatten, {})
120
+ end
121
+
122
+ ['CLUSTER', 'HOST', 'DATASTORE', 'VNET'].each do |resource|
123
+ res_array = vdc_hash['VDC']["#{resource}S"][resource]
124
+ if(res_array != nil)
125
+ puts
126
+ CLIHelper.print_header(str_h1 % "#{resource}S", false)
127
+
128
+ CLIHelper::ShowTable.new(nil, self) do
129
+ column :"ZONE", "", :right, :size=>7 do |d|
130
+ d['ZONE_ID']
131
+ end
132
+
133
+ column :"#{resource}", "", :right, :size=>9 do |d|
134
+ d["#{resource}_ID"] == Vdc::ALL_RESOURCES ? 'ALL' : d["#{resource}_ID"]
135
+ end
136
+ end.show([res_array].flatten, {})
137
+ end
138
+ end
139
+
140
+ puts
141
+ CLIHelper.print_header(str_h1 % "VDC TEMPLATE", false)
142
+ puts vdc.template_str
143
+ end
144
+ end
@@ -404,63 +404,24 @@ class OneVMHelper < OpenNebulaHelper::OneHelper
404
404
  end if !options[:all]
405
405
  end
406
406
 
407
- if vm.has_elements?("/VM/USER_TEMPLATE/HYPERVISOR")
408
- vm_information = vm.to_hash['VM']
409
- hybridvisor = vm_information['USER_TEMPLATE']['HYPERVISOR'].to_s
410
- isHybrid = %w{vcenter ec2 azure softlayer}.include? hybridvisor
411
-
412
- if isHybrid
413
- vm_tmplt = vm_information['TEMPLATE']
414
- nic = {"NETWORK" => "-",
415
- "IP" => "-",
416
- "MAC"=> "-",
417
- "VLAN"=>"no",
418
- "BRIDGE"=>"-"}
407
+ sg_nics = []
419
408
 
420
- case hybridvisor
421
- when "vcenter"
422
- nic["IP"] = vm_tmplt['GUEST_IP'] if vm_tmplt['GUEST_IP']
423
- when "ec2"
424
- nic["IP"] = vm_tmplt['IP_ADDRESS'] if vm_tmplt['IP_ADDRESS']
425
- when "azure"
426
- nic["IP"] = vm_tmplt['IPADDRESS'] if vm_tmplt['IPADDRESS']
427
- when "softlayer"
428
- nic["IP"] = vm_tmplt['PRIMARYIPADDRESS'] if vm_tmplt['PRIMARYIPADDRESS']
429
- else
430
- isHybrid = false
431
- end
409
+ if (vm.has_elements?("/VM/TEMPLATE/NIC/SECURITY_GROUPS"))
410
+ sg_nics = [vm.to_hash['VM']['TEMPLATE']['NIC']].flatten
411
+
412
+ sg_nics.each do |nic|
413
+ sg = nic["SECURITY_GROUPS"]
432
414
 
433
- vm_nics = [nic]
415
+ if sg.nil?
416
+ next
417
+ end
434
418
  end
435
419
  end
436
420
 
437
- if vm.has_elements?("/VM/TEMPLATE/NIC") || vm_nics
421
+ if vm.has_elements?("/VM/TEMPLATE/NIC")
438
422
  puts
439
423
  CLIHelper.print_header(str_h1 % "VM NICS",false)
440
424
 
441
- # vm_nics is defined for hybridvisors. If there are both IP from
442
- # the hybridvisor and from OpenNebula nics check if the IP is the
443
- # same as one of IPs generated by OpenNebula and show standard
444
- # information. If it's a different IP show all the information.
445
- #
446
- # The template can already contain one NIC not controled by
447
- # OpenNebula and we want to show also that info.
448
- if vm_nics
449
- if vm.has_elements?("/VM/TEMPLATE/NIC")
450
- nics = [vm.to_hash['VM']['TEMPLATE']['NIC']].flatten
451
- ips = nics.map {|n| n['IP'] }
452
- ip = vm_nics.first['IP']
453
-
454
- if ips.include? ip
455
- vm_nics = nics
456
- else
457
- vm_nics += nics
458
- end
459
- end
460
- else
461
- vm_nics = [vm.to_hash['VM']['TEMPLATE']['NIC']].flatten
462
- end
463
-
464
425
  nic_default = {"NETWORK" => "-",
465
426
  "IP" => "-",
466
427
  "MAC"=> "-",
@@ -468,7 +429,7 @@ class OneVMHelper < OpenNebulaHelper::OneHelper
468
429
  "BRIDGE"=>"-"}
469
430
 
470
431
  array_id = 0
471
-
432
+ vm_nics = [vm.to_hash['VM']['TEMPLATE']['NIC']].flatten
472
433
  vm_nics.each {|nic|
473
434
 
474
435
  next if nic.has_key?("CLI_DONE")
@@ -556,6 +517,88 @@ class OneVMHelper < OpenNebulaHelper::OneHelper
556
517
  end if !options[:all]
557
518
  end
558
519
 
520
+ while vm.has_elements?("/VM/TEMPLATE/NIC")
521
+ vm.delete_element("/VM/TEMPLATE/NIC")
522
+ end if !options[:all]
523
+
524
+ if vm.has_elements?("/VM/TEMPLATE/SECURITY_GROUP_RULE")
525
+ puts
526
+ CLIHelper.print_header(str_h1 % "SECURITY",false)
527
+ puts
528
+
529
+ CLIHelper::ShowTable.new(nil, self) do
530
+ column :NIC_ID, "", :size=>6 do |d|
531
+ d["NIC_ID"]
532
+ end
533
+
534
+ column :NETWORK, "", :left, :size=>25 do |d|
535
+ d["NETWORK"]
536
+ end
537
+
538
+ column :SECURITY_GROUPS, "", :left, :size=>47 do |d|
539
+ d["SECURITY_GROUPS"]
540
+ end
541
+ end.show(sg_nics,{})
542
+
543
+ puts
544
+
545
+ CLIHelper.print_header(str_h1 % "SECURITY GROUP TYPE PROTOCOL NETWORK RANGE ",false)
546
+
547
+ CLIHelper::ShowTable.new(nil, self) do
548
+ column :ID, "", :size=>4 do |d|
549
+ d["SECURITY_GROUP_ID"]
550
+ end
551
+
552
+ column :NAME, "", :left, :size=>11 do |d|
553
+ d["SECURITY_GROUP_NAME"]
554
+ end
555
+
556
+ column :" ", "", :left, :size=>8 do |d|
557
+ d["RULE_TYPE"]
558
+ end
559
+
560
+ column :" ", "", :left, :size=>8 do |d|
561
+ protocol = d["PROTOCOL"]
562
+
563
+ if(protocol.upcase == "ICMP")
564
+ icmp = d["ICMP_TYPE"].nil? ? "" : "-#{d["ICMP_TYPE"]}"
565
+ protocol += icmp
566
+ end
567
+
568
+ protocol
569
+ end
570
+
571
+ column :VNET, "", :size=>4 do |d|
572
+ d["NETWORK_ID"]
573
+ end
574
+
575
+ column :START, "", :left, :donottruncate, :size=>17 do |d|
576
+ network = ""
577
+
578
+ if(!d["IP"].nil? && d["IP"] != "")
579
+ network = d["IP"]
580
+ elsif(!d["MAC"].nil? && d["MAC"] != "")
581
+ network = d["MAC"]
582
+ end
583
+
584
+ network
585
+ end
586
+
587
+ column :SIZE, "", :left, :donottruncate, :size=>6 do |d|
588
+ d["SIZE"]
589
+ end
590
+
591
+ column :" ", "", :left, :donottruncate, :size=>15 do |d|
592
+ d["RANGE"]
593
+ end
594
+
595
+ end.show([vm.to_hash['VM']['TEMPLATE']['SECURITY_GROUP_RULE']].flatten, {})
596
+
597
+ while vm.has_elements?("/VM/TEMPLATE/SECURITY_GROUP_RULE")
598
+ vm.delete_element("/VM/TEMPLATE/SECURITY_GROUP_RULE")
599
+ end if !options[:all]
600
+ end
601
+
559
602
  if vm.has_elements?("/VM/TEMPLATE/SNAPSHOT")
560
603
  puts
561
604
  CLIHelper.print_header(str_h1 % "SNAPSHOTS",false)