Azure Management API - Create VMImage - InvalidXmlRequest - The request body XML was invalid or not correctly specified

I'm hoping someone can put me in the right direction regarding creating a VM Image via the service management REST API. Everything I've tried has led me to get back a 400 InvalidXmlRequest error which states that "The request body's XML was invalid or not correctly specified."

Assume that I have a properly provisioned subscription, storage account, container, and blob. I've been sending a properly authenticated POST request with the x-ms-version: 2014-06-01 header to the https://management.core.windows.net/[OmittedSubscriptionId]/services/vmimages API with the following XM in the body:

<VMImages xmlns="http://schemas.microsoft.com/windowsazure" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
    <VMImage>
        <Name>my_image_20141120_service_sa01</Name>
        <Label>my_Image_20141120_service_SA01</Label>
        <Description>testimage</Description>
        <OSDiskConfiguration>
            <HostCaching>ReadWrite</HostCaching>
            <OSState>Specialized</OSState>
            <OS>Windows</OS>
            <MediaLink>https://myservicesa.blob.core.windows.net/vhds/myimage_20141120.vhd</MediaLink>
        </OSDiskConfiguration>
    </VMImage>
</VMImages>

Per the instructions here http://msdn.microsoft.com/en-us/library/dn775054.aspx, I've specified all the required bits so I’m not sure what is invalid about the xml I'm sending. Any help would be greatly appreciated!

Upvotes: 0

Views: 324

Answers (3)

The documentation is incorrect and we apologize for any inconvenience this caused. The request should work if you change it to:

<VMImage xmlns="http://schemas.microsoft.com/windowsazure" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
    <Name>my_image_20141120_service_sa01</Name>
    <Label>my_Image_20141120_service_SA01</Label>
    <Description>testimage</Description>
    <OSDiskConfiguration>
        <HostCaching>ReadWrite</HostCaching>
        <OSState>Specialized</OSState>
        <OS>Windows</OS>
        <MediaLink>https://myservicesa.blob.core.windows.net/vhds/myimage_20141120.vhd</MediaLink>
    </OSDiskConfiguration>
</VMImage>

There are two types of images that can be used to create virtual machines. OS Images are always generalized and do not maintain a previous state of the originating machine. VM Images can be specialized and maintain the state of attached data disks.

There are two sets of REST operations that can be used Operations on Operating System Images and Operations on Virtual Machine Images.

When using PowerShell, I believe that you use Add-AzureVMImage to create an OS Image and you use Save-AzureVMImage with the -OSState parameter to create a VM Image.

Also not mentioned in the documentation, is that the Create VM Image operation is asynchronous, so the Get Operation Status operation needs to be used to get the status of the image creation. The documentation will be corrected soon.

Upvotes: 2

proteus
proteus

Reputation: 505

Modify the payload as such and it should work.

<VMImage xmlns="http://schemas.microsoft.com/windowsazure" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
    <Name>my_image_20141120_service_sa01</Name>
    <Label>my_Image_20141120_service_SA01</Label>
    <Description>testimage</Description>
    <OSDiskConfiguration>
        <HostCaching>ReadWrite</HostCaching>
        <OSState>Specialized</OSState>
        <OS>Windows</OS>
        <MediaLink>https://myservicesa.blob.core.windows.net/vhds/myimage_20141120.vhd</MediaLink>
    </OSDiskConfiguration>
</VMImage>

POST it on

https://management.core.windows.net/[OmittedSubscriptionId]/services/vmimages

Upvotes: 0

Thanks astaykov, looking at the traffic from PowerShell was an excellent idea. Turns out the documentation is totally wrong for this API! Not only is the XML payload completely different, the API itself is different. The actual API endpoint that needs to get called is:

https://management.core.windows.net/[OmittedSubscriptionId]/services/images 

Note it's "images" vs "vmimages"

The body of the POST should be as follows:

<OSImage xmlns="http://schemas.microsoft.com/windowsazure">
    <Label>identifier-of-image</Label>
    <MediaLink>uri-to-vhd</MediaLink>
    <Name>name-of-image</Name>
    <OS>Opearting-System</OS>
    <IsPremium>bool</IsPremium>
    <ShowInGui>bool</ShowInGui>
</OSImage>

Upvotes: 0

Related Questions