コード例 #1
0
        /// <summary>
        /// This function is responsible to remove the information about the
        /// vm network(s) for the connection.
        /// </summary>
        protected override void DoODLVSEMCmdlet()
        {
            TransactionManager txnMng = new TransactionManager();
            txnMng.StartTransaction();
            var ope = TransactionManager.Operation.None;
            bool needRefresh = false;
            VSEMVMSubnetManagement vSEMVmNetworkDefinitionManagement = null;
            try {
                var JavaScriptSerializer = new JavaScriptSerializer();
                JavaScriptSerializer.MaxJsonLength = int.MaxValue;
                StringBuilder json = new StringBuilder("\"VMSubnetId\":\"" + this.VMSubnetId + "\"");
                ODLVSEMETW.EventWriteDoCmdlet(this.CmdletName,
                    "Removing VMSubnet.",
                    json.ToString());
                string connectionString =
                this.conn.ConnectionString.Split(',').FirstOrDefault();
                vSEMVmNetworkDefinitionManagement =
                    new VSEMVMSubnetManagement(connectionString,
                this.conn.Credential);
                needRefresh = vSEMVmNetworkDefinitionManagement.RemoveVmNetworkDefinition(
                    txnMng,
                    this.VMSubnetId,
                    this.conn,
                    out this.name);
                ODLVSEMETW.EventWriteReturnLibrary(string.Format(CultureInfo.CurrentCulture,
                "VM Subnet with ID: {0} is removed",
                this.VMSubnetId.ToString("B")),
                string.Empty);

                ope = TransactionManager.Operation.Commit;
            } catch (Exception ex) {
                ope = TransactionManager.Operation.Rollback;
                if (!string.IsNullOrEmpty(this.name)
                    && string.Compare(ex.GetType().ToString(), "System.Net.WebException", StringComparison.Ordinal) == 0) {
                    ODLVSEMETW.EventWriteFailedCmdlet(string.Format(CultureInfo.CurrentCulture,
                        "Due to some problem in connection with ODL, VSEM VM Subnet '{0}' removal process is terminated in the middle of the request. vBridge may have been deleted from ODL, Please check. Please retry and delete VM Subnet if inconsistency is created.",
                    this.name),
                    string.Empty);
                    Exception exception = VSEMODLExceptionUtil.ConvertExceptionToVSEMException(
                        new System.Net.WebException(string.Format(CultureInfo.CurrentCulture,
                            "Due to some problem in connection with ODL, VSEM VM Subnet '{0}' removal process is terminated in the middle of the request. vBridge may have been deleted from ODL, Please check. Please retry and delete VM Subnet if inconsistency is created.",
                            this.name),
                            ex));
                    ODLVSEMETW.EventWriteFailedCmdlet(this.CmdletName, exception.GetType() + " : " + ex.Message);
                    ope = TransactionManager.Operation.Rollback;
                    throw exception;
                } else {
                    ODLVSEMETW.EventWriteFailedCmdlet(
                        "VSEM VM Subnet removal is failed.",
                        string.Empty);
                    Exception exception = VSEMODLExceptionUtil.ConvertExceptionToVSEMException(ex);
                    ODLVSEMETW.EventWriteFailedCmdlet(this.CmdletName, exception.GetType() + " : " + exception.Message);
                    ope = TransactionManager.Operation.Rollback;
                    throw exception;
                }
            } finally {
                txnMng.EndTransaction(ope);
                ODLVSEMETW.EventWriteEndCmdlet(this.CmdletName, string.Empty);
            }
        }
