opennebula 5.12.12 → 5.13.80.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. checksums.yaml +5 -5
  2. data/lib/DriverExecHelper.rb +43 -27
  3. data/lib/OpenNebulaDriver.rb +7 -3
  4. data/lib/VirtualMachineDriver.rb +8 -1
  5. data/lib/cloud/CloudClient.rb +1 -1
  6. data/lib/datacenter.rb +1258 -0
  7. data/lib/datastore.rb +1025 -0
  8. data/lib/distributed_firewall.rb +280 -0
  9. data/lib/file_helper.rb +370 -0
  10. data/lib/host.rb +1517 -0
  11. data/lib/logical_port.rb +50 -0
  12. data/lib/logical_switch.rb +77 -0
  13. data/lib/memoize.rb +74 -0
  14. data/lib/models/role.rb +1126 -0
  15. data/lib/models/service.rb +709 -0
  16. data/lib/models.rb +32 -0
  17. data/lib/network.rb +635 -0
  18. data/lib/nsx_client.rb +144 -0
  19. data/lib/nsx_component.rb +28 -0
  20. data/lib/nsx_constants.rb +149 -0
  21. data/lib/nsx_driver.rb +78 -0
  22. data/lib/nsx_error.rb +77 -0
  23. data/lib/nsx_rule.rb +193 -0
  24. data/lib/nsxt_client.rb +176 -0
  25. data/lib/nsxt_dfw.rb +196 -0
  26. data/lib/nsxt_logical_port.rb +94 -0
  27. data/lib/nsxt_rule.rb +188 -0
  28. data/lib/nsxt_tz.rb +38 -0
  29. data/lib/nsxv_client.rb +176 -0
  30. data/lib/nsxv_dfw.rb +202 -0
  31. data/lib/nsxv_logical_port.rb +107 -0
  32. data/lib/nsxv_rule.rb +172 -0
  33. data/lib/nsxv_tz.rb +41 -0
  34. data/lib/opaque_network.rb +134 -0
  35. data/lib/opennebula/document.rb +7 -28
  36. data/lib/opennebula/document_json.rb +41 -11
  37. data/lib/opennebula/error.rb +3 -0
  38. data/lib/opennebula/flow/grammar.rb +1195 -0
  39. data/lib/opennebula/flow/service_pool.rb +190 -0
  40. data/lib/opennebula/flow/service_template.rb +572 -0
  41. data/lib/opennebula/flow/service_template_ext.rb +84 -0
  42. data/lib/opennebula/flow/service_template_pool.rb +32 -0
  43. data/lib/opennebula/flow/validator.rb +499 -0
  44. data/lib/opennebula/flow.rb +23 -0
  45. data/lib/opennebula/hook.rb +4 -11
  46. data/lib/opennebula/image.rb +16 -13
  47. data/lib/opennebula/lockable_ext.rb +163 -0
  48. data/lib/opennebula/marketplaceapp.rb +8 -118
  49. data/lib/opennebula/marketplaceapp_ext.rb +522 -0
  50. data/lib/opennebula/oneflow_client.rb +3 -2
  51. data/lib/opennebula/pool.rb +3 -2
  52. data/lib/opennebula/template.rb +3 -12
  53. data/lib/opennebula/template_ext.rb +325 -0
  54. data/lib/opennebula/user.rb +25 -1
  55. data/lib/opennebula/virtual_machine.rb +24 -206
  56. data/lib/opennebula/virtual_machine_ext.rb +469 -0
  57. data/lib/opennebula/virtual_machine_pool.rb +0 -4
  58. data/lib/opennebula/virtual_network.rb +3 -9
  59. data/lib/opennebula/virtual_router.rb +3 -11
  60. data/lib/opennebula/vm_group.rb +3 -10
  61. data/lib/opennebula/vntemplate.rb +3 -12
  62. data/lib/opennebula/wait_ext.rb +222 -0
  63. data/lib/opennebula.rb +4 -1
  64. data/lib/rest_client.rb +201 -0
  65. data/lib/scripts_common.rb +180 -0
  66. data/lib/transport_zone.rb +43 -0
  67. data/lib/vcenter_driver.rb +8 -21
  68. data/lib/vcenter_importer.rb +616 -0
  69. data/lib/vi_client.rb +281 -0
  70. data/lib/vi_helper.rb +312 -0
  71. data/lib/virtual_machine.rb +3477 -0
  72. data/lib/virtual_wire.rb +158 -0
  73. data/lib/vm_device.rb +80 -0
  74. data/lib/vm_disk.rb +202 -0
  75. data/lib/vm_folder.rb +69 -0
  76. data/lib/vm_helper.rb +30 -0
  77. data/lib/vm_monitor.rb +303 -0
  78. data/lib/vm_nic.rb +70 -0
  79. data/lib/vm_template.rb +1961 -0
  80. data/lib/vmm_importer.rb +121 -0
  81. metadata +140 -26
