Example #1
0
        /// <summary>
        /// Process the updated logical network.
        /// </summary>
        /// <remarks>
        /// Ignore logical network that does not belong to us.
        /// </remarks>
        protected override void DoODLVSEMCmdlet()
        {
            var hnvLogicalNetworkManagement = new HNVLogicalNetworkManagement(this.conn.GetVtnHostName());

            // Make sure we are managing this logical network.
            if (hnvLogicalNetworkManagement.IsHNVLogicalNetwork(this.LogicalNetwork) == true)
            {
                var txnMng = new TransactionManager();
                txnMng.StartTransaction();
                var  ope         = TransactionManager.Operation.None;
                bool writeResult = false;

                try {
                    switch (this.OperationType)
                    {
                    case NetworkEntityPublishType.Create:
                    {
                        // Create is not supported through VMM.
                        writeResult = true;
                    }
                    break;

                    case NetworkEntityPublishType.Update:
                    {
                        hnvLogicalNetworkManagement.UpdateLogicalNetwork(txnMng, this.LogicalNetwork);
                        writeResult = hnvLogicalNetworkManagement.IsLogicalNetworkValid(this.LogicalNetwork);
                    }
                    break;

                    case NetworkEntityPublishType.Delete:
                    {
                        // Delete is not supported through VMM.
                        writeResult = true;
                    }
                    break;
                    }

                    ope = TransactionManager.Operation.Commit;
                } catch (Exception ex) {
                    ope = TransactionManager.Operation.Rollback;
                    throw VSEMODLExceptionUtil.ConvertExceptionToVSEMException(ex);
                } finally {
                    txnMng.EndTransaction(ope);
                }

                string output = "\"Logical Network\":" + new JavaScriptSerializer().Serialize(this.LogicalNetwork);
                ODLVSEMETW.EventWriteEndCmdlet(this.CmdletName, output);

                // Indicate errors.
                if (!writeResult)
                {
                    this.WriteObject(this.LogicalNetwork);
                }
            }
        }
        /// <summary>
        /// This function is responsible to retrieve the VSEMFabricNetworkDefinition information
        /// for the connection.
        /// </summary>
        protected override void DoODLVSEMCmdlet()
        {
            var JavaScriptSerializer = new JavaScriptSerializer();

            JavaScriptSerializer.MaxJsonLength = int.MaxValue;
            StringBuilder json = new StringBuilder(" \"ID\":" + JavaScriptSerializer.Serialize(this.ID));

            ODLVSEMETW.EventWriteDoCmdlet(this.CmdletName,
                                          "Retrieving logical network definition.",
                                          json.ToString());
            List <LogicalNetwork> vmNw   = null;
            TransactionManager    txnMng = new TransactionManager();

            txnMng.StartTransaction();
            var operation = TransactionManager.Operation.None;

            try {
                if (this.ID != Guid.Empty)
                {
                    vmNw = new List <LogicalNetwork>();
                    vmNw.Add(this.conn.GetVSEMLogicalNetworkById(txnMng, this.ID));
                    ODLVSEMETW.EventWriteReturnLibrary(string.Format(CultureInfo.CurrentCulture,
                                                                     "Logical network definition is retrieved by ID: {0}.",
                                                                     this.ID.ToString("B")),
                                                       string.Empty);

                    if (vmNw[0] == null)
                    {
                        ODLVSEMETW.EventWriteProcessCmdletWarning(this.CmdletName,
                                                                  string.Format(CultureInfo.CurrentCulture,
                                                                                "ID '{0}' not found.",
                                                                                this.ID.ToString("B")));
                        this.WriteWarning(string.Format(CultureInfo.CurrentCulture,
                                                        "ID '{0}' not found.",
                                                        this.ID.ToString("B")));
                    }
                    else
                    {
                        var hnvmgmt = new HNVLogicalNetworkManagement(this.conn.GetVtnHostName());

                        // Validate HNV LogicalNetwork. Need not check return value.
                        hnvmgmt.IsLogicalNetworkValid(vmNw[0]);
                        this.WriteObject(vmNw, true);
                    }
                }
                else
                {
                    vmNw = this.conn.GetVSEMLogicalNetwork(txnMng);
                    ODLVSEMETW.EventWriteReturnLibrary(
                        "Logical networks are retrieved.", string.Empty);
                    if (vmNw == null)
                    {
                        ODLVSEMETW.EventWriteProcessCmdletWarning(this.CmdletName,
                                                                  "Logical network not found.");
                        this.WriteWarning("Logical network not found.");
                    }
                    else
                    {
                        var hnvmgmt = new HNVLogicalNetworkManagement(this.conn.GetVtnHostName());
                        for (int i = 0; i < vmNw.Count; i++)
                        {
                            // Validate HNV LogicalNetworks. Need not check return value.
                            hnvmgmt.IsLogicalNetworkValid(vmNw[i]);
                        }
                        this.WriteObject(vmNw, true);
                    }
                }
            } catch (Exception ex) {
                Exception exception = VSEMODLExceptionUtil.ConvertExceptionToVSEMException(ex);
                ODLVSEMETW.EventWriteFailedCmdlet(this.CmdletName, exception.GetType() + " : " + ex.Message);
                operation = TransactionManager.Operation.Rollback;
                throw exception;
            } finally {
                txnMng.EndTransaction(operation);

                string output = "\"LogicalNetwork\":" + JavaScriptSerializer.Serialize(vmNw);
                ODLVSEMETW.EventWriteEndCmdlet(this.CmdletName, output);
            }
        }