How to Mount a Content Library ISO on a VM

While Content Libraries are becoming more and more used, there are still some features that are not yet implemented in PowerCLI. So is it for example not possible to mount an ISO file located in a Content Library on a VM. The Set-CDDrive cmdlet is currently lacking this functionality, while the Web Client offers this option.

Like often, and one of the VMware PowerCLI features I absolutely like, when a cmdlet is missing a feature, you can fall back on the API to solve the issue.

Introduction

Like so often, the reason I had a closer look at this issue was due to a question in PowerCLI Community on VMTN.

My first step in such cases is always to have a look at the vSphere Web Services API.

But unfortunately, the ReconfigVM_Task method documentation didn’t make me any wiser. There is apparently no object, property, or method to mount an ISO from a Content Library onto a VM.

In the next step I had a look at the vSphere REST API Reference. But in there I could also not find anything specific about Content Library ISOs and VM CD drives.

When all else fails, look at the code!

And with Code Capture we have just that option!

The first thing I noticed while looking at the generated code, there are no ‘special’ object, properties, or method used. Just a plain ReconfigVM_Task call with an edit action on the CD drive device.

The only special feature was the value in the FileName property.

That value definitely pointed to the ISO file in the Content Library. At first I tried to compose that value by hand/script. But it turned out that some parts of the value were not obtainable via normal ways.

I found out then when I use the vimdatastore provider, the returned FullDatastorePath contained exactly the value I neededd.

The Code

Annotations

Line 34-37: The parameters that the function requires are objects returned by the Get-CDDrive and Get-ContentLibraryItem cmdlets. The function does not implement OBN support.

Line 40-41: This provides meaningful content for the message returned when the WhatIf switch is used.

Line 44-46: To avoid conflicts with PSDrives the user might already have defined, the function generates a 3-letter, random string that will be used as the drivename.

Line 52-53: To avoid a situation where the same ISO file might be uploaded to two different Content Libraries, the function first finds the path to the folder that corresponds with the requested Content Library.

Line 54-55: This search finds the actual path to the desired ISO file.

Line 60-72: A ‘regular’ call to the ReconfigVM_Task method.

Line 74: The function returns the CDDrive object, just like the regular Set-CDDrive cmdlet does. But since there is currently not yet support for ISO files from a Content Library, the filepath looks like a regular path to an ISO file. The Web Client does show that this is an ISO from a Content Library.

Sample Run

Using the function is rather straightforward.

The Web Client shows that an ISO from a Content Library is loaded.

Enjoy!

Leave a Reply

Your email address will not be published. Required fields are marked *

*
*

This site uses Akismet to reduce spam. Learn how your comment data is processed.