예제 #1
0
        /// <summary>
        /// Initializes a new instance of the VSEMSynchronization class.
        /// </summary>
        /// <param name="txnMng">Transaction Manager.</param>
        public VSEMSynchronization(TransactionManager txnMng)
        {
            var JavaScriptSerializer = new JavaScriptSerializer();

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

            ODLVSEMETW.EventWriteStartLibrary(MethodBase.GetCurrentMethod().DeclaringType.Name.ToString(),
                                              json.ToString());
            if (txnMng == null)
            {
                ODLVSEMETW.EventWriteArgumentError(
                    MethodBase.GetCurrentMethod().DeclaringType.Name.ToString(),
                    MethodBase.GetCurrentMethod().Name,
                    "The parameter 'transaction' is null or invalid.");
                throw new ArgumentException("The parameter 'transaction' is null or invalid.");
            }
            var vSEMConfig = new VSEMConfig();

            try {
                txnMng.SetConfigManager(vSEMConfig, TransactionManager.OpenMode.ReadMode);
            } catch (Exception ex) {
                ODLVSEMETW.EventWriteConfigManagerFileIOError(
                    MethodBase.GetCurrentMethod().Name,
                    string.Format(CultureInfo.CurrentCulture,
                                  "VSEM.config {0}\n",
                                  configFileIOErrorValidationMessage) +
                    ex.Message);
                ODLVSEMETW.EventWriteEndLibrary(MethodBase.GetCurrentMethod().Name, string.Empty);
                throw new InvalidOperationException(
                          string.Format(CultureInfo.CurrentCulture,
                                        "Either the NetworkService is not added in SCVMM or VSEM.config {0}",
                                        configFileIOErrorValidationMessage));
            }
            try {
                var odlInformation = new OdlInformation(vSEMConfig.Info.ServerName);
                txnMng.SetConfigManager(odlInformation, TransactionManager.OpenMode.ReadMode);
                this.ConnectionString = odlInformation.GetConnectionString();
                this.Credential       = odlInformation.GetCredentials();
            } catch (Exception ex) {
                ODLVSEMETW.EventWriteConfigManagerFileIOError(
                    MethodBase.GetCurrentMethod().Name,
                    string.Format(CultureInfo.CurrentCulture,
                                  "ODLInformation.config {0}\n",
                                  configFileIOErrorValidationMessage) +
                    ex.Message);
                ODLVSEMETW.EventWriteEndLibrary(MethodBase.GetCurrentMethod().Name, string.Empty);
                throw new InvalidOperationException(
                          string.Format(CultureInfo.CurrentCulture,
                                        "ODLInformation.config {0}",
                                        configFileIOErrorValidationMessage));
            }
        }
예제 #2
0
        /// <summary>
        /// This constructor is responsible for instantiating the vlanMapInfo.
        /// </summary>
        /// <param name="txnMng">Transaction manager object.</param>
        /// <param name="VtnHostName">Parent Folder name.</param>
        /// <param name="mode">Write or Read mode in which file to be opened.</param>
        public VLANIDMap(TransactionManager txnMng,
                         string VtnHostName,
                         TransactionManager.OpenMode mode)
        {
            var JavaScriptSerializer = new JavaScriptSerializer();

            JavaScriptSerializer.MaxJsonLength = int.MaxValue;
            StringBuilder json = new StringBuilder("\"vMNetworkName\":\"" + VtnHostName + "\"");

            json.Append(" \"TransactionManager\":" + JavaScriptSerializer.Serialize(txnMng));
            json.Append(" \"OpenMode\":\"" + mode + "\"");
            ODLVSEMETW.EventWriteStartLibrary(
                MethodBase.GetCurrentMethod().Name,
                json.ToString());
            if (txnMng == null)
            {
                throw new ArgumentException(
                          "Parameter 'txnMng' is null or invalid.");
            }
            if (string.IsNullOrWhiteSpace(VtnHostName))
            {
                VSEMConfig vsemConfig = new VSEMConfig();
                txnMng.SetConfigManager(vsemConfig, TransactionManager.OpenMode.ReadMode);
                VtnHostName = vsemConfig.Info.ServerName;
            }
            if (string.IsNullOrWhiteSpace(VtnHostName))
            {
                throw new ArgumentException(
                          "Parameter 'VTNCoordinatorHostName' is null or invalid.");
            }
            try {
                VLANIDMappingConfig vLANIDMappingConfig = new VLANIDMappingConfig(VtnHostName);
                txnMng.SetConfigManager(vLANIDMappingConfig, mode);
                this.vlanMapInfo = vLANIDMappingConfig.VLANIDMapping;
            } catch (System.IO.IOException) {
                ODLVSEMETW.EventWriteConfigManagerFileIOError(MethodBase.GetCurrentMethod().Name,
                                                              configFileIOErrorValidationMessage);
                throw new InvalidOperationException(
                          configFileIOErrorValidationMessage);
            }
        }
