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 #
@@ -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 #
@@ -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 #
@@ -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,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
@@ -0,0 +1,43 @@
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 Transport Zone
19
+ class TransportZone < NSXComponent
20
+
21
+ # ATTRIBUTES
22
+ attr_reader :tz_id
23
+
24
+ def self.new_child(nsx_client)
25
+ case nsx_client.nsx_type.upcase
26
+ when NSXConstants::NSXT
27
+ NSXTtz.new(nsx_client)
28
+ when NSXConstants::NSXV
29
+ NSXVtz.new(nsx_client)
30
+ else
31
+ error_msg = "Unknown NSX type: #{nsx_client.nsx_type}"
32
+ error = NSXError::UnknownObject.new(error_msg)
33
+ raise error
34
+ end
35
+ end
36
+
37
+ # METHODS
38
+ # Return the transport zones list
39
+ def tzs; end
40
+
41
+ end
42
+
43
+ end