VMware Cloud Community
sarin1
Contributor
Contributor

Unable to Add a Datastore using the Vsphere Api CreateVmfsDatastore : Error returned by expat parser: not well-formed (invalid token)

I am trying to call the Vsphere Api (6.5.0) CreateVmfsDatastore method in javascript  in order to Add a Datastoreand am getting an Invalid request with the following error:

<?xml version="1.0" encoding="UTF-8"?>

<soapenv:Envelope xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"

xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"

xmlns:xsd="http://www.w3.org/2001/XMLSchema"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

    <soapenv:Body>

        <soapenv:Fault>

            <faultcode>ServerFaultCode</faultcode>

            <faultstring>

Error returned by expat parser: not well-formed (invalid token)

while parsing property &quot;totalSectors&quot; of static type long

while parsing serialized DataObject of type vim.host.DiskPartitionInfo.Specification at line 1, column 527

while parsing property &quot;partition&quot; of static type HostDiskPartitionSpec

while parsing serialized DataObject of type vim.host.VmfsDatastoreCreateSpec at line 1, column 385

while parsing call information for method CreateVmfsDatastore at line 1, column 243

while parsing SOAP body at line 1, column 232

while parsing SOAP envelope at line 1, column 0 while parsing HTTP request for method createVmfsDatastore

on object of type vim.host.DatastoreSystem at line 1, column 0</faultstring>

            <detail>

                <InvalidRequestFault xmlns="urn:vim25" xsi:type="InvalidRequest"></InvalidRequestFault>

            </detail>

        </soapenv:Fault>

    </soapenv:Body>

</soapenv:Envelope>

I am passing the following json to the method of which the spec property has been returned from calling the QueryVmfsDatastoreCreateOptions method:

{

    "_this": {

        "attributes": {

            "type": "HostDatastoreSystem"

        },

        "$value": "datastoreSystem-379"

    },

    "spec": {

        "attributes": {

            "xsi:type": "VmfsDatastoreCreateSpec"

        },

        "diskUuid": "0100000000533352304e42304a38313532353541202020202053616d73756e",

        "partition": {

            "partitionFormat": "gpt",

            "chs": {

                "cylinder": "30401",

                "head": "255",

                "sector": "63"

            },

            "totalSectors": "488397168",

            "partition": {

                "partition": "1",

                "startSector": "2048",

                "endSector": "488396799",

                "type": "vmfs",

                "logical": "false",

                "attributes": "0",

                "partitionAlignment": "1048576"

            }

        },

        "vmfs": {

            "extent": {

                "diskName": "t10.ATA_____Samsung_SSD_850_EVO_250GB_______________S3R0NB0J815255A_____",

                "partition": "1"

            },

            "blockSizeMb": "1",

            "majorVersion": "5",

            "volumeName": "test",

            "blockSize": "1024",

            "unmapGranularity": "1024",

            "unmapPriority": "low"

        }

    }

}

Any ideas why it can't deserialise a number or what the problem could be?

Cheers

Reply
0 Kudos
1 Reply
sarin1
Contributor
Contributor

Found the issue in the javascript npm package we were using to communicate to vsphere (node-vsphere and node-vsphere-soap). It turns out that the package is reserving usage of properties called 'attributes' and is replacing them with the XML object Type for the parser. This was effectively overwriting our attributes property. Vsphere was getting incorrect XML and spitting back an error roughly in the same place as the problem. We have a work around for the moment specifying the XML, but ultimately the package needs to be updated or an alternative used.

https://github.com/reedog117/node-vsphere/issues/11

Cheers

Reply
0 Kudos