繁体   English   中英

Azure虚拟机没有终结点

[英]Azure Virtual Machine has no endpoint

我试图从我的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。 有谁知道我想念的东西吗? 或是否有关于此主题的好的教程? 先感谢您

好的,所以我遇到了完全相同的问题,并找出了问题所在。

您需要使用ConfigurationSetTypeConfigurationSetTypes.NetworkConfiguration创建其他ConfigurationSet ,然后在其中添加端点。

像这样:

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部分。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM