This is a handy little utility created to speedup the workflow on my home ESXi/vCenter lab. If you have a similarly operated lab it may save you some time while testing multiple VMs.
- Tested on vCenter 6.5.0
- Tested on Mikrotik 6.39.2
- VM image: Ubuntu 16.04.2 server 64bit
- Create a VM in ESXi/vCenter (usually, cloning a template with a generic image)
- Find the VM's MAC address on ESXi/vCenter console.
- Create a DHCP entry in Mikrotik for the new VM
- Create a DNS entry in Mikrotik for the new VM
- Modify VM's /etc/hostname
- Modify VM's /etc/hosts
- Reboot the VM
- Check the VM is accessible on the new IP address
This script automates all steps but #1. #1 could be easily automated too, however providing VM-level configuration options would be far outside the scope of this script.
Usage instructions:
java -jar target/esxi2mikrotik-1.0.0-SNAPSHOT.jar
Example:
java -jar esxi2mikrotik-1.0.0-SNAPSHOT.jar \
-eh vcenter.domain \
-eu [email protected] \
-ep secret \
-mh mikrotik.domain \
-mu admin \
-mp secret2 \
-vn MyTestVM \
-vh my-test-vm.domain \
-vi 1.2.3.4 \
-vu superuser \
-vp secret3
usage: help
-eh,--esxiHostname <arg> ESXi/vCenter hostname
-ep,--esxiPassword <arg> ESXi/vCenter password
-eu,--esxiUsername <arg> ESXi/vCenter username
-mh,--mikrotikHostname <arg> Mikrotik hostname
-mp,--mikrotikPassword <arg> Mikrotik password
-mu,--mikrotikUsername <arg> Mikrotik username
-vh,--vmHostname <arg> The hostname to be assigned to the VM
-vi,--vmIP <arg> The new IP for the VM
-vn,--vmName <arg> The name of the VM in ESXi/vCenter
-vp,--vmPassword <arg> The password to connect to the VM via SSH
-vu,--vmUsername <arg> The username to connect to the VM via SSH
To build this script you need Java 1.8.x, Maven 3.2.x, an Internet connection and running the following command:
mvn clean install
mvn install exec:java \-Dexec.args="\
-eh vcenter.domain \
-eu [email protected] \
-ep secret \
-mh mikrotik.domain \
-mu admin \
-mp secret2 \
-vn MyTestVM \
-vh my-test-vm.domain \
-vi 1.2.3.4 \
-vu superuser \
-vp secret3"