v_potnis2001
Contributor
Contributor

Can someone explain why RetrieveProperty() returns junk value in DynamicProperty?

Jump to solution

My mgmt application is using gSoap-2.7 as the SOAP engine.

Code snippet:

VimBindingProxy *vim = NULL;

ns2__ServiceContent *sc = NULL;

/* objects to retrieve VM info */

ns2__PropertySpec *pSpec = NULL;

ns2__ObjectSpec *oSpec = NULL;

ns2__PropertyFilterSpec *pfSpec = NULL;

ns2_RetrieveProperties retProp;

ns2_RetrievePropertiesResponse propRes;

ns2__ObjectContent *objcont = NULL;

ns2__DynamicProperty *dynaprop = NULL;

pSpec = new ns2__PropertySpec();

pSpec->__sizedynamicProperty = 0;

pSpec->dynamicProperty = NULL;

pSpec->dynamicType = NULL;

pSpec->type = vmref->type;

pSpec->pathSet = new char*;

pSpec->pathSet[0] = "config.name";

pSpec->pathSet[1] = "config.uuid";

pSpec->pathSet[2] = "runtime.powerState";

pSpec->__sizepathSet = 3;

oSpec = new ns2__ObjectSpec();

oSpec->__sizedynamicProperty = 0;

oSpec->dynamicProperty = NULL;

oSpec->dynamicType = NULL;

oSpec->obj = vmref;

oSpec->skip = false;

pfSpec = new ns2__PropertyFilterSpec();

pfSpec->__sizedynamicProperty = 0;

pfSpec->dynamicProperty = NULL;

pfSpec->dynamicType = NULL;

pfSpec->propSet = &pSpec;

pfSpec->__sizepropSet = 1;

pfSpec->objectSet = &oSpec;

pfSpec->__sizeobjectSet = 1;

retProp._USCOREthis = sc->propertyCollector;

retProp.__sizespecSet = 1;

retProp.specSet = &pfSpec;

if (vim->RetrieveProperties(&retProp, &propRes) != SOAP_OK) {

vim->soap_print_fault(stderr);

return 1;

}

printf("\tNo. of Objects : %d\n", propRes.__sizereturnval);

for (int i = 0; i < propRes.__sizereturnval; i++) {

objcont = propRes.returnval[i];

printf("\tSize of dynamic property: %d\n", objcont->__sizepropSet);

for (int j = 0; j < objcont->__sizepropSet; j++) {

dynaprop = objcont->propSet[j];

printf("\t\tName : %s\n", dynaprop->name);

if (0 == strcmp(dynaprop->name, "runtime.powerState")) {

printf("\t\tValue: %d\n", (int)dynaprop->val);

} else {

printf("\t\tValue: %s\n", (char*)dynaprop->val);

}

}

}

From vimService.h (generated by wsdl2h from vimService.wsdl) :

/// Class wrapper for built-in type "xs:string" derived from xsd__anyType

class xsd__string : public xsd__anyType

;

/// "urn:vim2":VirtualMachinePowerState is a simpleType restriction of xs:string.

/// Note: enum values are prefixed with 'ns2__VirtualMachinePowerState' to avoid name clashes, please use wsdl2h option -e to omit this prefix

enum ns2__VirtualMachinePowerState

{

ns2__VirtualMachinePowerState__poweredOff, ///< xs:string value="poweredOff"

ns2__VirtualMachinePowerState__poweredOn, ///< xs:string value="poweredOn"

ns2__VirtualMachinePowerState__suspended, ///< xs:string value="suspended"

};

static const struct soap_code_map soap_codes_ns2__VirtualMachinePowerState[] =

{ { (long)ns2__VirtualMachinePowerState__poweredOff, "poweredOff" },

{ (long)ns2__VirtualMachinePowerState__poweredOn, "poweredOn" },

{ (long)ns2__VirtualMachinePowerState__suspended, "suspended" },

{ 0, NULL }

};

Output:

No. of Objects : 1

Size of dynamic property: 3

Name : config.name

Value: È°

Name : config.uuid

Value: È°

Name : runtime.powerState

Value: 150510944

0 Kudos
1 Solution

Accepted Solutions
tmadam
Contributor
Contributor

dynaprop->val is of type xsd__anyType *. You can't just cast this to char * or int. However, you can cast it to the correct subtype of xsd__anyType based on the type of property.

You can find the correct subtype for that property either by looking in the documentation/generated header file, or by calling dynaprop->soap_type().

In this case, you need to cast dynaprop->val to xsd__string * (for name and uuid) or vim2__VirtualMachinePowerState__ *, and then access the __item member.

Tim.

View solution in original post

0 Kudos
1 Reply
tmadam
Contributor
Contributor

dynaprop->val is of type xsd__anyType *. You can't just cast this to char * or int. However, you can cast it to the correct subtype of xsd__anyType based on the type of property.

You can find the correct subtype for that property either by looking in the documentation/generated header file, or by calling dynaprop->soap_type().

In this case, you need to cast dynaprop->val to xsd__string * (for name and uuid) or vim2__VirtualMachinePowerState__ *, and then access the __item member.

Tim.

View solution in original post

0 Kudos