Azure创建虚拟机/部署REST API
我试图使用.NET管理库通过RESTAPI创建一个虚拟机,但我总是遇到同样的错误。我尝试了VirtualMachines操作的CreateDeployment和CreateAsync,但都得到了相同的结果。 代码如下:Azure创建虚拟机/部署REST API,azure,Azure,我试图使用.NET管理库通过RESTAPI创建一个虚拟机,但我总是遇到同样的错误。我尝试了VirtualMachines操作的CreateDeployment和CreateAsync,但都得到了相同的结果。 代码如下: ComputeManagementClient computeClient = CloudContext.Clients.CreateComputeManagementClient(credentials); var status = await computeC
ComputeManagementClient computeClient = CloudContext.Clients.CreateComputeManagementClient(credentials);
var status = await computeClient.VirtualMachines.CreateDeploymentAsync("testClService",
new Microsoft.WindowsAzure.Management.Compute.Models.VirtualMachineCreateDeploymentParameters()
{
Name = "test-deployment",
Roles = new List<Role>
{
new Role(){
OSVirtualHardDisk = new OSVirtualHardDisk()
{
DiskName = "testDisk"
},
RoleType = "PersistentVMRole",
RoleName = "testMachine1",
RoleSize = "Medium",
ConfigurationSets = new List<ConfigurationSet>{ new ConfigurationSet()
{
AdminUserName = "ssadmin",
AdminPassword = "testp12334!",
ComputerName = "mycomptest",
ConfigurationSetType = "WindowsProvisioningConfiguration"
}}
}
},
DeploymentSlot = DeploymentSlot.Staging,
Label = "test-deploymentL"
});
ComputeManagementClient computeClient=CloudContext.Clients.CreateComputeManagementClient(凭证);
var status=await computeClient.VirtualMachines.CreateDeploymentAsync(“testClService”,
新的Microsoft.WindowsAzure.Management.Compute.Models.VirtualMachineCreateDeploymentParameters()
{
Name=“测试部署”,
角色=新列表
{
新角色(){
OSVirtualHardDisk=新的OSVirtualHardDisk()
{
DiskName=“testDisk”
},
RoleType=“PersistentVMRole”,
RoleName=“testMachine1”,
RoleSize=“中等”,
ConfigurationSets=新列表{new ConfigurationSet()
{
AdminUserName=“ssadmin”,
AdminPassword=“testp12334!”,
ComputerName=“mycomptest”,
ConfigurationSetType=“WindowsProvisioningConfiguration”
}}
}
},
DeploymentSlot=DeploymentSlot.Staging,
Label=“测试部署”
});
CloudService和磁盘都存在(我甚至可以通过API获得它们)。我得到的错误是:
BadRequest:ProvisioningConfigurationSet位于名为testMachine的虚拟机的ConfigurationSet集合中。从操作系统磁盘配置虚拟机时,不得指定ProvisioningConfigurationSet。
我尝试删除OSVirtualHardDisk和ConfigurationSetType参数表,但随后出现错误,它们都是必需的。因此,API似乎告诉我这两个参数都是必需的,但不能同时存在。
任何帮助都将不胜感激 问题在于“ConfigurationSets”参数本身是必需的,而不是ConfigurationSetType。因此,在创建一个空的ConfigurationSets元素之后,所有这些都可以正常工作:
ConfigurationSets=new List()