/// <summary> /// Verify whether the specified VMNetwork is HNV resource or not. /// </summary> /// <param name="vmnetwork">VMNetwork instance.</param> /// <returns>True if HNV resource, else false.</returns> public bool IsHNVVMNetwork(VMNetwork vmnetwork) { if (vmnetwork == null) { return false; } // Create txn and read configuration. var txnMng = new TransactionManager(); txnMng.StartTransaction(); var logicalNetworkConfig = new LogicalNetworkConfig(this.VtnHostName); txnMng.SetConfigManager(logicalNetworkConfig, TransactionManager.OpenMode.ReadMode); bool ret; // Get LogicalNetowork that Guid equals vmnetwork.LogicalNetwork. LogicalNetwork logicalnetwork = logicalNetworkConfig.GetLogicalNetworkById(vmnetwork.LogicalNetwork); if (logicalnetwork == null) { ret = false; goto txnEnd; } var hnvLogicalNetworkManagement = new HNVLogicalNetworkManagement(this.VtnHostName); ret = hnvLogicalNetworkManagement.IsHNVLogicalNetwork(logicalnetwork); if (ret == false) { ODLVSEMETW.EventWriteNotHNVVMNetwork( MethodBase.GetCurrentMethod().Name, string.Format("VMNetwork name is {0}", vmnetwork.Name)); } txnEnd: txnMng.EndTransaction(TransactionManager.Operation.None); return ret; }
/// <summary> /// Create default LogicalNetwork and add to configuration. /// </summary> /// <param name="logicalNetworkConfig">FabricNetworkConfig instance.</param> public void CreateHNVLogicalNetwork(LogicalNetworkConfig logicalNetworkConfig) { // Verify arguments. if (logicalNetworkConfig == null) { return; } if (logicalNetworkConfig.GetLogicalNetworkById(HNVODLConstants.LOGICAL_NETWORK.LOGICALNETWORK_ID) != null) { // If exists, nothing to do. return; } ODLVSEMETW.EventWriteGetHNVLogicalNetworkNotFound(MethodBase.GetCurrentMethod().Name, string.Format("Create LogicalNetwork that Guid is {0}", HNVODLConstants.LOGICAL_NETWORK.LOGICALNETWORK_ID)); // Create LogicalNetwork instance. var logicalNetwork = new LogicalNetwork() { AreLogicalNetworkDefinitionsIsolated = HNVODLConstants.LOGICAL_NETWORK.ARE_LOGICALNETWORK_DEFINITIONS_ISOLATED, Description = HNVODLConstants.LOGICAL_NETWORK.DESCRIPTION, Id = HNVODLConstants.LOGICAL_NETWORK.LOGICALNETWORK_ID, LastModifiedTimeStamp = DateTime.Now, LogicalNetworkDefinitions = new LogicalNetworkDefinition[1], Name = string.Format(HNVODLConstants.LOGICAL_NETWORK.NAME, this.VtnHostName) }; logicalNetwork.LogicalNetworkDefinitions[0] = this.CreateDefaultLogicalNetworkDefinition(); // Add created logical network to the configuration. logicalNetworkConfig.LogicalNetworks.Add(logicalNetwork); }