2011/5/4 Jiri Denemark <jdenemar@xxxxxxxxxx>: > Reason is currently always set to 0 (i.e., *_UNKNOWN). > --- > Âsrc/esx/esx_driver.c    |  54 ++++++++++++++++++++++++- > Âsrc/libxl/libxl_driver.c  |  31 +++++++++++++- > Âsrc/lxc/lxc_driver.c    |  33 ++++++++++++++- > Âsrc/openvz/openvz_driver.c |  32 ++++++++++++++- > Âsrc/phyp/phyp_driver.c   |  12 +++++- > Âsrc/qemu/qemu_driver.c   |  33 ++++++++++++++- > Âsrc/test/test_driver.c   |  31 +++++++++++++- > Âsrc/uml/uml_driver.c    |  32 ++++++++++++++- > Âsrc/vbox/vbox_tmpl.c    |  56 +++++++++++++++++++++++++- > Âsrc/vmware/vmware_driver.c |  31 +++++++++++++- > Âsrc/xen/xen_driver.c    |  18 ++++++++- > Âsrc/xen/xen_hypervisor.c  |  34 +++++++++++++++- > Âsrc/xen/xen_hypervisor.h  |  Â4 ++ > Âsrc/xen/xend_internal.c  Â|  97 ++++++++++++++++++++++++++++++++----------- > Âsrc/xen/xend_internal.h  Â|  Â1 + > Âsrc/xen/xm_internal.c   Â|  19 ++++++++- > Âsrc/xen/xm_internal.h   Â|  Â1 + > Âsrc/xen/xs_internal.c   Â|  32 ++++++++++++++- > Âsrc/xen/xs_internal.h   Â|  Â3 + > Âsrc/xenapi/xenapi_driver.c |  45 ++++++++++++++++++++- > Â20 files changed, 559 insertions(+), 40 deletions(-) > > diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c > index 543ebe6..94b0121 100644 > --- a/src/esx/esx_driver.c > +++ b/src/esx/esx_driver.c > @@ -2425,6 +2425,58 @@ esxDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info) > > > Âstatic int > +esxDomainGetState(virDomainPtr domain, int *state, int *reason) > +{ > +  Âint result = -1; > +  ÂesxPrivate *priv = domain->conn->privateData; > +  ÂesxVI_String *propertyNameList = NULL; > +  ÂesxVI_ObjectContent *virtualMachine = NULL; > +  ÂesxVI_DynamicProperty *dynamicProperty = NULL; > +  ÂesxVI_VirtualMachinePowerState powerState; > + > +  Âif (esxVI_EnsureSession(priv->primary) < 0) { > +    Âreturn -1; > +  Â} > + > +  Âif (esxVI_String_AppendValueListToList(&propertyNameList, > +                      "runtime.powerState\0") < 0 || > +    ÂesxVI_LookupVirtualMachineByUuid(priv->primary, domain->uuid, > +                     propertyNameList, &virtualMachine, > +                     esxVI_Occurrence_RequiredItem) < 0) { > +    Âgoto cleanup; > +  Â} > + > +  Â*state = VIR_DOMAIN_NOSTATE; > +  Âif (reason) > +    Â*reason = 0; > + > +  Âfor (dynamicProperty = virtualMachine->propSet; dynamicProperty != NULL; > +     dynamicProperty = dynamicProperty->_next) { > +    Âif (STREQ(dynamicProperty->name, "runtime.powerState")) { > +      Âif (esxVI_VirtualMachinePowerState_CastFromAnyType > +         Â(dynamicProperty->val, &powerState) < 0) { > +        Âgoto cleanup; > +      Â} > + > +      Â*state = esxVI_VirtualMachinePowerState_ConvertToLibvirt > +            (powerState); > +    Â} else { > +      ÂVIR_WARN("Unexpected '%s' property", dynamicProperty->name); > +    Â} > +  Â} > + > +  Âresult = 0; > + > + Âcleanup: > +  ÂesxVI_String_Free(&propertyNameList); > +  ÂesxVI_ObjectContent_Free(&virtualMachine); > + > +  Âreturn result; > +} > + This can be simplified to: static int esxDomainGetState(virDomainPtr domain, int *state, int *reason) { int result = -1; esxPrivate *priv = domain->conn->privateData; esxVI_String *propertyNameList = NULL; esxVI_ObjectContent *virtualMachine = NULL; esxVI_VirtualMachinePowerState powerState; if (esxVI_EnsureSession(priv->primary) < 0) { return -1; } if (esxVI_String_AppendValueToList(&propertyNameList, "runtime.powerState") < 0 || esxVI_LookupVirtualMachineByUuid(priv->primary, domain->uuid, propertyNameList, &virtualMachine, esxVI_Occurrence_RequiredItem) < 0 || esxVI_GetVirtualMachinePowerState(virtualMachine, &powerState) < 0) { goto cleanup; } *state = esxVI_VirtualMachinePowerState_ConvertToLibvirt(powerState); if (reason) { *reason = 0; } result = 0; cleanup: esxVI_String_Free(&propertyNameList); esxVI_ObjectContent_Free(&virtualMachine); return result; } Matthias -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list