Im trying to create VM's from a template in my ASP.NET MVC web application. So I wrote an action is structured in 4 steps (I added some comments to make it more understandable)
[HttpPost]
public ActionResult QuickCreateVM(string VirtualMachineName, string OSImage, string Username, string Password)
{
string Location = "North Europe";
string StorageAccountName = "azuremanagersharepoint";
try
{
ComputeManagementClient client = new ComputeManagementClient(cloudCredentials);
string vmName = VirtualMachineName;
//STEP1:Create Hosted Service
//Azure VM must be hosted in a hosted cloud service.
createCloudService(vmName, Location);
//STEP2:Construct VM Role instance
var vmRole = new Role();
vmRole.RoleType = VirtualMachineRoleType.PersistentVMRole.ToString();
vmRole.RoleName = vmName;
vmRole.Label = vmName;
vmRole.RoleSize = VirtualMachineRoleSize.Small;
vmRole.ConfigurationSets = new List<ConfigurationSet>();
vmRole.OSVirtualHardDisk = new OSVirtualHardDisk()
{
MediaLink = getVhdUri(string.Format("{0}.blob.core.windows.net/uploads", StorageAccountName)),
SourceImageName = OSImage
};
ConfigurationSet configSet = new ConfigurationSet
{
ConfigurationSetType = ConfigurationSetTypes.WindowsProvisioningConfiguration,
EnableAutomaticUpdates = true,
ResetPasswordOnFirstLogon = false,
ComputerName = vmName,
AdminUserName = Username,
AdminPassword = Password,
InputEndpoints = new BindingList<InputEndpoint>
{
new InputEndpoint { LocalPort = 3389, Port = 3389, Name = "Remote Desktop", Protocol = "TCP", EnableDirectServerReturn = true }
}
};
vmRole.ConfigurationSets.Add(configSet);
vmRole.ResourceExtensionReferences = null;
//STEP3: Add Role instance to Deployment Parmeters
List<Role> roleList = new List<Role>() { vmRole };
VirtualMachineCreateDeploymentParameters createDeploymentParams = new VirtualMachineCreateDeploymentParameters
{
Name = vmName,
Label = vmName,
Roles = roleList,
DeploymentSlot = DeploymentSlot.Production
};
//STEP4: Create a Deployment with VM Roles.
client.VirtualMachines.CreateDeployment(vmName, createDeploymentParams);
}
catch (CloudException e)
{
throw e;
}
catch (Exception ex)
{
throw ex;
}
return View("Panel");
}
My problem: It seems like my VM has no endpoint. Although the ConfigurationSet was configured correctly. So, in my code I say
new InputEndpoint { LocalPort = 3389, Port = 3388, Name = "Remote Desktop", Protocol = "TCP", EnableDirectServerReturn = true }
But in the azure portal So I'm not able to start the Vm. Has anyone an idea what I'm missing? Or are there any good tutorials to this topic? Thank you in advance
Ok, so I had the exact same issue and figured out the problem.
You need to create an additional ConfigurationSet
with a ConfigurationSetType
of ConfigurationSetTypes.NetworkConfiguration
, and then add your endpoints in there.
Something like this:
ConfigurationSet networkConfigSet = new ConfigurationSet
{
ConfigurationSetType = ConfigurationSetTypes.NetworkConfiguration,
InputEndpoints = new BindingList<InputEndpoint>
{
new InputEndpoint { LocalPort = 3389, Port = 3389, Name = "Remote Desktop", Protocol = "TCP", EnableDirectServerReturn = true }
}
};
vmRole.ConfigurationSets.Add(networkConfigSet);
See here:
https://msdn.microsoft.com/en-us/library/azure/jj157194.aspx
...specifically the ConfigurationSets section.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.