簡體   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