opennebula-cli 6.0.0.3 → 6.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -16,71 +16,73 @@
16
16
 
17
17
  require 'one_helper'
18
18
 
19
- # OneCluster CLI command helper
20
19
  class OneClusterHelper < OpenNebulaHelper::OneHelper
21
20
 
22
21
  CLUSTER = {
23
- :name => 'cluster',
24
- :short => '-c id|name',
25
- :large => '--cluster id|name',
26
- :description => 'Selects the cluster',
22
+ :name => "cluster",
23
+ :short => "-c id|name",
24
+ :large => "--cluster id|name" ,
25
+ :description => "Selects the cluster",
27
26
  :format => String,
28
- :proc => lambda {|o, _options|
29
- OpenNebulaHelper.rname_to_id(o, 'CLUSTER')
27
+ :proc => lambda { |o, options|
28
+ OpenNebulaHelper.rname_to_id(o, "CLUSTER")
30
29
  }
31
30
  }
32
31
 
33
32
  def self.rname
34
- 'CLUSTER'
33
+ "CLUSTER"
35
34
  end
36
35
 
37
36
  def self.conf_file
38
- 'onecluster.yaml'
37
+ "onecluster.yaml"
39
38
  end
40
39
 
41
40
  def element_size(ehash, ename)
42
- ids = ehash[ename]['ID']
41
+ ids = ehash[ename]["ID"]
43
42
 
44
43
  if ids.nil?
45
- 0
44
+ return 0
46
45
  elsif ids.class == String
47
- 1
46
+ return 1
48
47
  else
49
- ids.size
48
+ return ids.size
50
49
  end
51
50
  end
52
51
 
53
- def format_pool(_options)
52
+
53
+ def format_pool(options)
54
54
  config_file = self.class.table_conf
55
55
 
56
- CLIHelper::ShowTable.new(config_file, self) do
57
- column :ID, 'ONE identifier for the Cluster', :size=>5 do |d|
58
- d['ID']
56
+ table = CLIHelper::ShowTable.new(config_file, self) do
57
+ column :ID, "ONE identifier for the Cluster", :size=>5 do |d|
58
+ d["ID"]
59
59
  end
60
60
 
61
- column :NAME, 'Name of the Cluster', :left, :size=>25 do |d|
62
- d['NAME']
61
+ column :NAME, "Name of the Cluster", :left, :size=>25 do |d|
62
+ d["NAME"]
63
63
  end
64
64
 
65
- column :HOSTS, 'Number of Hosts', :size=>5 do |d|
66
- @ext.element_size(d, 'HOSTS') rescue 0
65
+ column :HOSTS, "Number of Hosts", :size=>5 do |d|
66
+ @ext.element_size(d,"HOSTS") rescue 0
67
67
  end
68
68
 
69
- column :VNETS, 'Number of Networks', :size=>5 do |d|
70
- @ext.element_size(d, 'VNETS') rescue 0
69
+ column :VNETS, "Number of Networks", :size=>5 do |d|
70
+ @ext.element_size(d,"VNETS") rescue 0
71
71
  end
72
72
 
73
- column :DATASTORES, 'Number of Datastores', :size=>10 do |d|
74
- @ext.element_size(d, 'DATASTORES') rescue 0
73
+ column :DATASTORES, "Number of Datastores", :size=>10 do |d|
74
+ @ext.element_size(d,"DATASTORES") rescue 0
75
75
  end
76
76
 
77
77
  default :ID, :NAME, :HOSTS, :VNETS, :DATASTORES
78
78
  end
79
+
80
+ table
79
81
  end
80
82
 
81
83
  private
82
84
 
83
- def factory(id = nil)
85
+ def factory(id=nil)
84
86
  if id
85
87
  OpenNebula::Cluster.new_with_id(id, @client)
86
88
  else
@@ -89,74 +91,39 @@ class OneClusterHelper < OpenNebulaHelper::OneHelper
89
91
  end
90
92
  end
91
93
 
92
- def factory_pool(_user_flag = -2)
94
+ def factory_pool(user_flag=-2)
93
95
  OpenNebula::ClusterPool.new(@client)
94
96
  end
95
97
 
96
- def format_resource(cluster, _options = {})
97
- str='%-18s: %-20s'
98
- str_h1='%-80s'
98
+ def format_resource(cluster, options = {})
99
+ str="%-18s: %-20s"
100
+ str_h1="%-80s"
99
101
 
100
102
  CLIHelper.print_header(str_h1 % "CLUSTER #{cluster['ID']} INFORMATION")
101
- puts format(str, 'ID', cluster.id.to_s)
102
- puts format(str, 'NAME', cluster.name)
103
-
103
+ puts str % ["ID", cluster.id.to_s]
104
+ puts str % ["NAME", cluster.name]
104
105
  puts
105
- CLIHelper.print_header(str_h1 % 'CLUSTER RESOURCES', false)
106
- cluster.info!
107
-
108
- hosts = cluster.to_hash['CLUSTER']['HOSTS']['ID']
109
-
110
- if hosts
111
- total_cpu = 0
112
- used_cpu = 0
113
- total_ram = 0
114
- used_ram = 0
115
-
116
- [hosts].flatten.each do |h|
117
- h = OpenNebula::Host.new_with_id(h, @client)
118
-
119
- h.info!
120
-
121
- h = h.to_hash
122
- h = h['HOST']['HOST_SHARE']
123
106
 
124
- total_cpu += h['TOTAL_CPU'].to_i / 100
125
- used_cpu += h['CPU_USAGE'].to_i / 100
126
- total_ram += h['TOTAL_MEM'].to_i / 1024 / 1024
127
- used_ram += h['MEM_USAGE'].to_i / 1024 / 1024
128
- end
129
-
130
- puts "TOTAL CPUs: #{total_cpu}"
131
- puts "OCCUPIED CPUs: #{used_cpu}"
132
- puts "AVAILABLE CPUs: #{total_cpu - used_cpu}"
133
- puts
134
- puts "TOTAL RAM: #{total_ram}"
135
- puts "OCCUPIED RAM: #{used_ram}"
136
- puts "AVAILABLE RAM: #{total_ram - used_ram}"
137
- end
138
-
139
- puts
140
- CLIHelper.print_header(str_h1 % 'CLUSTER TEMPLATE', false)
107
+ CLIHelper.print_header(str_h1 % "CLUSTER TEMPLATE", false)
141
108
  puts cluster.template_str
142
109
 
143
110
  puts
144
- CLIHelper.print_header(format('%-15s', 'HOSTS'))
111
+
112
+ CLIHelper.print_header("%-15s" % ["HOSTS"])
145
113
  cluster.host_ids.each do |id|
146
- puts format('%-15s', id)
114
+ puts "%-15s" % [id]
147
115
  end
148
116
 
149
117
  puts
150
- CLIHelper.print_header(format('%-15s', 'VNETS'))
118
+ CLIHelper.print_header("%-15s" % ["VNETS"])
151
119
  cluster.vnet_ids.each do |id|
152
- puts format('%-15s', id)
120
+ puts "%-15s" % [id]
153
121
  end
154
122
 
155
123
  puts
156
- CLIHelper.print_header(format('%-15s', 'DATASTORES'))
124
+ CLIHelper.print_header("%-15s" % ["DATASTORES"])
157
125
  cluster.datastore_ids.each do |id|
158
- puts format('%-15s', id)
126
+ puts "%-15s" % [id]
159
127
  end
160
128
  end
161
-
162
129
  end
@@ -1086,26 +1086,6 @@ class OneVMHelper < OpenNebulaHelper::OneHelper
1086
1086
  end
1087
1087
  end
1088
1088
 
1089
- if vm_hash['VM']['TEMPLATE']['NIC']
1090
- nic = [vm_hash['VM']['TEMPLATE']['NIC']]
1091
- nic = nic.flatten
1092
- nic = nic.select {|v| !v['EXTERNAL_PORT_RANGE'].nil? }[0]
1093
-
1094
- if nic
1095
- ip = vm_hash['VM']['HISTORY_RECORDS']['HISTORY']
1096
- ip = [ip].flatten[-1]['HOSTNAME']
1097
- port = Integer(nic['EXTERNAL_PORT_RANGE'].split(':')[0]) + 21
1098
-
1099
- puts
1100
- CLIHelper.print_header(str_h1 % 'PORT FORWARD', false)
1101
-
1102
- puts "[#{nic['EXTERNAL_PORT_RANGE']}]:" \
1103
- "[#{nic['INTERNAL_PORT_RANGE'].split('/')[0]}]"
1104
-
1105
- puts "SSH on #{ip} at port #{port}"
1106
- end
1107
- end
1108
-
1109
1089
  if !options[:all]
1110
1090
  while vm.has_elements?('/VM/TEMPLATE/NIC')
1111
1091
  vm.delete_element('/VM/TEMPLATE/NIC')