Contributor
Contributor

A few problems with API

Hello.

I have a problem with getting reference to datastore and host. I could not find any method in SDK reference to find a datastore. How do I get a reference to a datastore? Also non of FineBy* fundcyion helped me to get a reference to a host. neither FindByIP nor FindByInventoryPath does not find my specific host. Another question is regarding OS customization via Api. CustomizationSpec class has a property called "encryptionkey". How should I fill it?

Best Regards.

0 Kudos
15 Replies
Virtuoso
Virtuoso

You probably don't have the actual inventory path, but FindByDnsName should work.

You can also build a traversal spec for datastores and get them.  You could also create a container view and specify datastores with the start entity being the root folder to get a list of all datastores.  From there, select specific datastore(s) from the results.

If you want a datastore in relation to a VM or host, both VirtualMachine and HostSystem objects have datastore properties that contain their related datastores.

As for the encryptionKey, never used it myself, but I believe it's related to vCenter.  Each vCenter encrypts the passwords of the customization spec using it's certificate.  I believe it's just there so vCenter can determine if the encrypted passwords are from it's own key or another key (and therefor unusable).

Reuben Stump | http://www.virtuin.com | @ReubenStump
0 Kudos
Contributor
Contributor

Hi.

For host, it worked. But for datastore, I could get reference to ithe datastore. In MOB it shows that there is a property for HostSystem called datastore which is an array of references to the each datastore. My following code shows I am doing it. Please see what wrong I am going.

$soap_message["_this"] = $service_instance->searchIndex;
$soap_message["ip"] = $server_ip;
$soap_message["vmSearch"] = false;
$result = $client->FindByIp($soap_message);

$host = $result->returnval;

$datastore = $host->datastore[0];

0 Kudos
Virtuoso
Virtuoso

The host you got from returnval is just the host MOREF.  You'll need to call RetrievePropertiesEx() or WaitForPropertiesEx() to get properties of the Host.  It's more complex to code, but it can be very efficient and powerful in larger VMware environments.

If you're looking for something that has more examples and a lot less raw-SOAP API formatting, I'd recommend getting the VI Perl Toolkit SDK and using an HTML templating kit for Perl.  It will be significantly easier.  You could also look at the Ruby binding for vSphere, it's a non-VMware library, but it's got some traction.  I do remember a PHP kit someone put together, but I don't think it was maintained.

Without some abstraction methods for the API similar to what Perl and other language bindings provide, you'll have to learn the raw internals of the API to work with it.

Reuben Stump | http://www.virtuin.com | @ReubenStump
0 Kudos
Contributor
Contributor

Hi

I used the following code:

$soap_message["_this"] = $host;
$result = $client->RetrievePropertiesEx($soap_message);
$datastore = $result->returnval->datastore;
print_r($datastore);

Then I got the following exception:

SoapFault exception: [Client] SOAP-ERROR: Encoding: object has no 'specSet' property

0 Kudos
Contributor
Contributor

Hi.

I managed to use the following code to retrive properties of host ad get its datastore property but I get the following Soap Fault

// Get datastore
$prop_set = array(new SoapVar(array('all' => true,
    'type' => "Datastore"
   ), SOAP_ENC_OBJECT, "PropertySpec"));

$spec_set = array(new SoapVar(array('propSet' => $prop_set,
    'reportMissing' => false
   ), SOAP_ENC_OBJECT, "PropertyFilterSpec"));

$soap_message["_this"] = $service_instance->propertyCollector;
$soap_message["specSet"] = $spec_set;
$soap_message["options"] = new SoapVar(array(), SOAP_ENC_OBJECT, "RetrieveOptions");
$result = $client->RetrievePropertiesEx($soap_message);
$datastore = $result->returnval;
print_r($datastore);

Error:

SoapFault exception: [ServerFaultCode] Required property type is missing from data object of type PropertySpec while parsing serialized DataObject of type vmodl.query.PropertyCollector.PropertySpec

What is wrong with my code?

Thanks in advance.

0 Kudos
Contributor
Contributor

Hi.

This is my code to retrieve 'datastore' property of a host but am presented with a soap exception which saus "required

$prop_set = array(new SoapVar(array('all' => true,
       'type' => "Datastore"
      ), SOAP_ENC_OBJECT, "PropertySpec"));

$spec_set = array(new SoapVar(array('propSet' => $prop_set,
    'reportMissing' => false
   ), SOAP_ENC_OBJECT, "PropertyFilterSpec"));

$soap_message["_this"] = $service_instance->propertyCollector;
$soap_message["specSet"] = $spec_set;
$soap_message["options"] = new SoapVar(array(), SOAP_ENC_OBJECT, "RetrieveOptions");
$result = $client->RetrievePropertiesEx($soap_message);
$datastore = $result->returnval;

print_r($datastore);

Where am I doing wrong? I have followed steps according to web service API reference.

Please assist me. I think retrieving the reference to datastore is the last thing I should provide in order to achieve my goal which is deploying, reconfiguring and customizing the guest OS all via API.

Thanks in advance.

0 Kudos
Contributor
Contributor

Please help me getting reference to datastore is the last point in my project. Please guide me.

0 Kudos
Contributor
Contributor

Please anyboday help me to come over this simple problem. Dear stumpr, please help me! Please!

0 Kudos
Virtuoso
Virtuoso

Can you post up your entire script?  I'll figure out the PropertySpec if I can from your existing work.  I don't have time to start from scratch at the moment.

Reuben Stump | http://www.virtuin.com | @ReubenStump
0 Kudos
Contributor
Contributor

Hi Dear,

Thanks for reply. I've attached the script. I'll highly appreciate if you can assist me to pass this phase of my project which I have stuck in.

You can download the script from the following link:

http://www.shetabrayan.com/vmware.zip

0 Kudos
Contributor
Contributor

Hi Dear stumpr,

Did you take a look at my code?

0 Kudos
Contributor
Contributor

Hi Dear,

Did you tried out my code to find out what's the problem?

0 Kudos
Contributor
Contributor

Hi.

I managed today to use Vmwarephp library to perform CloneVM task. I have supplied any required data and parameters but am continuously getting InvalidProperty error. Please see the following link:

http://www.shetabrayan.com/vmware/

Please help me to come over this problem.

0 Kudos
Virtuoso
Virtuoso

My apologies, with the holidays and vacation I haven't had time to dig into your code.  But if you found a functional wrapper library that should get you past some of the VI SDK SOAP complexities.

In terms of which property is causing your invalid property fault, take a look at the vpxd.log file.  It's location will vary depending on what OS you installed vCenter on, but generally if you execute your script then review the current vpxd log file, you'll get a more specific error message that will indicate which property caused the vCenter server to error.

Reuben Stump | http://www.virtuin.com | @ReubenStump
0 Kudos
Enthusiast
Enthusiast

Hello.

The message "Error:SoapFault exception: [ServerFaultCode] Required property type is missing from data object of type PropertySpec while parsing serialized DataObject of type vmodl.query.PropertyCollector.PropertySpec"

means that vSphere Server is expecting to find property "type" in your PropertySpec object. As your code contains this property, then one thing which can be wrong is this property's position. Try to put it before property "all" like here:


$prop_set = array(new SoapVar(array('type' => "Datastore", 'all' => true), SOAP_ENC_OBJECT, "PropertySpec"));


Regards.

0 Kudos