/// <summary> /// This method is responsible to add specified vlan entry into the local variable. /// </summary> protected override void DoODLVSEMCmdlet() { StringBuilder json = new StringBuilder("\"VMNetworkName\":\"" + this.VMNetworkName + "\""); json.Append("\"VMSubnetworkName\":\"" + this.VMSubnetworkName + "\""); json.Append("\"VlanIdList\":\"" + this.VlanIdList + "\""); json.Append("\"VtnHostName\":\"" + this.VtnCoHostName + "\""); ODLVSEMETW.EventWriteDoCmdlet(this.CmdletName, "Registering VlanId map information.", json.ToString()); TransactionManager txnMng = new TransactionManager(); txnMng.StartTransaction(); var ope = TransactionManager.Operation.None; VSEMVLANIDMapping vSEMVLANIDMapping = null; try { if (string.IsNullOrWhiteSpace(this.VMNetworkName)) { this.VMNetworkName = "*"; } if (string.IsNullOrWhiteSpace(this.VMSubnetworkName)) { this.VMSubnetworkName = "*"; } VLANIDMap vLANIDMap = new VLANIDMap(txnMng, this.VtnCoHostName, TransactionManager.OpenMode.WriteMode); vSEMVLANIDMapping = vLANIDMap.RegisterVlanId(this.VMNetworkName, this.VMSubnetworkName, this.VlanIdList); ODLVSEMETW.EventWriteReturnLibrary("VlanId map information is registered.", string.Empty); ope = TransactionManager.Operation.Commit; } catch (Exception ex) { Exception exception = VSEMODLExceptionUtil.ConvertExceptionToVSEMException(ex); ODLVSEMETW.EventWriteFailedCmdlet(this.CmdletName, exception.GetType() + " : VlanId map information registration is failed. \n" + ex.Message); ope = TransactionManager.Operation.Rollback; throw exception; } finally { txnMng.EndTransaction(ope); var JavaScriptSerializer = new JavaScriptSerializer(); JavaScriptSerializer.MaxJsonLength = int.MaxValue; string output = "\"vSEMVLANIDMapping\":" + JavaScriptSerializer.Serialize(vSEMVLANIDMapping); ODLVSEMETW.EventWriteEndCmdlet(this.CmdletName, output); } // Return the VSEMVLANIDMapping object this.WriteObject(vSEMVLANIDMapping); }
/// <summary> /// This method is responsible to retrieve the VlanId map information. /// </summary> protected override void DoODLVSEMCmdlet() { StringBuilder json = new StringBuilder("\"VMNetworkName\":\"" + this.VMNetworkName + "\""); json.Append("\"VMSubnetworkName\":\"" + this.VMSubnetworkName + "\""); json.Append("\"VtncoHostName\":\"" + this.VTNCoHostName + "\""); ODLVSEMETW.EventWriteDoCmdlet(this.CmdletName, "Retrieving VlanId map information.", json.ToString()); TransactionManager txnMng = new TransactionManager(); txnMng.StartTransaction(); var ope = TransactionManager.Operation.None; List <VSEMVLANIDMapping> vSEMVLANIDMapping = new List <VSEMVLANIDMapping>(); try { VLANIDMap vLANIDMap = new VLANIDMap(txnMng, this.VTNCoHostName, TransactionManager.OpenMode.ReadMode); vSEMVLANIDMapping.AddRange(vLANIDMap.SelectVlanIdWildCardMatch( this.VMNetworkName, this.VMSubnetworkName)); ODLVSEMETW.EventWriteReturnLibrary("VlanId map information is retrieved.", string.Empty); ope = TransactionManager.Operation.Commit; } catch (Exception ex) { Exception exception = VSEMODLExceptionUtil.ConvertExceptionToVSEMException(ex); ODLVSEMETW.EventWriteFailedCmdlet(this.CmdletName, exception.GetType() + " : " + ex.Message); ope = TransactionManager.Operation.Rollback; throw exception; } finally { txnMng.EndTransaction(ope); var JavaScriptSerializer = new JavaScriptSerializer(); JavaScriptSerializer.MaxJsonLength = int.MaxValue; string output = "\"vSEMVLANIDMapping\":" + JavaScriptSerializer.Serialize(vSEMVLANIDMapping); ODLVSEMETW.EventWriteEndCmdlet(this.CmdletName, output); } if (vSEMVLANIDMapping == null || vSEMVLANIDMapping.Count == 0) { this.WriteWarning("Vlan-mapping not found."); } else { this.WriteObject(vSEMVLANIDMapping); } }
/// <summary> /// This method is responsible to dump the VlanId map information. /// </summary> protected override void DoODLVSEMCmdlet() { StringBuilder json = new StringBuilder("\"VMNetworkName\":\"" + this.VMNetworkName + "\""); json.Append("\"VMSubnetworkName\":\"" + this.VMSubnetworkName + "\""); json.Append("\"MatchType\":\"" + this.MatchType + "\""); json.Append("\"VTNcoHostName\":\"" + this.VTNCoHostName + "\""); ODLVSEMETW.EventWriteDoCmdlet(this.CmdletName, "Removing VlanId map information.", json.ToString()); TransactionManager txnMng = new TransactionManager(); txnMng.StartTransaction(); var ope = TransactionManager.Operation.None; try { VLANIDMap vLANIDMap = new VLANIDMap(txnMng, this.VTNCoHostName, TransactionManager.OpenMode.WriteMode); vLANIDMap.DeregisterVlanId(this.VMNetworkName, this.VMSubnetworkName, this.MatchType); ODLVSEMETW.EventWriteReturnLibrary("VlanId map information is un-registered.", string.Empty); ope = TransactionManager.Operation.Commit; } catch (Exception ex) { Exception exception = VSEMODLExceptionUtil.ConvertExceptionToVSEMException(ex); ODLVSEMETW.EventWriteFailedCmdlet(this.CmdletName, exception.GetType() + " : " + ex.Message); ope = TransactionManager.Operation.Rollback; throw exception; } finally { txnMng.EndTransaction(ope); var JavaScriptSerializer = new JavaScriptSerializer(); JavaScriptSerializer.MaxJsonLength = int.MaxValue; ODLVSEMETW.EventWriteEndCmdlet(this.CmdletName, string.Empty); } }