/// <summary> /// This function is responsible for updating the IP address pool. /// </summary> protected override void DoODLVSEMCmdlet() { var JavaScriptSerializer = new JavaScriptSerializer(); JavaScriptSerializer.MaxJsonLength = int.MaxValue; StringBuilder json = new StringBuilder(" \"NetworkGatewayInfo\":" + JavaScriptSerializer.Serialize(this.NetworkGatewayInfo)); json.Append("\"Name\":\"" + this.Name + "\""); json.Append("\"Description\":\"" + this.Description + "\""); json.Append("\"IPAddressSubnet\":\"" + this.IPAddressSubnet + "\""); json.Append("\"AddressRangeStart\":\"" + this.AddressRangeStart + "\""); json.Append("\"AddressRangeEnd\":\"" + this.AddressRangeEnd + "\""); json.Append("\"IPAddressPoolId\":\"" + this.IPAddressPoolId + "\""); ODLVSEMETW.EventWriteDoCmdlet(MethodBase.GetCurrentMethod().Name, "Updating IP Address Pool.", string.Empty); TransactionManager txnMng = new TransactionManager(); txnMng.StartTransaction(); var ope = TransactionManager.Operation.None; VSEMIPAddressPoolManagement vSEMIPAddressPoolManagement = null; try { string connectionString = this.conn.ConnectionString.Split(',').FirstOrDefault(); vSEMIPAddressPoolManagement = new VSEMIPAddressPoolManagement(connectionString, this.conn.Credential); IPAddressPool pool = vSEMIPAddressPoolManagement.UpdateIpAddressPool(txnMng, this.Name, this.Description, this.IPAddressSubnet, this.AddressRangeStart, this.AddressRangeEnd, this.NetworkGatewayInfo, this.conn, this.IPAddressPoolId); ODLVSEMETW.EventWriteReturnLibrary(string.Format(CultureInfo.CurrentCulture, "VSEM IP address pool with ID: {0} is updated", this.IPAddressPoolId.ToString("B")), string.Empty); string output = "\"pool\":" + JavaScriptSerializer.Serialize(pool); ODLVSEMETW.EventWriteEndCmdlet(this.CmdletName, output); this.WriteObject(pool); ope = TransactionManager.Operation.Commit; } catch (Exception ex) { Exception exception = VSEMODLExceptionUtil.ConvertExceptionToVSEMException(ex); ODLVSEMETW.EventWriteFailedCmdlet(this.CmdletName, exception.GetType() + " : " + ex.Message); ope = TransactionManager.Operation.Rollback; ODLVSEMETW.EventWriteEndCmdlet(this.CmdletName, string.Empty); throw exception; } finally { txnMng.EndTransaction(ope); } }
/// <summary> /// This method is responsible to remove static Ip address pool. /// </summary> protected override void DoODLVSEMCmdlet() { var JavaScriptSerializer = new JavaScriptSerializer(); JavaScriptSerializer.MaxJsonLength = int.MaxValue; TransactionManager txnMng = new TransactionManager(); txnMng.StartTransaction(); var ope = TransactionManager.Operation.None; VSEMIPAddressPoolManagement vSEMIPAddressPoolManagement = null; try { StringBuilder json = new StringBuilder("\"IPAddressPoolId\":\"" + this.IPAddressPoolId + "\""); ODLVSEMETW.EventWriteDoCmdlet(this.CmdletName, "Removing IP Address Pool.", json.ToString()); string connectionString = this.conn.ConnectionString.Split(',').FirstOrDefault(); vSEMIPAddressPoolManagement = new VSEMIPAddressPoolManagement(connectionString, this.conn.Credential); if (!vSEMIPAddressPoolManagement.RemoveIpAddressPool( txnMng, this.IPAddressPoolId, this.conn)) { ODLVSEMETW.EventWriteRemoveIPPoolWarning(this.CmdletName, string.Format(CultureInfo.CurrentCulture, "IP Address Pool '{0}' not found.", this.IPAddressPoolId.ToString("B"))); // if IP address pool was not found in Remove-Odl.VSEMRemoveIpAddressPool, // ignore it } ODLVSEMETW.EventWriteReturnLibrary("VSEMIpAddressPool is removed.", 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); ODLVSEMETW.EventWriteEndCmdlet(this.CmdletName, string.Empty); } }