In vCloud API/GUI Throwdown part 2, I showed you how to modify VM disk sizes in vCloud Director while the VM is still powered on. However, we did *not* cover adding new disks to a VM.
Adding new harddisks is a little tricky because of the implementation of the object in the SDK.. The conversion from XML to a .NET object is not an easy thing, especially with the vCloud API’s intricate nodes, elements, attributes, etc. Because of this, you can’t create a representation of a harddisk as a .NET object. Trust me, I’ve tried.
That being said, we’re working with a REST API, and Powershell LOVES REST APIs. Using the [System.Net.WebRequest] class, we can talk HTTP just like any web browser. That means we can use the 4 HTTP methods used in REST APIs: GET, POST, PUT, DELETE.
So, with a mix of PowerCLI and some Powershell .NET magic, I give you… New-CIHarddisk! I made this one an advanced function, so you can just pipe a vCloud VM to it, like so:
*Note the harddisk size is in bytes.
Here are a couple different ways to run the command:
# Passing VM via pipeline Get-CIVM "MyVM" | New-CIHarddisk -size 10240 # Or just using a VM name New-CIHarddisk -vm "MyVM" -size 10240
Here’s what it looks like after you add more harddisks to a running VM…I may have had a little too much fun with this one:
This content has been re-posted courtesy of Bluelock Solutions Architect Jake Robinson from his personal Blog, Geek After Five.