VMware Cloud Community
codeace
Contributor
Contributor
Jump to solution

vmware-cmd setconfig Alternative??

Hi folks,

I was looking to see if I could dynamically change the Network Configuration of a Clone running on a ESXi 3.5 host from command line. So I installed the CLI tools to access. But sadly the CLI documentation on Vmwaredoesn't tell anything about changing virtual machine configuration (NO SETCONFIG / GETCONFIG).

Then I found a lot of posts talking about the not working vmware-cmd <> setconfig <> command. I thought the problem has been fixed in the recent version, but looks like they just removed the "getconfig / setconfig" option. Even the setresource option is non-existent. BTW, the getconfigfile works great. But when I run the getconfig / setconfig nothing is returned to my console.

So I was wondering if they replaced it with some other option??? Does vmware-vim-cmd and vimsh scripting help?

Thanks in advance.

ssk

ssk
0 Kudos
1 Solution

Accepted Solutions
lamw
Community Manager
Community Manager
Jump to solution

Here is a script I just wrote using the vSphere SDK for Perl:

You'll need to install either the VI Perl Toolkit (VI 3.5) or vSphere SDK for Perl (vSphere 4.0), take a look at the documentation for the respective toolkit for further setup. Once you have it configured you'll be able to use the scrip to update a specific VM network adapter and set a specific portgroup.



=========================================================================

William Lam

VMware vExpert 2009

VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/

vGhetto Script Repository

VMware Code Central - Scripts/Sample code for Developers and Administrators

http://twitter.com/lamw

If you find this information useful, please award points for "correct" or "helpful".

View solution in original post

0 Kudos
13 Replies
codeace
Contributor
Contributor
Jump to solution

vimsh doesn't seem to do the job to change config. At least that is what I see from their documentation on their website.

Forgot to mention, I'm trying to change the Network configuration (change portgroup) of a particular clone from command line. Would be glad to try-out new tools.

ssk

ssk
0 Kudos
codeace
Contributor
Contributor
Jump to solution

To be more specific...

SETUP: I have two virtual machine port groups (VM_NET_1 and VM_NET_2) connected to same VMKernel port (MGMT_NETWORK) which inturn is linked to a single Physical adapter (NIC_1). I also have a virtual machine (CLONE_001) running and connected to VM_NET_1 by default.

PROBLEM: I would like to change the CLONE_001's network connection from VM_NET_1 to VM_NET_2 from command-line.

I tried esxcfg-vmmknic but doesn't look like that's the command I'll need :?

ssk

ssk
0 Kudos
AndreTheGiant
Immortal
Immortal
Jump to solution

I would like to change the CLONE_001's network connection from VM_NET_1 to VM_NET_2 from command-line.

You have to add a new portgroup and delete the old one.

Use:

esxcfg-vswitch

Andre

**if you found this or any other answer useful please consider allocating points for helpful or correct answers

Andrew | http://about.me/amauro | http://vinfrastructure.it/ | @Andrea_Mauro
0 Kudos
lamw
Community Manager
Community Manager
Jump to solution

Unfortunately there are no commands in vimsh that'll allow you to change a VMs portgroup, this was something I've tried to investigate but had no luck. You may want to take a look at using the VI API and utilize either vSphere SDK for Perl or PowerCLI to modify your VM. Take a look at this for a Perl solution, you can probably find something similar in the PowerCLI's forum

If you're still interested in doing this via the Service Console, take a look at a script I wrote: There is an operation called vnic which allows you to change the portgroup of the VM, it's really a hack because I'm actually manually updating the VM configuration file (.vmx) and then using vimsh to reload the configurations which will allow you to change the portgroup. One big caveat is this will not work if the VM is running, it must be powered down else the configurations will not persist.

Hopefully this will get you going in the right direction.

=========================================================================

William Lam

VMware vExpert 2009

VMware ESX/ESXi scripts and resources at:

VMware Code Central - Scripts/Sample code for Developers and Administrators

If you find this information useful, please award points for "correct" or "helpful".

lamw
Community Manager
Community Manager
Jump to solution

Please read the OP request more carefully, the question is regarding changing the portgroup/vlan of a VM, this has nothing to do with adding a portgroup to a vSwitch. Take a look at my reply for a possible solution

=========================================================================

William Lam

VMware vExpert 2009

VMware ESX/ESXi scripts and resources at:

VMware Code Central - Scripts/Sample code for Developers and Administrators

If you find this information useful, please award points for "correct" or "helpful".

0 Kudos
AndreTheGiant
Immortal
Immortal
Jump to solution

the question is regarding changing the portgroup/vlan of a VM, this has nothing to do with adding a portgroup to a vSwitch.

You are right, sorry for the misunderstanding.

Andre

Andrew | http://about.me/amauro | http://vinfrastructure.it/ | @Andrea_Mauro
0 Kudos
codeace
Contributor
Contributor
Jump to solution

Andre,

Once I read about the vicfg-vswitch, I thought maybe I didn't take a look at the command. But then it looks like I tried it and it doesn't help me solve the problem.

Lam,

Your post helps me. I would rather not be interested in the my-vmware-cmd because I don't want to have the ethernet changed upon power-off. It would have been awesome if I could use the vmware-cmd <> setconfig <> <> But to my sadness, it lookes like the options setconfig and getconfig has been chucked out of their documents and help list. I tried a vmware-cmd -h and it didn't list the setconfig option. Similar is it with their Command Line documentation Smiley Sad

Question 1: If look at this post people have been able to get the vmware-cmd <> setconfig <> <> to work. I believe they are using an older version of Vmware Remote CLI.. Is there a way to download a older version of RCLI???

