mirror of
https://github.com/OpenNebula/one.git
synced 2026-11-23 05:04:56 +09:00
* F #3440: Added basic support to Opaque Networks Support to: Import Opaque Networks Import Templates with Opaque Networks Import Wild VMs with Opaque Networks Attach/Detach Opaque Network nics Poweron/Poweroff.. Instances with Opaque Networks * F #3440: Fix typo on Standard Port Group Fix Port Group typo and remove pry-byebug
This commit is contained in:
1 parent
dd72b19817
commit
17b1b8628b
4 files changed
+144
-38
No files matched your search
@@ -332,14 +332,13 @@ class DatacenterFolder
|
||||
end
|
||||
|
||||
def get_unimported_networks(npool,vcenter_instance_name, hpool)
|
||||
|
||||
vcenter_uuid = get_vcenter_instance_uuid
|
||||
pc = @vi_client.vim.serviceContent.propertyCollector
|
||||
|
||||
#Get all port groups and distributed port groups in vcenter instance
|
||||
view = @vi_client.vim.serviceContent.viewManager.CreateContainerView({
|
||||
container: @vi_client.vim.rootFolder,
|
||||
type: ['Network','DistributedVirtualPortgroup'],
|
||||
type: ['Network','DistributedVirtualPortgroup','OpaqueNetwork'],
|
||||
recursive: true
|
||||
})
|
||||
|
||||
@@ -358,7 +357,8 @@ class DatacenterFolder
|
||||
],
|
||||
:propSet => [
|
||||
{ :type => 'Network', :pathSet => ['name'] },
|
||||
{ :type => 'DistributedVirtualPortgroup', :pathSet => ['name'] }
|
||||
{ :type => 'DistributedVirtualPortgroup', :pathSet => ['name'] },
|
||||
{ :type => 'OpaqueNetwork', :pathSet => ['name'] }
|
||||
]
|
||||
)
|
||||
result = pc.RetrieveProperties(:specSet => [filterSpec])
|
||||
@@ -372,8 +372,19 @@ class DatacenterFolder
|
||||
npool)
|
||||
|
||||
next if exist
|
||||
networks[r.obj._ref] = r.to_hash if r.obj.is_a?(RbVmomi::VIM::DistributedVirtualPortgroup) || r.obj.is_a?(RbVmomi::VIM::Network)
|
||||
networks[r.obj._ref][:network_type] = r.obj.is_a?(RbVmomi::VIM::DistributedVirtualPortgroup) ? "Distributed Port Group" : "Port Group"
|
||||
|
||||
networks[r.obj._ref] = r.to_hash if r.obj.is_a?(RbVmomi::VIM::DistributedVirtualPortgroup) || r.obj.is_a?(RbVmomi::VIM::Network) || r.obj.is_a?(RbVmomi::VIM::OpaqueNetwork)
|
||||
|
||||
if r.obj.is_a?(RbVmomi::VIM::DistributedVirtualPortgroup)
|
||||
networks[r.obj._ref][:network_type] = "Distributed Port Group"
|
||||
elsif r.obj.is_a?(RbVmomi::VIM::Network)
|
||||
networks[r.obj._ref][:network_type] = "Port Group"
|
||||
elsif r.obj.is_a?(RbVmomi::VIM::OpaqueNetwork)
|
||||
networks[r.obj._ref][:network_type] = "Opaque Network"
|
||||
else
|
||||
networks[r.obj._ref][:network_type] = "Unknown Network"
|
||||
end
|
||||
# networks[r.obj._ref][:network_type] = r.obj.is_a?(RbVmomi::VIM::DistributedVirtualPortgroup) ? "Distributed Port Group" : "Port Group"
|
||||
networks[r.obj._ref][:uplink] = false
|
||||
networks[r.obj._ref][:processed] = false
|
||||
|
||||
|
||||
@@ -205,11 +205,17 @@ class Network
|
||||
one_vn
|
||||
end
|
||||
|
||||
def self.get_network_type(device)
|
||||
if device.backing.is_a? RbVmomi::VIM::VirtualEthernetCardDistributedVirtualPortBackingInfo
|
||||
def self.get_network_type(network)
|
||||
netString = network.class.to_s
|
||||
case netString
|
||||
when "DistributedVirtualPortgroup"
|
||||
return "Distributed Port Group"
|
||||
else
|
||||
when "Network"
|
||||
return "Port Group"
|
||||
when "OpaqueNetwork"
|
||||
return "Opaque Network"
|
||||
else
|
||||
return "Network not defined"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -268,6 +274,8 @@ class DistributedPortGroup < Network
|
||||
|
||||
def clusters
|
||||
net_clusters = {}
|
||||
# should have to work
|
||||
# host_members =@item['host']
|
||||
host_members = self['config.distributedVirtualSwitch.summary.hostMember']
|
||||
host_members.each do |h|
|
||||
if !net_clusters.key?(h.parent._ref.to_s)
|
||||
@@ -282,6 +290,32 @@ class DistributedPortGroup < Network
|
||||
end
|
||||
end # class DistributedPortGroup
|
||||
|
||||
class OpaqueNetwork < Network
|
||||
|
||||
def initialize(item, vi_client=nil)
|
||||
|
||||
check_item(item, RbVmomi::VIM::OpaqueNetwork)
|
||||
|
||||
@vi_client = vi_client
|
||||
@item = item
|
||||
end
|
||||
|
||||
def clusters
|
||||
net_clusters = {}
|
||||
host_members =@item['host']
|
||||
host_members.each do |h|
|
||||
if !net_clusters.key?(h.parent._ref.to_s)
|
||||
net_clusters[h.parent._ref.to_s] = h.parent.name.to_s
|
||||
end
|
||||
end
|
||||
net_clusters
|
||||
end
|
||||
|
||||
def network_type
|
||||
"Opaque Network"
|
||||
end
|
||||
end # class OpaqueNetwork
|
||||
|
||||
class DistributedVirtualSwitch < Network
|
||||
|
||||
def initialize(item, vi_client=nil)
|
||||
|
||||
@@ -51,6 +51,7 @@ module VCenterDriver
|
||||
|
||||
DNET_CARD = RbVmomi::VIM::VirtualEthernetCardDistributedVirtualPortBackingInfo
|
||||
NET_CARD = RbVmomi::VIM::VirtualEthernetCardNetworkBackingInfo
|
||||
OPAQUE_CARD = RbVmomi::VIM::VirtualEthernetCardOpaqueNetworkBackingInfo
|
||||
|
||||
VM_SHUTDOWN_TIMEOUT = 600 #10 minutes til poweroff hard
|
||||
|
||||
@@ -718,8 +719,17 @@ module VCenterDriver
|
||||
|
||||
if backing.class == NET_CARD
|
||||
key = backing.network._ref
|
||||
else
|
||||
elsif backing.class == DNET_CARD
|
||||
key = backing.port.portgroupKey
|
||||
elsif backing.class == OPAQUE_CARD
|
||||
# Select only Opaque Networks
|
||||
opaqueNetworks = @item.network.select{|net|
|
||||
RbVmomi::VIM::OpaqueNetwork == net.class}
|
||||
opaqueNetwork = opaqueNetworks.find{|opn|
|
||||
backing.opaqueNetworkId == opn.summary.opaqueNetworkId}
|
||||
key = opaqueNetwork._ref
|
||||
else
|
||||
raise "Unsupported network card type: #{backing.class}"
|
||||
end
|
||||
|
||||
@nics["#{key}#{d.key}"] = Nic.vc_nic(d)
|
||||
@@ -866,7 +876,7 @@ module VCenterDriver
|
||||
|
||||
begin
|
||||
if !unmanaged_nics.empty?
|
||||
nics = get_vcenter_nics
|
||||
nics = get_vcenter_nics
|
||||
|
||||
select_net =->(ref){
|
||||
device = nil
|
||||
@@ -874,8 +884,17 @@ module VCenterDriver
|
||||
type = nic.backing.class
|
||||
if type == NET_CARD
|
||||
nref = nic.backing.network._ref
|
||||
else
|
||||
elsif type == DNET_CARD
|
||||
nref = nic.backing.port.portgroupKey
|
||||
elsif type == OPAQUE_CARD
|
||||
# Select only Opaque Networks
|
||||
opaqueNetworks = @item.network.select{|net|
|
||||
RbVmomi::VIM::OpaqueNetwork == net.class}
|
||||
opaqueNetwork = opaqueNetworks.find{|opn|
|
||||
nic.backing.opaqueNetworkId == opn.summary.opaqueNetworkId}
|
||||
nref = opaqueNetwork._ref
|
||||
else
|
||||
raise "Unsupported network card type: #{nic.backing.class}"
|
||||
end
|
||||
|
||||
next unless nref == ref
|
||||
@@ -1237,7 +1256,7 @@ module VCenterDriver
|
||||
backing = RbVmomi::VIM.VirtualEthernetCardNetworkBackingInfo(
|
||||
:deviceName => pg_name,
|
||||
:network => network)
|
||||
else
|
||||
elsif network.class == RbVmomi::VIM::DistributedVirtualPortgroup
|
||||
port = RbVmomi::VIM::DistributedVirtualSwitchPortConnection(
|
||||
:switchUuid =>
|
||||
network.config.distributedVirtualSwitch.uuid,
|
||||
@@ -1245,6 +1264,12 @@ module VCenterDriver
|
||||
backing =
|
||||
RbVmomi::VIM.VirtualEthernetCardDistributedVirtualPortBackingInfo(
|
||||
:port => port)
|
||||
elsif network.class == RbVmomi::VIM::OpaqueNetwork
|
||||
backing = RbVmomi::VIM.VirtualEthernetCardOpaqueNetworkBackingInfo(
|
||||
:opaqueNetworkId => network.summary.opaqueNetworkId,
|
||||
:opaqueNetworkType => "nsx.LogicalSwitch")
|
||||
else
|
||||
raise "Unknown network class"
|
||||
end
|
||||
|
||||
# grab the last unitNumber to ensure the nic to be added at the end
|
||||
|
||||
@@ -445,7 +445,7 @@ class Template
|
||||
ccr_ref = self["runtime.host.parent._ref"]
|
||||
ccr_name = self["runtime.host.parent.name"]
|
||||
|
||||
#Get disks and info required
|
||||
#Get nics and info required
|
||||
vc_nics = get_vcenter_nics_hash
|
||||
|
||||
# Track allocated networks for rollback
|
||||
@@ -665,38 +665,73 @@ class Template
|
||||
nics
|
||||
end
|
||||
|
||||
def retrieve_from_device(device)
|
||||
res = {}
|
||||
|
||||
# Lets find out if it is a standard or distributed network
|
||||
# If distributed, it needs to be instantiated from the ref
|
||||
vim_eth_dist_class =
|
||||
RbVmomi::VIM::VirtualEthernetCardDistributedVirtualPortBackingInfo
|
||||
|
||||
if device.backing.is_a? vim_eth_dist_class
|
||||
if device.backing.port.portKey &&
|
||||
device.backing.port.portKey.match(/^[a-z]+-\d+$/)
|
||||
ref = device.backing.port.portKey
|
||||
elsif device.backing.port.portgroupKey &&
|
||||
device.backing.port.portgroupKey.match(/^[a-z]+-\d+$/)
|
||||
ref = device.backing.port.portgroupKey
|
||||
def identify_network(identifier, network)
|
||||
if network.class == RbVmomi::VIM::DistributedVirtualPortgroup
|
||||
if identifier == network.key
|
||||
return network
|
||||
else
|
||||
raise "Cannot get hold of Network for device #{device}"
|
||||
return nil
|
||||
end
|
||||
|
||||
network = RbVmomi::VIM::Network.new(@vi_client.vim, ref)
|
||||
else
|
||||
network = device.backing.network
|
||||
end
|
||||
|
||||
res[:refs] = network.host.map do |h|
|
||||
if network.class == RbVmomi::VIM::Network
|
||||
if identifier == network
|
||||
return network
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
|
||||
if network.class == RbVmomi::VIM::OpaqueNetwork
|
||||
if identifier == network.summary.opaqueNetworkId
|
||||
return network
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def retrieve_from_device(device)
|
||||
deviceNetwork = nil
|
||||
deviceNetworkId = nil
|
||||
# First search network corresponding this device
|
||||
# Distributed Networks and NSX-V Networks
|
||||
if device.backing[:port] != nil
|
||||
deviceNetworkId = device.backing.port.portgroupKey
|
||||
# Standard Networks
|
||||
elsif device.backing[:network] != nil
|
||||
deviceNetworkId = device.backing[:network]
|
||||
# NSX-T Opaque Networks
|
||||
elsif device.backing[:opaqueNetworkId] != nil
|
||||
deviceNetworkId = device.backing[:opaqueNetworkId]
|
||||
end
|
||||
|
||||
# Check if networkId exists
|
||||
if deviceNetworkId == nil
|
||||
raise "Invalid or not supported network #{device.backing}"
|
||||
end
|
||||
|
||||
# Matching between device and network objects
|
||||
@item.network.each do |net|
|
||||
deviceNetwork = identify_network(deviceNetworkId, net)
|
||||
break unless deviceNetwork.nil?
|
||||
end
|
||||
|
||||
# Check network matching
|
||||
if deviceNetwork.nil?
|
||||
raise "\"#{device.deviceInfo.label}\" not match any known network"
|
||||
end
|
||||
|
||||
res = {}
|
||||
|
||||
res[:refs] = deviceNetwork.host.map do |h|
|
||||
h.parent._ref if h.parent
|
||||
end
|
||||
|
||||
res[:net_name] = network.name
|
||||
res[:net_ref] = network._ref
|
||||
res[:pg_type] = VCenterDriver::Network.get_network_type(device)
|
||||
res[:network] = network
|
||||
res[:net_name] = deviceNetwork.name
|
||||
res[:net_ref] = deviceNetwork._ref
|
||||
res[:pg_type] = VCenterDriver::Network.get_network_type(deviceNetwork)
|
||||
res[:network] = deviceNetwork
|
||||
|
||||
res
|
||||
end
|
||||
@@ -719,6 +754,7 @@ class Template
|
||||
nics = []
|
||||
inets_raw = nil
|
||||
inets = {}
|
||||
|
||||
@item["config.hardware.device"].each do |device|
|
||||
next unless is_nic?(device)
|
||||
|
||||
|
||||
Reference in new issue
Block a user