/// <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)); } }
/// <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); } }
/// <summary> /// Update the VSEM repository. /// </summary> /// <param name="txnMng">Transaction manager.</param> public void UpdateConnection(TransactionManager txnMng) { var JavaScriptSerializer = new JavaScriptSerializer(); JavaScriptSerializer.MaxJsonLength = int.MaxValue; StringBuilder json = new StringBuilder("\"TransactionManager\":" + JavaScriptSerializer.Serialize(txnMng)); ODLVSEMETW.EventWriteStartLibrary(MethodBase.GetCurrentMethod().Name, json.ToString()); if (txnMng == null) { throw new ArgumentException( "txnMng' is null or invalid."); } string VtnHostName = this.ConnectionString; if (VtnHostName.StartsWith(@"https://", StringComparison.Ordinal)) { VtnHostName = VtnHostName.Substring(8); } VtnHostName = VtnHostName.Split('.', ':').First(); var vseminformation = this.CreateVSEMInfo(); // Make sure we can connect to the ODL if (!this.VerifyConnection(vseminformation.MinVTNCoVersion)) { ODLVSEMETW.EventWriteProcesOdlLibraryError(MethodBase.GetCurrentMethod().Name, "WebAPI version is not supported."); throw new ArgumentException("WebAPI version is not supported."); } Controller odl_ctr = new Controller(this.ConnectionString, this.controllers, this.Credential); odl_ctr.Create_ctr(Constants.CTR_NAME); ODLVSEMETW.EventWriteCreateODLData( MethodBase.GetCurrentMethod().Name, "Creating VSEM repository."); VSEMConfig vsemConfig = new VSEMConfig(); txnMng.SetConfigManager(vsemConfig, TransactionManager.OpenMode.WriteMode); // Update Configuration Data; vsemConfig.Info = vseminformation; vsemConfig.Controller = new VSEMController(); vsemConfig.Controller.ControllerInfo = this.controllers; if (vsemConfig.NetworkServiceSystemInformation.Id.CompareTo(Guid.Empty) == 0) { vsemConfig.NetworkServiceSystemInformation = VSEMConnection.CreateSystemInfo(); } else { VSEMODLConstants.SYSTEM_INFO_ID = vsemConfig.NetworkServiceSystemInformation.Id; } if (vsemConfig.SwitchExtensionInfo.Count == 0) { vsemConfig.SwitchExtensionInfo = VSEMConnection.CreateSwitchExtensionInfos(); } else { VSEMODLConstants.SWITCH_EXTENSION_INFO_ID = vsemConfig.SwitchExtensionInfo[0].Id; } vsemConfig.SwitchExtensionInfo.ForEach((i) => VSEMConnection.AddSwitchFeatureToSwitchExtInfos(i, this.controllers)); LogicalNetworkConfig logicalNetworkConfig = new LogicalNetworkConfig(VtnHostName); txnMng.SetConfigManager(logicalNetworkConfig, TransactionManager.OpenMode.WriteMode); if (logicalNetworkConfig.LogicalNetworks.Count == 0) { logicalNetworkConfig.LogicalNetworks = this.CreateLogicalNetworks(); } PortProfileConfig portProfileConfig = new PortProfileConfig(); txnMng.SetConfigManager(portProfileConfig, TransactionManager.OpenMode.WriteMode); if (portProfileConfig.UplinkPortProfiles.Count == 0) { portProfileConfig.UplinkPortProfiles = VSEMConnection.CreateUplinkPortProfiles(); } else { VSEMODLConstants.UPLINK_PORT_PROFILE_ID = portProfileConfig.UplinkPortProfiles[0].Id; } if (portProfileConfig.VirtualPortProfiles.Count == 0) { portProfileConfig.VirtualPortProfiles = VSEMConnection.CreateVirtualPortProfiles(); } // Create HNV default resource. HNVLogicalNetworkManagement hnvMgmt = new HNVLogicalNetworkManagement(this.VtnHostName); hnvMgmt.CreateHNVLogicalNetwork(logicalNetworkConfig); hnvMgmt.AssociatePortProfileWithHNV(portProfileConfig); this.SaveVtncoInfo(txnMng, VtnHostName); ODLVSEMETW.EventWriteEndLibrary(MethodBase.GetCurrentMethod().Name, string.Empty); }
/// <summary> /// This method is responsible for extracting the VSEMSystemInfo /// from the VSEM repository for the corresponding connection. /// </summary> /// <param name="txnMng">Transaction manager.</param> /// <returns>VSEMSystemInfo instance attached with the connection.</returns> public NetworkServiceSystemInformation GetVSEMSystemInfo(TransactionManager txnMng) { var JavaScriptSerializer = new JavaScriptSerializer(); JavaScriptSerializer.MaxJsonLength = int.MaxValue; StringBuilder json = new StringBuilder("\"TransactionManager\":" + JavaScriptSerializer.Serialize(txnMng)); ODLVSEMETW.EventWriteStartLibrary(MethodBase.GetCurrentMethod().Name, json.ToString()); ODLVSEMETW.EventWriteExtractsystemInfo("Extracting System Info.", string.Empty); 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{1}", configFileIOErrorValidationMessage, ex.Message)); throw new InvalidOperationException( string.Format(CultureInfo.CurrentCulture, "VSEM.config {0}", configFileIOErrorValidationMessage)); } string output = "\"NetworkServiceSystemInformation\":" + JavaScriptSerializer.Serialize(vsemConfig.NetworkServiceSystemInformation); ODLVSEMETW.EventWriteEndLibrary(MethodBase.GetCurrentMethod().Name, output); return vsemConfig.NetworkServiceSystemInformation; }
/// <summary> /// This method is responsible for extracting the VSEMSwitchExtensionInfo /// from the VSEM repository for the corresponding connection for the specified id. /// </summary> /// <param name="txnMng">Transaction manager.</param> /// <param name="id"> Id of the VSEMSwitchExtensionInfo.</param> /// <returns>VSEMSwitchExtensionInfo instance attached with the connection.</returns> public VSEMSwitchExtensionInfo GetVSEMSwitchExtensionInfoById( TransactionManager txnMng, Guid id) { var JavaScriptSerializer = new JavaScriptSerializer(); JavaScriptSerializer.MaxJsonLength = int.MaxValue; StringBuilder json = new StringBuilder("\"TransactionManager\":" + JavaScriptSerializer.Serialize(txnMng)); json.Append(" \"id\":" + id.ToString("B")); ODLVSEMETW.EventWriteStartLibrary( MethodBase.GetCurrentMethod().Name, json.ToString()); ODLVSEMETW.EventWriteExtractSwitchExtensionInfo( "Extracting VSEMSwitchExtension Info.", string.Empty); if (id == Guid.Empty) { ODLVSEMETW.EventWriteArgumentError( MethodBase.GetCurrentMethod().DeclaringType.Name.ToString(), MethodBase.GetCurrentMethod().Name, "The parameter 'id' is null or invalid."); throw new ArgumentException("'id' is null or invalid."); } var vsemConfig = new VSEMConfig(); try { txnMng.SetConfigManager(vsemConfig, TransactionManager.OpenMode.ReadMode); var ret = vsemConfig.SwitchExtensionInfo.FirstOrDefault( (x) => x.Id == id); string output = "\"VSEMSwitchExtensionInfo\":" + JavaScriptSerializer.Serialize(ret); ODLVSEMETW.EventWriteEndLibrary(MethodBase.GetCurrentMethod().Name, output); return ret; } catch (Exception ex) { ODLVSEMETW.EventWriteConfigManagerFileIOError( MethodBase.GetCurrentMethod().Name, string.Format(CultureInfo.CurrentCulture, "VSEM.config {0}\n{1}", configFileIOErrorValidationMessage, ex.Message)); ODLVSEMETW.EventWriteEndLibrary(MethodBase.GetCurrentMethod().Name, string.Empty); throw new InvalidOperationException( string.Format(CultureInfo.CurrentCulture, "VSEM.config {0}", configFileIOErrorValidationMessage)); } }
/// <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)); } }