配置网络并将添加的VM供电到重构的vApp

时间:2014-01-30 08:14:44

标签: php vmware vcloud-director-rest-api

我想重新构建vApp并向其添加新VM。我在SDK示例中使用了稍微修改过的recomposevapp.php

我正在使用此代码:

// Create Network Connection Section
$info = new VMware_VCloud_API_OVF_Msg_Type();
$info->set_valueOf("Network Paramemters for my source");
$nsection = new VMware_VCloud_API_NetworkConnectionSectionType();
$nsection->setInfo($info);
$nsection->setPrimaryNetworkConnectionIndex(0);

// Create Network Connection
$netconf = new VMware_VCloud_API_NetworkConnectionType();
$netconf->set_network($orgNetName);
$netconf->set_needsCustomization(false);
$netconf->setNetworkConnectionIndex(0);
$netconf->setIpAddress(NULL);
$netconf->setExternalIpAddress(NULL);
$netconf->setIsConnected(true);
$netconf->setMACAddress(NULL);
$netconf->setIpAddressAllocationMode("DHCP");

// Add Network Connection to Network Connection Section
$nsection->addNetworkConnection($netconf);

$iparams = new VMware_VCloud_API_InstantiationParamsType();
$iparams->setSection(array($nsection));

$params = new VMware_VCloud_API_RecomposeVAppParamsType();
...
$params->setInstantiationParams($iparams);
...

$task = $sdkVApp->recompose($params);

但是我收到以下错误:

<Error xmlns="http://www.vmware.com/vcloud/v1.5" minorErrorCode="BAD_REQUEST" message="Unsupported instantiation section: {http://www.vmware.com/vcloud/v1.5}NetworkConnectionSection" majorErrorCode="400" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.vmware.com/vcloud/v1.5 http://some_ip/api/v1.5/schema/master.xsd"></Error>

奖金问题:如何打开实例化的虚拟机?

1 个答案:

答案 0 :(得分:0)

我有一个解决方案!您必须引用刚刚添加的VM,然后配置网络。在此之后,它很容易实现。

$vmRefs = $sdkVApp->getContainedVmRefs($newVmName);
$sdkVm = $service->createSDKObj($vmRefs[0]);
$service->waitForTask($sdkVm->modifyNetworkConnectionSettings($nsection));
$service->waitForTask($sdkVm->powerOn());