Cloning VMs/Directly Edit FOG MYSQL Database?
-
Hi all,
First, let me explain the scenario: we often have to clone VMs in Hyper-V, which means we need to run sysyprep.exe on the VM we want to clone, copy the associated VHD file, and then create a new VM with the copied VHD file.
The problem comes when we want to automate this with PowerShell, and we’re unable to join the systems to the domain automatically (both the original and the clone). If we were running Server 2016 on all of our hypervisors, this would be no problem considering we could connect in through Hyper-V’s cmdlets. Alas, we’re running Server 2012 R2 with no plan to upgrade for some years.
My line of thinking is that if the original has the FOG client installed, I’d just need PowerShell to edit the MYSQL database on the FOG server to create a new record with the associated image, group, etc (the key thing being the MAC address and having it set to join the domain automatically).
So, a few questions:
- Is this the way to go about doing this, or is there a better method?
- Is this possible with FOG?
- If it is possible with FOG, what’s the recommended method of creating a new record? Is it to directly edit the MYSQL database? Or would I be able to connect through an API?
I’d be interested to know if anyone else has had a similar issue and how they’ve worked around it.
I did wonder whether it was worth uploading the image of the clone and then redeploying it, but that would take far too long.Any help as usual would be greatly appreciated!
-
This answer is going to be in two parts.
First let me tell you how my server group guys do it and then I’ll follow up with your specific questions.
We use vmware so some of these features do not directly translate to Hyper-V, but if you are OK with powershell you should be able to simulate it a bit of skill. Let me also say we don’t use FOG to spin up new server VMs, that is handled by our hypervisor. In vmware we have the ability to convert an VM to a Template. Then from that Template we can clone to a new machine. This Convert to Template basically sets a flag in the VM configuration to indicate its a Template and that the VM is not startable. When we want a new VM we use the vmware built in macro of Clone Template to New VM. This basically copies the VMDK (disk) files and then creates a new VM reference in the hypervisor and then starts it. From there Windows OOBE takes off, commissions the system and then connects the system to Microsoft AD via the unattend.xml file. In our case when we create a Reference VM image, we build the image with MDT and then when MDT is done we copy in our default unattend.xml file and then sysprep the system. We have sysprep power off the server and then we run the Convert to Template macro. Done.
Now in your case you don’t need to edit the MYSQL database directly because FOG has a crude (crude in that its not highly refined at the moment) RESTful api. You can make API calls to create new systems or interact with the FOG database. There are some setup things you need to do, but you can surely call the FOG API from powershell script using the build in capabilities or by using wget like cmdlet.
-
@george1421 Thanks very much! I’ll give it a go.
-
@george1421 Is there an Active Directory core object missing from the documentation (found here: https://news.fogproject.org/simplified-api-documentation/)?
I’ve managed to create a new host with the correct MAC address. I just now need to ensure ‘Join after domain deploy’ is somehow enabled through the API (if possible) to get it working as I’d like it to.
-
@george1421 Actually, I’ve just figured it out for the most part. However, is there a way to set it to use the default values already set in FOG?
I’ve updated the JSON to have:
“useAD” = “Y”
This ticks the ‘Join Domain after deploy’ box. I don’t particularly fancy having to tap in the details for the system to join the domain when they’re already configured within FOG itself, though.