mirror of
https://github.com/OpenNebula/one.git
synced 2026-11-22 20:54:49 +09:00
Added code to treat inputs in the creation network form Puts errors on network creations in hook STDERR and in VCENTER_NET_ERROR attribute.
This commit is contained in:
1 parent
2202a7da3f
commit
2bfda02621
4 files changed
+42
-8
No files matched your search
@@ -204,14 +204,16 @@ def create_opaque_network(one_vnet, host_id)
|
||||
ls_name = one_vnet['NAME']
|
||||
ls_description = one_vnet['TEMPLATE/DESCRIPTION']
|
||||
tz_id = one_vnet['TEMPLATE/NSX_TZ_ID']
|
||||
replication_mode = one_vnet['TEMPLATE/NSX_REP_MODE']
|
||||
admin_state = one_vnet['TEMPLATE/NSX_ADMIN_STATUS']
|
||||
|
||||
nsx_client = NSXDriver::NSXClient.new_from_id(host_id)
|
||||
|
||||
opaque_network_spec = %(
|
||||
{
|
||||
"transport_zone_id": "#{tz_id}",
|
||||
"replication_mode": "MTEP",
|
||||
"admin_state": "UP",
|
||||
"replication_mode": "#{replication_mode}",
|
||||
"admin_state": "#{admin_state}",
|
||||
"display_name": "#{ls_name}",
|
||||
"description": "#{ls_description}"
|
||||
}
|
||||
@@ -225,6 +227,7 @@ def create_virtual_wire(one_vnet, host_id)
|
||||
ls_name = one_vnet['NAME']
|
||||
ls_description = one_vnet['TEMPLATE/DESCRIPTION']
|
||||
tz_id = one_vnet['TEMPLATE/NSX_TZ_ID']
|
||||
replication_mode = one_vnet['TEMPLATE/NSX_REP_MODE']
|
||||
|
||||
nsx_client = NSXDriver::NSXClient.new_from_id(host_id)
|
||||
|
||||
@@ -233,7 +236,7 @@ def create_virtual_wire(one_vnet, host_id)
|
||||
<name>#{ls_name}</name>\
|
||||
<description>#{ls_description}</description>\
|
||||
<tenantId>virtual wire tenant</tenantId>\
|
||||
<controlPlaneMode>UNICAST_MODE</controlPlaneMode>\
|
||||
<controlPlaneMode>#{replication_mode}</controlPlaneMode>\
|
||||
<guestVlanAllowed>false</guestVlanAllowed>\
|
||||
</virtualWireCreateSpec>"
|
||||
|
||||
@@ -283,8 +286,8 @@ end
|
||||
|
||||
# Constants
|
||||
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'
|
||||
ERROR_XPATH = '//PARAMETER[TYPE="OUT" and POSITION="3"]/VALUE'
|
||||
|
||||
# Changes due to new hook subsystem
|
||||
# https://github.com/OpenNebula/one/issues/3380
|
||||
|
||||
@@ -41,6 +41,9 @@ module NSXDriver
|
||||
require 'opennebula'
|
||||
require 'vcenter_driver'
|
||||
|
||||
# Exceptions
|
||||
class IncorrectResponseCodeError < StandardError; end
|
||||
|
||||
# Class NSXClient
|
||||
class NSXClient
|
||||
|
||||
@@ -126,6 +129,12 @@ module NSXDriver
|
||||
https.request(request)
|
||||
end
|
||||
return response.body if check_response(response, 201)
|
||||
|
||||
# If response is different as expected raise the message
|
||||
response_json = JSON.parse(response.body)
|
||||
nsx_error = "\nNSX error code: #{response_json['errorCode']}, " \
|
||||
"\nNSX error details: #{response_json['details']}"
|
||||
raise IncorrectResponseCodeError, nsx_error
|
||||
end
|
||||
|
||||
def get_json(url)
|
||||
@@ -160,6 +169,12 @@ module NSXDriver
|
||||
end
|
||||
return JSON.parse(response.body)['id'] \
|
||||
if check_response(response, 201)
|
||||
|
||||
# If response is different as expected raise the message
|
||||
response_json = JSON.parse(response.body)
|
||||
nsx_error = "\nNSX error code: #{response_json['errorCode']}, " \
|
||||
"\nNSX error details: #{response_json['details']}"
|
||||
raise IncorrectResponseCodeError, nsx_error
|
||||
end
|
||||
|
||||
def delete(url, header)
|
||||
|
||||
@@ -34,8 +34,16 @@ module NSXDriver
|
||||
else
|
||||
if tz_id
|
||||
if ls_data
|
||||
@ls_id = new_logical_switch(ls_data)
|
||||
raise 'Opaque Network not created in NSX' unless @ls_id
|
||||
begin
|
||||
@ls_id = new_logical_switch(ls_data)
|
||||
rescue IncorrectResponseCodeError => e
|
||||
raise 'Opaque Network not created in ' \
|
||||
"NSX Manager: #{e.message}"
|
||||
end
|
||||
unless @ls_id
|
||||
raise 'Opaque Network not created in NSX Manager: '\
|
||||
'generic error'
|
||||
end
|
||||
|
||||
# Construct URL of the created logical switch
|
||||
@url_ls = @base_url + SECTION_LS + @ls_id
|
||||
|
||||
@@ -40,8 +40,16 @@ module NSXDriver
|
||||
else
|
||||
if tz_id
|
||||
if ls_data
|
||||
@ls_id = new_logical_switch(ls_data, tz_id)
|
||||
raise 'Virtual Wire not created in NSX' unless @ls_id
|
||||
begin
|
||||
@ls_id = new_logical_switch(ls_data, tz_id)
|
||||
rescue IncorrectResponseCodeError => e
|
||||
raise 'VirtualWire not created in NSX Manager: ' \
|
||||
"#{e.message}"
|
||||
end
|
||||
unless @ls_id
|
||||
raise 'Virtual Wire not created in NSX Manager: ' \
|
||||
'generic error'
|
||||
end
|
||||
|
||||
# Construct URL of the created logical switch
|
||||
@url_ls = @base_url + SECTION_LS + @ls_id
|
||||
|
||||
Reference in new issue
Block a user