예제 #3
0
        /// <summary>
        /// This method is responsible for extracting the list of VSEMVmNetwork
        /// from the VSEM repository for the corresponding connection.
        /// </summary>
        /// <param name="txnMng">Transaction manager.</param>
        /// <param name="VtnHostName">Host name of the VTNCoordinator.</param>
        /// <returns>List of VSEMVmNetwork instances attached with the connection.</returns>
        public static VMNetworkMappingInfo GetVSEMVMNetworkMappingInfo(TransactionManager txnMng, string VtnHostName)
        {
            var JavaScriptSerializer = new JavaScriptSerializer();

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

            ODLVSEMETW.EventWriteStartLibrary(
                MethodBase.GetCurrentMethod().Name,
                json.ToString());
            ODLVSEMETW.EventWriteExtractVMNetworkInfolist(
                "Extracting list of VMNetwork Info.",
                string.Empty);
            if (string.IsNullOrWhiteSpace(VtnHostName))
            {
                VSEMConfig vsemConfig = new VSEMConfig();
                try {
                    txnMng.SetConfigManager(vsemConfig, TransactionManager.OpenMode.ReadMode);
                } catch (Exception ex) {
                    ODLVSEMETW.EventWriteConfigManagerFileIOError(
                        MethodBase.GetCurrentMethod().Name,
                        string.Format(CultureInfo.CurrentCulture,
                                      "VSEM.config {0}\n",
                                      configFileIOErrorValidationMessage) +
                        ex.Message);
                    ODLVSEMETW.EventWriteEndLibrary(MethodBase.GetCurrentMethod().Name, string.Empty);
                    throw new InvalidOperationException(
                              string.Format(CultureInfo.CurrentCulture,
                                            "Either the NetworkService is not added in SCVMM or VSEM.config {0}",
                                            configFileIOErrorValidationMessage));
                }
                VtnHostName = vsemConfig.Info.ServerName;
            }
            if (string.IsNullOrWhiteSpace(VtnHostName))
            {
                throw new ArgumentException(
                          "Parameter 'VTNCoordinatorHostName' is null or invalid.");
            }
            var vMNetworkConfig = new VMNetworkConfig(VtnHostName);

            try {
                txnMng.SetConfigManager(vMNetworkConfig, TransactionManager.OpenMode.ReadMode);
                var    ret    = vMNetworkConfig.VMNetwork.VMNetworkMappingInformation;
                string output = "\"VMNetwork\":" + JavaScriptSerializer.Serialize(ret);
                ODLVSEMETW.EventWriteEndLibrary(MethodBase.GetCurrentMethod().Name,
                                                output);
                return(ret);
            } catch (System.IO.FileNotFoundException) {
                // Ignore if the file is not yet created and return empty list.
                return(new VMNetworkMappingInfo());
            } catch (Exception ex) {
                ODLVSEMETW.EventWriteConfigManagerFileIOError(
                    MethodBase.GetCurrentMethod().Name,
                    string.Format(CultureInfo.CurrentCulture,
                                  "VMNetwork.config {0}\n{1}",
                                  configFileIOErrorValidationMessage,
                                  ex.Message));
                throw new InvalidOperationException(
                          string.Format(CultureInfo.CurrentCulture,
                                        "VMNetwork.config {0}",
                                        configFileIOErrorValidationMessage));
            }
        }