コード例 #2
0
        /// <summary>
        /// This function is responsible for creating a VM Subnet.
        /// </summary>
        protected override void DoODLVSEMCmdlet()
        {
            var JavaScriptSerializer = new JavaScriptSerializer();
            JavaScriptSerializer.MaxJsonLength = int.MaxValue;
            StringBuilder json = new StringBuilder(" \"IPSubnets\":" + JavaScriptSerializer.Serialize(this.IPSubnets));
            json.Append("\"MaxNumberOfPorts\":\"" + this.MaxNumberOfPorts + "\"");
            json.Append("\"Name\":\"" + this.Name + "\"");
            json.Append("\"VMNetworkId\":\"" + this.VMNetworkId + "\"");
            json.Append("\"LogicalNetworkDefinitionId\":\"" + this.LogicalNetworkDefinitionId + "\"");
            ODLVSEMETW.EventWriteDoCmdlet(this.CmdletName,
                    "Creating VM Subnet.",
                    json.ToString());
            TransactionManager txnMng = new TransactionManager();
            txnMng.StartTransaction();
            var ope = TransactionManager.Operation.None;
            string vtnName = string.Empty;
            string vbrName = string.Empty;
            VMSubnet nw = null;
            string connectionString =
                this.conn.ConnectionString.Split(',').FirstOrDefault();
            VSEMVMSubnetManagement vSEMVMSubnetManagement =
                new VSEMVMSubnetManagement(connectionString,
                    this.conn.Credential);
            try {
                nw = vSEMVMSubnetManagement.CreateVMNetworkDefinition(txnMng,
                    this.Name,
                    this.VMNetworkId,
                    this.MaxNumberOfPorts,
                    this.IPSubnets,
                    this.LogicalNetworkDefinitionId,
                    this.conn,
                    out vtnName,
                    out vbrName);
                ODLVSEMETW.EventWriteReturnLibrary("VM Subnet is created.",
                    string.Empty);

                ope = TransactionManager.Operation.Commit;
            }
            catch (Exception ex) {
                    Exception userException = ex;
                    ODLVSEMETW.EventWriteFailedCmdlet(
                        "VM Subnet creation is failed. ODL changes rollback is started.",
                        string.Empty);
                    ope = TransactionManager.Operation.Rollback;
                    try {
                        if (!string.IsNullOrEmpty(vtnName) && !string.IsNullOrEmpty(vbrName)) {
                            vSEMVMSubnetManagement.RemoveVmNetworkDefinition(
                                vtnName, vbrName);
                            ODLVSEMETW.EventWriteFailedCmdlet(
                                "VM Subnet creation is failed. ODL changes are successfully rolled back.",
                                string.Empty);
                        }
                    } catch (Exception excep) {
                        // VM Network Creation Process is terminated in the middle of the request. VTN
                        ODLVSEMETW.EventWriteFailedCmdlet(
                            string.Format(
                            CultureInfo.CurrentCulture,
                            "Due to some problem in connection with ODL, VSEM VM Subnet creation process terminated in the middle of the request. vBridge '{0}' may have been created on ODL, Please check. If inconsistency is created, Please delete the vBridge from ODL to maintain the consistency between ODL and SCVMM.\n{1}",
                            vbrName,
                            excep.Message),
                            string.Empty);
                        userException = new System.Net.WebException(string.Format(
                            CultureInfo.CurrentCulture,
                            "Due to some problem in connection with ODL, VSEM VM Subnet creation process terminated in the middle of the request. vBridge '{0}' may have been created on ODL, Please check. If inconsistency is created, Please delete the vBridge from ODL to maintain the consistency between ODL and SCVMM.",
                            vbrName),
                            ex);
                    }
                    Exception exception = VSEMODLExceptionUtil.ConvertExceptionToVSEMException(userException);
                    ODLVSEMETW.EventWriteFailedCmdlet(this.CmdletName, exception.GetType() + " : " + ex.Message);
                    throw exception;
            } finally {
                txnMng.EndTransaction(ope);

                string output = "\"VMSubnet\":" + JavaScriptSerializer.Serialize(nw);
                ODLVSEMETW.EventWriteEndCmdlet(this.CmdletName, output);
                this.WriteObject(nw);
            }
        }