Azure / azure-sdk-for-net

This repository is for active development of the Azure SDK for .NET. For consumers of the SDK we recommend visiting our public developer docs at https://learn.microsoft.com/dotnet/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-net.
MIT License
5.35k stars 4.66k forks source link

Creating a cloud service fails with "BadRequest: The condition specified by the ETag is not satisfied." #879

Closed ghost closed 6 years ago

ghost commented 9 years ago

Just installed this Git package and tried to create a CloudService. Using the provided example for creating a storage account I inferred what would be required for CloudService creation and wrote the following:

using (CloudServiceManagementClient client = CloudContext.Clients.CreateCloudServiceManagementClient(credentials))
{
    await client.CloudServices.CreateAsync(
        cloudServiceName,
        new CloudServiceCreateParameters
        {
            Label = cloudServiceName.ToBase64(),
            GeoRegion = LocationNames.EastUS,
            Description = cloudServiceName
        });
}

Unfortunately I get an error back stating that the etag is not satisfied. I have a few questions that hopefully someone can answer: 1) How does one determine what conditions are in place by this etag and how to meet them? 2) Why does the PUT body of the XML that's sent with this request not contain the cloudServiceName parameter that I've passed in?

Also for what its worth I wrote a quick app to directly invoke the REST API via the documentation here (http://msdn.microsoft.com/en-us/library/gg441304.aspx) and I'm a bit confused why the documentation is so different from what the library is actually doing. For instance the MSDN article says send a POST to /[subscription-id]/services/hostedservices where as the library is sending a PUT to /[subscription-id]/CloudServices. Another key difference is the XML that's being sent. Per the MSDN article I've posted

<CreateHostedService xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/windowsazure">
    <ServiceName>[servicename]</ServiceName>
    <Label>[Base64(servicename)]</Label>
    <Location>East US</Location>
</CreateHostedService>

And the library puts

<CloudService xmlns="http://schemas.microsoft.com/windowsazure">
  <Label>[Base64(servicename)]</Label>
  <Description>[description]</Description>
  <GeoRegion>East US</GeoRegion>
</CloudService>

Any help here would be greatly appreciated.

markcowl commented 9 years ago

Thank you for the report of this issue, assigning to the area owner

vivsriaus commented 9 years ago

@cbroussa Apologize for the delay here. The MSDN article you linked in the comment above is for creating a hosted service (exposed as cloud service in management portal) in Azure. The CloudServiceManagement client is used to create a "cloud service" that is only meant to be internally used by Azure Resource Providers, like Scheduler for instance. More info on this is here: https://msdn.microsoft.com/en-us/library/azure/dn528943.aspx

To create the above cloud service using CloudServiceManagementClient, use this as an example:

CertificateCloudCredentials certCloudCredentials = new CertificateCloudCredentials("subId", new System.Security.Cryptography.X509Certificates.X509Certificate2("MyManagemetCert.pfx", "[redacted]", X509KeyStorageFlags.PersistKeySet | X509KeyStorageFlags.Exportable));

        CloudServiceManagementClient csmClient = new CloudServiceManagementClient(certCloudCredentials);
shahabhijeet commented 6 years ago

please reopen if this is still an issue.