mirror of
https://github.com/OpenNebula/one.git
synced 2025-01-07 17:17:41 +03:00
Signed-off-by: Carlos Herrera <cherrera@opennebula.io>
This commit is contained in:
parent
04f5345c41
commit
15ecc2b47a
@ -342,30 +342,6 @@ class DatacenterFolder
|
||||
return networks
|
||||
end
|
||||
|
||||
# Return network type of a given network:
|
||||
# "Port Group"
|
||||
# "Distributed Port Group"
|
||||
# "NSX-V"
|
||||
# "Opaque Network"
|
||||
# "Unknown Network"
|
||||
def identify_network_type(vc_network)
|
||||
case vc_network
|
||||
when RbVmomi::VIM::DistributedVirtualPortgroup
|
||||
if vc_network['name']
|
||||
.match(/^vxw-dvs-(.*)-virtualwire-(.*)-sid-(.*)/)
|
||||
VCenterDriver::Network::NETWORK_TYPE_NSXV
|
||||
else
|
||||
VCenterDriver::Network::NETWORK_TYPE_DPG
|
||||
end
|
||||
when RbVmomi::VIM::OpaqueNetwork
|
||||
VCenterDriver::Network::NETWORK_TYPE_NSXT
|
||||
when RbVmomi::VIM::Network
|
||||
VCenterDriver::Network::NETWORK_TYPE_PG
|
||||
else
|
||||
VCenterDriver::Network::NETWORK_TYPE_UNKNOWN
|
||||
end
|
||||
end
|
||||
|
||||
# Return ONE cluster ID
|
||||
def one_cluster_id(one_host)
|
||||
if !one_host || !one_host['CLUSTER_ID']
|
||||
@ -401,7 +377,7 @@ class DatacenterFolder
|
||||
if args[:filter]
|
||||
if ( one_host && one_host['TEMPLATE/NSX_PASSWORD'].nil?)
|
||||
# Only NSX-V and NSX-T can be excluded
|
||||
network_type = identify_network_type(vc_network)
|
||||
network_type = VCenterDriver::Network.get_network_type(vc_network)
|
||||
if network_type == VCenterDriver::Network::NETWORK_TYPE_NSXT ||\
|
||||
network_type == VCenterDriver::Network::NETWORK_TYPE_NSXV
|
||||
|
||||
@ -446,7 +422,7 @@ class DatacenterFolder
|
||||
opts = {}
|
||||
|
||||
# Add network type to network hash
|
||||
network_type = identify_network_type(vc_network)
|
||||
network_type = VCenterDriver::Network.get_network_type(vc_network)
|
||||
network[vc_network._ref][:network_type] = network_type
|
||||
|
||||
# Determine if the network must be excluded
|
||||
|
@ -151,6 +151,12 @@ class Network
|
||||
dc_ref = opts[:dc_ref] || nil
|
||||
template_id = opts[:template_id] || nil
|
||||
|
||||
nsx_id = opts[:nsx_id] || nil
|
||||
nsx_vni = opts[:nsx_vni] || nil
|
||||
nsx_tz_id = opts[:nsx_tz_id] || nil
|
||||
|
||||
vlanid = opts[:vlanid] || nil
|
||||
|
||||
bridge_name = network_name
|
||||
network_name = network_name.gsub("/","_")
|
||||
|
||||
@ -164,29 +170,50 @@ class Network
|
||||
one_tmp[:one_cluster_id] = cluster_id
|
||||
one_tmp[:ref] = network_ref
|
||||
|
||||
one_tmp[:one] = to_one(network_import_name, bridge_name, network_ref, network_type,
|
||||
vcenter_uuid, unmanaged, template_ref, dc_ref, template_id, sw_name)
|
||||
opts = {
|
||||
:network_import_name => network_import_name,
|
||||
:bridge_name => bridge_name,
|
||||
:network_ref => network_ref,
|
||||
:network_type => network_type,
|
||||
:vcenter_uuid => vcenter_uuid,
|
||||
:unmanaged => unmanaged,
|
||||
:template_ref => template_ref,
|
||||
:dc_ref => dc_ref,
|
||||
:template_id => template_id,
|
||||
:sw_name => sw_name,
|
||||
:nsx_id => nsx_id,
|
||||
:nsx_vni => nsx_vni,
|
||||
:nsx_tz_id => nsx_tz_id,
|
||||
:vlanid => vlanid,
|
||||
}
|
||||
|
||||
one_tmp[:one] = to_one(opts)
|
||||
return one_tmp
|
||||
end
|
||||
|
||||
def self.to_one(network_import_name, network_name, network_ref, network_type,
|
||||
vcenter_uuid, unmanaged, template_ref, dc_ref, template_id, sw_name)
|
||||
def self.to_one(opts)
|
||||
|
||||
template = "NAME=\"#{network_import_name}\"\n"\
|
||||
"BRIDGE=\"#{network_name}\"\n"\
|
||||
template = "NAME=\"#{opts[:network_import_name]}\"\n"\
|
||||
"BRIDGE=\"#{opts[:bridge_name]}\"\n"\
|
||||
"VN_MAD=\"vcenter\"\n"\
|
||||
"VCENTER_PORTGROUP_TYPE=\"#{network_type}\"\n"\
|
||||
"VCENTER_NET_REF=\"#{network_ref}\"\n"\
|
||||
"VCENTER_INSTANCE_ID=\"#{vcenter_uuid}\"\n"\
|
||||
"VCENTER_PORTGROUP_TYPE=\"#{opts[:network_type]}\"\n"\
|
||||
"VCENTER_NET_REF=\"#{opts[:network_ref]}\"\n"\
|
||||
"VCENTER_INSTANCE_ID=\"#{opts[:vcenter_uuid]}\"\n"\
|
||||
"VCENTER_IMPORTED=\"YES\"\n"
|
||||
|
||||
if unmanaged == "wild"
|
||||
template += "VCENTER_FROM_WILD=\"#{template_id}\"\n"
|
||||
if opts[:unmanaged] == "wild"
|
||||
template += "VCENTER_FROM_WILD=\"#{opts[:template_id]}\"\n"
|
||||
end
|
||||
|
||||
template += "VCENTER_TEMPLATE_REF=\"#{template_ref}\"\n" if template_ref
|
||||
template += "VCENTER_TEMPLATE_REF=\"#{opts[:template_ref]}\"\n" if opts[:template_ref]
|
||||
|
||||
template += "VCENTER_SWITCH_NAME=\"#{sw_name}\"\n" if sw_name
|
||||
template += "VCENTER_SWITCH_NAME=\"#{opts[:sw_name]}\"\n" if opts[:sw_name]
|
||||
|
||||
template += "NSX_ID=\"#{opts[:nsx_id]}\"\n" if opts[:nsx_id]
|
||||
template += "NSX_VNI=\"#{opts[:nsx_vni]}\"\n" if opts[:nsx_vni]
|
||||
template += "NSX_TZ_ID=\"#{opts[:nsx_tz_id]}\"\n" if opts[:nsx_tz_id]
|
||||
|
||||
template += "VCENTER_VLAN_ID=\"#{opts[:vlanid]}\"\n" if opts[:vlanid]
|
||||
|
||||
return template
|
||||
end
|
||||
@ -222,17 +249,20 @@ class Network
|
||||
end
|
||||
|
||||
def self.get_network_type(network)
|
||||
netString = network.class.to_s
|
||||
case netString
|
||||
when "DistributedVirtualPortgroup"
|
||||
return VCenterDriver::Network::NETWORK_TYPE_DPG
|
||||
when "OpaqueNetwork"
|
||||
return VCenterDriver::Network::NETWORK_TYPE_NSXT
|
||||
when "Network"
|
||||
return VCenterDriver::Network::NETWORK_TYPE_PG
|
||||
|
||||
else
|
||||
return "Network not defined"
|
||||
case network
|
||||
when RbVmomi::VIM::DistributedVirtualPortgroup
|
||||
if network['name']
|
||||
.match(/^vxw-dvs-(.*)-virtualwire-(.*)-sid-(.*)/)
|
||||
VCenterDriver::Network::NETWORK_TYPE_NSXV
|
||||
else
|
||||
VCenterDriver::Network::NETWORK_TYPE_DPG
|
||||
end
|
||||
when RbVmomi::VIM::OpaqueNetwork
|
||||
VCenterDriver::Network::NETWORK_TYPE_NSXT
|
||||
when RbVmomi::VIM::Network
|
||||
VCenterDriver::Network::NETWORK_TYPE_PG
|
||||
else
|
||||
VCenterDriver::Network::NETWORK_TYPE_UNKNOWN
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -453,7 +453,7 @@ class Template
|
||||
vswitch.join(" / ")
|
||||
end
|
||||
|
||||
def import_vcenter_nics(vc_uuid, npool, hpool, vcenter_instance_name,
|
||||
def import_vcenter_nics(vi_client, vc_uuid, npool, hpool, vcenter_instance_name,
|
||||
template_ref, vm_object, vm_id=nil, dc_name=nil)
|
||||
nic_info = ''
|
||||
error = ''
|
||||
@ -538,6 +538,9 @@ class Template
|
||||
unmanaged = "template"
|
||||
end
|
||||
|
||||
net = VCenterDriver::Network.new_from_ref(nic[:net_ref], vi_client)
|
||||
vid = VCenterDriver::Network.retrieve_vlanid(net.item) if net
|
||||
|
||||
case nic[:pg_type]
|
||||
# Distributed PortGroups
|
||||
when VCenterDriver::Network::NETWORK_TYPE_DPG
|
||||
@ -550,6 +553,22 @@ class Template
|
||||
# For NSX-V ( is the same as DistributedVirtualPortgroups )
|
||||
# there is networks and uplinks
|
||||
config[:uplink] = false
|
||||
|
||||
host_id = vi_client.instance_variable_get '@host_id'
|
||||
|
||||
begin
|
||||
nsx_client = NSXDriver::NSXClient.new_from_id(host_id)
|
||||
rescue
|
||||
nsx_client = nil
|
||||
end
|
||||
|
||||
if nsx_client != nil
|
||||
nsx_net = NSXDriver::VirtualWire.new_from_name(nsx_client, nic[:net_name])
|
||||
|
||||
config[:nsx_id] = nsx_net.ls_id
|
||||
config[:nsx_vni] = nsx_net.ls_vni
|
||||
config[:nsx_tz_id] = nsx_net.tz_id
|
||||
end
|
||||
# Standard PortGroups
|
||||
when VCenterDriver::Network::NETWORK_TYPE_PG
|
||||
# There is no uplinks for standard portgroups, so all Standard
|
||||
@ -563,6 +582,22 @@ class Template
|
||||
# There is no uplinks for NSX-T networks, so all NSX-T networks
|
||||
# are networks and no uplinks
|
||||
config[:uplink] = false
|
||||
|
||||
host_id = vi_client.instance_variable_get '@host_id'
|
||||
|
||||
begin
|
||||
nsx_client = NSXDriver::NSXClient.new_from_id(host_id)
|
||||
rescue
|
||||
nsx_client = nil
|
||||
end
|
||||
|
||||
if nsx_client != nil
|
||||
nsx_net = NSXDriver::OpaqueNetwork.new_from_name(nsx_client, nic[:net_name])
|
||||
|
||||
config[:nsx_id] = nsx_net.ls_id
|
||||
config[:nsx_vni] = nsx_net.ls_vni
|
||||
config[:nsx_tz_id] = nsx_net.tz_id
|
||||
end
|
||||
else
|
||||
raise "Unknown network type: #{nic[:pg_type]}"
|
||||
end
|
||||
@ -583,6 +618,21 @@ class Template
|
||||
:template_id=> vm_id
|
||||
}
|
||||
|
||||
if nic[:pg_type] == VCenterDriver::Network::NETWORK_TYPE_NSXV || nic[:pg_type] == VCenterDriver::Network::NETWORK_TYPE_NSXT
|
||||
import_opts[:nsx_id] = config[:nsx_id]
|
||||
import_opts[:nsx_vni] = config[:nsx_vni]
|
||||
import_opts[:nsx_tz_id] = config[:nsx_tz_id]
|
||||
end
|
||||
|
||||
if vid
|
||||
vlanid = VCenterDriver::Network.vlanid(vid)
|
||||
|
||||
# we have vlan id
|
||||
if /\A\d+\z/.match(vlanid)
|
||||
import_opts[:vlanid] = vlanid
|
||||
end
|
||||
end
|
||||
|
||||
# Prepare the Virtual Network template
|
||||
one_vnet = VCenterDriver::Network.to_one_template(import_opts)
|
||||
|
||||
@ -1319,7 +1369,8 @@ class VmImporter < VCenterDriver::VcImporter
|
||||
|
||||
template_moref = template_copy_ref ? template_copy_ref : selected[:vcenter_ref]
|
||||
|
||||
error, template_nics, ar_ids, allocated_nets = template.import_vcenter_nics(vc_uuid,
|
||||
error, template_nics, ar_ids, allocated_nets = template.import_vcenter_nics(@vi_client,
|
||||
vc_uuid,
|
||||
npool,
|
||||
hpool,
|
||||
vcenter,
|
||||
|
@ -65,7 +65,8 @@ module VCenterDriver
|
||||
|
||||
# Create images or get nics information for template
|
||||
error, template_nics, ar_ids = vc_vm
|
||||
.import_vcenter_nics(vc_uuid,
|
||||
.import_vcenter_nics(@vi_client,
|
||||
vc_uuid,
|
||||
npool,
|
||||
hpool,
|
||||
vc_name,
|
||||
|
Loading…
Reference in New Issue
Block a user