67
68
69
70
71
72
73
74
75
76
77
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
112
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
|
# File 'lib/one_helper/onegroup_helper.rb', line 67
def format_pool(_options)
config_file = self.class.table_conf
CLIHelper::ShowTable.new(config_file, self) do
pool_default_quotas = lambda do |path|
limit = @data.dsearch('/GROUP_POOL/DEFAULT_GROUP_QUOTAS/'+path)
limit = OneQuotaHelper::LIMIT_UNLIMITED if limit.nil? || limit.empty?
limit
end
quotas_proc = lambda do
if !defined?(@quotas)
quotas = @data.dsearch('GROUP_POOL/QUOTAS')
@quotas = {}
if !quotas.nil?
quotas = [quotas].flatten
quotas.each do |q|
vm_quota = q['VM_QUOTA']
if vm_quota.is_a?(Array)
q['VM_QUOTA'] = vm_quota.max_by {|h| h.size }
end
@quotas[q['ID']] = q
end
end
end
@quotas
end
column :ID, 'ONE identifier for the Group', :size=>4 do |d|
d['ID']
end
column :NAME, 'Name of the Group', :left, :size=>29 do |d|
d['NAME']
end
column :USERS, 'Number of Users in this group', :size=>5 do |d|
ids = d['USERS']['ID']
case ids
when String
'1'
when Array
ids.size
else
'0'
end
end
column :VMS, 'Number of VMS', :size=>9 do |d|
begin
q = quotas_proc.call[d['ID']]['VM_QUOTA']['VM']
if q.nil? && d['ID'].to_i != 0
q = OneQuotaHelper::DEFAULT_VM_QUOTA
end
if q.is_a?(Array)
global_h = q.find {|h| h['CLUSTER_IDS'].nil? || h['CLUSTER_IDS'].empty? }
q = global_h || q[0]
end
limit = q['VMS']
limit = pool_default_quotas.call('VM_QUOTA/VM/VMS') if limit == OneQuotaHelper::LIMIT_DEFAULT
if limit == OneQuotaHelper::LIMIT_UNLIMITED
format('%3d / -', q['VMS_USED'])
else
format('%3d / %3d', q['VMS_USED'], limit)
end
rescue NoMethodError
'-'
end
end
column :MEMORY, 'Total memory allocated to user VMs', :size=>15 do |d|
begin
q = quotas_proc.call[d['ID']]['VM_QUOTA']['VM']
if q.nil? && d['ID'].to_i != 0
q = OneQuotaHelper::DEFAULT_VM_QUOTA
end
if q.is_a?(Array)
global_h = q.find {|h| h['CLUSTER_IDS'].nil? || h['CLUSTER_IDS'].empty? }
q = global_h || q[0]
end
limit = q['MEMORY']
limit = pool_default_quotas.call('VM_QUOTA/VM/MEMORY') if limit == OneQuotaHelper::LIMIT_DEFAULT
if limit == OneQuotaHelper::LIMIT_UNLIMITED
format('%6s / -',
OpenNebulaHelper.unit_to_str(q['MEMORY_USED'].to_i, {}, 'M'))
else
format('%6s / %6s',
OpenNebulaHelper.unit_to_str(q['MEMORY_USED'].to_i, {}, 'M'),
OpenNebulaHelper.unit_to_str(limit.to_i, {}, 'M'))
end
rescue NoMethodError
'-'
end
end
column :CPU, 'Total CPU allocated to user VMs', :size=>11 do |d|
begin
q = quotas_proc.call[d['ID']]['VM_QUOTA']['VM']
if q.nil? && d['ID'].to_i != 0
q = OneQuotaHelper::DEFAULT_VM_QUOTA
end
if q.is_a?(Array)
global_h = q.find {|h| h['CLUSTER_IDS'].nil? || h['CLUSTER_IDS'].empty? }
q = global_h || q[0]
end
limit = q['CPU']
limit = pool_default_quotas.call('VM_QUOTA/VM/CPU') if limit == OneQuotaHelper::LIMIT_DEFAULT
if limit == OneQuotaHelper::LIMIT_UNLIMITED
format('%3.1f / -', q['CPU_USED'])
else
format('%3.1f / %3.1f', q['CPU_USED'], limit)
end
rescue NoMethodError
'-'
end
end
column :PCI, 'Total PCIs allocated to user VMs', :size=>9 do |d|
begin
q = quotas_proc.call[d['ID']]['VM_QUOTA']['VM']
if q.nil? && d['ID'].to_i != 0
q = OneQuotaHelper::DEFAULT_VM_QUOTA
end
if q.is_a?(Array)
global_q = q.find {|h| h['CLUSTER_IDS'].nil? || h['CLUSTER_IDS'].empty? }
q = global_q || q[0]
end
limit = q['PCI_DEV']
limit = pool_default_quotas.call('VM_QUOTA/VM/PCI_DEV') if limit == OneQuotaHelper::LIMIT_DEFAULT
if limit == OneQuotaHelper::LIMIT_UNLIMITED
format('%3s / -', q['PCI_DEV_USED'])
else
format('%3s / %3s', q['PCI_DEV_USED'], limit)
end
rescue NoMethodError
'-'
end
end
default :ID, :NAME, :USERS, :VMS, :MEMORY, :CPU, :PCI
end
end
|