Synchronizing records about the occupied IP-addresses between two CloudStack databases

Sometimes it’s necessary to maintain 2 different CloudStack setups (let’s call them Cloud-A and Cloud-B) sharing the same IP-address ranges. For example, we might need that when we’re building a new CloudStack-driven environment and going to move all the virtual infrastructure from the old setup to the new one, but as we can’t just make move everything in a couple of hours (let’s say, we have about a thousand of VMs), we have to let 2 different CloudStack-driven virtual datacenters use the same networks. We should understand that we might have to maintain 2 different CloudStack setups for a few days or weeks or even months, so we have to take care about the situation when someone deploys a new VM or assign a new IP-address to a currently running VM. It means that both CloudStack setups should understand that the IP-address has been allocated, otherwise we might come to the situation when both CloudStacks will assign the same IP-address to their VMs and we’ll face a major trouble.

We can solve it by making a simple script that would look up what IP-addresses are being in the “Allocated” state in Cloud-A and make them “Allocated” to a certain account in Cloud-B. Then the script would do the same to mark as “Allocated” in Cloud-A the addresses that are really assigned to some instances in Cloud-B. Also it would be great if the script would mark as “Free” the IP-addresses that aren’t being used, of course.

In the very first apporach such a sctipt might be looking like that:

I’m going to add some functionality (for example, notifications about the IP-address that are already having the same assigned/free state in both clouds), so you’re welcome to get the latest revision on GitHub.

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.