Iam trying to create a VM from ova using REST API. I can do this using this Rest API:
https://vcenter_ip/rest/com/vmware/vcenter/ovf/library-item/id:<library_item_id_ie_ova_item>?~action=deploy
To do this, I uploaded the ova through VSphere client. (Content library->Select library ->Import Item-> Select .ovf file from local -> (prompts to select reference files) select dependent .vmdk from local)
But I want to perform the upload through Rest API.
The steps I have done so far are:
- Create a Library
URL: https://vcenter_ip/rest/com/vmware/content/local-library
Method: POST
Headers:
Key:Content-Type
value: application/json
Request Body:
{
"create_spec": {
"name": "CL1",
"description": "CL1 Desc",
"publish_info": {
"authentication_method": "NONE",
"persist_json_enabled": false,
"published": false
},
"storage_backings": [
{
"datastore_id": "datastore-144",
"type": "DATASTORE"
}
],
"type": "LOCAL"
}
}
- Create a Library Item
Method: POST
Headers:
Key:Content-Type
value: application/json
Request Body:
{
"create_spec": {
"library_id": "<library_id",
"description": "mydesc",
"name": "Damn Small Linux",
"type": "ovf"
}
}
- Create new update Session
URL: https://vcenter_ip/rest/com/vmware/content/library/item/update-session
Method: POST
Headers:
Key:Content-Type
value: application/json
Request Body:
{
"create_spec":{
"library_item_id": "<lib_item_id>"
}
}
Response:
{
"value": "26f143a2-fb9d-4ed9-bd5f-c7be5825ee37:ec4f8df0-249f-4887-ab84-0933f86e106c"
}
Next, I try to upload the files to content-library item and that is where Iam facing issues.
- To upload ovf
4(a). request endpoint to upload .ovf file
Method: POST
Headers:
Key:Content-Type
value: application/json
Key:update_session_id
value: 26f143a2-fb9d-4ed9-bd5f-c7be5825ee37:ec4f8df0-249f-4887-ab84-0933f86e106c
{
"file_spec": {
"source_type": "PUSH",
"name": "Damn Small Linux.ovf",
"size": 9
}
}
Response Body:
{
"value": {
"bytes_transferred": 0,
"upload_endpoint": {
"uri": "https://<vcenter_ip>:443/cls/data/1a5129a1-87e8-4650-855d-9041c493c475/Damn%20Small%20Linux.ovf"
},
"name": "Damn Small Linux.ovf",
"source_type": "PUSH",
"status": "WAITING_FOR_TRANSFER"
}
}
4(b). Uploading to that URI with put request with file uploaded as multipart form data (I did this with postman- I did the rest of the calls through Vcenter api explorer)
4(c). Validate file in update session
URL: https://vcenter_ip/rest/com/vmware/content/library/item/updatesession/file/id:26f143a2-fb9d-4ed9-bd5f-c7be5825ee37%3Aec4f8df0-249f-4887-ab84-0933f86e106c?~action=validate
Method: POST
Headers:
Key:Content-Type
value: application/json
Key:update_session_id
value: 26f143a2-fb9d-4ed9-bd5f-c7be5825ee37:ec4f8df0-249f-4887-ab84-0933f86e106c
Response Body:
{
"value": {
"has_errors": true,
"invalid_files": [
{
"error_message": {
"args": [
"Damn Small Linux.ovf",
"1:1:PARSE_ERROR: Parse error: Unexpected character '-' (code 45) in prolog; expected '<'\r\n at [row,col {unknown-source}]: [1,1].\r\n"
],
"default_message": "File Damn Small Linux.ovf was considered invalid. Reason: 1:1:PARSE_ERROR: Parse error: Unexpected character '-' (code 45) in prolog; expected '<'\r\n at [row,col {unknown-source}]: [1,1].\r\n.",
"id": "com.vmware.vdcs.cls-main.update_session_file_validation"
},
"name": "Damn Small Linux.ovf"
}
],
"missing_files": []
}
}
But this is the same file I have uploaded while uploading through vsphere client successfully.
What is the issue here? And how do I next upload a reference .vmdk following this?