我试图从我的ASP.NET MVC Web应用程序中的模板创建VM。所以我写了一个动作是按照4个步骤构建的(我添加了一些注释以使其更容易理解)
[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");
}
我的问题:好像我的VM没有端点。尽管ConfigurationSet配置正确。所以,在我的代码中我说
new InputEndpoint { LocalPort = 3389, Port = 3388, Name = "Remote Desktop", Protocol = "TCP", EnableDirectServerReturn = true }
但是在天蓝色的门户网站上 所以我无法启动Vm。 有谁知道我错过了什么?或者这个主题有什么好的教程吗? 提前谢谢
答案 0 :(得分:0)
好的,所以我遇到了完全相同的问题并找出了问题。
您需要使用ConfigurationSet
ConfigurationSetType
创建额外的ConfigurationSetTypes.NetworkConfiguration
,然后在其中添加您的终结点。
这样的事情:
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);
见这里:
https://msdn.microsoft.com/en-us/library/azure/jj157194.aspx
...特别是 ConfigurationSets 部分。