/// <summary> /// Validate the parameters. /// </summary> protected override void BeginODLVSEMCmdlet() { this.conn = this.Connection as VSEMConnection; if (this.conn == null) { ODLVSEMETW.EventWriteValidateConnectionObjectError(this.CmdletName, "Connection object is NULL."); throw new NSPluginArgumentException("Invalid connection object."); } if (string.IsNullOrEmpty(this.conn.ConnectionString)) { ODLVSEMETW.EventWriteValidateVSEMRepositoryError(this.CmdletName, "Invalid connection object."); throw new NSPluginInvalidOperationException( "Invalid connection object."); } if ((this.LogicalNetwork == null) || (this.LogicalNetwork.LogicalNetworkDefinitions == null) || (this.LogicalNetwork.LogicalNetworkDefinitions.Length == 0)) { throw new NSPluginArgumentException( "No logical network definitions found."); } }
/// <summary> /// This function is responsible for validating the parameters. /// </summary> protected override void BeginODLVSEMCmdlet() { if (this.Connection == null || this.VMNetwork == null) { ODLVSEMETW.EventWriteValidateCmdletParameter(this.CmdletName, "Mandatory parameter(s) not provided."); throw new NSPluginArgumentException("Mandatory parameter(s) not provided."); } this.conn = VSEMODLCmdletUtility.ValidateConnectionObject(this.Connection, this.CmdletName); }
/// <summary> /// This function is responsible for validating the parameters. /// </summary> protected override void BeginODLVSEMCmdlet() { if (this.Connection == null || this.VMSubnetId == null || this.VMSubnetId == Guid.Empty || string.IsNullOrWhiteSpace(this.Name) || string.IsNullOrWhiteSpace(this.IPAddressSubnet) || string.IsNullOrWhiteSpace(this.AddressRangeStart) || string.IsNullOrWhiteSpace(this.AddressRangeEnd)) { ODLVSEMETW.EventWriteValidateCmdletParameter(this.CmdletName, "Mandatory parameter(s) not provided."); throw new NSPluginArgumentException("Mandatory parameter(s) not provided."); } this.conn = VSEMODLCmdletUtility.ValidateConnectionObject(this.Connection, this.CmdletName); }
/// <summary> /// This function is responsible for creating a connection object for this VSEM provider. /// </summary> protected override void DoODLVSEMCmdlet() { var JavaScriptSerializer = new JavaScriptSerializer(); JavaScriptSerializer.MaxJsonLength = int.MaxValue; StringBuilder json = new StringBuilder("\"ConnectionString\":" + JavaScriptSerializer.Serialize(this.ConnectionParams.ConnectionString)); ODLVSEMETW.EventWriteDoCmdlet(this.CmdletName, "Connecting to VSEM.", json.ToString()); this.ValidateConnectionString(); string controllers = this.ValidateControllers(); string connectionString = this.ConnectionParams.ConnectionString.Split(',').FirstOrDefault(); TransactionManager txnMng = new TransactionManager(); txnMng.StartTransaction(); var operation = TransactionManager.Operation.None; VSEMConnection conn = new VSEMConnection(connectionString, this.ConnectionParams.Credential, controllers); try { conn.UpdateConnection(txnMng); ODLVSEMETW.EventWriteReturnLibrary(string.Format(CultureInfo.CurrentCulture, "Connected to {0} as user '{1}'.", this.ConnectionParams.ConnectionString, this.ConnectionParams.Credential.UserName), string.Empty); operation = TransactionManager.Operation.Commit; } 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); ODLVSEMETW.EventWriteEndCmdlet(this.CmdletName, string.Empty); this.WriteObject(conn); } }
/// <summary> /// This function is responsible for validating the parameters. /// </summary> protected override void BeginODLVSEMCmdlet() { if (this.Connection == null || string.IsNullOrWhiteSpace(this.VMSubnetName) || this.IPSubnets == null || this.LogicalNetworkDefinitionId == null || this.LogicalNetworkDefinitionId == Guid.Empty || string.IsNullOrWhiteSpace(this.VMNetworkName)) { ODLVSEMETW.EventWriteValidateCmdletParameter(this.CmdletName, "Mandatory parameter(s) not provided."); throw new NSPluginArgumentException("Mandatory parameter(s) not provided."); } this.conn = VSEMODLCmdletUtility.ValidateConnectionObject(this.Connection, this.CmdletName); if (this.IPSubnets.Any(subnet => string.IsNullOrEmpty(subnet.Subnet) || subnet.AddressFamily == null)) { ODLVSEMETW.EventWriteValidateCmdletParameter(this.CmdletName, "IPSubnets is invalid. Please provide AddressFamily and Subnet in IPSubnets."); throw new NSPluginArgumentException("IPSubnets is invalid. Please provide AddressFamily and Subnet in IPSubnets."); } }
/// <summary> /// This function is responsible for validating the parameters. /// </summary> protected override void BeginODLVSEMCmdlet() { this.conn = VSEMODLCmdletUtility.ValidateConnectionObject(this.Connection, this.CmdletName); }
/// <summary> /// Publish VM Network. /// </summary> /// <param name="txnMng">TransactionManager instance.</param> /// <param name="vMNetwork">VM Network.</param> /// <param name="operationType">Operation type performed on SCVMM.</param> /// <param name="connection">Connection object.</param> /// <returns>Boolean indicating whether network service refresh is needed..</returns> public bool PublishVMNetwork(TransactionManager txnMng, VMNetwork vMNetwork, NetworkEntityPublishType operationType, VSEMConnection connection) { bool needRefresh = false; var JavaScriptSerializer = new JavaScriptSerializer(); JavaScriptSerializer.MaxJsonLength = int.MaxValue; StringBuilder json = new StringBuilder("\"txnMng\":" + JavaScriptSerializer.Serialize(txnMng)); json.Append(" \"vMNetwork\":" + JavaScriptSerializer.Serialize(vMNetwork)); json.Append(" \"operationType\":" + JavaScriptSerializer.Serialize(operationType)); ODLVSEMETW.EventWriteStartLibrary(MethodBase.GetCurrentMethod().Name, 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."); } if (vMNetwork == null) { ODLVSEMETW.EventWriteArgumentError( MethodBase.GetCurrentMethod().DeclaringType.Name.ToString(), MethodBase.GetCurrentMethod().Name, "The parameter 'vMNetwork' is null or invalid."); throw new ArgumentException("The parameter 'vMNetworkName' is null or invalid."); } if (connection == null) { ODLVSEMETW.EventWriteArgumentError( MethodBase.GetCurrentMethod().DeclaringType.Name.ToString(), MethodBase.GetCurrentMethod().Name, "The parameter 'connection' is null or invalid."); throw new ArgumentException("The parameter 'connection' is null or invalid."); } string VtnHostName = this.ConnectionString; if (VtnHostName.StartsWith(@"https://", StringComparison.Ordinal)) { VtnHostName = VtnHostName.Substring(8); } VtnHostName = VtnHostName.Split('.', ':').First(); var vMNetworkConfig = new VMNetworkConfig(VtnHostName); txnMng.SetConfigManager(vMNetworkConfig, TransactionManager.OpenMode.WriteMode); var vmnetworkFound = vMNetworkConfig.VMNetwork.VmNetworks.FirstOrDefault( nw => nw.Id == vMNetwork.Id); var vmnetworkMappigInfoFound = vMNetworkConfig.VMNetwork.VMNetworkMappingInformation.VMNetworkInfo.FirstOrDefault( nw => nw.VMNetworkID == vMNetwork.Id); if (vmnetworkMappigInfoFound == null) { return(needRefresh); } if (operationType != NetworkEntityPublishType.Delete) { vmnetworkMappigInfoFound.VMNetworkName = vMNetwork.Name; if (vmnetworkMappigInfoFound.VTNName.CompareTo(string.Empty) == 0) { return(needRefresh); } vmnetworkFound.OwnerName = vMNetwork.OwnerName; vmnetworkFound.RoutingDomainId = vMNetwork.RoutingDomainId; if (operationType == NetworkEntityPublishType.Create) { foreach (var subnetinfo in vmnetworkMappigInfoFound.VMSubnetInfo) { subnetinfo.VMSubnetName = subnetinfo.VBridgeName; subnetinfo.VMSubnetVlanId = subnetinfo.VBridgeVlanId; } Controller odl = new Controller(this.ConnectionString, this.Credential); List <Vtn> vtns = odl.ReadVTNObjects(vmnetworkMappigInfoFound.VTNName); if (vtns.Count == 0) { needRefresh = true; vMNetworkConfig.VMNetwork.VmNetworks.Remove(vmnetworkFound); vMNetworkConfig.VMNetwork.VMNetworkMappingInformation.VMNetworkInfo.Remove(vmnetworkMappigInfoFound); } if (vtns.Count != 0) { needRefresh = this.SyncVTN(vmnetworkFound.VMSubnets.First().LogicalNetworkDefinitionId, vmnetworkFound, vtns.First(), vmnetworkMappigInfoFound, txnMng, VtnHostName); } } vmnetworkMappigInfoFound.Description = string.Empty; } else { if (vmnetworkMappigInfoFound.VTNName.CompareTo(string.Empty) == 0) { vMNetworkConfig.VMNetwork.VMNetworkMappingInformation.VMNetworkInfo.Remove(vmnetworkMappigInfoFound); return(needRefresh); } vmnetworkMappigInfoFound.VMNetworkName = string.Empty; vmnetworkMappigInfoFound.VMSubnetInfo.ForEach(subnet => { subnet.VMSubnetName = string.Empty; subnet.VMSubnetVlanId = 0; }); vmnetworkMappigInfoFound.Description = "VM Network corresponding to this VTN is not created on SCVMM"; vmnetworkFound.Name = vmnetworkMappigInfoFound.VTNName; vmnetworkFound.RoutingDomainId = null; vmnetworkFound.OwnerName = string.Empty; } string output = "\"VMNetwork\":" + JavaScriptSerializer.Serialize(vmnetworkFound); string outputMappingInfo = "\"VMNetworkInfo\":" + JavaScriptSerializer.Serialize(vmnetworkMappigInfoFound); ODLVSEMETW.EventWriteEndLibrary(MethodBase.GetCurrentMethod().Name, output); return(needRefresh); }
/// <summary> /// Update the specified IP Address Pool with the specified info. /// </summary> /// <param name="txnMng">Transaction manager.</param> /// <param name="name">Name of IP Address Pool.</param> /// <param name="description">Description for IP address Pool.</param> /// <param name="subnet">IP address subnet.</param> /// <param name="addressStart">Starting address for IP Address Pool.</param> /// <param name="addressEnd">Ending address for IP Address Pool.</param> /// <param name="gatewayInfo">Network gateway info.</param> /// <param name="conn">VSEM connection object.</param> /// <param name="ipAddressPoolId">IP address pool.</param> /// <returns>Updated IP address pool.</returns> public IPAddressPool UpdateIpAddressPool(TransactionManager txnMng, string name, string description, string subnet, string addressStart, string addressEnd, NetworkGatewayInfo[] gatewayInfo, VSEMConnection conn, Guid ipAddressPoolId) { var JavaScriptSerializer = new JavaScriptSerializer(); JavaScriptSerializer.MaxJsonLength = int.MaxValue; StringBuilder json = new StringBuilder("\"txnMng\":" + JavaScriptSerializer.Serialize(txnMng)); json.Append(" \"gatewayInfo\":" + JavaScriptSerializer.Serialize(gatewayInfo)); json.Append("\"name\":\"" + name + "\""); json.Append("\"description\":\"" + description + "\""); json.Append("\"subnet\":\"" + subnet + "\""); json.Append("\"addressStart\":\"" + addressStart + "\""); json.Append("\"addressEnd\":\"" + addressEnd + "\""); json.Append("\"ipAddressPoolId\":\"" + ipAddressPoolId + "\""); ODLVSEMETW.EventWriteStartLibrary(MethodBase.GetCurrentMethod().Name, json.ToString()); if (txnMng == null) { ODLVSEMETW.EventWriteArgumentError( MethodBase.GetCurrentMethod().DeclaringType.Name.ToString(), MethodBase.GetCurrentMethod().Name, "The parameter 'txnMng' is null or invalid."); throw new ArgumentException("The parameter 'txnMng' is null or invalid."); } if (conn == null) { ODLVSEMETW.EventWriteArgumentError( MethodBase.GetCurrentMethod().DeclaringType.Name.ToString(), MethodBase.GetCurrentMethod().Name, "The parameter 'conn' is null or invalid."); throw new ArgumentException("The parameter 'conn' is null or invalid."); } if (name != null) { if (string.IsNullOrWhiteSpace(name)) { ODLVSEMETW.EventWriteArgumentError( MethodBase.GetCurrentMethod().DeclaringType.Name.ToString(), MethodBase.GetCurrentMethod().Name, "The parameter 'name' is invalid."); throw new ArgumentException( "The parameter 'name' is invalid."); } } string VtnHostName = this.ConnectionString; if (VtnHostName.StartsWith(@"https://", StringComparison.Ordinal)) { VtnHostName = VtnHostName.Substring(8); } VtnHostName = VtnHostName.Split('.', ':').First(); var vMNetworkConfig = new VMNetworkConfig(VtnHostName); txnMng.SetConfigManager(vMNetworkConfig, TransactionManager.OpenMode.WriteMode); if (vMNetworkConfig.VMNetwork.VMNetworkMappingInformation.VMNetworkInfo.Count == 0) { ODLVSEMETW.EventWriteConfigManagerFileIOError(MethodBase.GetCurrentMethod().Name, string.Format(CultureInfo.CurrentCulture, "VMNetwork.config {0}", configFileIOErrorValidationMessage)); throw new InvalidOperationException( string.Format(CultureInfo.CurrentCulture, "VMNetwork.config {0}", configFileIOErrorValidationMessage)); } VMSubnet vmNetDefFrom = null; IPAddressPool pool = null; foreach (var vmNet in vMNetworkConfig.VMNetwork.VmNetworks) { foreach (var vmNetDef in vmNet.VMSubnets) { if (vmNetDef.IPSubnets != null) { foreach (var ipsunet in vmNetDef.IPSubnets) { pool = ipsunet.IPAddressPools.FirstOrDefault(p => p.Id == ipAddressPoolId); if (pool != null) { vmNetDefFrom = vmNetDef; break; } } } if (vmNetDefFrom != null) { break; } } if (vmNetDefFrom != null) { break; } } if (vmNetDefFrom == null) { ODLVSEMETW.EventWriteValidateIPAddressPoolError( MethodBase.GetCurrentMethod().Name, string.Format(CultureInfo.CurrentCulture, "IP Address Pool '{0}' not found.", ipAddressPoolId)); throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, "IP Address Pool '{0}' not found.", ipAddressPoolId)); } this.SyncVMSubnet(vmNetDefFrom.Id, vMNetworkConfig); if (pool != null) { // Update the IP Address Pool if (name != null) { pool.Name = name; } if (description != null) { pool.Description = description; } if (subnet != null) { pool.IPAddressSubnet = subnet; } if (addressStart != null) { pool.AddressRangeStart = addressStart; } if (addressEnd != null) { pool.AddressRangeEnd = addressEnd; } if (gatewayInfo != null) { pool.NetworkGateways = gatewayInfo; } string error = Validations.IsIPSubnetListValid( vmNetDefFrom.IPSubnets.ToList(), ipAddressPoolId); if (!string.IsNullOrEmpty(error)) { ODLVSEMETW.EventWriteValidateVMNetDefinitionError( MethodBase.GetCurrentMethod().Name, error); throw new ArgumentException(error); } } string output = "\"pool\":" + JavaScriptSerializer.Serialize(pool); ODLVSEMETW.EventWriteEndLibrary(MethodBase.GetCurrentMethod().Name, output); return(pool); }
/// <summary> /// Remove the specified IP Address Pool. /// </summary> /// <param name="txnMng">Transaction manager.</param> /// <param name="id">ID of IP Address Pool to remove.</param> /// <param name="conn">Connecion object.</param> /// <returns>True if successful, else false.</returns> public bool RemoveIpAddressPool(TransactionManager txnMng, Guid id, VSEMConnection conn) { var JavaScriptSerializer = new JavaScriptSerializer(); JavaScriptSerializer.MaxJsonLength = int.MaxValue; StringBuilder json = new StringBuilder("\"txnMng\":" + JavaScriptSerializer.Serialize(txnMng)); json.Append("\"id\":\"" + id + "\""); ODLVSEMETW.EventWriteStartLibrary(MethodBase.GetCurrentMethod().Name, string.Empty); ODLVSEMETW.EventWriteRemoveIpAddressPool(MethodBase.GetCurrentMethod().Name, "Removing IP Address pool."); if (txnMng == null) { ODLVSEMETW.EventWriteArgumentError( MethodBase.GetCurrentMethod().DeclaringType.Name.ToString(), MethodBase.GetCurrentMethod().Name, "The parameter 'txnMng' is null or invalid."); throw new ArgumentException("The parameter 'txnMng' is null or invalid."); } if (id == Guid.Empty) { ODLVSEMETW.EventWriteArgumentError( MethodBase.GetCurrentMethod().DeclaringType.Name.ToString(), MethodBase.GetCurrentMethod().Name, "The parameter 'txnMng' is null or invalid."); throw new ArgumentException("The parameter 'txnMng' is null or invalid."); } if (conn == null) { ODLVSEMETW.EventWriteArgumentError( MethodBase.GetCurrentMethod().DeclaringType.Name.ToString(), MethodBase.GetCurrentMethod().Name, "The parameter 'txnMng' is null or invalid."); throw new ArgumentException("The parameter 'txnMng' is null or invalid."); } string VtnHostName = this.ConnectionString; if (VtnHostName.StartsWith(@"https://", StringComparison.Ordinal)) { VtnHostName = VtnHostName.Substring(8); } VtnHostName = VtnHostName.Split('.', ':').First(); var vMNetworkConfig = new VMNetworkConfig(VtnHostName); txnMng.SetConfigManager(vMNetworkConfig, TransactionManager.OpenMode.WriteMode); foreach (var vmNet in vMNetworkConfig.VMNetwork.VmNetworks) { foreach (var vmNetDef in vmNet.VMSubnets) { if (vmNetDef.IPSubnets != null) { foreach (var ipsunet in vmNetDef.IPSubnets) { var pool = ipsunet.IPAddressPools.FirstOrDefault(p => p.Id == id); if (pool != null) { var pools = ipsunet.IPAddressPools.ToList(); pools.Remove(pool); ipsunet.IPAddressPools = pools.ToArray(); ipsunet.LastModifiedTimeStamp = DateTime.Now; string output = "\"output\":" + JavaScriptSerializer.Serialize(true); ODLVSEMETW.EventWriteEndLibrary(MethodBase.GetCurrentMethod().Name, output); return(true); } } } } } string outputLib = "\"output\":" + JavaScriptSerializer.Serialize(false); ODLVSEMETW.EventWriteEndLibrary(MethodBase.GetCurrentMethod().Name, outputLib); return(false); }
/// <summary> /// Create a new VM network with specified parameters using VTN on demand. /// </summary> /// <param name="txnMng">Transaction manager.</param> /// <param name="vMSubnetName">Name of VM Subnet to create.</param> /// <param name="vMNetworkName">Name of VM network to create.</param> /// <param name="maxNumberOfPorts">Maximum number of ports.</param> /// <param name="ipSubnets">IP pools to use.</param> /// <param name="logicalNetworkDefinitionId">ID of logical network definition /// to associate with.</param> /// <param name="connection">VSEM connection.</param> /// <param name="vtnName">VTN name.</param> /// <returns>VM network if successful, else null.</returns> public VMNetwork CreateVMNetwork(TransactionManager txnMng, string vMSubnetName, string vMNetworkName, long?maxNumberOfPorts, IPSubnet[] ipSubnets, Guid logicalNetworkDefinitionId, VSEMConnection connection, out string vtnName) { var JavaScriptSerializer = new JavaScriptSerializer(); JavaScriptSerializer.MaxJsonLength = int.MaxValue; StringBuilder json = new StringBuilder("\"txnMng\":" + JavaScriptSerializer.Serialize(txnMng)); json.Append(" \"ipSubnets\":" + JavaScriptSerializer.Serialize(ipSubnets)); json.Append("\"maxNumberOfPorts\":\"" + maxNumberOfPorts + "\""); json.Append("\"vMNetworkName\":\"" + vMNetworkName + "\""); json.Append("\"vMSubnetName\":\"" + vMSubnetName + "\""); json.Append("\"logicalNetworkDefinitionId\":\"" + logicalNetworkDefinitionId + "\""); ODLVSEMETW.EventWriteStartLibrary(MethodBase.GetCurrentMethod().Name, 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."); } if (string.IsNullOrEmpty(vMNetworkName)) { ODLVSEMETW.EventWriteArgumentError( MethodBase.GetCurrentMethod().DeclaringType.Name.ToString(), MethodBase.GetCurrentMethod().Name, "The parameter 'vMNetworkName' is null or invalid."); throw new ArgumentException("The parameter 'vMNetworkName' is null or invalid."); } if (logicalNetworkDefinitionId == Guid.Empty) { ODLVSEMETW.EventWriteArgumentError( MethodBase.GetCurrentMethod().DeclaringType.Name.ToString(), MethodBase.GetCurrentMethod().Name, "The parameter 'logicalNetworkDefinitionId' is null or invalid."); throw new ArgumentException( "The parameter 'logicalNetworkDefinitionId' is null or invalid."); } if (connection == null) { ODLVSEMETW.EventWriteArgumentError( MethodBase.GetCurrentMethod().DeclaringType.Name.ToString(), MethodBase.GetCurrentMethod().Name, "The parameter 'connection' is null or invalid."); throw new ArgumentException("The parameter 'connection' is null or invalid."); } string VtnHostName = this.ConnectionString; if (VtnHostName.StartsWith(@"https://", StringComparison.Ordinal)) { VtnHostName = VtnHostName.Substring(8); } VtnHostName = VtnHostName.Split('.', ':').First(); var vMNetworkConfig = new VMNetworkConfig(VtnHostName); txnMng.SetConfigManager(vMNetworkConfig, TransactionManager.OpenMode.WriteMode); var LogicalNetworkConfig = new LogicalNetworkConfig(VtnHostName); txnMng.SetConfigManager(LogicalNetworkConfig, TransactionManager.OpenMode.ReadMode); if (LogicalNetworkConfig.LogicalNetworks.Count == 0) { ODLVSEMETW.EventWriteConfigManagerFileIOError( MethodBase.GetCurrentMethod().Name, string.Format(CultureInfo.CurrentCulture, "LogicalNetwork.config {0}", configFileIOErrorValidationMessage)); throw new InvalidOperationException( string.Format(CultureInfo.CurrentCulture, "LogicalNetwork.config {0}", configFileIOErrorValidationMessage)); } var logicalNetName = VSEMODLConstants.LOGICAL_NETWORK_NAME; logicalNetName += VtnHostName; var fabricNwDef = LogicalNetworkConfig.LogicalNetworks.First( log => log.Name.Equals(logicalNetName)).LogicalNetworkDefinitions.FirstOrDefault( fabnw => fabnw.Id == logicalNetworkDefinitionId); if (fabricNwDef == null) { ODLVSEMETW.EventWriteGetFabricNetworkDefinitionError( MethodBase.GetCurrentMethod().Name, string.Format(CultureInfo.CurrentCulture, "Logical network definition '{0}' not found.", logicalNetworkDefinitionId.ToString("B"))); throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, "Logical network definition '{0}' not found.", logicalNetworkDefinitionId.ToString("B"))); } ODLVSEMETW.EventWriteReturnLibrary(string.Format(CultureInfo.CurrentCulture, "VSEMLogicalNetworkDefinition is retrieved by ID: {0}", logicalNetworkDefinitionId.ToString("B")), string.Empty); if (!fabricNwDef.SupportsVMNetworkProvisioning) { ODLVSEMETW.EventWriteSupportsVMNetworkProvisioningError( "Logical network does not support VM network creation.", string.Empty); throw new InvalidOperationException( "Logical network does not support VM network creation."); } vtnName = this.CreateUniqueNameForVTN(vMNetworkName); Vtn vtn = new Vtn(this.ConnectionString, this.Credential); vtn.AddVtn(vtnName); ODLVSEMETW.EventWriteReturnODLLibrary(string.Format(CultureInfo.CurrentCulture, "VTN '{0}' is created", vtnName), string.Empty); VMNetwork vmNet = CreateVtnVmNetwork(vMNetworkName); vmNet.LogicalNetwork = fabricNwDef.LogicalNetworkId; if (vmNet == null) { ODLVSEMETW.EventWriteProcessFailedVMNetworkError( MethodBase.GetCurrentMethod().Name, "Failed to create VM Network."); throw new InvalidOperationException("Failed to create VM Network."); } ODLVSEMETW.EventWriteSuccessVmNetwork(MethodBase.GetCurrentMethod().Name, "VM Network Successfully Created."); // Create the VM Subnet vMNetworkConfig.VMNetwork.VmNetworks.Add(vmNet); if (vMNetworkConfig.VMNetwork.VMNetworkMappingInformation.VMNetworkInfo == null) { vMNetworkConfig.VMNetwork.VMNetworkMappingInformation.VMNetworkInfo = new List <VMNetworkInfo>(); } vMNetworkConfig.VMNetwork.VMNetworkMappingInformation.VMNetworkInfo.Add( new VMNetworkInfo { VMNetworkID = vmNet.Id, VMNetworkName = vmNet.Name, VTNName = vtnName, VMSubnetInfo = new List <VMSubnetInfo>(), CreatedFrom = "SCVMM", VMNetworkOriginalName = vmNet.Name }); var vsemvmnetworkDefinition = new VSEMVMSubnetManagement( this.ConnectionString, this.Credential); ODLVSEMETW.EventWriteCreateVMsubNetwork(MethodBase.GetCurrentMethod().Name, "VM Sub Network creation process started."); string vbrName = string.Empty; VMSubnet vmNetworkDef = vsemvmnetworkDefinition.CreateVMNetworkDefinitionforVtn( txnMng, LogicalNetworkConfig, vMNetworkConfig, vMSubnetName, vmNet.Id, maxNumberOfPorts, ipSubnets, logicalNetworkDefinitionId, connection, out vtnName, out vbrName); Controller odl = new Controller(this.ConnectionString, this.Credential); odl.UpdateStartupConfiguration(); string output = "\"vmNet\":" + JavaScriptSerializer.Serialize(vmNet); ODLVSEMETW.EventWriteReturnODLLibrary("Return from ODL Library.", output); ODLVSEMETW.EventWriteEndLibrary(MethodBase.GetCurrentMethod().Name, output); return(vmNet); }