我正在尝试使用.NET管理库通过REST API创建虚拟机,但我总是遇到同样的错误。我尝试使用VirtualMachines操作的CreateDeployment和CreateAsync,但两者都导致相同的结果。 这是代码:
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"
});
CloudService和磁盘都存在(我甚至可以通过API获取它们)。我得到的错误是:
BadRequest:ProvisioningConfigurationSet位于名为testMachine的虚拟机的ConfigurationSet集合中。从OS磁盘配置虚拟机时,不得指定ProvisioningConfigurationSet。
我尝试删除OSVirtualHardDisk和ConfigurationSetType参数,但后来我发现错误都是必需的。因此,似乎API告诉我两个参数都是必需的,但不能同时存在。 任何帮助将受到高度赞赏。
答案 0 :(得分:0)
问题是“ConfigurationSets”参数本身是必需的,而不是ConfigurationSetType。因此,在创建一个空的ConfigurationSets元素后,一切正常:
ConfigurationSets = new List<ConfigurationSet>()