I’ve been working with Content Library a bit lately for a number of internal projects. I was intrigued by William Lam’s post a while back on how to create a 3rd Party Content Library.
I am running Gigabit Internet so with ~980Mbit Up/Down I wasn’t worried about bandwidth issues.
I first considered just running this from my vCenter in my lab, but I end up trashing and reprovisioning my vCenter frequently and didn’t want to deal with having to recreate content library every time. So I set out on an adventure to create a 3rd party content library with the goal of running it from my Synology (DS1812+).
Let’s get started…
I ran into a number of gotchas when trying to implement Content Library following William’s post, so I decided I’d write up my experience and share them for all of you to take advantage of.
- Take all ISOs and Templates (OVFs) and place them in a folder on your local machine (I’ll explain why in a bit)
- Within this folder, ensure that each ISO is in it’s own sub-folder (otherwise Content Library will not like it much and will error on you)
- Files and folder names cannot have spaces, use ‘-‘ or ‘_’ instead of spaces
- Ensure that all folders and file names are less than 60 characters, otherwise Content Library will error out on you as well.
- Templates should have all of it’s files in the same sub-directory, unlike ISOs, you can have more files in a single folder for OVFs, but do not allow multiple OVFs to share a sub-folder.
Once you have setup the folder structure, you are ready to use the python script linked to on William’s blog to create the metadata that Content Library will use.
- Grab the Python script and download it to your local machine: https://github.com/lamw/vghetto-scripts/blob/master/python/make_vcsp_2015.py
- Ensure you have a Python interpreter installed (I did this on my Windows 10 Desktop)
- For Windows, go to Python.org and click on ‘Download’
- DO NOT SELECT PYTHON 3.X the script will not run correctly if you do.
- Select version 2.7.X and download it
- Run the installer and make sure that Python is added to the environment variables.
- Open CMD or PowerShell and type ‘Python <location of script> <Name of Content Library> <Location of folder of content>
- For me this looked like: Python c:\temp\CLGenerator.py Brians-Test-CL I:\Content_Library
- Be prepared to wait…
One of the things Content Library does is it reads the entire file and generates an MD5 hash of said file. This can take a while depending on the number of items you have in your content folders and their sizes. For me, this took roughly an hour for the script to generate all of the JSON files and generate all of the MD5 hashes.
You should now see an ‘items.json’ file in each folder, as well as an ‘items.json’ and ‘lib.json’ file in the root folder. Your Content Library structure has been created, we now need to place it somewhere to be consumed.
Prepping my Synology
Since I have about 12 TB of free space on my NAS, I decided I would give it a shot to host it there. There were a couple of gotchas that took me a while to figure out but I’ll lay everything out here so that it runs smoothly for you.
- If this is going to be seen outside of your network (externally) you’ll need to open port 443 on your firewall and port-forward 443 to your Synology.
- Login to your Synology, click on ‘Package Center’ and install ‘Apache HTTP Server 2.2’, ‘PHP 5.6’, as well as ‘WebStation’.
- Once these three have downloaded and installed, you will need to go into Web Station > General Settings > and choose ‘Apache’ as your Web framework, and PHP as your backend.
- Once you’ve performed the previous steps, you can copy your Content Library folder into a newly created folder (Synology creates it for you when you install/enable Web Station) called ‘Web’ on your Synology.
- Once all the files have been moved over, you can attempt to resolve lib.json by opening your web browser and typing your https://<external IP address>/lib.json if this resolves, then you are almost ready to use it (still a few more steps).
- You will notice that you cannot reach any of the sub-folders in this folder. This is by design and we need to create and add an .htaccess file that tells the clients that they can see the other sub-folders.
- On your local machine, create a file and name it .htaccess (do not add an extension)
- Open .htaccess and type the following:
- Save the file and drop it into the root folder next to your lib.json file.
- Try to access a sub-folder from your browser again: https://<external IP address>/<folder name>
- If this returns the list of items/additional folders, then we are good to go.
- The next step is to add this content library to your vCenter as a ‘Subscribed’ library. I set mine up to not auto-synchronize all content (roughly 150GB), rather to do on-demand, which I then went in and synchronized the few ISOs I use frequently so they will be ready for use.
You should now be good to go! Enjoy!