Suggestion 1: Try the perl script suggested by Lam. I think Lam's other thread on the VIX API to the rescue is connected. Could you give me suggestions on where I must start to get working with the perl script post?? Is it VIX API 1.6.2 that I have to look into, to understand the working of that script??

Suggestion 2: There seem to a popular post that doing round on this community for the week. It is exactly the same question as mine, except that using API part. http://communities.vmware.com/thread/213679

Thanks Andre and Lam !!!

ssk
0 Kudos
lamw
Community Manager
Community Manager
Jump to solution

The vmware-cmd is actually a deprecated utility and there are known issues and some of the params may have worked in previous releases, but YMMV. It's really available for backwards compatibility for any scripts that may have been written in the past, but you won't find any new changes/improvements to the tool.

Best practice is to definitely taking a look at the VI API, which is exposed through vSphere SDK for Perl or PowerCLI. If you're looking at the Perl example, you'll want to start taking a look at the following documentation and install the toolkit on either your Windows/Linux or even VMware vMA system.

http://www.vmware.com/support/developer/vcli/

Here are additional links with more information and examples:

http://engr.ucsb.edu/~duonglt/vmware/#vmware_viptk

http://engr.ucsb.edu/~duonglt/vmware/#vmware_rcli

With regards to the Perl solution, you may need to write your own script using the snippet of code to get it working. I won't have access to my development system for few more days so I won't be able provide a working sample. You also may find something already written in PowerCLI, but you'll need to search the forum.

VIX is a totally different API and is specifically for guest management and not modifying the VM shell params, take a look here for more info: http://engr.ucsb.edu/~duonglt/vmware/#vmware_vix

Regarding: the OP was looking in changing the IP Address within the guest VM, this is different from what you're looking for and you will not be able to use VIX to do the same.

Hopefully this clears everything up, and definitely go through the documentation to get a better understanding of the various ways of accomplishing your task. At the end, if you're looking for a quick and completed solution without digging too much, I would highly recommend looking into PowerCLI...perhaps a solution already exists.

=========================================================================

William Lam

VMware vExpert 2009

VMware ESX/ESXi scripts and resources at:

VMware Code Central - Scripts/Sample code for Developers and Administrators

If you find this information useful, please award points for "correct" or "helpful".

lamw
Community Manager
Community Manager
Jump to solution

Here is a script I just wrote using the vSphere SDK for Perl:

You'll need to install either the VI Perl Toolkit (VI 3.5) or vSphere SDK for Perl (vSphere 4.0), take a look at the documentation for the respective toolkit for further setup. Once you have it configured you'll be able to use the scrip to update a specific VM network adapter and set a specific portgroup.



=========================================================================

William Lam

VMware vExpert 2009

VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/

vGhetto Script Repository

VMware Code Central - Scripts/Sample code for Developers and Administrators

http://twitter.com/lamw

If you find this information useful, please award points for "correct" or "helpful".

0 Kudos
codeace
Contributor
Contributor
Jump to solution

Gosh !! That was super-fast. Thanks Lam !!

I went to this http://communities.vmware.com/docs/DOC-10112 and there isin't any download link. Is it me or is there something I need to do to get the updateVMPortGroup.pl file??

ssk
0 Kudos
lamw
Community Manager
Community Manager
Jump to solution

Looks like the script did not get uploaded, give me a few. There are known issues with trying to create,modify VMTN documents which have been quite frustrating!

For now, I've attached the script here so you can download.

UPDATE1: It looks like the forum might have some issue with attaching files

UPDATE2: I've uploaded the script to our site, please find it here: http://engineering.ucsb.edu/~duonglt/vmware/updateVMPortgroup.pl


=========================================================================

William Lam

VMware vExpert 2009

VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/

vGhetto Script Repository

VMware Code Central - Scripts/Sample code for Developers and Administrators

http://twitter.com/lamw

If you find this information useful, please award points for "correct" or "helpful".

0 Kudos
codeace
Contributor
Contributor
Jump to solution

I don't have access to my ESXi server from here. So will try it and get back to at the earliest.

You are way too fast and definitely an VMware expert at this !!

Thanks again William Smiley Happy

ssk
0 Kudos
codeace
Contributor
Contributor
Jump to solution

HURRAYYYYYYYYY !http://communities.vmware.com/!!You rock man !! !http://communities.vmware.com/images/emoticons/confused.gif!

Your perl script works super-awesome !! Thanks a ton William !!

P.S: When I first run the script using my VMware Infrastructure Client login, it didn't work. So, you'll need the VCenter login details to use this script.

This is how I went about doing it.... (For quick reference am attaching the un-touched version of Lam's Script to this post)

1>> Download vSphere SKD for perl from

2>> You might want to setup PATH environment variable if you are using windows XP -

3>> Execute script with the following parameters from command line

<code>perl.exe updateVMPortgroup.pl --server SERVER_NAME_OR_IP --vmname VIRTUAL_MACHINE_NAME --vnic NETWORK_ADAPTER_NUMBER --portgroup NEW_PORT_GROUP_NAME</code>

Sample execution 1 : Update Network Adapter 1 to portgroup "production_network"

$ ./updateVMPortgroup.pl --server everest.primp-industries.com --vmname "thegeneral" --vnic 1 --portgroup "production_network"

Sample execution 2 : Update Network Adapter 2 to portgroup "test_network"

$ ./updateVMPortgroup.pl --server everest.primp-industries.com --vmname "thegeneral" --vnic 2 --portgroup "test_network"

Make sure you spell the VM portgroup correctly as it is case sensitive to your vSwitch configurations. To check, you can always run esxcfg-vswitch -l on the Service Console or using the vCLI.

All credits to Lam !!

http://communities.vmware.com/docs/DOC-10112

Thanks again Lam Smiley Happy

ssk
0 Kudos