Hi,
There is this VMWare suite in our infrastructure. vSphere 6.0 is being used.
I have been assigned this task:
A VM running RHEL 6 needs to be migrated to a new VM that will have RHEL 7.
This needs done automatically from within a Shell Script (Bash, for instance). We cannot delete the existing VM and its associated disks. We need to create the new VM with the same name and in the same Data-Store and in the same Path/Directory where the current VM is lying.
---
I have prepared the steps with the commands. However, I am stuck at this stage:
When I create a New VM with the Same Name as the Existing VM's Name, I am manually renaming the Old VM from "ExampleHost" to "ExampleHost-Pre-Upgrade".
Then I am deploying the OVF. As the name is already existing in the Data-Store and in the directory/path, it automatically renames the path from "ExampleHost" to "ExampleHost
_1/ExampleHost.vmdk".
That "
_1" part is a problem.
We also have 3 Additional Disks:
- ExampleHost-backup.vmdk
- ExampleHost-log.vmdk
- ExampleHost-x.vmdk
So their existing path / directory names (or Disk File Names) are:
- ExampleHost/ExampleHost-backup.vmdk
- ExampleHost/ExampleHost-log.vmdk
- ExampleHost/ExampleHost-x.vmdk
I have been asked to move only the existing ExampleHost-backup.vmdk from the Old VM to the New VM. I am able to do it as the disk file name with the path name remains the same as before: "ExampleHost/ExampleHost-backup.vmdk" so I can simply detach it from the old one and attach it to the new one.
However, I need to create the rest 2 disks afresh with the same name/path. This will not be allowed as there are already disk file names there.
So, how to rename the VM from a command-line such that the VM's Name gets changed to "*-Pre-Upgrade" and also its disk file names get changed to "ExampleHost/Pre-Upgrade-ExampleHost-log.vmdk" similarly for "ExampleHost/Pre-Upgrade-ExampleHost-x.vmdk".
Please note: I mentioned above: That "
_1" part is a problem.
So, I have been asked to make sure that the new disk file name/path with the containing directory name remains the same as before: ExampleHost/ExampleHost.vmdk. There must not be an underscore "_" appended to the directory name as in: ExampleHost
_1/ExampleHost.vmdk. So, we do need to rename the old root disk file name first to ExampleHost-Pre-Upgrade/ExamExampleHost.vmdk before deploying the OVF. So that I can easily add the New Disks in "ExampleHost/" as this will not contain the other 3 disks.
So, we need to first rename the old VM Name to something else and also Change the Path/Directory Name so that the new Path / Directory Name will be the same as the old one.
My second problem is also related and is as follows:
I need to fetch information on the Path / Directory where the VM is currently deployed so that the new VM can be deployed in the same path/directory when I deploy the OVF from the command line.
Please note that using the GUI, I am able to achieve all that, but I need a command line approach here because I need to write a script to do it all automatically. The end user will only input these 2 things:
Host Name (which is same as the VM Name)
IP Address
I need to take care of the rest of the things from within a Bash Script.