【问题标题】:vCenter REST API - Deploy a template with network parametersvCenter REST API - 使用网络参数部署模板
【发布时间】:2019-07-20 22:34:28
【问题描述】:

我正在使用 php 工具通过 CURL 和 JSON 从 vCenter (vmWare) 部署 ovf 模板。该工具已经在工作并成功部署了一个 ovf 模板。我的问题是网络参数被完全忽略了。

vmWare 纪录片中的大量信息对我没有帮助。我认为解决方案是找到正确的“关键”-整数。

这是我使用的一些 Dokus:

另外,我的 google-searche 也不是很有帮助。

我目前的 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"
}}

我希望有人可以帮助我。

【问题讨论】:

    标签: rest api templates deployment vcenter


    【解决方案1】:

    我没有为这种情况找到任何解决方案。我现在使用的解决方法是在部署 VM 后更改网络。如果有人对使用 REST API 更改 vCenter 中现有 VM 的网络的代码感兴趣,我在下面发布代码。

        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;
    
    }
    

    【讨论】:

      猜你喜欢
      • 2016-11-20
      • 2019-06-10
      • 2017-06-24
      • 2014-03-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-15
      • 1970-01-01
      相关资源
      最近更新 更多