VMware Cloud Community
NathanEly
Contributor
Contributor
Jump to solution

Scripts to disconnect device mappings

We all know that VMotion and DRS won't work when virtual machines have devices mapped to host or remote media (/dev/cdrom, client device, etc). In the interest of optimizing cluster resources, ensure DRS and Vmotion will work for any VM, I'd like to run a script periodically to disconnect or remove all mappings on all VMs.

Has anyone built a script to do this? If so, I'd GREATLY appreciate if you could share. I know this would be a 'use at your own risk' script...

Thanks in advance

-N

Reply
0 Kudos
1 Solution

Accepted Solutions
TCronin
Expert
Expert
Jump to solution

Richard from www.run-virtual.com has a script that does exatly what you are looking for here:

http://www.run-virtual.com/?page_id=182

Tom Cronin, VCP, VMware vExpert 2009 - 2021, Co-Leader Buffalo, NY VMUG

View solution in original post

Reply
0 Kudos
3 Replies
conradsia
Hot Shot
Hot Shot
Jump to solution

Here is a script someone posted here (sorry for whoever wrote this and I can't give you credit for it) or somewhere to start all vm's registered on a host:

vmware-cmd -l | awk '\{cfg = $_} {command = "vmware-cmd \"" $cfg "\" start" } \{print cfg} \{system(command)}'

You can modify the script and change it from "start" to "disconnectdevice " for each device you want to disconnect. Create one of these for every device you want to disconnect and then create a shell script that calls each of these individually. You would need to run this on every ESX host.

Run the script at your will or schedule cron to run it for you every N mins, hours, days, etc. I tried to use the vmware-cmd to disconnect cd-roms in the past and I had no luck so if you get it working please post it.

TCronin
Expert
Expert
Jump to solution

Richard from www.run-virtual.com has a script that does exatly what you are looking for here:

http://www.run-virtual.com/?page_id=182

Tom Cronin, VCP, VMware vExpert 2009 - 2021, Co-Leader Buffalo, NY VMUG
Reply
0 Kudos
NathanEly
Contributor
Contributor
Jump to solution

Thank you both for your help. Both of these are very helpful.

Reply
0 Kudos