From 4523f5d8de64761a507b5a8f1f9b4d451a8be17a Mon Sep 17 00:00:00 2001 From: Rajesh Battala Date: Wed, 12 Mar 2014 07:45:50 +0530 Subject: [PATCH] CLOUDSTACK-6106 Agent side changes for VPC on Hyper-V --- .../HypervResourceController.cs | 14 +++++++--- .../HypervResource/IWmiCallsV2.cs | 1 + .../HypervResource/WmiCallsV2.cs | 26 ++++++++++++++++++- 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/HypervResourceController.cs b/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/HypervResourceController.cs index 2d447532d7f..40609e4e857 100644 --- a/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/HypervResourceController.cs +++ b/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/HypervResourceController.cs @@ -992,6 +992,7 @@ namespace HypervResource using (log4net.NDC.Push(Guid.NewGuid().ToString())) { logger.Info(CloudStackTypes.PlugNicCommand + cmd.ToString()); + object ansContent = new { result = true, @@ -1299,9 +1300,16 @@ namespace HypervResource String vmName = cmd.vmName; uint vlan = (uint)cmd.vlan; string macAddress = cmd.macAddress; - wmiCallsV2.ModifyVmVLan(vmName, vlan, macAddress); - - result = true; + uint pos = cmd.index; + if (macAddress != null) + { + wmiCallsV2.ModifyVmVLan(vmName, vlan, macAddress); + } + else if (pos > 1) + { + wmiCallsV2.ModifyVmVLan(vmName, vlan, pos); + } + result = true; object ansContent = new { diff --git a/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/IWmiCallsV2.cs b/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/IWmiCallsV2.cs index 601889646bd..8c682ad68b2 100644 --- a/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/IWmiCallsV2.cs +++ b/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/IWmiCallsV2.cs @@ -70,5 +70,6 @@ namespace HypervResource void SetState(ComputerSystem vm, ushort requiredState); Dictionary GetVmSync(String privateIpAddress); void ModifyVmVLan(string vmName, uint vlanid, string mac); + void ModifyVmVLan(string vmName, uint vlanid, uint pos); } } diff --git a/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/WmiCallsV2.cs b/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/WmiCallsV2.cs index 73156c5e3e7..d5cf7c91432 100644 --- a/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/WmiCallsV2.cs +++ b/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/WmiCallsV2.cs @@ -229,6 +229,7 @@ namespace HypervResource string errMsg = vmName; var diskDrives = vmInfo.disks; var bootArgs = vmInfo.bootArgs; + string defaultvlan = "4094"; // assert errMsg = vmName + ": missing disk information, array empty or missing, agent expects *at least* one disk for a VM"; @@ -391,6 +392,8 @@ namespace HypervResource string vlan = null; string isolationUri = nic.isolationUri; string broadcastUri = nic.broadcastUri; + string nicIp = nic.ip; + string nicNetmask = nic.netmask; if ( (broadcastUri != null ) || (isolationUri != null && isolationUri.StartsWith("vlan://"))) { if (broadcastUri != null && broadcastUri.StartsWith("storage")) @@ -415,6 +418,10 @@ namespace HypervResource throw ex; } } + if(nicIp.Equals("0.0.0.0") && nicNetmask.Equals("255.255.255.255") ) { + // this is the extra nic added to VR. + vlan = defaultvlan; + } if (nicCount == 2) { @@ -913,7 +920,6 @@ namespace HypervResource ResourceAllocationSettingData defaultDiskDriveSettings = defaultDiskDriveSettingsObjs.OfType().First(); return new ResourceAllocationSettingData((ManagementBaseObject)defaultDiskDriveSettings.LateBoundObject.Clone()); } - // Modify the systemvm nic's VLAN id public void ModifyVmVLan(string vmName, uint vlanid, String mac) @@ -945,6 +951,24 @@ namespace HypervResource vlanSettings.LateBoundObject.GetText(TextFormat.CimDtd20)}); } + // Modify the systemvm nic's VLAN id + public void ModifyVmVLan(string vmName, uint vlanid, uint pos) + { + ComputerSystem vm = GetComputerSystem(vmName); + SyntheticEthernetPortSettingData[] nicSettingsViaVm = GetEthernetPortSettings(vm); + // Obtain controller for Hyper-V virtualisation subsystem + VirtualSystemManagementService vmMgmtSvc = GetVirtualisationSystemManagementService(); + + EthernetPortAllocationSettingData[] ethernetConnections = GetEthernetConnections(vm); + EthernetSwitchPortVlanSettingData vlanSettings = GetVlanSettings(ethernetConnections[pos]); + + //Assign configuration to new NIC + vlanSettings.LateBoundObject["AccessVlanId"] = vlanid; + vlanSettings.LateBoundObject["OperationMode"] = 1; + ModifyFeatureVmResources(vmMgmtSvc, vm, new String[] { + vlanSettings.LateBoundObject.GetText(TextFormat.CimDtd20)}); + } + public void AttachIso(string displayName, string iso) { logger.DebugFormat("Got request to attach iso {0} to vm {1}", iso, displayName);