Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't pass parameters to method #12

Closed
kevinmccarthy opened this issue May 7, 2018 · 5 comments
Closed

Can't pass parameters to method #12

kevinmccarthy opened this issue May 7, 2018 · 5 comments

Comments

@kevinmccarthy
Copy link

Looks like method invocation is not slotting arguments into SOAP document properly.

Example:

// list all files in a given datastore
async function listFiles( client, datastore ) {
    let flags = {
        fileSize: true,
        fileType:  true,
        modification: true
    };
    let spec = {
        details: flags
    }
    let moref = await vconnect.util.moRef( 'HostDatastoreBrowser', datastore.browser );
    return await client.method( 'SearchDatastore_Task', {
        _this: moref,
        dataStorePath: '/',
        searchSpec: spec
    }).then(function(result) {
        console.log( "Found " + results.length + " files on " + datastore.name );
        return results;
    }).caught(function(err) {
        console.error( "Can't list files: " err );
        throw(err);
    });
}

Returns this:

Can't list files: {"errorCode":400,"message":"Got <dataStorePath> tag when expecting <_this> tag\n\nwhile parsing call information for method SearchDatastore_Task\nat line 1, column 281\n\nwhile parsing SOAP body\nat line 1, column 270\n\nwhile parsing SOAP envelope\nat line 1, column 38\n\nwhile parsing HTTP request for method search\non object of type vim.host.DatastoreBrowser\nat line 1, column 0"}
@kevinmccarthy
Copy link
Author

User error. :) dataStorePath is invalid -- needed to be datastorePath

@kevinmccarthy
Copy link
Author

I am not able to specify the enumerated /dynamic types. For instance:
https://pubs.vmware.com/vi3/sdk/ReferenceGuide/vim.host.DatastoreBrowser.Query.html

the FileFolderQuery is simply a marker (has no attributes or members), but I method.js does not seen to be able to map 'FileFolderQuery', ['FileFolderQuery'], or { FileFolderQuery: null } into that dynamic type definition.

Is there any way to specify this using a typing function?

@kevinmccarthy
Copy link
Author

kevinmccarthy commented Jun 1, 2018

This also does not work:

const spec = {
    query: vconnect.util.sType('FolderFileQuery'),
    details: {
        fileOwner: false,
        fileSize: true,
        fileType:  false,
        modification: true
    }
};

I noticed the type is defined in the vsphere-schema instance, but still don't see any docs on how to resolve it.

"FolderFileQuery": {
    "type": "FolderFileQuery",
    "inherits": "FileQuery"
  },

@bhoriuchi
Copy link
Owner

bhoriuchi commented Jun 1, 2018

It looks like you are using the v1 code which is no longer in development. In the v2 code which is currently in development you can accomplish this similar to https://github.com/bhoriuchi/vsphere-connect/blob/master/src/spec/VirtualMachine.js#L163 . The v2 api is documented http://bhoriuchi.github.io/vsphere-connect/#/api

If you absolutely need to use the v1 code which uses the node-soap library you can specify an attributes property with the xsi type like here https://github.com/bhoriuchi/vsphere-connect/blob/v1/lib/specUtil.js#L18-L20

@kevinmccarthy
Copy link
Author

This seems to work:

const spec = {
    details: {
        fileOwner: false,
        fileSize: true,
        fileType:  false,
        modification: true
    },
    query: {
        attributes: {
            'xsi:type': 'FolderFileQuery'
        }
    }
};

Thanks! I will upgrade to v2 shortly, but the v1 fix is super helpful!

Regards,
Kevin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants