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

时间:2011-12-06 00:35:19

标签: php api vmware

我通过vCloud API(1.5)和vCloud PHP SDK(1.5)管理vApp。

我可以使用以下内容启动已停止的VM,但是我不确定如何在阅读文档时停止正在运行/部署的VM。我看到你可以调用一个动作/ powerOff,但是我不确定你将如何在SDK中做到这一点。任何帮助表示赞赏!

<?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\n");
    }
    $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\n");
    }
    $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\n");
    }
    $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

参考文献:

vCloud API编程指南 http://vmware.com/pdf/vcd_15_api_guide.pdf

vCloud SDK for PHP开发人员指南 http://www.vmware.com/pdf/vcd_15_sdk_php_dg.pdf

2 个答案:

答案 0 :(得分:2)

使用您的$sdkVApp对象:

$sdkVApp->powerOff();

$sdkVApp类型为VMware_VCloud_SDK_VApp。 powerOff函数在父抽象类VMWare_VCloud_SDK_VApp_Abstract中定义。此抽象类中还有其他函数,例如suspend()powerOn()reset()等。

我唯一无法弄清楚的是当使用powerOff()suspend()功能时,VApp将关机或暂停(显示在vCenter中),但vCD显示VM已部分关闭/ suspended并且VApp仍显示正在运行。

答案 1 :(得分:2)

刚刚找到我们看到部分断电/暂停的原因。 我们需要使用undeploy()函数... http://blogs.vmware.com/vsphere/2012/04/partially-powered-off-vapp-vms.html#more

BR, DanB