I am woking on a php tool to deploy ovf templates from the vCenter (vmWare) via CURL and JSON. The tool is already working and deploys an ovf template succesfully. My problem is that the network-parameters are getting ignored completly.
The massive informations in the vmWare documentary doesnt help me out. I think the solution is to find the right "key"-integer.
Here are some Dokus i used:
https://vcenter.iseage.org/apiexplorer/ -> ovfLibraryItem->deploy
Also my google-searche was not realy helpful.
My currently json-code:
{
"deployment_spec": {
"accept_all_EULA": true,
"default_datastore_id": "datastore-30598",
"network_mappings": [
{
"key": "4000",
"value": "network-154"
}
],
"name": "AATest08"
},
"target": {
"folder_id": "group-v5920",
"host_id": "host-1934",
"resource_pool_id": "resgroup-43"
}}
I hope someone can help me out.
I didn't find any solution for this case. The workaround that i use now, is to change the network after deloying the VM. If someone is interest in the code to change the network of an existing VM in the vCenter with the REST API, i post the code below.
function updateNetwork($IdFromTheVM, $NewNetworkID)
{
$requestUrl = 'https://' . $yourVCenterHost . '/rest/vcenter/vm/' . $IdFromTheVM . '/hardware/ethernet/4000';
$data = array(
'spec' => array(
'backing' => array(
'type' => 'STANDARD_PORTGROUP',
'network' => $NewNetworkID,
)
));
$dataJson = json_encode($data);
$ch = curl_init();
$header = array(
'vmware-api-session-id: ' . $yourVCenterSessionID,
'content-Type: application/json',
'Accept: application/json'
);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PATCH');
curl_setopt($ch, CURLOPT_POSTFIELDS, $dataJson);
curl_setopt($ch, CURLOPT_URL, $requestUrl);
curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($httpcode != 200){
return false;
}
return true;
}