/// <summary> /// This function is responsible for creating a VM Network /// with one VM Subnet on the VSEM. /// </summary> protected override void DoODLVSEMCmdlet() { var JavaScriptSerializer = new JavaScriptSerializer(); JavaScriptSerializer.MaxJsonLength = int.MaxValue; StringBuilder json = new StringBuilder(" \"VMNetwork\":" + JavaScriptSerializer.Serialize(this.VMNetwork)); json.Append(" \"OperationType\":" + JavaScriptSerializer.Serialize(this.OperationType)); ODLVSEMETW.EventWriteDoCmdlet(this.CmdletName, "VM Network creation process started.", json.ToString()); // If VMNetwork is HNV resource, return immediately. var mgmt = new HNVVMNetworkManagement(this.conn.GetVtnHostName()); if (mgmt.IsHNVVMNetwork(this.VMNetwork) == true) { return; } TransactionManager txnMng = new TransactionManager(); txnMng.StartTransaction(); var ope = TransactionManager.Operation.None; VMNetwork nw = null; string connectionString = this.conn.ConnectionString.Split(',').FirstOrDefault(); VSEMSynchronization vSEMSynchronization = new VSEMSynchronization(connectionString, this.conn.Credential); try { bool needRefresh = vSEMSynchronization.PublishVMNetwork(txnMng, this.VMNetwork, this.OperationType, this.conn); ODLVSEMETW.EventWriteReturnLibrary("VM network is updated.", string.Empty); if (needRefresh) { this.conn.RefreshConnection(); } 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); string output = "\"VM Network\":" + JavaScriptSerializer.Serialize(nw); ODLVSEMETW.EventWriteEndCmdlet(this.CmdletName, output); this.WriteObject(this.VMNetwork); } }
/// <summary> /// This method is responsible to add specified vlan entry into the local variable. /// </summary> protected override void DoODLVSEMCmdlet() { ODLVSEMETW.EventWriteDoCmdlet(this.CmdletName, "Synchronizing SCVMM and ODL.", string.Empty); VSEMSynchronization vSEMSynchronization = null; if (string.IsNullOrEmpty(this.SCVMSubnets)) { TransactionManager txnMng = new TransactionManager(); txnMng.StartTransaction(); var operation = TransactionManager.Operation.None; try { vSEMSynchronization = new VSEMSynchronization(txnMng); vSEMSynchronization.SynchronizeVTNObjects(txnMng); operation = TransactionManager.Operation.Commit; } catch (Exception ex) { Exception exception = VSEMODLExceptionUtil.ConvertExceptionToVSEMException(ex); ODLVSEMETW.EventWriteFailedCmdlet(this.CmdletName, exception.GetType() + " : synchronization is failed. \n" + ex.Message); operation = TransactionManager.Operation.Rollback; ODLVSEMETW.EventWriteEndCmdlet(this.CmdletName, string.Empty); throw exception; } finally { txnMng.EndTransaction(operation); } } else { TransactionManager txnMng = new TransactionManager(); txnMng.StartTransaction(); var operation = TransactionManager.Operation.Commit; try { vSEMSynchronization = new VSEMSynchronization(txnMng); vSEMSynchronization.StatusAfterRefreshNetworkService(txnMng, this.SCVMSubnets); } catch (Exception ex) { operation = TransactionManager.Operation.Rollback; if (ex.GetType() != typeof(NSPluginSynchronizationException)) { ODLVSEMETW.EventWriteFailedCmdlet("NetworkService could not be refreshed in SCVMM. " + ex.Message, string.Empty); throw new NSPluginSynchronizationException("NetworkService could not be refreshed in SCVMM. " + ex.Message); } else { throw; } } finally { txnMng.EndTransaction(operation); ODLVSEMETW.EventWriteEndCmdlet(this.CmdletName, string.Empty); } } }