summaryrefslogtreecommitdiff
path: root/datapath-windows/misc
diff options
context:
space:
mode:
authorAlin Serdean <aserdean@cloudbasesolutions.com>2014-11-11 18:45:32 +0000
committerBen Pfaff <blp@nicira.com>2014-11-12 08:50:31 -0800
commita22a9529fb86aa906a6a4e1f014826380f4e81d0 (patch)
tree32c5380d5bbbe3e9c370d482903f3f041ad03537 /datapath-windows/misc
parentf71a0f8308754b483708938901a48a0623ba242d (diff)
downloadopenvswitch-a22a9529fb86aa906a6a4e1f014826380f4e81d0.tar.gz
datapath-windows: Add functionality to return OVSPortName given a VM
This commit adds functionality to return the ElementName of all the VNIC of a given virtual machine name. The function returns all the allocated ports including the ones which the OVS port name was not set. The default OVS port name that is set is the following: "ElementName : Dynamic Ethernet Switch Port". Example of usage: Import-Module OVS.psm1 Get-VMNetworkAdapterWithOvsPort test_ubuntu_1 $a = Get-VMNetworkAdapterWithOvsPort test_2_1 $a | findstr ElementName Requested-by: Nithin Raju <nithin@vmware.com> Reported-at: https://github.com/openvswitch/ovs-issues/issues/51 Signed-off-by: Alin Gabriel Serdean <aserdean@cloudbasesolutions.com> Tested-by: Nithin Raju <nithin@vmware.com> Acked-by: Nithin Raju <nithin@vmware.com> Signed-off-by: Ben Pfaff <blp@nicira.com>
Diffstat (limited to 'datapath-windows/misc')
-rw-r--r--datapath-windows/misc/OVS.psm132
1 files changed, 30 insertions, 2 deletions
diff --git a/datapath-windows/misc/OVS.psm1 b/datapath-windows/misc/OVS.psm1
index 617f02550..d6b6b0047 100644
--- a/datapath-windows/misc/OVS.psm1
+++ b/datapath-windows/misc/OVS.psm1
@@ -40,7 +40,8 @@ function Set-VMNetworkAdapterOVSPort
$sd = gwmi -namespace $ns -class Msvm_EthernetPortAllocationSettingData -Filter "ElementName = '$OVSPortName'"
if($sd)
{
- if($sd.InstanceId.Contains($VMNetworkAdapter.Id)){
+ if($sd.InstanceId.Contains($VMNetworkAdapter.Id))
+ {
throw "The OVS port name '$OVSPortName' is already assigned to this port."
}
throw "Cannot assign the OVS port name '$OVSPortName' as it is already assigned to an other port."
@@ -107,13 +108,40 @@ function Get-VMByOVSPort
$ports = gwmi -Namespace $ns -Query "
Associators of {$vm} Where
ResultClass = Msvm_EthernetPortAllocationSettingData"
- if ($ports.ElementName -eq $OVSPortName){
+ if ($ports.ElementName -eq $OVSPortName)
+ {
return $vm
}
}
}
}
+#This function returns the Msvm_VirtualSystemSettingData given a VMName
+function Get-VMNetworkAdapterWithOVSPort
+{
+ [CmdletBinding()]
+ param
+ (
+ [parameter(Mandatory=$true)]
+ [ValidateLength(1, 1024)]
+ [string]$vmName
+ )
+ process
+ {
+ $ns = "root\virtualization\v2"
+ $vm = {}
+ $ports = {}
+
+ $vm = gwmi -namespace $ns -class Msvm_VirtualSystemSettingData -Filter "ElementName = '$VMName'"
+
+ $ports = gwmi -Namespace $ns -Query "
+ Associators of {$vm} Where
+ ResultClass = Msvm_EthernetPortAllocationSettingData"
+
+ return $ports
+ }
+}
+
function Check-WMIReturnValue($retVal)
{
if ($retVal.ReturnValue -ne 0)