VMware Cloud Community
MR-T
Immortal
Immortal

Registering virtual machines without access to their vmx files

For DR purposes I want to pre-register all my virtual machines with hosts in a DR site.

This way, when the storage fails across the vm's can just power on.

Does anyone have a method for registering machines without actually touching the storage.

Sadly my usual method vmware-cmd requires .

Thanks

0 Kudos
10 Replies
admin
Immortal
Immortal

Hmmm, difficult one, the only way I can think to do it is to create 'dummy' VMs from scratch on the DR host, and then edit the .vmx files with the correct paths for the storage so that when it fails over you don't need to make anhy changes to the VMs.

0 Kudos
MR-T
Immortal
Immortal

Cheers mate.

I think it's going to need some SDK action to get this one fixed.

It must be doable though.

When I fail my storage between sites, I register on hosts in a different datacenter and VirtualCenter remembers this.

When I flip the storage back and forth between sites, any previously known vm's can be powered on after answering the UUID question.

What I now need is a slick way to pre-register each VM on the DR hosts as they are created in the primary site.

I should point out, the main reason I'm doing this is to organise the structure. I've already written a DR script which basically registers everything and powers up, but all VM's land in the 'discovered' pot.

How do other people handle this?

0 Kudos
VMKR9
Expert
Expert

we are currently testing this and its all manual steps, would you mind sharing your script that registers and powers up the vms?

0 Kudos
MR-T
Immortal
Immortal

Sure, I'll stick it in an email.

The 2 basic commands for starting a vm & answering the UUI question are:

for a in `vmware-cmd -l`; do vmware-cmd $a start; done

for a in `vmware-cmd -l`; do echo "1" | vmware-cmd $a answer; done

When you power up a VM which has moved location it will ask if you what you wish to do with the unique identifier. You have 5 choices:

0) Create

1) Keep

2) Always Create

3) Always Keep

4) Cancel

My script selects option 1 to keep the UUID.

Message was edited by:

MR-T

0 Kudos
admin
Immortal
Immortal

How about scping the .vmx files over and registering them from those? The .vmx files don't have to be in the same place - just point to the same disks.

i.e. in sudo-code

vmlist=vmware-cmd -l

for vmx in vmlist

do

scp vmx to remote host

done

then on remote the remote host register the .vmx file. You won't be able to power them on until your storage fails over to the DR side but that's what you want.

Without some 'real' .vmx files I'm pretty sure the VMs will appear as 'orphaned' on the host even if you do get them to register.

MR-T
Immortal
Immortal

Good call, I'm starting to like this.

I guess the only manual process from here is that I'd need to drag the objects around inside VC to get them into the correct containers.

Thanks Alex.

0 Kudos
sbeaver
Leadership
Leadership

#!/bin/bash

\# Enable Disk Resignature of the LUNS

esxcfg-advcfg -s 1 /LVM/EnableResignature

service mgmt-vmware restart

\# Scan for new Luns

esxcfg-rescan vmhba0

esxcfg-rescan vmhba1

esxcfg-rescan vmhba2

\# Balance HBA

PREVIOUS="vmhba1"

echo "Starting HBA Balance....."

  1. Execute new config

for LUN in $(esxcfg-vmhbadevs | tail +2 | awk '\{print $1}')

do

CURRENT=$(esxcfg-mpath -q --lun=$\{LUN} | grep FC | grep "preferred" | awk '\{print $4}' | awk -F ":" '\{print $1}')

if [\[ $\{CURRENT} = $\{PREVIOUS} ]]

then

NEW=$(esxcfg-mpath -q --lun=$\{LUN} | grep FC | grep -v "preferred" | awk '\{print $4}' | awk -F ":" '\{print $1}')

NEWPATH=$(esxcfg-mpath -q --lun=$\{LUN} | grep FC | grep -v "preferred" | awk '\{print $4}')

esxcfg-mpath --lun=$\{LUN} --path=$\{NEWPATH} --preferred

PREVIOUS=$\{NEW}

else

PREVIOUS=$\{CURRENT}

fi

done

echo

echo "****** NEW HBA CONFIG *****"

echo

for LUN in $(esxcfg-vmhbadevs | tail +2 | awk '\{print $1}')

do

esxcfg-mpath -q --lun=$\{LUN} | grep FC

echo

done

echo

echo "****** \"active\" flag will be moved after disk activity *****"

echo

echo "Finished HBA Balance....."

find /vmfs/volumes -name *.vmx | while read vm

do

echo $vm

esxcfg-advcfg -s 0 /LVM/EnableResignature

service mgmt-vmware restart

vmware-cmd -s register "$vm"

vmware-cmd "$vm" start

done

Steve Beaver
VMware Communities User Moderator
VMware vExpert 2009 - 2020
VMware NSX vExpert - 2019 - 2020
====
Co-Author of "VMware ESX Essentials in the Virtual Data Center"
(ISBN:1420070274) from Auerbach
Come check out my blog: [www.virtualizationpractice.com/blog|http://www.virtualizationpractice.com/blog/]
Come follow me on twitter http://www.twitter.com/sbeaver

**The Cloud is a journey, not a project.**
0 Kudos
admin
Immortal
Immortal

Maybe if you used vimsh to register the VM you could specify the target folder directly, although I'm not sure exactly how to do it at the moment.

I also notice using vimsh there's a 'createdummyvm' command in the vmsvc section - not sure what this does but might be worth investigating.

Check out pages 9 & 10 of this whitepaper.

http://www.xtravirt.com/index.php?option=com_remository&Itemid=75&func=startdown&id=4

0 Kudos
VMKR9
Expert
Expert

For the UUID question what are people saying; Create or Keep, what are the affects / differences?

0 Kudos
lettech
Enthusiast
Enthusiast

General rule is if you copy a VM - use "create", if you move a VM use "keep". It is the unique identifier of the VM so if you copy a VM and use the same UUID you could likely cause a conflict.

0 Kudos