opennebula 5.12.4 → 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 +4 -4
  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.rb +32 -0
  17. data/lib/models/role.rb +1126 -0
  18. data/lib/models/service.rb +709 -0
  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.rb +5 -2
  38. data/lib/opennebula/acl.rb +1 -1
  39. data/lib/opennebula/acl_pool.rb +1 -1
  40. data/lib/opennebula/client.rb +1 -1
  41. data/lib/opennebula/cluster.rb +1 -1
  42. data/lib/opennebula/cluster_pool.rb +1 -1
  43. data/lib/opennebula/datastore.rb +1 -1
  44. data/lib/opennebula/datastore_pool.rb +1 -1
  45. data/lib/opennebula/document.rb +8 -29
  46. data/lib/opennebula/document_json.rb +42 -12
  47. data/lib/opennebula/document_pool.rb +1 -1
  48. data/lib/opennebula/document_pool_json.rb +1 -1
  49. data/lib/opennebula/error.rb +4 -1
  50. data/lib/opennebula/flow.rb +23 -0
  51. data/lib/opennebula/flow/grammar.rb +1195 -0
  52. data/lib/opennebula/flow/service_pool.rb +190 -0
  53. data/lib/opennebula/flow/service_template.rb +572 -0
  54. data/lib/opennebula/flow/service_template_ext.rb +84 -0
  55. data/lib/opennebula/flow/service_template_pool.rb +32 -0
  56. data/lib/opennebula/flow/validator.rb +499 -0
  57. data/lib/opennebula/group.rb +1 -1
  58. data/lib/opennebula/group_pool.rb +1 -1
  59. data/lib/opennebula/hook.rb +5 -12
  60. data/lib/opennebula/hook_log.rb +1 -1
  61. data/lib/opennebula/hook_pool.rb +1 -1
  62. data/lib/opennebula/host.rb +1 -1
  63. data/lib/opennebula/host_pool.rb +1 -1
  64. data/lib/opennebula/image.rb +17 -14
  65. data/lib/opennebula/image_pool.rb +1 -1
  66. data/lib/opennebula/ldap_auth.rb +1 -1
  67. data/lib/opennebula/ldap_auth_spec.rb +1 -1
  68. data/lib/opennebula/lockable_ext.rb +163 -0
  69. data/lib/opennebula/marketplace.rb +1 -1
  70. data/lib/opennebula/marketplace_pool.rb +1 -1
  71. data/lib/opennebula/marketplaceapp.rb +9 -119
  72. data/lib/opennebula/marketplaceapp_ext.rb +522 -0
  73. data/lib/opennebula/marketplaceapp_pool.rb +1 -1
  74. data/lib/opennebula/oneflow_client.rb +4 -3
  75. data/lib/opennebula/pool.rb +17 -3
  76. data/lib/opennebula/pool_element.rb +1 -1
  77. data/lib/opennebula/security_group.rb +1 -1
  78. data/lib/opennebula/security_group_pool.rb +1 -1
  79. data/lib/opennebula/server_cipher_auth.rb +1 -1
  80. data/lib/opennebula/server_x509_auth.rb +1 -1
  81. data/lib/opennebula/ssh_auth.rb +1 -1
  82. data/lib/opennebula/system.rb +1 -1
  83. data/lib/opennebula/template.rb +4 -13
  84. data/lib/opennebula/template_ext.rb +325 -0
  85. data/lib/opennebula/template_pool.rb +1 -1
  86. data/lib/opennebula/user.rb +26 -2
  87. data/lib/opennebula/user_pool.rb +1 -1
  88. data/lib/opennebula/utils.rb +1 -1
  89. data/lib/opennebula/vdc.rb +1 -1
  90. data/lib/opennebula/vdc_pool.rb +1 -1
  91. data/lib/opennebula/virtual_machine.rb +25 -207
  92. data/lib/opennebula/virtual_machine_ext.rb +469 -0
  93. data/lib/opennebula/virtual_machine_pool.rb +28 -17
  94. data/lib/opennebula/virtual_network.rb +4 -10
  95. data/lib/opennebula/virtual_network_pool.rb +1 -1
  96. data/lib/opennebula/virtual_router.rb +4 -12
  97. data/lib/opennebula/virtual_router_pool.rb +1 -1
  98. data/lib/opennebula/vm_group.rb +4 -11
  99. data/lib/opennebula/vm_group_pool.rb +1 -1
  100. data/lib/opennebula/vntemplate.rb +4 -13
  101. data/lib/opennebula/vntemplate_pool.rb +1 -1
  102. data/lib/opennebula/wait_ext.rb +222 -0
  103. data/lib/opennebula/x509_auth.rb +1 -1
  104. data/lib/opennebula/xml_element.rb +1 -1
  105. data/lib/opennebula/xml_pool.rb +1 -1
  106. data/lib/opennebula/xml_utils.rb +1 -1
  107. data/lib/opennebula/zone.rb +1 -1
  108. data/lib/opennebula/zone_pool.rb +1 -1
  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 +13 -11
  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 +118 -5
