dpnzf48660 2011-12-06 00:35
浏览 123
已采纳

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

  • 写回答

2条回答 默认 最新

  • dongsu1951 2012-05-02 01:48
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!