Azure Create VirtualMachine/Deployment REST API

user3347810 Source

I am trying to create a Virtual Machine through the REST API, using the .NET Management Library but I am always getting to the same error. I tried with both the CreateDeployment and CreateAsync of the VirtualMachines operations, but both lead to the same result. Here's the code:

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"
            });

Both the CloudService and the Disk are existing (I can even get them through the API). The error that I am getting is:

BadRequest: ProvisioningConfigurationSet is found in ConfigurationSet collection of the virtual machine with name testMachine. When provisioning a virtual machine from an OS disk, ProvisioningConfigurationSet must not be specified.

I tried removing both the OSVirtualHardDisk and the ConfigurationSetType paremeters, but then I am getting errors that they are both required. So it seems that the API is telling me the two parameters are both required but cannot exist together at the same time. Any help would be highly appreciated.

azure

Answers

answered 4 years ago user3347810 #1

The problem was that the "ConfigurationSets" parameter itself was required, not the ConfigurationSetType. So, after creating an empty ConfigurationSets element, all works fine: ConfigurationSets = new List<ConfigurationSet>()

comments powered by Disqus