Migration of VM Templates in a Content Library to another datastore
search cancel

Migration of VM Templates in a Content Library to another datastore

book

Article ID: 400125

calendar_today

Updated On:

Products

VMware Cloud Foundation

Issue/Introduction

The Migrate Content Library feature supports only the migration of OVF templates and Other types. For migration of VM templates, there is a separate manual process that needs to be followed, the runbook for which is being detailed in this KB article.

Environment

vCenter 9.0.0

Cause

VMTX storage migration is not automated along with library migration. This is due to the reason that VMTX templates are not organized in content library backed datastore, rather these templates are stored in their chosen storage location at the time of creation of VM template.

Resolution

Follow the below steps to migrate the VM templates inside the Content Library:

Get Libraries In a Datastore

VAPI way

1. Existing Find Library API is enhanced to filter libraries that are backed by a specific Datastore.

https://developer.broadcom.com/xapis/vsphere-automation-api/latest/content/api/content/library__action=find/post/

2. Library FindSpec now have an filter input to accept datastore id as parameter for filtering libraries by it

https://developer.broadcom.com/xapis/vsphere-automation-api/9.0/data-structures/Content%20Library%20FindSpec/index.html?scrollString=Library_FindSpec

FindSpec :
{
  "name": "string",
  "type": "string",
  "storage_backing": {
    "datastore_id": "datastore-xx",
    "type": "DATASTORE"
  }
}
 
Sample Request

curl --location --insecure 'https://<ip>/api/content/library?action=find' \
    --header 'Content-Type: application/json' \
    --header 'Cookie: vmware-api-session-id=<id>' \
    --data '{
                "storage_backing" : {
                                        "datastore_id" : "datastore-xx",
                                        "type" : "DATASTORE"
                        }
            }'
 
Sample Response
 [  
    "<id-1>",
    "<id-2>",
    "<id-3>"
]
 

 

Get Library Details

3. Use 'Get Library Id Content' API for each of libraryID listed in above Find API to find library details

https://developer.broadcom.com/xapis/vsphere-automation-api/9.0/data-structures/Content%20Library%20Item%20FindSpec/index.html?scrollString=library_id

Sample Request
curl --location 'https://<ip>/api/content/library/<id>' \
--header 'Cookie: vmware-api-session-id=<id>' \
--data '
 
Sample Response
{
    "creation_time": "YYYY-MM-DDThh:mm:ss.usZ",
    "storage_backings": [
        {
            "datastore_id": "datastore-xx",
            "type": "DATASTORE"
        }
    ],
    "last_modified_time": "YYYY-MM-DDThh:mm:ss.usZ",
    "server_guid": "<id>",
    "description": "",
    "type": "LOCAL",
    "version": "2",
    "state_info": {
        "state": "ACTIVE"
    },
    "name": "local",
    "publish_info": {
        "authentication_method": "NONE",
        "user_name": "vcsp",
        "published": false,
        "publish_url": "https://<fqdn>:443/cls/vcsp/lib/<id>/lib.json",
        "persist_json_enabled": false
    },
    "id": "<id>"
}


Migrate VMTX (UI)

4. For each library in details, go to VC UI Home → Content Libraries → Library → VM Templates tab.

For each template, perform below actions to migrate the templates to desired storage

  • Checkout (as VM)
  • Migrate Storage (Storage vMotion of powered-on/powered-off VM)
  • Checkin as new version of VMTX

Additional Information