@@ -1,5 +1,5 @@
1
1
  # -------------------------------------------------------------------------- #
2
- # Copyright 2002-2020, OpenNebula Project, OpenNebula Systems #
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 #
@@ -23,14 +23,14 @@ module OpenNebula
23
23
  # Constants and Class attribute accessors
24
24
  #######################################################################
25
25
 
26
-
27
26
  VM_POOL_METHODS = {
28
- :info => "vmpool.info",
29
- :info_extended => "vmpool.infoextended",
30
- :monitoring => "vmpool.monitoring",
31
- :accounting => "vmpool.accounting",
32
- :showback => "vmpool.showback",
33
- :calculate_showback => "vmpool.calculateshowback"
27
+ :info => 'vmpool.info',
28
+ :info_extended => 'vmpool.infoextended',
29
+ :info_set => 'vmpool.infoset',
30
+ :monitoring => 'vmpool.monitoring',
31
+ :accounting => 'vmpool.accounting',
32
+ :showback => 'vmpool.showback',
33
+ :calculate_showback => 'vmpool.calculateshowback'
34
34
  }
35
35
 
36
36
  # Constants for info queries (include/RequestManagerPoolInfoFilter.h)
@@ -41,7 +41,6 @@ module OpenNebula
41
41
  # Class constructor & Pool Methods
42
42
  #######################################################################
43
43
 
44
-
45
44
  # +client+ a Client object that represents a XML-RPC connection
46
45
  # +user_id+ is to refer to a Pool with VirtualMachines from that user
47
46
  def initialize(client, user_id=0)
@@ -102,21 +101,21 @@ module OpenNebula
102
101
  end
103
102
 
104
103
  # Define info methods shortcuts for different filters
105
- # info_all()
104
+ # info_all()
106
105
  # info_all!()
107
- # info_all_extended
106
+ # info_all_extended
108
107
  # info_all_extended!()
109
- # info_mine()
108
+ # info_mine()
110
109
  # info_mine!()
111
- # info_mine_extended
110
+ # info_mine_extended
112
111
  # info_mine_extended!()
113
- # info_group()
112
+ # info_group()
114
113
  # info_group!()
115
- # info_group_extended
114
+ # info_group_extended
116
115
  # info_group_extended!()
117
- # info_primary_group()
116
+ # info_primary_group()
118
117
  # info_primary_group!()
119
- # info_primary_group_extended
118
+ # info_primary_group_extended
120
119
  # info_primary_group_extended!()
121
120
  %w[mine all group primary_group].each do |ifilter|
122
121
  const_name = "OpenNebula::Pool::INFO_#{ifilter.upcase}"
@@ -160,6 +159,14 @@ module OpenNebula
160
159
  default_args[:query])
161
160
  end
162
161
 
162
+ # Retrieves the set of VMs especified in vm_ids
163
+ #
164
+ # @param [String] comma separated list of vm ids.
165
+ # @param [Boolean] if true extended body is retrieved.
166
+ #
167
+ def info_set(vm_ids, extended)
168
+ xmlrpc_info(VM_POOL_METHODS[:info_set], vm_ids, extended)
169
+ end
163
170
 
164
171
  # Retrieves the monitoring data for all the VMs in the pool
165
172
  #
@@ -195,6 +202,10 @@ module OpenNebula
195
202
  return super(VM_POOL_METHODS[:monitoring], xpaths, filter_flag)
196
203
  end
197
204
 
205
+ def monitoring_last(filter_flag=INFO_ALL)
206
+ return super(VM_POOL_METHODS[:monitoring], filter_flag, 0)
207
+ end
208
+
198
209
  # Retrieves the monitoring data for all the VMs in the pool, in XML
199
210
  #
200
211
  # @param [Integer] filter_flag Optional filter flag to retrieve all or
@@ -1,5 +1,5 @@
1
1
  # -------------------------------------------------------------------------- #
2
- # Copyright 2002-2020, OpenNebula Project, OpenNebula Systems #
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 #
@@ -14,7 +14,7 @@
14
14
  # limitations under the License. #
15
15
  #--------------------------------------------------------------------------- #
16
16
 
17
-
17
+ require 'opennebula/lockable_ext'
18
18
  require 'opennebula/pool_element'
19
19
  require 'ipaddr'
20
20
 
@@ -62,6 +62,8 @@ module OpenNebula
62
62
 
63
63
  # Class constructor
64
64
  def initialize(xml, client)
65
+ LockableExt.make_lockable(self, VN_METHODS)
66
+
65
67
  super(xml,client)
66
68
  end
67
69
 
@@ -338,14 +340,6 @@ module OpenNebula
338
340
  return array
339
341
  end
340
342
 
341
- def lock(level)
342
- return call(VN_METHODS[:lock], @pe_id, level)
343
- end
344
-
345
- def unlock()
346
- return call(VN_METHODS[:unlock], @pe_id)
347
- end
348
-
349
343
  private
350
344
  def set_publish(published)
351
345
  group_u = published ? 1 : 0
