opennebula 5.12.13 → 5.13.80.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (126) hide show
  1. checksums.yaml +5 -5
  2. data/lib/ActionManager.rb +1 -1
  3. data/lib/CommandManager.rb +1 -1
  4. data/lib/DriverExecHelper.rb +44 -28
  5. data/lib/OpenNebulaDriver.rb +8 -4
  6. data/lib/VirtualMachineDriver.rb +9 -2
  7. data/lib/cloud/CloudClient.rb +3 -3
  8. data/lib/datacenter.rb +1258 -0
  9. data/lib/datastore.rb +1025 -0
  10. data/lib/distributed_firewall.rb +280 -0
  11. data/lib/file_helper.rb +370 -0
  12. data/lib/host.rb +1517 -0
  13. data/lib/logical_port.rb +50 -0
  14. data/lib/logical_switch.rb +77 -0
  15. data/lib/memoize.rb +74 -0
  16. data/lib/models/role.rb +39 -8
  17. data/lib/models/service.rb +92 -31
  18. data/lib/models.rb +5 -5
  19. data/lib/network.rb +635 -0
  20. data/lib/nsx_client.rb +144 -0
  21. data/lib/nsx_component.rb +28 -0
  22. data/lib/nsx_constants.rb +149 -0
  23. data/lib/nsx_driver.rb +78 -0
  24. data/lib/nsx_error.rb +77 -0
  25. data/lib/nsx_rule.rb +193 -0
  26. data/lib/nsxt_client.rb +176 -0
  27. data/lib/nsxt_dfw.rb +196 -0
  28. data/lib/nsxt_logical_port.rb +94 -0
  29. data/lib/nsxt_rule.rb +188 -0
  30. data/lib/nsxt_tz.rb +38 -0
  31. data/lib/nsxv_client.rb +176 -0
  32. data/lib/nsxv_dfw.rb +202 -0
  33. data/lib/nsxv_logical_port.rb +107 -0
  34. data/lib/nsxv_rule.rb +172 -0
  35. data/lib/nsxv_tz.rb +41 -0
  36. data/lib/opaque_network.rb +134 -0
  37. data/lib/opennebula/acl.rb +1 -1
  38. data/lib/opennebula/acl_pool.rb +1 -1
  39. data/lib/opennebula/client.rb +1 -1
  40. data/lib/opennebula/cluster.rb +1 -1
  41. data/lib/opennebula/cluster_pool.rb +1 -1
  42. data/lib/opennebula/datastore.rb +1 -1
  43. data/lib/opennebula/datastore_pool.rb +1 -1
  44. data/lib/opennebula/document.rb +8 -29
  45. data/lib/opennebula/document_json.rb +42 -12
  46. data/lib/opennebula/document_pool.rb +1 -1
  47. data/lib/opennebula/document_pool_json.rb +1 -1
  48. data/lib/opennebula/error.rb +4 -1
  49. data/lib/opennebula/flow/grammar.rb +1195 -0
  50. data/lib/{models → opennebula/flow}/service_pool.rb +26 -2
  51. data/lib/{models → opennebula/flow}/service_template.rb +86 -17
  52. data/lib/opennebula/flow/service_template_ext.rb +84 -0
  53. data/lib/{models → opennebula/flow}/service_template_pool.rb +1 -1
  54. data/lib/opennebula/flow/validator.rb +499 -0
  55. data/lib/opennebula/flow.rb +23 -0
  56. data/lib/opennebula/group.rb +1 -1
  57. data/lib/opennebula/group_pool.rb +1 -1
  58. data/lib/opennebula/hook.rb +5 -12
  59. data/lib/opennebula/hook_log.rb +1 -1
  60. data/lib/opennebula/hook_pool.rb +1 -1
  61. data/lib/opennebula/host.rb +1 -1
  62. data/lib/opennebula/host_pool.rb +1 -1
  63. data/lib/opennebula/image.rb +17 -14
  64. data/lib/opennebula/image_pool.rb +1 -1
  65. data/lib/opennebula/ldap_auth.rb +1 -1
  66. data/lib/opennebula/ldap_auth_spec.rb +1 -1
  67. data/lib/opennebula/lockable_ext.rb +163 -0
  68. data/lib/opennebula/marketplace.rb +1 -1
  69. data/lib/opennebula/marketplace_pool.rb +1 -1
  70. data/lib/opennebula/marketplaceapp.rb +9 -119
  71. data/lib/opennebula/marketplaceapp_ext.rb +522 -0
  72. data/lib/opennebula/marketplaceapp_pool.rb +1 -1
  73. data/lib/opennebula/oneflow_client.rb +4 -3
  74. data/lib/opennebula/pool.rb +4 -3
  75. data/lib/opennebula/pool_element.rb +1 -1
  76. data/lib/opennebula/security_group.rb +1 -1
  77. data/lib/opennebula/security_group_pool.rb +1 -1
  78. data/lib/opennebula/server_cipher_auth.rb +1 -1
  79. data/lib/opennebula/server_x509_auth.rb +1 -1
  80. data/lib/opennebula/ssh_auth.rb +1 -1
  81. data/lib/opennebula/system.rb +1 -1
  82. data/lib/opennebula/template.rb +4 -13
  83. data/lib/opennebula/template_ext.rb +325 -0
  84. data/lib/opennebula/template_pool.rb +1 -1
  85. data/lib/opennebula/user.rb +26 -2
  86. data/lib/opennebula/user_pool.rb +1 -1
  87. data/lib/opennebula/utils.rb +1 -1
  88. data/lib/opennebula/vdc.rb +1 -1
  89. data/lib/opennebula/vdc_pool.rb +1 -1
  90. data/lib/opennebula/virtual_machine.rb +25 -207
  91. data/lib/opennebula/virtual_machine_ext.rb +469 -0
  92. data/lib/opennebula/virtual_machine_pool.rb +1 -5
  93. data/lib/opennebula/virtual_network.rb +4 -10
  94. data/lib/opennebula/virtual_network_pool.rb +1 -1
  95. data/lib/opennebula/virtual_router.rb +4 -12
  96. data/lib/opennebula/virtual_router_pool.rb +1 -1
  97. data/lib/opennebula/vm_group.rb +4 -11
  98. data/lib/opennebula/vm_group_pool.rb +1 -1
  99. data/lib/opennebula/vntemplate.rb +4 -13
  100. data/lib/opennebula/vntemplate_pool.rb +1 -1
  101. data/lib/opennebula/wait_ext.rb +222 -0
  102. data/lib/opennebula/x509_auth.rb +1 -1
  103. data/lib/opennebula/xml_element.rb +1 -1
  104. data/lib/opennebula/xml_pool.rb +1 -1
  105. data/lib/opennebula/xml_utils.rb +1 -1
  106. data/lib/opennebula/zone.rb +1 -1
  107. data/lib/opennebula/zone_pool.rb +1 -1
  108. data/lib/opennebula.rb +5 -2
  109. data/lib/rest_client.rb +201 -0
  110. data/lib/scripts_common.rb +180 -0
  111. data/lib/transport_zone.rb +43 -0
  112. data/lib/vcenter_driver.rb +9 -22
  113. data/lib/vcenter_importer.rb +616 -0
  114. data/lib/vi_client.rb +281 -0
  115. data/lib/vi_helper.rb +312 -0
  116. data/lib/virtual_machine.rb +3477 -0
  117. data/lib/virtual_wire.rb +158 -0
  118. data/lib/vm_device.rb +80 -0
  119. data/lib/vm_disk.rb +202 -0
  120. data/lib/vm_folder.rb +69 -0
  121. data/lib/vm_helper.rb +30 -0
  122. data/lib/vm_monitor.rb +303 -0
  123. data/lib/vm_nic.rb +70 -0
  124. data/lib/vm_template.rb +1961 -0
  125. data/lib/vmm_importer.rb +121 -0
  126. metadata +101 -35
