VMWare vCloud API v1.5 - 使用PHP SDK关闭vApp电源?

I am managing vApps via the vCloud API(1.5) and the vCloud PHP SDK(1.5).

I can start a stopped VM using the following below, however I am not sure how you can stop a running/deployed VM while reading the documentation. I see that you can invoke an action/powerOff, however I am not sure how you would do it within the SDK. Any help is appreciated!

<?php
    // This will start/turn on a vApp/VM. However, I cannot figure out how to turn it off from reading the documentation using the PHP SDK. Any help is appreciated!
    // login
    $service = VMware_VCloud_SDK_Service::getService();
    $service->login($server, array('username'=>$user, 'password'=>$pswd), $httpConfig);

    // create an SDK Org object
    $orgRefs = $service->getOrgRefs($orgName);
    if (0 == count($orgRefs))
    {
        exit("No organization with name $orgName is found
");
    }
    $orgRef = $orgRefs[0];
    $sdkOrg = $service->createSDKObj($orgRef);

    // create an SDK vDC object
    $vdcRefs = $sdkOrg->getVdcRefs($vdcName);
    if (0 == count($vdcRefs))
    {
        exit("No vDC with name $vdcName is found
");
    }
    $vdcRef = $vdcRefs[0];
    $sdkVdc = $service->createSDKObj($vdcRef);

    // get a reference to a vApp in the vDC
    $vAppRefs = $sdkVdc->getVAppRefs($vAppName);
    if (!$vAppRefs)
    {
        exit("No vApp with name $vAppName is found
");
    }
    $vAppRef = $vAppRefs[0];
    // create an SDK vApp object
    $sdkVApp = $service->createSDKObj($vAppRef);

    // create a VMware_VCloud_API_DeployVAppParamsType data object
    $params = new VMware_VCloud_API_DeployVAppParamsType();
    $params->set_powerOn($powerOn);
    $params->set_deploymentLeaseSeconds($deploymentLeaseSeconds);

    // deploy the vApp
    $sdkVApp->deploy($params) 
<?php

References:

vCloud API Programming Guide : http://vmware.com/pdf/vcd_15_api_guide.pdf

vCloud SDK for PHP Developer's Guide : http://www.vmware.com/pdf/vcd_15_sdk_php_dg.pdf

Use your $sdkVApp object:

$sdkVApp->powerOff();

Your $sdkVApp is of type VMware_VCloud_SDK_VApp. The powerOff function is defined in the parent abstract class VMWare_VCloud_SDK_VApp_Abstract. There are other functions in this abstract class such as suspend(), powerOn(), reset(), etc.

The only thing I could not figure out yet is when using the powerOff() or suspend() function, the VApp gets powered Off or Suspended (shown in vCenter) but vCD shows the VM partially powered-off/suspended and the VApp still show Running.

Just found the reason why we see the partially powered-off/suspended. We need to use the undeploy() function... http://blogs.vmware.com/vsphere/2012/04/partially-powered-off-vapp-vms.html#more

BR, DanB