@@ -1,5 +1,5 @@
1
1
  # -------------------------------------------------------------------------- #
2
- # Copyright 2002-2020, OpenNebula Project, OpenNebula Systems #
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-2020, OpenNebula Project, OpenNebula Systems #
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 #
@@ -14,7 +14,7 @@
14
14
  # limitations under the License. #
15
15
  #--------------------------------------------------------------------------- #
16
16
 
17
-
17
+ require 'opennebula/lockable_ext'
18
18
  require 'opennebula/pool_element'
19
19
 
20
20
  module OpenNebula
@@ -57,6 +57,8 @@ module OpenNebula
57
57
 
58
58
  # Class constructor
59
59
  def initialize(xml, client)
60
+ LockableExt.make_lockable(self, VIRTUAL_ROUTER_METHODS)
61
+
60
62
  super(xml,client)
61
63
 
62
64
  @client = client
@@ -177,16 +179,6 @@ module OpenNebula
177
179
  return call(VIRTUAL_ROUTER_METHODS[:detachnic], @pe_id, nic_id)
178
180
  end
179
181
 
180
- # Lock a VRouter
181
- def lock(level)
182
- return call(VIRTUAL_ROUTER_METHODS[:lock], @pe_id, level)
183
- end
184
-
185
- # Unlock a VRouter
186
- def unlock()
187
- return call(VIRTUAL_ROUTER_METHODS[:unlock], @pe_id)
188
- end
189
-
190
182
  #######################################################################
191
183
  # Helpers to get VirtualRouter information
192
184
  #######################################################################
@@ -1,5 +1,5 @@
1
1
  # -------------------------------------------------------------------------- #
2
- # Copyright 2002-2020, OpenNebula Project, OpenNebula Systems #
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-2020, OpenNebula Project, OpenNebula Systems #
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 #
@@ -14,6 +14,7 @@
14
14
  # limitations under the License. #
15
15
  #--------------------------------------------------------------------------- #
16
16
 
17
+ require 'opennebula/lockable_ext'
17
18
  require 'opennebula/pool_element'
18
19
 
19
20
  module OpenNebula
@@ -48,6 +49,8 @@ module OpenNebula
48
49
 
49
50
  # Class constructor
50
51
  def initialize(xml, client)
52
+ LockableExt.make_lockable(self, VMGROUP_METHODS)
53
+
51
54
  super(xml,client)
52
55
 
53
56
  @client = client
@@ -131,16 +134,6 @@ module OpenNebula
131
134
  return call(VMGROUP_METHODS[:rename], @pe_id, name)
132
135
  end
133
136
 
134
- # Lock a VMGroup
135
- def lock(level)
136
- return call(VMGROUP_METHODS[:lock], @pe_id, level)
137
- end
138
-
139
- # Unlock a VMGroup
140
- def unlock()
141
- return call(VMGROUP_METHODS[:unlock], @pe_id)
142
- end
143
-
144
137
  #######################################################################
145
138
  # Helpers to get VMGroup information
146
139
  #######################################################################
@@ -1,5 +1,5 @@
1
1
  # -------------------------------------------------------------------------- #
2
- # Copyright 2002-2020, OpenNebula Project, OpenNebula Systems #
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-2020, OpenNebula Project, OpenNebula Systems #
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 #
@@ -14,7 +14,7 @@
14
14
  # limitations under the License. #
15
15
  #--------------------------------------------------------------------------- #
16
16
 
17
-
17
+ require 'opennebula/lockable_ext'
18
18
  require 'opennebula/pool_element'
19
19
 
20
20
  module OpenNebula
@@ -23,7 +23,6 @@ module OpenNebula
23
23
  # Constants and Class Methods
24
24
  #######################################################################
25
25
 
26
-
27
26
  TEMPLATE_METHODS = {
28
27
  :allocate => "vntemplate.allocate",
29
28
  :instantiate => "vntemplate.instantiate",
@@ -57,6 +56,8 @@ module OpenNebula
57
56
 
58
57
  # Class constructor
59
58
  def initialize(xml, client)
59
+ LockableExt.make_lockable(self, TEMPLATE_METHODS)
60
+
60
61
  super(xml,client)
61
62
 
62
63
  @client = client
@@ -231,16 +232,6 @@ module OpenNebula
231
232
  self['UID'].to_i
232
233
  end
233
234
 
234
- # Lock a VNTemplate
235
- def lock(level)
236
- return call(TEMPLATE_METHODS[:lock], @pe_id, level)
237
- end
238
-
239
- # Unlock a VNTemplate
240
- def unlock()
241
- return call(TEMPLATE_METHODS[:unlock], @pe_id)
242
- end
243
-
244
235
  def public?
245
236
  if self['PERMISSIONS/GROUP_U'] == "1" || self['PERMISSIONS/OTHER_U'] == "1"
246
237
  true
@@ -1,5 +1,5 @@
1
1
  # -------------------------------------------------------------------------- #
2
- # Copyright 2002-2020, OpenNebula Project, OpenNebula Systems #
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