1
0
mirror of https://github.com/OpenNebula/one.git synced 2024-12-23 17:33:56 +03:00

F #3380: Changes hook parameters (#3721)

Change the way of get parameters due to new hooks system
This commit is contained in:
Angel Luis Moya Gonzalez 2019-09-17 17:22:00 +02:00 committed by Tino Vázquez
parent c78e2f2006
commit d45bd83b7c
2 changed files with 40 additions and 13 deletions

View File

@ -41,11 +41,23 @@ require 'vcenter_driver'
require 'base64'
require 'nsx_driver'
network_id = ARGV[0]
# base64_temp = ARGV[1]
SUCCESS_XPATH = '//PARAMETER[TYPE="OUT" and POSITION="1"]/VALUE'
ERROR_XPATH = '//PARAMETER[TYPE="OUT" and POSITION="2"]/VALUE'
NETWORK_ID_XPATH = '//PARAMETER[TYPE="OUT" and POSITION="2"]/VALUE'
# template = OpenNebula::XMLElement.new
# template.initialize_xml(Base64.decode64(base64_temp), 'VNET')
# Changes due to new hook subsystem
# https://github.com/OpenNebula/one/issues/3380
arguments_raw = Base64.decode64(STDIN.read)
arguments_xml = Nokogiri::XML(arguments_raw)
success = arguments_xml.xpath(SUCCESS_XPATH).text
if success == 'false'
error = arguments_xml.xpath(ERROR_XPATH).text
STDERR.puts error
exit(-1)
end
response_id = arguments_xml.xpath(NETWORK_ID_XPATH).text
network_id = response_id.to_i
# waits for a vlan_id attribute to be generated
# only if automatic_vlan activated
@ -74,8 +86,9 @@ one_vnet = OpenNebula::VirtualNetwork
rc = one_vnet.info
if OpenNebula.is_error?(rc)
STDERR.puts rc.message
exit 1
exit(1)
end
one_vnet.lock(1)
esx_rollback = [] # Track hosts that require a rollback
managed = one_vnet['TEMPLATE/OPENNEBULA_MANAGED'] != 'NO'
@ -85,6 +98,7 @@ begin
# Step 0. Only execute for vcenter network driver && managed by one
if one_vnet['VN_MAD'] == 'vcenter' && managed && imported.nil?
wait_vlanid(one_vnet) if one_vnet['VLAN_ID_AUTOMATIC'] == '1'
# Step 1. Extract vnet settings
host_id = one_vnet['TEMPLATE/VCENTER_ONE_HOST_ID']
raise 'Missing VCENTER_ONE_HOST_ID' unless host_id
@ -107,7 +121,7 @@ begin
pg_type == 'Port Group' ? nports = 128 : nports = 8
end
# Step 2. Contact cluster and extract cluster's info
# Step 2. Contact vCenter cluster and extract cluster's info
vi_client = VCenterDriver::VIClient.new_from_host(host_id)
vc_uuid = vi_client.vim.serviceContent.about.instanceUuid
one_client = OpenNebula::Client.new
@ -205,8 +219,8 @@ begin
end
end
# Step 3. Loop through hosts in clusters
cluster['host'].each do |host|
# Step 3. Loop through hosts in clusters
esx_host = VCenterDriver::ESXHost.new_from_ref(host._ref, vi_client)
if pg_type == VCenterDriver::Network::NETWORK_TYPE_PG
@ -226,7 +240,7 @@ begin
'this kind of hange is not supported.'
end
# Pg does not exits
# Pg does not exist
if !pg
# Get standard switch if it exists
vs = esx_host.vss_exists(sw_name)

View File

@ -41,9 +41,25 @@ require 'vcenter_driver'
require 'base64'
require 'nsx_driver'
base64_temp = ARGV[1]
SUCCESS_XPATH = '//PARAMETER[TYPE="OUT" and POSITION="1"]/VALUE'
ERROR_XPATH = '//PARAMETER[TYPE="OUT" and POSITION="2"]/VALUE'
VNET_XPATH = '//EXTRA/VNET'
# Changes due to new hooks
arguments_raw = Base64.decode64(STDIN.read)
arguments_xml = Nokogiri::XML(arguments_raw)
success = arguments_xml.xpath(SUCCESS_XPATH).text
if success == 'false'
error = arguments_xml.xpath(ERROR_XPATH).text
STDERR.puts error
exit(-1)
end
vnet_xml = arguments_xml.xpath(VNET_XPATH).to_s
template = OpenNebula::XMLElement.new
template.initialize_xml(Base64.decode64(base64_temp), 'VNET')
template.initialize_xml(vnet_xml, 'VNET')
managed = template['TEMPLATE/OPENNEBULA_MANAGED'] != 'NO'
imported = template['TEMPLATE/VCENTER_IMPORTED']
error = template['TEMPLATE/VCENTER_NET_STATE'] == 'ERROR'
@ -72,9 +88,6 @@ begin
dc = cluster.get_dc
# NSX
# nsxmgr = one_host['TEMPLATE/NSX_MANAGER']
# nsx_user = one_host['TEMPLATE/NSX_USER']
# nsx_pass_enc = one_host['TEMPLATE/NSX_MANAGER']
ls_id = template['TEMPLATE/NSX_ID']
# NSX