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.
- checksums.yaml +5 -5
- data/lib/ActionManager.rb +1 -1
- data/lib/CommandManager.rb +1 -1
- data/lib/DriverExecHelper.rb +44 -28
- data/lib/OpenNebulaDriver.rb +8 -4
- data/lib/VirtualMachineDriver.rb +9 -2
- data/lib/cloud/CloudClient.rb +3 -3
- data/lib/datacenter.rb +1258 -0
- data/lib/datastore.rb +1025 -0
- data/lib/distributed_firewall.rb +280 -0
- data/lib/file_helper.rb +370 -0
- data/lib/host.rb +1517 -0
- data/lib/logical_port.rb +50 -0
- data/lib/logical_switch.rb +77 -0
- data/lib/memoize.rb +74 -0
- data/lib/models/role.rb +39 -8
- data/lib/models/service.rb +92 -31
- data/lib/models.rb +5 -5
- data/lib/network.rb +635 -0
- data/lib/nsx_client.rb +144 -0
- data/lib/nsx_component.rb +28 -0
- data/lib/nsx_constants.rb +149 -0
- data/lib/nsx_driver.rb +78 -0
- data/lib/nsx_error.rb +77 -0
- data/lib/nsx_rule.rb +193 -0
- data/lib/nsxt_client.rb +176 -0
- data/lib/nsxt_dfw.rb +196 -0
- data/lib/nsxt_logical_port.rb +94 -0
- data/lib/nsxt_rule.rb +188 -0
- data/lib/nsxt_tz.rb +38 -0
- data/lib/nsxv_client.rb +176 -0
- data/lib/nsxv_dfw.rb +202 -0
- data/lib/nsxv_logical_port.rb +107 -0
- data/lib/nsxv_rule.rb +172 -0
- data/lib/nsxv_tz.rb +41 -0
- data/lib/opaque_network.rb +134 -0
- data/lib/opennebula/acl.rb +1 -1
- data/lib/opennebula/acl_pool.rb +1 -1
- data/lib/opennebula/client.rb +1 -1
- data/lib/opennebula/cluster.rb +1 -1
- data/lib/opennebula/cluster_pool.rb +1 -1
- data/lib/opennebula/datastore.rb +1 -1
- data/lib/opennebula/datastore_pool.rb +1 -1
- data/lib/opennebula/document.rb +8 -29
- data/lib/opennebula/document_json.rb +42 -12
- data/lib/opennebula/document_pool.rb +1 -1
- data/lib/opennebula/document_pool_json.rb +1 -1
- data/lib/opennebula/error.rb +4 -1
- data/lib/opennebula/flow/grammar.rb +1195 -0
- data/lib/{models → opennebula/flow}/service_pool.rb +26 -2
- data/lib/{models → opennebula/flow}/service_template.rb +86 -17
- data/lib/opennebula/flow/service_template_ext.rb +84 -0
- data/lib/{models → opennebula/flow}/service_template_pool.rb +1 -1
- data/lib/opennebula/flow/validator.rb +499 -0
- data/lib/opennebula/flow.rb +23 -0
- data/lib/opennebula/group.rb +1 -1
- data/lib/opennebula/group_pool.rb +1 -1
- data/lib/opennebula/hook.rb +5 -12
- data/lib/opennebula/hook_log.rb +1 -1
- data/lib/opennebula/hook_pool.rb +1 -1
- data/lib/opennebula/host.rb +1 -1
- data/lib/opennebula/host_pool.rb +1 -1
- data/lib/opennebula/image.rb +17 -14
- data/lib/opennebula/image_pool.rb +1 -1
- data/lib/opennebula/ldap_auth.rb +1 -1
- data/lib/opennebula/ldap_auth_spec.rb +1 -1
- data/lib/opennebula/lockable_ext.rb +163 -0
- data/lib/opennebula/marketplace.rb +1 -1
- data/lib/opennebula/marketplace_pool.rb +1 -1
- data/lib/opennebula/marketplaceapp.rb +9 -119
- data/lib/opennebula/marketplaceapp_ext.rb +522 -0
- data/lib/opennebula/marketplaceapp_pool.rb +1 -1
- data/lib/opennebula/oneflow_client.rb +4 -3
- data/lib/opennebula/pool.rb +4 -3
- data/lib/opennebula/pool_element.rb +1 -1
- data/lib/opennebula/security_group.rb +1 -1
- data/lib/opennebula/security_group_pool.rb +1 -1
- data/lib/opennebula/server_cipher_auth.rb +1 -1
- data/lib/opennebula/server_x509_auth.rb +1 -1
- data/lib/opennebula/ssh_auth.rb +1 -1
- data/lib/opennebula/system.rb +1 -1
- data/lib/opennebula/template.rb +4 -13
- data/lib/opennebula/template_ext.rb +325 -0
- data/lib/opennebula/template_pool.rb +1 -1
- data/lib/opennebula/user.rb +26 -2
- data/lib/opennebula/user_pool.rb +1 -1
- data/lib/opennebula/utils.rb +1 -1
- data/lib/opennebula/vdc.rb +1 -1
- data/lib/opennebula/vdc_pool.rb +1 -1
- data/lib/opennebula/virtual_machine.rb +25 -207
- data/lib/opennebula/virtual_machine_ext.rb +469 -0
- data/lib/opennebula/virtual_machine_pool.rb +1 -5
- data/lib/opennebula/virtual_network.rb +4 -10
- data/lib/opennebula/virtual_network_pool.rb +1 -1
- data/lib/opennebula/virtual_router.rb +4 -12
- data/lib/opennebula/virtual_router_pool.rb +1 -1
- data/lib/opennebula/vm_group.rb +4 -11
- data/lib/opennebula/vm_group_pool.rb +1 -1
- data/lib/opennebula/vntemplate.rb +4 -13
- data/lib/opennebula/vntemplate_pool.rb +1 -1
- data/lib/opennebula/wait_ext.rb +222 -0
- data/lib/opennebula/x509_auth.rb +1 -1
- data/lib/opennebula/xml_element.rb +1 -1
- data/lib/opennebula/xml_pool.rb +1 -1
- data/lib/opennebula/xml_utils.rb +1 -1
- data/lib/opennebula/zone.rb +1 -1
- data/lib/opennebula/zone_pool.rb +1 -1
- data/lib/opennebula.rb +5 -2
- data/lib/rest_client.rb +201 -0
- data/lib/scripts_common.rb +180 -0
- data/lib/transport_zone.rb +43 -0
- data/lib/vcenter_driver.rb +9 -22
- data/lib/vcenter_importer.rb +616 -0
- data/lib/vi_client.rb +281 -0
- data/lib/vi_helper.rb +312 -0
- data/lib/virtual_machine.rb +3477 -0
- data/lib/virtual_wire.rb +158 -0
- data/lib/vm_device.rb +80 -0
- data/lib/vm_disk.rb +202 -0
- data/lib/vm_folder.rb +69 -0
- data/lib/vm_helper.rb +30 -0
- data/lib/vm_monitor.rb +303 -0
- data/lib/vm_nic.rb +70 -0
- data/lib/vm_template.rb +1961 -0
- data/lib/vmm_importer.rb +121 -0
- metadata +101 -35
@@ -1,5 +1,5 @@
|
|
1
1
|
# -------------------------------------------------------------------------- #
|
2
|
-
# Copyright 2002-
|
2
|
+
# Copyright 2002-2021, OpenNebula Project, OpenNebula Systems #
|
3
3
|
# #
|
4
4
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
5
5
|
# not use this file except in compliance with the License. You may obtain #
|
@@ -0,0 +1,222 @@
|
|
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
|
+
|
17
|
+
require 'ffi-rzmq'
|
18
|
+
|
19
|
+
require 'opennebula/host'
|
20
|
+
require 'opennebula/image'
|
21
|
+
require 'opennebula/virtual_machine'
|
22
|
+
|
23
|
+
# Module to decorate Wait classes with the following methods:
|
24
|
+
# - Wait
|
25
|
+
#
|
26
|
+
# rubocop:disable Style/ClassAndModuleChildren
|
27
|
+
module OpenNebula::WaitExt
|
28
|
+
|
29
|
+
# Wait classes and the name published in ZMQ
|
30
|
+
WAIT = {
|
31
|
+
OpenNebula::Host => {
|
32
|
+
:event => lambda {|o, s1, _s2|
|
33
|
+
"EVENT STATE HOST/#{s1}//#{o['ID']}"
|
34
|
+
},
|
35
|
+
|
36
|
+
:in_state => lambda {|o, s1, _s2|
|
37
|
+
obj_s = Integer(o['STATE'])
|
38
|
+
inx_s = OpenNebula::Host::HOST_STATES.index(s1)
|
39
|
+
|
40
|
+
obj_s == inx_s
|
41
|
+
},
|
42
|
+
|
43
|
+
:in_state_e => lambda {|s1, _s2, content|
|
44
|
+
xml = Nokogiri::XML(Base64.decode64(content))
|
45
|
+
|
46
|
+
obj_s = Integer(xml.xpath('//HOST/STATE').text)
|
47
|
+
inx_s = OpenNebula::Host::HOST_STATES.index(s1)
|
48
|
+
|
49
|
+
obj_s == inx_s
|
50
|
+
}
|
51
|
+
},
|
52
|
+
|
53
|
+
OpenNebula::Image => {
|
54
|
+
:event => lambda {|o, s1, _s2|
|
55
|
+
"EVENT STATE IMAGE/#{s1}//#{o['ID']}"
|
56
|
+
},
|
57
|
+
|
58
|
+
:in_state => lambda {|o, s1, _s2|
|
59
|
+
obj_s = Integer(o['STATE'])
|
60
|
+
inx_s = OpenNebula::Image::IMAGE_STATES.index(s1)
|
61
|
+
|
62
|
+
obj_s == inx_s
|
63
|
+
},
|
64
|
+
|
65
|
+
:in_state_e => lambda {|s1, _s2, content|
|
66
|
+
xml = Nokogiri::XML(Base64.decode64(content))
|
67
|
+
|
68
|
+
obj_s = Integer(xml.xpath('//IMAGE/STATE').text)
|
69
|
+
inx_s = OpenNebula::Image::IMAGE_STATES.index(s1)
|
70
|
+
|
71
|
+
obj_s == inx_s
|
72
|
+
}
|
73
|
+
},
|
74
|
+
|
75
|
+
OpenNebula::VirtualMachine => {
|
76
|
+
:event => lambda {|o, s1, s2|
|
77
|
+
"EVENT STATE VM/#{s1}/#{s2}/#{o['ID']}"
|
78
|
+
},
|
79
|
+
|
80
|
+
:in_state => lambda {|o, s1, s2|
|
81
|
+
obj_s1 = Integer(o['STATE'])
|
82
|
+
inx_s1 = OpenNebula::VirtualMachine::VM_STATE.index(s1)
|
83
|
+
|
84
|
+
obj_s2 = Integer(o['LCM_STATE'])
|
85
|
+
inx_s2 = OpenNebula::VirtualMachine::LCM_STATE.index(s2)
|
86
|
+
|
87
|
+
obj_s1 == inx_s1 && obj_s2 == inx_s2
|
88
|
+
},
|
89
|
+
|
90
|
+
:in_state_e => lambda {|s1, s2, content|
|
91
|
+
xml = Nokogiri::XML(Base64.decode64(content))
|
92
|
+
|
93
|
+
obj_s1 = Integer(xml.xpath('//VM/STATE').text)
|
94
|
+
inx_s1 = OpenNebula::VirtualMachine::VM_STATE.index(s1)
|
95
|
+
|
96
|
+
obj_s2 = Integer(xml.xpath('//VM/LCM_STATE').text)
|
97
|
+
inx_s2 = OpenNebula::VirtualMachine::LCM_STATE.index(s2)
|
98
|
+
|
99
|
+
obj_s1 == inx_s1 && obj_s2 == inx_s2
|
100
|
+
}
|
101
|
+
}
|
102
|
+
}
|
103
|
+
|
104
|
+
def self.extend_object(obj)
|
105
|
+
wait?(obj)
|
106
|
+
|
107
|
+
class << obj
|
108
|
+
|
109
|
+
# Wait until the element reaches some specific state
|
110
|
+
# It waits until the state can be found in ZMQ event message
|
111
|
+
#
|
112
|
+
# @param state_str [String] State name to wait
|
113
|
+
# @param timeout [Integer] Number of seconds to timeout event recv
|
114
|
+
# @param cycles [Integer] Number of recv cycles. After each one
|
115
|
+
# object status is checked in OpenNebula.
|
116
|
+
# Use -1 (default) to wait forever.
|
117
|
+
def wait(state_str, timeout = 60, cycles = -1)
|
118
|
+
wait2(state_str, '', timeout, cycles)
|
119
|
+
end
|
120
|
+
|
121
|
+
def wait_event(ctx, event, timeout)
|
122
|
+
subscriber = ctx.socket(ZMQ::SUB)
|
123
|
+
|
124
|
+
# Create subscriber
|
125
|
+
key = ''
|
126
|
+
content = ''
|
127
|
+
|
128
|
+
subscriber.setsockopt(ZMQ::RCVTIMEO, timeout * 1000)
|
129
|
+
subscriber.setsockopt(ZMQ::SUBSCRIBE, event)
|
130
|
+
subscriber.connect('tcp://localhost:2101')
|
131
|
+
|
132
|
+
rc = subscriber.recv_string(key)
|
133
|
+
rc = subscriber.recv_string(content) if rc != -1
|
134
|
+
|
135
|
+
return if ZMQ::Util.errno == ZMQ::EAGAIN || rc == -1
|
136
|
+
|
137
|
+
content
|
138
|
+
ensure
|
139
|
+
subscriber.setsockopt(ZMQ::UNSUBSCRIBE, event)
|
140
|
+
subscriber.close
|
141
|
+
end
|
142
|
+
|
143
|
+
def wait2(sstr1, sstr2, timeout = 60, cycles = -1)
|
144
|
+
wfun = WAIT[self.class]
|
145
|
+
|
146
|
+
# Start with a timeout of 2 seconds, to wait until the first
|
147
|
+
# info.
|
148
|
+
#
|
149
|
+
# The timeout is increased later, to avoid multiple info calls.
|
150
|
+
c_timeout = 2
|
151
|
+
recvs = 0
|
152
|
+
in_state = false
|
153
|
+
|
154
|
+
# Subscribe with timeout seconds
|
155
|
+
#
|
156
|
+
# Subscribe string:
|
157
|
+
#
|
158
|
+
# EVENT STATE element_name/state_str//self.ID
|
159
|
+
#
|
160
|
+
# - element_name: is the element name to find in the message
|
161
|
+
# - self.ID: returns element ID to find in the message
|
162
|
+
ctx = ZMQ::Context.new(1)
|
163
|
+
|
164
|
+
until in_state || (cycles != -1 && recvs >= cycles)
|
165
|
+
content = wait_event(ctx,
|
166
|
+
wfun[:event].call(self, sstr1, sstr2),
|
167
|
+
c_timeout)
|
168
|
+
|
169
|
+
if content && !content.empty?
|
170
|
+
in_state = wfun[:in_state_e].call(sstr1, sstr2, content)
|
171
|
+
|
172
|
+
break if in_state
|
173
|
+
end
|
174
|
+
|
175
|
+
c_timeout *= 10
|
176
|
+
c_timeout = timeout if c_timeout > timeout
|
177
|
+
|
178
|
+
rco = info
|
179
|
+
|
180
|
+
return false if OpenNebula.is_error?(rco)
|
181
|
+
|
182
|
+
in_state = wfun[:in_state].call(self, sstr1, sstr2)
|
183
|
+
|
184
|
+
recvs += 1
|
185
|
+
end
|
186
|
+
|
187
|
+
in_state
|
188
|
+
end
|
189
|
+
|
190
|
+
end
|
191
|
+
|
192
|
+
super
|
193
|
+
end
|
194
|
+
|
195
|
+
# Check if object has the method wait or not
|
196
|
+
#
|
197
|
+
# @param obj [Object or Class] Object to check class
|
198
|
+
def self.wait?(obj)
|
199
|
+
# Get obj class to find parents in wait class
|
200
|
+
# rubocop:disable Style/TernaryParentheses
|
201
|
+
(obj.is_a? Class) ? o_class = obj : o_class = obj.class
|
202
|
+
# rubocop:enable Style/TernaryParentheses
|
203
|
+
|
204
|
+
found = false
|
205
|
+
i_class = o_class
|
206
|
+
|
207
|
+
while i_class
|
208
|
+
if WAIT.keys.include?(i_class)
|
209
|
+
found = true
|
210
|
+
break
|
211
|
+
end
|
212
|
+
|
213
|
+
i_class = i_class.superclass
|
214
|
+
end
|
215
|
+
|
216
|
+
return if found
|
217
|
+
|
218
|
+
raise StandardError, "Cannot extend #{o_class} with WaitExt"
|
219
|
+
end
|
220
|
+
|
221
|
+
end
|
222
|
+
# rubocop:enable Style/ClassAndModuleChildren
|
data/lib/opennebula/x509_auth.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# -------------------------------------------------------------------------- #
|
2
|
-
# Copyright 2002-
|
2
|
+
# Copyright 2002-2021, OpenNebula Project, OpenNebula Systems #
|
3
3
|
# #
|
4
4
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
5
5
|
# not use this file except in compliance with the License. You may obtain #
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# -------------------------------------------------------------------------- #
|
2
|
-
# Copyright 2002-
|
2
|
+
# Copyright 2002-2021, OpenNebula Project, OpenNebula Systems #
|
3
3
|
# #
|
4
4
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
5
5
|
# not use this file except in compliance with the License. You may obtain #
|
data/lib/opennebula/xml_pool.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# -------------------------------------------------------------------------- #
|
2
|
-
# Copyright 2002-
|
2
|
+
# Copyright 2002-2021, OpenNebula Project, OpenNebula Systems #
|
3
3
|
# #
|
4
4
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
5
5
|
# not use this file except in compliance with the License. You may obtain #
|
data/lib/opennebula/xml_utils.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# -------------------------------------------------------------------------- #
|
2
|
-
# Copyright 2002-
|
2
|
+
# Copyright 2002-2021, OpenNebula Project, OpenNebula Systems #
|
3
3
|
# #
|
4
4
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
5
5
|
# not use this file except in compliance with the License. You may obtain #
|
data/lib/opennebula/zone.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# -------------------------------------------------------------------------- #
|
2
|
-
# Copyright 2002-
|
2
|
+
# Copyright 2002-2021, OpenNebula Project, OpenNebula Systems #
|
3
3
|
# #
|
4
4
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
5
5
|
# not use this file except in compliance with the License. You may obtain #
|
data/lib/opennebula/zone_pool.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# -------------------------------------------------------------------------- #
|
2
|
-
# Copyright 2002-
|
2
|
+
# Copyright 2002-2021, OpenNebula Project, OpenNebula Systems #
|
3
3
|
# #
|
4
4
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
5
5
|
# not use this file except in compliance with the License. You may obtain #
|
data/lib/opennebula.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# -------------------------------------------------------------------------- #
|
2
|
-
# Copyright 2002-
|
2
|
+
# Copyright 2002-2021, OpenNebula Project, OpenNebula Systems #
|
3
3
|
# #
|
4
4
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
5
5
|
# not use this file except in compliance with the License. You may obtain #
|
@@ -49,7 +49,9 @@ require 'opennebula/datastore_pool'
|
|
49
49
|
require 'opennebula/cluster'
|
50
50
|
require 'opennebula/cluster_pool'
|
51
51
|
require 'opennebula/document'
|
52
|
+
require 'opennebula/document_json'
|
52
53
|
require 'opennebula/document_pool'
|
54
|
+
require 'opennebula/document_pool_json'
|
53
55
|
require 'opennebula/zone'
|
54
56
|
require 'opennebula/zone_pool'
|
55
57
|
require 'opennebula/security_group'
|
@@ -70,9 +72,10 @@ require 'opennebula/vntemplate_pool'
|
|
70
72
|
require 'opennebula/hook'
|
71
73
|
require 'opennebula/hook_pool'
|
72
74
|
require 'opennebula/hook_log'
|
75
|
+
require 'opennebula/flow'
|
73
76
|
|
74
77
|
module OpenNebula
|
75
78
|
|
76
79
|
# OpenNebula version
|
77
|
-
VERSION = '5.
|
80
|
+
VERSION = '5.13.80'
|
78
81
|
end
|
data/lib/rest_client.rb
ADDED
@@ -0,0 +1,201 @@
|
|
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
|
+
require 'openssl'
|
17
|
+
require 'yaml'
|
18
|
+
require 'vsphere-automation-vcenter'
|
19
|
+
require 'vsphere-automation-cis'
|
20
|
+
|
21
|
+
module VCenterDriver
|
22
|
+
|
23
|
+
########################################################################
|
24
|
+
# Class RESTClient
|
25
|
+
########################################################################
|
26
|
+
class RESTClient
|
27
|
+
|
28
|
+
attr_accessor :configuration
|
29
|
+
|
30
|
+
def initialize(opts)
|
31
|
+
@opts = {
|
32
|
+
:insecure => true,
|
33
|
+
:associable_types => [
|
34
|
+
ClusterComputeResource,
|
35
|
+
DistributedVirtualSwitch,
|
36
|
+
VmwareDistributedVirtualSwitch,
|
37
|
+
LibraryItem,
|
38
|
+
ResourcePool,
|
39
|
+
Folder,
|
40
|
+
HostNetwork,
|
41
|
+
DistributedVirtualPortgroup,
|
42
|
+
VirtualApp,
|
43
|
+
StoragePod,
|
44
|
+
Datastore,
|
45
|
+
Network,
|
46
|
+
Datacenter,
|
47
|
+
Library,
|
48
|
+
HostSystem,
|
49
|
+
OpaqueNetwork,
|
50
|
+
VirtualMachine
|
51
|
+
],
|
52
|
+
:category_name => 'OpenNebula',
|
53
|
+
:category_description => 'OpenNebula Category',
|
54
|
+
:cardinality =>
|
55
|
+
VSphereAutomation::CIS::CisTaggingCategoryModelCardinality
|
56
|
+
.const_get(
|
57
|
+
'multiple'.upcase
|
58
|
+
)
|
59
|
+
}.merge(opts)
|
60
|
+
|
61
|
+
@configuration = VSphereAutomation::Configuration.new.tap do |c|
|
62
|
+
c.host = @opts[:hostname]
|
63
|
+
c.username = @opts[:username]
|
64
|
+
c.password = @opts[:password]
|
65
|
+
c.scheme = 'https'
|
66
|
+
c.verify_ssl = !@opts[:insecure]
|
67
|
+
c.verify_ssl_host = !@opts[:insecure]
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def self.new_from_host(host_id)
|
72
|
+
begin
|
73
|
+
client = OpenNebula::Client.new
|
74
|
+
host = OpenNebula::Host.new_with_id(host_id, client)
|
75
|
+
rc = host.info(true)
|
76
|
+
if OpenNebula.is_error?(rc)
|
77
|
+
raise "Could not get host info for ID: \
|
78
|
+
#{host_id} - #{rc.message}"
|
79
|
+
end
|
80
|
+
|
81
|
+
connection = {
|
82
|
+
:hostname => host['TEMPLATE/VCENTER_HOST'],
|
83
|
+
:username => host['TEMPLATE/VCENTER_USER'],
|
84
|
+
:password => host['TEMPLATE/VCENTER_PASSWORD']
|
85
|
+
}
|
86
|
+
|
87
|
+
new(connection)
|
88
|
+
rescue StandardError => e
|
89
|
+
raise e
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def get_or_create_tag(
|
94
|
+
api_client,
|
95
|
+
category_id,
|
96
|
+
tag_name,
|
97
|
+
tag_description
|
98
|
+
)
|
99
|
+
|
100
|
+
tag_api = VSphereAutomation::CIS::TaggingTagApi.new(api_client)
|
101
|
+
tag = tag_api.list.value.find do |id|
|
102
|
+
c = tag_api.get(id).value
|
103
|
+
break c if c.name == tag_name
|
104
|
+
end
|
105
|
+
|
106
|
+
if tag.nil?
|
107
|
+
create_spec =
|
108
|
+
VSphereAutomation::CIS::CisTaggingTagCreateSpec
|
109
|
+
.new(
|
110
|
+
name => tag_name,
|
111
|
+
description => tag_description,
|
112
|
+
category_id => category_id
|
113
|
+
)
|
114
|
+
create_model = VSphereAutomation::CIS::CisTaggingTagCreate.new(
|
115
|
+
create_spec => create_spec
|
116
|
+
)
|
117
|
+
|
118
|
+
api_instance =
|
119
|
+
VSphereAutomation::CIS::TaggingTagApi.new(api_client)
|
120
|
+
api_instance.create(create_model).value
|
121
|
+
else
|
122
|
+
tag.id
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
def get_or_create_category(api_client, category_name)
|
127
|
+
category_api =
|
128
|
+
VSphereAutomation::CIS::TaggingCategoryApi.new(api_client)
|
129
|
+
category = category_api.list.value.find do |id|
|
130
|
+
c = category_api.get(id).value
|
131
|
+
break c if c.name == category_name
|
132
|
+
end
|
133
|
+
if category.nil?
|
134
|
+
create_spec =
|
135
|
+
VSphereAutomation::CIS::CisTaggingCategoryCreateSpec
|
136
|
+
.new(
|
137
|
+
name => category_name,
|
138
|
+
description => @opts[:category_description],
|
139
|
+
associable_types => @opts[:associable_types],
|
140
|
+
cardinality => @opts[:cardinality]
|
141
|
+
)
|
142
|
+
create_model =
|
143
|
+
VSphereAutomation::CIS::CisTaggingCategoryCreate
|
144
|
+
.new(create_spec => create_spec)
|
145
|
+
|
146
|
+
category = category_api.create(create_model)
|
147
|
+
category.value
|
148
|
+
else
|
149
|
+
category.id
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
def sync_tags(vm)
|
154
|
+
api_client = VSphereAutomation::ApiClient.new(@configuration)
|
155
|
+
VSphereAutomation::CIS::SessionApi.new(api_client).create('')
|
156
|
+
|
157
|
+
association_api =
|
158
|
+
VSphereAutomation::CIS::TaggingTagAssociationApi
|
159
|
+
.new(api_client)
|
160
|
+
|
161
|
+
vm.vcenter_tags.each do |tag|
|
162
|
+
category_name = @opts[:category_name]
|
163
|
+
|
164
|
+
unless tag['CATEGORY_NAME'].nil?
|
165
|
+
category_name = tag['CATEGORY_NAME']
|
166
|
+
end
|
167
|
+
|
168
|
+
category_id = get_or_create_category(api_client, category_name)
|
169
|
+
|
170
|
+
tag_name = tag['NAME']
|
171
|
+
tag_description = tag['DESCRIPTION']
|
172
|
+
|
173
|
+
tag_id =
|
174
|
+
get_or_create_tag(
|
175
|
+
api_client,
|
176
|
+
category_id,
|
177
|
+
tag_name,
|
178
|
+
tag_description
|
179
|
+
)
|
180
|
+
|
181
|
+
request_body =
|
182
|
+
VSphereAutomation::CIS::CisTaggingTagAssociationAttach.new
|
183
|
+
|
184
|
+
object_id = VSphereAutomation::CIS::VapiStdDynamicID.new
|
185
|
+
object_id.id = vm['_ref']
|
186
|
+
object_id.type = 'VirtualMachine'
|
187
|
+
|
188
|
+
request_body.object_id = object_id
|
189
|
+
|
190
|
+
begin
|
191
|
+
association_api.attach(tag_id, request_body)
|
192
|
+
rescue VSphereAutomation::ApiError => e
|
193
|
+
puts "Exception when calling \
|
194
|
+
TaggingTagAssociationApi->attach: #{e}"
|
195
|
+
end
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
end
|
200
|
+
|
201
|
+
end
|
@@ -0,0 +1,180 @@
|
|
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
|
+
|
17
|
+
module OpenNebula
|
18
|
+
|
19
|
+
# Generic log function
|
20
|
+
def self.log_function(severity, message)
|
21
|
+
STDERR.puts "#{severity}: #{File.basename $0}: #{message}"
|
22
|
+
end
|
23
|
+
|
24
|
+
# Logs an info message
|
25
|
+
def self.log_info(message)
|
26
|
+
log_function("INFO", message)
|
27
|
+
end
|
28
|
+
|
29
|
+
# Logs an error message
|
30
|
+
def self.log_error(message)
|
31
|
+
log_function("ERROR", message)
|
32
|
+
end
|
33
|
+
|
34
|
+
# Logs a debug message
|
35
|
+
def self.log_debug(message)
|
36
|
+
log_function("DEBUG", message)
|
37
|
+
end
|
38
|
+
|
39
|
+
# Alias log to log_info in the singleton class
|
40
|
+
class << self
|
41
|
+
alias :log :log_info
|
42
|
+
end
|
43
|
+
|
44
|
+
# This function is used to pass error message to the mad
|
45
|
+
def self.error_message(message)
|
46
|
+
STDERR.puts format_error_message(message)
|
47
|
+
end
|
48
|
+
|
49
|
+
#This function formats an error message for OpenNebula
|
50
|
+
def self.format_error_message(message)
|
51
|
+
error_str = "ERROR MESSAGE --8<------\n"
|
52
|
+
error_str << message
|
53
|
+
error_str << "\nERROR MESSAGE ------>8--"
|
54
|
+
|
55
|
+
return error_str
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.is_disk?(arg)
|
59
|
+
arg.match("disk\.[0-9]+$")
|
60
|
+
end
|
61
|
+
|
62
|
+
# Gets the host from an argument
|
63
|
+
def self.arg_host(arg)
|
64
|
+
result = arg.match("^\([^:]*\):.*$")
|
65
|
+
|
66
|
+
return result[1] if result
|
67
|
+
end
|
68
|
+
|
69
|
+
def self.arg_path(arg)
|
70
|
+
result = arg.match('^[^:]*:(.*)$')
|
71
|
+
|
72
|
+
return result[1] if result
|
73
|
+
end
|
74
|
+
|
75
|
+
# Executes a command, if it fails returns error message and exits
|
76
|
+
# If a second parameter is present it is used as the error message when
|
77
|
+
# the command fails
|
78
|
+
def self.exec_and_log(command, message=nil, allowed_return_code=0)
|
79
|
+
output=`#{command} 2>&1 1>/dev/null`
|
80
|
+
code=$?.exitstatus
|
81
|
+
|
82
|
+
if code!=0 && code!=allowed_return_code
|
83
|
+
log_error "Command \"#{command}\" failed."
|
84
|
+
log_error output
|
85
|
+
if !message
|
86
|
+
error_message output
|
87
|
+
else
|
88
|
+
error_message message
|
89
|
+
end
|
90
|
+
exit code
|
91
|
+
end
|
92
|
+
log "Executed \"#{command}\"."
|
93
|
+
end
|
94
|
+
|
95
|
+
def self.send_to_monitor(msg_type, result, oid, data)
|
96
|
+
# Read monitord.conf
|
97
|
+
one_location = ENV['ONE_LOCATION']
|
98
|
+
|
99
|
+
if !one_location
|
100
|
+
file_dir = '/etc/one/'
|
101
|
+
else
|
102
|
+
file_dir = one_location + '/etc/'
|
103
|
+
end
|
104
|
+
|
105
|
+
file_name = 'monitord.conf'
|
106
|
+
|
107
|
+
begin
|
108
|
+
# Suppress augeas require warning message
|
109
|
+
$VERBOSE = nil
|
110
|
+
|
111
|
+
require 'augeas'
|
112
|
+
|
113
|
+
aug = Augeas.create(:no_modl_autoload => true,
|
114
|
+
:no_load => true,
|
115
|
+
:root => file_dir,
|
116
|
+
:loadpath => file_name)
|
117
|
+
|
118
|
+
aug.clear_transforms
|
119
|
+
aug.transform(:lens => 'Oned.lns', :incl => file_name)
|
120
|
+
aug.context = "/files/#{file_name}"
|
121
|
+
aug.load
|
122
|
+
|
123
|
+
mon_address = aug.get('NETWORK/MONITOR_ADDRESS')
|
124
|
+
mon_port = aug.get('NETWORK/PORT')
|
125
|
+
mon_key = aug.get('NETWORK/PUBKEY').tr('"', '')
|
126
|
+
|
127
|
+
mon_address = "127.0.0.1" if mon_address.include? "auto"
|
128
|
+
rescue LoadError
|
129
|
+
mon_address = "127.0.0.1"
|
130
|
+
mon_port = 4124
|
131
|
+
end
|
132
|
+
|
133
|
+
# Encrypt
|
134
|
+
if mon_key && !mon_key.empty?
|
135
|
+
block_size = mon_key.n.num_bytes - 11
|
136
|
+
|
137
|
+
edata = ''
|
138
|
+
index = 0
|
139
|
+
|
140
|
+
loop do
|
141
|
+
break if index >= data.length
|
142
|
+
|
143
|
+
edata << mon_key.public_encrypt(data[index, block_size])
|
144
|
+
|
145
|
+
index += block_size
|
146
|
+
end
|
147
|
+
|
148
|
+
data = edata
|
149
|
+
end
|
150
|
+
|
151
|
+
# Send data
|
152
|
+
begin
|
153
|
+
require 'base64'
|
154
|
+
require 'zlib'
|
155
|
+
require 'socket'
|
156
|
+
|
157
|
+
zdata = Zlib::Deflate.deflate(data, Zlib::BEST_COMPRESSION)
|
158
|
+
data64 = Base64.strict_encode64(zdata)
|
159
|
+
|
160
|
+
if (result == "SUCCESS" || result == "0")
|
161
|
+
result = "SUCCESS"
|
162
|
+
else
|
163
|
+
result = "FAILURE"
|
164
|
+
end
|
165
|
+
|
166
|
+
if Integer(oid) == -1
|
167
|
+
ts = 0
|
168
|
+
else
|
169
|
+
ts = Time.now.to_i
|
170
|
+
end
|
171
|
+
|
172
|
+
msg = "#{msg_type} #{result} #{oid} #{ts} #{data64}"
|
173
|
+
|
174
|
+
socket_udp = UDPSocket.new()
|
175
|
+
socket_udp.send(msg, 0, mon_address, mon_port)
|
176
|
+
rescue LoadError
|
177
|
+
STDERR.puts('Unable to send data to Monitor Daemon')
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|