data/lib/vm_monitor.rb ADDED
@@ -0,0 +1,303 @@
1
+ # -------------------------------------------------------------------------- #
2
+ # Copyright 2002-2021, 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
+ module VirtualMachineMonitor
17
+
18
+ POLL_ATTRIBUTE = OpenNebula::VirtualMachine::Driver::POLL_ATTRIBUTE
19
+ VM_STATE = OpenNebula::VirtualMachine::Driver::VM_STATE
20
+
21
+ # Converts the VI string state to OpenNebula state convention
22
+ # Guest states are:
23
+ # - poweredOff The virtual machine is currently powered off.
24
+ # - poweredOn The virtual machine is currently powered on.
25
+ # - suspended The virtual machine is currently suspended.
26
+ def state_to_c(state)
27
+ case state
28
+ when 'poweredOn'
29
+ VM_STATE[:active]
30
+ when 'suspended'
31
+ VM_STATE[:paused]
32
+ when 'poweredOff'
33
+ VM_STATE[:deleted]
34
+ else
35
+ VM_STATE[:unknown]
36
+ end
37
+ end
38
+
39
+ # monitor function used when poll action is called for all vms
40
+ def monitor(stats)
41
+ reset_monitor
42
+
43
+ refresh_rate = 20 # 20 seconds between samples (realtime)
44
+
45
+ @state = state_to_c(@vm_info['summary.runtime.powerState'])
46
+
47
+ return if @state != VM_STATE[:active]
48
+
49
+ cpuMhz = @vm_info[:esx_host_cpu]
50
+
51
+ @monitor[:used_memory] = @vm_info['summary.quickStats.hostMemoryUsage']
52
+ .to_i * 1024
53
+
54
+ used_cpu = @vm_info['summary.quickStats.overallCpuUsage'].to_f / cpuMhz
55
+ used_cpu = (used_cpu * 100).to_s
56
+ @monitor[:used_cpu] = format('%.2f', used_cpu).to_s
57
+
58
+ # Check for negative values
59
+ @monitor[:used_memory] = 0 if @monitor[:used_memory].to_i < 0
60
+ @monitor[:used_cpu] = 0 if @monitor[:used_cpu].to_i < 0
61
+
62
+ guest_ip_addresses = []
63
+ unless self['guest.net'].empty?
64
+ @vm_info['guest.net'].each do |net|
65
+ next unless net.ipConfig
66
+ next if net.ipConfig.ipAddress.empty?
67
+
68
+ net.ipConfig.ipAddress.each do |ip|
69
+ guest_ip_addresses << ip.ipAddress
70
+ end
71
+ end
72
+ end
73
+
74
+ @guest_ip_addresses = guest_ip_addresses.join(',')
75
+
76
+ if stats.key?(@item)
77
+ metrics = stats[@item][:metrics]
78
+
79
+ nettx_kbpersec = 0
80
+ if metrics['net.transmitted']
81
+ metrics['net.transmitted'].each do |sample|
82
+ nettx_kbpersec += sample if sample > 0
83
+ end
84
+ end
85
+
86
+ netrx_kbpersec = 0
87
+ if metrics['net.bytesRx']
88
+ metrics['net.bytesRx'].each do |sample|
89
+ netrx_kbpersec += sample if sample > 0
90
+ end
91
+ end
92
+
93
+ read_kbpersec = 0
94
+ if metrics['virtualDisk.read']
95
+ metrics['virtualDisk.read'].each do |sample|
96
+ read_kbpersec += sample if sample > 0
97
+ end
98
+ end
99
+
100
+ read_iops = 0
101
+ if metrics['virtualDisk.numberReadAveraged']
102
+ metrics['virtualDisk.numberReadAveraged'].each do |sample|
103
+ read_iops += sample if sample > 0
104
+ end
105
+ end
106
+
107
+ write_kbpersec = 0
108
+ if metrics['virtualDisk.write']
109
+ metrics['virtualDisk.write'].each do |sample|
110
+ write_kbpersec += sample if sample > 0
111
+ end
112
+ end
113
+
114
+ write_iops = 0
115
+ if metrics['virtualDisk.numberWriteAveraged']
116
+ metrics['virtualDisk.numberWriteAveraged'].each do |sample|
117
+ write_iops += sample if sample > 0
118
+ end
119
+ end
120
+ else
121
+ nettx_kbpersec = 0
122
+ netrx_kbpersec = 0
123
+ read_kbpersec = 0
124
+ read_iops = 0
125
+ write_kbpersec = 0
126
+ write_iops = 0
127
+ end
128
+
129
+ # Accumulate values if present
130
+ if @one_item && @one_item['MONITORING/NETTX']
131
+ previous_nettx = @one_item['MONITORING/NETTX'].to_i
132
+ else
133
+ previous_nettx = 0
134
+ end
135
+
136
+ if @one_item && @one_item['MONITORING/NETRX']
137
+ previous_netrx = @one_item['MONITORING/NETRX'].to_i
138
+ else
139
+ previous_netrx = 0
140
+ end
141
+
142
+ if @one_item && @one_item['MONITORING/DISKRDIOPS']
143
+ previous_diskrdiops = @one_item['MONITORING/DISKRDIOPS'].to_i
144
+ else
145
+ previous_diskrdiops = 0
146
+ end
147
+
148
+ if @one_item && @one_item['MONITORING/DISKWRIOPS']
149
+ previous_diskwriops = @one_item['MONITORING/DISKWRIOPS'].to_i
150
+ else
151
+ previous_diskwriops = 0
152
+ end
153
+
154
+ if @one_item && @one_item['MONITORING/DISKRDBYTES']
155
+ previous_diskrdbytes = @one_item['MONITORING/DISKRDBYTES'].to_i
156
+ else
157
+ previous_diskrdbytes = 0
158
+ end
159
+
160
+ if @one_item && @one_item['MONITORING/DISKWRBYTES']
161
+ previous_diskwrbytes = @one_item['MONITORING/DISKWRBYTES'].to_i
162
+ else
163
+ previous_diskwrbytes = 0
164
+ end
165
+
166
+ @monitor[:nettx] = previous_nettx +
167
+ (nettx_kbpersec * 1024 * refresh_rate).to_i
168
+ @monitor[:netrx] = previous_netrx +
169
+ (netrx_kbpersec * 1024 * refresh_rate).to_i
170
+
171
+ @monitor[:diskrdiops] = previous_diskrdiops + read_iops
172
+ @monitor[:diskwriops] = previous_diskwriops + write_iops
173
+ @monitor[:diskrdbytes] = previous_diskrdbytes +
174
+ (read_kbpersec * 1024 * refresh_rate).to_i
175
+ @monitor[:diskwrbytes] = previous_diskwrbytes +
176
+ (write_kbpersec * 1024 * refresh_rate).to_i
177
+ end
178
+ # rubocop:enable Naming/VariableName
179
+ # rubocop:enable Style/FormatStringToken
180
+
181
+ # Generates a OpenNebula IM Driver valid string with the monitor info
182
+ def info
183
+ # return 'STATE=d' if @state == 'd'
184
+
185
+ if @vm_info
186
+ guest_ip = @vm_info['guest.ipAddress']
187
+ else
188
+ guest_ip = self['guest.ipAddress']
189
+ end
190
+
191
+ used_cpu = @monitor[:used_cpu]
192
+ used_memory = @monitor[:used_memory]
193
+ netrx = @monitor[:netrx]
194
+ nettx = @monitor[:nettx]
195
+ diskrdbytes = @monitor[:diskrdbytes]
196
+ diskwrbytes = @monitor[:diskwrbytes]
197
+ diskrdiops = @monitor[:diskrdiops]
198
+ diskwriops = @monitor[:diskwriops]
199
+
200
+ if @vm_info
201
+ esx_host = @vm_info[:esx_host_name].to_s
202
+ else
203
+ esx_host = self['runtime.host.name'].to_s
204
+ end
205
+
206
+ if @vm_info
207
+ guest_state = @vm_info['guest.guestState'].to_s
208
+ else
209
+ guest_state = self['guest.guestState'].to_s
210
+ end
211
+
212
+ if @vm_info
213
+ vmware_tools = @vm_info['guest.toolsRunningStatus'].to_s
214
+ else
215
+ vmware_tools = self['guest.toolsRunningStatus'].to_s
216
+ end
217
+
218
+ if @vm_info
219
+ vm_name = @vm_info['name'].to_s
220
+ else
221
+ vm_name = self['name'].to_s
222
+ end
223
+
224
+ if @vm_info
225
+ vmtools_ver = @vm_info['guest.toolsVersion'].to_s
226
+ else
227
+ vmtools_ver = self['guest.toolsVersion'].to_s
228
+ end
229
+
230
+ if @vm_info
231
+ vmtools_verst = @vm_info['guest.toolsVersionStatus2'].to_s
232
+ else
233
+ vmtools_verst = self['guest.toolsVersionStatus2'].to_s
234
+ end
235
+
236
+ if @vm_info
237
+ rp_name = @vm_info[:rp_list]
238
+ .select do |item|
239
+ item[:ref] == @vm_info['resourcePool']._ref
240
+ end
241
+ .first[:name] rescue ''
242
+
243
+ rp_name = 'Resources' if rp_name.empty?
244
+ else
245
+ rp_name = self['resourcePool'].name
246
+ end
247
+
248
+ str_info = ''
249
+
250
+ str_info = 'GUEST_IP=' << guest_ip.to_s << "\n" if guest_ip
251
+
252
+ if @guest_ip_addresses && !@guest_ip_addresses.empty?
253
+ str_info << 'GUEST_IP_ADDRESSES="' << @guest_ip_addresses.to_s \
254
+ << '" '
255
+ end
256
+
257
+ str_info << "#{POLL_ATTRIBUTE[:cpu]}=" << used_cpu.to_s << "\n"
258
+ str_info << "#{POLL_ATTRIBUTE[:memory]}=" << used_memory.to_s << "\n"
259
+ str_info << "#{POLL_ATTRIBUTE[:netrx]}=" << netrx.to_s << "\n"
260
+ str_info << "#{POLL_ATTRIBUTE[:nettx]}=" << nettx.to_s << "\n"
261
+
262
+ str_info << 'DISKRDBYTES=' << diskrdbytes.to_s << "\n"
263
+ str_info << 'DISKWRBYTES=' << diskwrbytes.to_s << "\n"
264
+ str_info << 'DISKRDIOPS=' << diskrdiops.to_s << "\n"
265
+ str_info << 'DISKWRIOPS=' << diskwriops.to_s << "\n"
266
+
267
+ str_info << 'VCENTER_ESX_HOST="' << esx_host << '" ' << "\n"
268
+ str_info << 'VCENTER_GUEST_STATE=' << guest_state << "\n"
269
+ str_info << 'VCENTER_VM_NAME="' << vm_name << '" ' << "\n"
270
+ str_info << 'VCENTER_VMWARETOOLS_RUNNING_STATUS=' \
271
+ << vmware_tools << "\n"
272
+ str_info << 'VCENTER_VMWARETOOLS_VERSION=' << vmtools_ver << "\n"
273
+ str_info << 'VCENTER_VMWARETOOLS_VERSION_STATUS=' \
274
+ << vmtools_verst << "\n"
275
+ str_info << 'VCENTER_RP_NAME="' << rp_name << '" ' << "\n"
276
+
277
+ info_disks.each do |disk|
278
+ next if disk[1].no_exists?
279
+
280
+ # Delete special characters
281
+ name = disk[0].gsub(/[^0-9A-Za-z]/, '_')
282
+
283
+ str_info << "DISK_#{name}_ACTUAL_PATH=\"[" <<
284
+ disk[1].ds.name << '] ' << disk[1].path << '" ' << "\n"
285
+ end
286
+
287
+ str_info
288
+ end
289
+
290
+ def reset_monitor
291
+ @monitor = {
292
+ :used_cpu => 0,
293
+ :used_memory => 0,
294
+ :netrx => 0,
295
+ :nettx => 0,
296
+ :diskrdbytes => 0,
297
+ :diskwrbytes => 0,
298
+ :diskrdiops => 0,
299
+ :diskwriops => 0
300
+ }
301
+ end
302
+
303
+ end
data/lib/vm_nic.rb ADDED
@@ -0,0 +1,70 @@
1
+ # -------------------------------------------------------------------------- #
2
+ # Copyright 2002-2021, 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
+ module VirtualMachineDevice
17
+
18
+ # Nic class
19
+ class Nic < Device
20
+
21
+ # Create the OpenNebula nic representation
22
+ # Allow as to create the class without vCenter representation
23
+ # example: attached nics not synced with vCenter
24
+ def self.one_nic(id, one_res)
25
+ new(id, one_res, nil)
26
+ end
27
+
28
+ # Create the vCenter nic representation
29
+ # Allow as to create the class without OpenNebula representation
30
+ # example: detached nics that not exists in OpenNebula
31
+ def self.vc_nic(vc_res)
32
+ new(nil, nil, vc_res)
33
+ end
34
+
35
+ def key
36
+ raise_if_no_exists_in_vcenter
37
+ @vc_res.key
38
+ end
39
+
40
+ def boot_dev
41
+ RbVmomi::VIM
42
+ .VirtualMachineBootOptionsBootableEthernetDevice(
43
+ :deviceKey => key
44
+ )
45
+ end
46
+
47
+ def self.nic_model_class(nicmodel)
48
+ case nicmodel
49
+ when 'virtuale1000', 'e1000'
50
+ RbVmomi::VIM::VirtualE1000
51
+ when 'virtuale1000e', 'e1000e'
52
+ RbVmomi::VIM::VirtualE1000e
53
+ when 'virtualpcnet32', 'pcnet32'
54
+ RbVmomi::VIM::VirtualPCNet32
55
+ when 'virtualsriovethernetcard', 'sriovethernetcard'
56
+ RbVmomi::VIM::VirtualSriovEthernetCard
57
+ when 'virtualvmxnetm', 'vmxnetm'
58
+ RbVmomi::VIM::VirtualVmxnetm
59
+ when 'virtualvmxnet2', 'vmnet2'
60
+ RbVmomi::VIM::VirtualVmxnet2
61
+ when 'virtualvmxnet3', 'vmxnet3'
62
+ RbVmomi::VIM::VirtualVmxnet3
63
+ else # If none matches, use vmxnet3
64
+ RbVmomi::VIM::VirtualVmxnet3
65
+ end
66
+ end
67
+
68
+ end
69
+
70
+ end