@@ -0,0 +1,158 @@
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 NSXDriver
17
+
18
+ # Class VirtualWire NSX-V Network
19
+ class VirtualWire < LogicalSwitch
20
+
21
+ # CONSTRUCTOR
22
+ def initialize(nsx_client, ls_id = nil, tz_id = nil, ls_data = nil)
23
+ super(nsx_client)
24
+ if ls_id
25
+ initialize_with_id(ls_id)
26
+ else
27
+ if tz_id && ls_data
28
+ begin
29
+ @ls_id = new_logical_switch(ls_data, tz_id)
30
+ rescue NSXError::IncorrectResponseCodeError => e
31
+ raise 'VirtualWire not created in NSX Manager: ' \
32
+ "#{e.message}"
33
+ end
34
+ unless @ls_id
35
+ raise 'Virtual Wire not created in NSX Manager: ' \
36
+ 'generic error'
37
+ end
38
+
39
+ # Construct URL of the created logical switch
40
+ @url_ls = NSXConstants::NSXV_LS_SECTION + @ls_id
41
+ @ls_vni = ls_vni
42
+ @ls_name = ls_name
43
+ @tz_id = ls_tz
44
+ @tenant_id = 'virtual wire tenant'
45
+ @guest_vlan_allowed = false
46
+ end
47
+ end
48
+ end
49
+
50
+ # Creates a VirtualWire from its name
51
+ def self.new_from_name(nsx_client, ls_name)
52
+ virtualwire = new(nsx_client)
53
+ ls_id = virtualwire.ls_id_from_name(nsx_client, ls_name)
54
+ unless ls_id
55
+ error_msg = "VirtualWire with name: #{ls_name} not found"
56
+ error = NSXError::ObjectNotFound
57
+ .new(error_msg)
58
+ raise error
59
+ end
60
+
61
+ # initialize_with_id(@ls_id)
62
+ virtualwire.initialize_with_id(ls_id)
63
+ virtualwire
64
+ end
65
+
66
+ # Creates a VirtualWire from its id
67
+ def initialize_with_id(ls_id)
68
+ @ls_id = ls_id
69
+ # Construct URL of the created logical switch
70
+ @url_ls = NSXConstants::NSXV_LS_SECTION + \
71
+ @ls_id
72
+ # Raise an error if VirtualWire id doesn't exists
73
+ unless ls?
74
+ error_msg = "VirtualWire with id: #{ls_id} not found"
75
+ error = NSXError::ObjectNotFound
76
+ .new(error_msg)
77
+ raise error
78
+ end
79
+
80
+ @ls_vni = ls_vni
81
+ @ls_name = ls_name
82
+ @tz_id = ls_tz
83
+ @tenant_id = 'virtual wire tenant'
84
+ @guest_vlan_allowed = false
85
+ end
86
+
87
+ # Get the logical switch id from its name
88
+ def ls_id_from_name(nsx_client, name)
89
+ url = NSXConstants::NSXV_LS_SECTION
90
+ virtualwires = nsx_client
91
+ .get(url)
92
+ .xpath(NSXConstants::NSXV_LS_XPATH)
93
+ virtualwires.each do |virtualwire|
94
+ lsname_arr = name.split(/-sid-/)
95
+ lsname = lsname_arr[-1].split('-', 2)[-1]
96
+ lsid = lsname_arr[0].split(/vxw-dvs-\w.-/)[-1]
97
+ if virtualwire.xpath('name').text == lsname &&
98
+ virtualwire.xpath('objectId').text == lsid
99
+ return virtualwire.xpath('objectId').text
100
+ end
101
+ end
102
+ nil
103
+ end
104
+
105
+ # METHODS
106
+
107
+ # Check if logical switch exists
108
+ def ls?
109
+ @nsx_client.get(@url_ls) ? true : false
110
+ end
111
+
112
+ # Get logical switch's name
113
+ def ls_name
114
+ @nsx_client.get(@url_ls)
115
+ .xpath(NSXConstants::NSXV_LS_NAME_XPATH).text
116
+ end
117
+
118
+ # Get logical switch's vni
119
+ def ls_vni
120
+ @nsx_client.get(@url_ls)
121
+ .xpath(NSXConstants::NSXV_LS_VNI_XPATH).text
122
+ end
123
+
124
+ # Get the Transport Zone of the logical switch
125
+ def ls_tz
126
+ @nsx_client.get(@url_ls)
127
+ .xpath(NSXConstants::NSXV_TZ_XPATH).text
128
+ end
129
+
130
+ # Get the logical switch reference into vcenter
131
+ def ls_vcenter_ref
132
+ @nsx_client.get(@url_ls)
133
+ .xpath(NSXConstants::NSXV_LS_BACKING_XPATH)
134
+ .text
135
+ end
136
+
137
+ # Get the distributed virtual switch's ref associated to a LS
138
+ def ls_dvs_ref
139
+ @nsx_client.get(@url_ls)
140
+ .xpath(NSXConstants::NSXV_LS_OBJECTID_XPATH)
141
+ .text
142
+ end
143
+
144
+ # Create a new logical switch (NSX-V: virtualwire)
145
+ def new_logical_switch(ls_data, tz_id)
146
+ url = "#{NSXConstants::NSXV_TZ_SECTION}#{tz_id}" \
147
+ '/virtualwires'
148
+ @nsx_client.post(url, ls_data)
149
+ end
150
+
151
+ # Delete a logical switch
152
+ def delete_logical_switch
153
+ @nsx_client.delete(@url_ls)
154
+ end
155
+
156
+ end
157
+
158
+ end
data/lib/vm_device.rb ADDED
@@ -0,0 +1,80 @@
1
+ module VirtualMachineDevice
2
+
3
+ ############################################################################
4
+ # Device Classes
5
+ ############################################################################
6
+ # Device base class
7
+ #
8
+ # @param id [Integer] The OpenNebula resource id
9
+ # @param one_res [XMLElement] The OpenNebula representation of the object
10
+ # @param vc_res [vCenter_class_specific] vCenter object representation
11
+ ############################################################################
12
+ class Device
13
+
14
+ def initialize(id, one_res, vc_res)
15
+ @id = id
16
+ @one_res = one_res
17
+ @vc_res = vc_res
18
+ end
19
+
20
+ def id
21
+ raise_if_no_exists_in_one
22
+ @id
23
+ end
24
+
25
+ def one_item
26
+ raise_if_no_exists_in_one
27
+ @one_res
28
+ end
29
+
30
+ def vc_item
31
+ raise_if_no_exists_in_vcenter
32
+ @vc_res
33
+ end
34
+
35
+ def one?
36
+ !@one_res.nil?
37
+ end
38
+
39
+ def exists?
40
+ !@vc_res.nil?
41
+ end
42
+
43
+ # Fails if the device is not present in OpenNebula
44
+ def raise_if_no_exists_in_one
45
+ raise 'OpenNebula device does not exist at the moment' unless one?
46
+ end
47
+
48
+ # Fails if the device is not present in vCenter
49
+ def raise_if_no_exists_in_vcenter
50
+ raise 'vCenter device does not exist at the moment' unless exists?
51
+ end
52
+
53
+ def no_exists?
54
+ !exists?
55
+ end
56
+
57
+ def synced?
58
+ one? && exists?
59
+ end
60
+
61
+ def unsynced?
62
+ !synced?
63
+ end
64
+
65
+ def detached?
66
+ !one?
67
+ end
68
+
69
+ def managed?
70
+ raise_if_no_exists_in_one
71
+
72
+ return unless @one_res
73
+
74
+ !(@one_res['OPENNEBULA_MANAGED'] &&
75
+ @one_res['OPENNEBULA_MANAGED'].downcase == 'no')
76
+ end
77
+
78
+ end
79
+
80
+ end
data/lib/vm_disk.rb ADDED
@@ -0,0 +1,202 @@
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
+ # Disk class
19
+ class Disk < Device
20
+
21
+ attr_reader :size
22
+
23
+ # Create the OpenNebula disk representation
24
+ # Allow us to create the class without vCenter representation
25
+ # example: attached disks not synced with vCenter
26
+ def self.one_disk(id, one_res)
27
+ new(id, one_res, nil)
28
+ end
29
+
30
+ # Create the vCenter disk representation
31
+ # Allow us to create the class without OpenNebula representation
32
+ # example: detached disks that not exists in OpenNebula
33
+ def self.vc_disk(vc_res)
34
+ new(nil, nil, vc_res)
35
+ end
36
+
37
+ def storpod?
38
+ raise_if_no_exists_in_one
39
+ @one_res['VCENTER_DS_REF'].start_with?('group-')
40
+ end
41
+
42
+ def device
43
+ raise_if_no_exists_in_vcenter
44
+ @vc_res[:device]
45
+ end
46
+
47
+ def node
48
+ raise_if_no_exists_in_vcenter
49
+ @vc_res[:tag]
50
+ end
51
+
52
+ def path
53
+ raise_if_no_exists_in_vcenter
54
+ @vc_res[:path_wo_ds]
55
+ end
56
+
57
+ def ds
58
+ raise_if_no_exists_in_vcenter
59
+ @vc_res[:datastore]
60
+ end
61
+
62
+ def image_ds_ref
63
+ raise_if_no_exists_in_one
64
+ @one_res['VCENTER_DS_REF']
65
+ end
66
+
67
+ def key
68
+ raise_if_no_exists_in_vcenter
69
+ @vc_res[:key]
70
+ end
71
+
72
+ def prefix
73
+ raise_if_no_exists_in_vcenter
74
+ @vc_res[:prefix]
75
+ end
76
+
77
+ def type
78
+ raise_if_no_exists_in_vcenter
79
+ @vc_res[:type]
80
+ end
81
+
82
+ def file
83
+ path.split('/').last
84
+ end
85
+
86
+ def cd?
87
+ raise_if_no_exists_in_vcenter
88
+ @vc_res[:type] == 'CDROM'
89
+ end
90
+
91
+ def config(action)
92
+ raise_if_no_exists_in_vcenter
93
+
94
+ config = {}
95
+
96
+ case action
97
+ when :delete
98
+ if managed?
99
+ key = "opennebula.mdisk.#{@id}"
100
+ else
101
+ key = "opennebula.disk.#{@id}"
102
+ end
103
+
104
+ config[:key] = key
105
+ config[:value] = ''
106
+ when :resize
107
+ if new_size
108
+ d = device
109
+ d.capacityInKB = new_size
110
+ config[:device] = d
111
+ config[:operation] = :edit
112
+ end
113
+ when :attach
114
+ puts 'not supported'
115
+ end
116
+
117
+ config
118
+ end
119
+
120
+ def persistent?
121
+ raise_if_no_exists_in_one
122
+ @one_res['PERSISTENT'] == 'YES'
123
+ end
124
+
125
+ def volatile?
126
+ raise_if_no_exists_in_one
127
+ @one_res['TYPE'] && @one_res['TYPE'].downcase == 'fs'
128
+ end
129
+
130
+ def cloned?
131
+ raise_if_no_exists_in_one
132
+ @one_res['SOURCE'] != @vc_res[:path_wo_ds]
133
+ end
134
+
135
+ def connected?
136
+ raise_if_no_exists_in_vcenter
137
+ @vc_res[:device].connectable.connected
138
+ end
139
+
140
+ def boot_dev
141
+ if cd?
142
+ RbVmomi::VIM.VirtualMachineBootOptionsBootableCdromDevice()
143
+ else
144
+ RbVmomi::VIM.VirtualMachineBootOptionsBootableDiskDevice(
145
+ :deviceKey => device.key
146
+ )
147
+ end
148
+ end
149
+
150
+ def change_size(size)
151
+ size = size.to_i
152
+
153
+ if @one_res['ORIGINAL_SIZE'] &&
154
+ @one_res['ORIGINAL_SIZE'].to_i >= size
155
+ raise "'disk-resize' cannot decrease the disk's size"
156
+ end
157
+
158
+ @size = size
159
+ end
160
+
161
+ # Shrink not supported (nil). Size is in KB
162
+ def new_size
163
+ return @size * 1024 if @size
164
+
165
+ return unless @one_res['ORIGINAL_SIZE']
166
+
167
+ osize = @one_res['ORIGINAL_SIZE'].to_i
168
+ nsize = @one_res['SIZE'].to_i
169
+ nsize > osize ? nsize * 1024 : nil
170
+ end
171
+
172
+ def destroy
173
+ return if cd?
174
+
175
+ raise_if_no_exists_in_vcenter
176
+
177
+ ds = VCenterDriver::Datastore.new(self.ds)
178
+ img_path = path
179
+
180
+ begin
181
+ img_dir = File.dirname(img_path)
182
+ search_params = ds.get_search_params(
183
+ ds['name'],
184
+ img_dir,
185
+ File.basename(img_path)
186
+ )
187
+ search_task = ds['browser']
188
+ .SearchDatastoreSubFolders_Task(search_params)
189
+ search_task.wait_for_completion
190
+ ds.delete_virtual_disk(img_path)
191
+ ds.rm_directory(img_dir) if ds.dir_empty?(img_dir)
192
+ rescue StandardError => e
193
+ if !e.message.start_with?('FileNotFound')
194
+ # Ignore FileNotFound
195
+ raise e.message
196
+ end
197
+ end
198
+ end
199
+
200
+ end
201
+
202
+ end
data/lib/vm_folder.rb ADDED
@@ -0,0 +1,69 @@
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 VCenterDriver
18
+
19
+ # VirtualMachineFolder class
20
+ class VirtualMachineFolder
21
+
22
+ attr_accessor :item, :items
23
+
24
+ def initialize(item)
25
+ @item = item
26
+ check_item(@item, nil)
27
+ @items = {}
28
+ end
29
+
30
+ ########################################################################
31
+ # Builds a hash with Datastore-Ref / Datastore to be used as a cache
32
+ # @return [Hash] in the form
33
+ # { ds_ref [Symbol] => Datastore object }
34
+ ########################################################################
35
+
36
+ def fetch!
37
+ VIClient.get_entities(@item, 'VirtualMachine').each do |item|
38
+ item_name = item._ref
39
+ @items[item_name.to_sym] = VirtualMachine.new_with_item(item)
40
+ end
41
+ end
42
+
43
+ def fetch_templates!
44
+ VIClient.get_entities(@item, 'VirtualMachine').each do |item|
45
+ if item.config.template
46
+ item_name = item._ref
47
+ @items[item_name.to_sym] = Template.new(item)
48
+ end
49
+ end
50
+ end
51
+
52
+ ########################################################################
53
+ # Returns a Datastore. Uses the cache if available.
54
+ # @param ref [Symbol] the vcenter ref
55
+ # @return Datastore
56
+ ########################################################################
57
+
58
+ def get(ref)
59
+ if !@items[ref.to_sym]
60
+ rbvmomi_dc = RbVmomi::VIM::Datastore.new(@item._connection, ref)
61
+ @items[ref.to_sym] = Datastore.new(rbvmomi_dc)
62
+ end
63
+
64
+ @items[ref.to_sym]
65
+ end
66
+
67
+ end
68
+
69
+ end
data/lib/vm_helper.rb ADDED
@@ -0,0 +1,30 @@
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 VirtualMachineHelper
17
+
18
+ # This method raises an exception if the timeout is reached
19
+ # The exception needs to be handled in the VMM drivers and any
20
+ # process that uses this method
21
+ def wait_timeout(action, timeout = 300)
22
+ time_start = Time.now
23
+ until send(action)
24
+ sleep(1)
25
+ condition = (Time.now - time_start).to_i >= timeout
26
+ raise 'Reached deploy timeout' if condition
27
+ end
28
+ end
29
+
30
+ end