bug_juice
Contributor
Contributor

How do you enable "Management traffic" with vim-cmd in ESXi 4.1?

Hi,

I need to enable "Traffic management" on a vmkernel port group from the commandline. I'm trying to use vim-cmd, but i can't seem to find the proper command for this. Is vim-cmd what i'm suppose to be using or is there a different way of doing this?

Thanks in advance.

16 Replies
FranckRookie
Leadership
Leadership

Hi Bug_juice,

I hope you'll find some information in that thread .

Regards

Franck

bug_juice
Contributor
Contributor

Thanks for the link. But i should of been more specific, i would like to use a command on the ESXi host itself so i can do everything from my post kickstart script. Is there any command within ESXi that I can enable "Management traffic"?

0 Kudos
FranckRookie
Leadership
Leadership

Have a look at "esxcfg-vmknic".

Regards

Franck

0 Kudos
bug_juice
Contributor
Contributor

I have. There doesn't seem to be any options in esxcfg-vmknic that enables "Management traffic".

0 Kudos
SVE
Contributor
Contributor

Did you find a way ton enable this from the commandline?

0 Kudos
bug_juice
Contributor
Contributor

Not at the moment, but i havent given up yet. i'm leaning on my internal contacts at VMware at the moment. When i learn more i'll post back.

0 Kudos
lamw
Community Manager
Community Manager

I'm sure you can use the vimsh's vim-cmd, but you can also enable and disable management traffic, vMotion and FT using vSphere SDK for Perl script remotely.

Check this script out -

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

William Lam

VMware vExpert 2009,2010

VMware scripts and resources at:

Twitter: @lamw

Getting Started with the vMA (tips/tricks)

Getting Started with the vSphere SDK for Perl

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

VMware Developer Community

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

0 Kudos
bug_juice
Contributor
Contributor

i've been unable to find the correct vimsh or vim-cmd for this. I've seen the SDK scripts but i'm just not ready to make that jump yet.

0 Kudos
lamw
Community Manager
Community Manager

I just played with it for a few minutes and found a way Smiley Wink It's actually pretty simple but may not be super obvious.

Remember that vimsh is still using the the APIs, but not all functionality is implemented or explicit. There's quite a few bugs with vimsh but if you want it all within a kickstart, it's understandable. Using the various SDK's like vSphere SDK for Perl or PowerCLI is really the approach to go.

Let me write this up tonight, as it's worth a post and I'll share with everyone tonight. Hope you can wait Smiley Happy

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

William Lam

VMware vExpert 2009,2010

VMware scripts and resources at:

Twitter: @lamw

Getting Started with the vMA (tips/tricks)

Getting Started with the vSphere SDK for Perl

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

VMware Developer Community

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

0 Kudos
bug_juice
Contributor
Contributor

You the man. Thanks!

0 Kudos
lamw
Community Manager
Community Manager

So I swear I was able to perform this option using just vimsh but once I got home, I've been unable to reproduce the results. I'm pretty sure it had worked, but perhaps it was too early in the morning ....

I'm assuming it was some type of advanced configuration to enable management interface, some of these advanced configurations are stored in /etc/vmware/esx.conf and if you've enabled vMotion or FT via vim-cmd, you'll notice entries in this configuration file. I took a look to see if there was anything related to the management interface and there is an entry called "/Net/ManagementIface" which by default is set to vmk0. I thought, perhaps this might be the correct entry and after giving it a try, I was able to enable the management interface for any valid vmkernel interface. I even created multiple interfaces and was able to enable without any issues. I'm not sure if it was a fluke or from other commands that some how made it work, as I said, I'm unable to reproduce the results.

Enable vMotion:

vim-cmd hostsvc/advopt/update Migrate.Vmknic string vmk1

Enable FT:

vim-cmd hostsvc/advopt/update FT.Vmknic string vmk1

Enable Management:

vim-cmd hostsvc/advopt/update Net.ManagementIface string vmk1

Refresh networking:

vim-cmd hostsvc/net/refresh

I was looking to see if there was another method and I thought of one which is indirectly making a call to the API method which is used in my vSphere SDK for Perl script to enable the various vmkernel interfaces using the vSphere MOB. I actually remembered another blogger who created a python script on an ESXi host which allowed him to join his host to vCenter w/o the use of the external SDK's - http://geauxvirtual.wordpress.com/2010/07/25/automatically-add-esxi-to-vcenter-from-esxi/

I adapted his example and produced the following python script:

import sys,re,os,urllib,urllib2

# William Lam
# Python URL code based on http://geauxvirtual.wordpress.com/2010/07/25/automatically-add-esxi-to-vcenter-from-esxi/

# connection info to MOB
url = "https://localhost/mob/?moid=ha-vnic-mgr&method=selectVnic"
username = "root"
password = "password"

#nicType = (management,vmotion,faultToleranceLogging)
nictype=sys.argv[1]

#device = (vmkX)
device=sys.argv[2]

#auth
passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
passman.add_password(None,url,username,password)
authhandler = urllib2.HTTPBasicAuthHandler(passman)
opener = urllib2.build_opener(authhandler)
urllib2.install_opener(opener)

#execute method
params = {'nicType':nictype,'device':device}
e_params = urllib.urlencode(params)
req = urllib2.Request(url,e_params)
page = urllib2.urlopen(req).read()

You will need to edit the script and specify the local root password and then the rest can be passed via the commandline.

You will need to specify the nicType which can be one of the following management,vmotion,faultToleranceLogging and the device which is vmkX where X is one of your vmkernel interface which can be listed using esxcfg-vmknic -l

Here is an example of enabling the management on vmk1:

~ # python enableVmkInterface.py management vmk1
~ #

If it was successful, you will not see any output from the script as the API method is void if executed successfully. If you take a look at the vSphere Client, you should see the Management Traffic enabled for the given vmkernel interface. It's not ideal as you require an additional script to execute, but at least this allows you to enable it directly in Tech Support Mode. Ideally, you'll want to use the SDK's to perform all this work, makes all this much much easier.

Sorry I was not able to get it working using vimsh

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

William Lam

VMware vExpert 2009,2010

VMware scripts and resources at:

Twitter: @lamw

Getting Started with the vMA (tips/tricks)

Getting Started with the vSphere SDK for Perl

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

VMware Developer Community

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

Tuurtje
Contributor
Contributor

Thank you so much for the pythonscript. If you use the script in %firstboot the root password is still empty.

%firstboot --unsupported --interpreter=python

import sys,re,os,urllib,urllib2

# William Lam
# Python URL code based on http://geauxvirtual.wordpress.com/2010/07/25/automatically-add-esxi-to-vcenter-from-esxi/

# connection info to MOB
url = "https://localhost/mob/?moid=ha-vnic-mgr&method=selectVnic"
username = "root"
password = ""

#auth
passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
passman.add_password(None,url,username,password)
authhandler = urllib2.HTTPBasicAuthHandler(passman)
opener = urllib2.build_opener(authhandler)
urllib2.install_opener(opener)

#execute method
params = {'nicType':'management','device':'vmk0'}
e_params = urllib.urlencode(params)
req = urllib2.Request(url,e_params)
page = urllib2.urlopen(req).read()

params = {'nicType':'management','device':'vmk2'}
e_params = urllib.urlencode(params)
req = urllib2.Request(url,e_params)
page = urllib2.urlopen(req).read()

0 Kudos
mossko
Contributor
Contributor

Hi Guys

I found another way to do this. After enabling Management Traffic in the VI Client, I noticed that one XML file on the ESXi host had changed: /etc/vmware/hostd/hostsvc.xml

Here's the code to enable the tickbox in the VI client

#

  1. Update the file /etc/vmware/hostd/hostsvc.xml with the parameters to tick the Management Network portgroup Management Traffic box

echo "Stopping the hostd"

/etc/init.d/hostd stop

sleep 5

echo "Enabling 'Management' on vmk0"

hostsvc=/etc/vmware/hostd/hostsvc.xml

hostsvcout=/etc/vmware/hostd/hostsvc.xml.new

sed -e 's/<ConfigRoot>/<ConfigRoot>\n <mangementVnics>\n <nic id="0000">vmk0<\/nic>\n <\/mangementVnics>/' $hostsvc > $hostsvcout

mv $hostsvcout $hostsvc

echo "Starting the hostd"

/etc/init.d/hostd start

NIC ID relates to the entry in /etc/vmware/esx.conf for vmk0

0 Kudos
Tuurtje
Contributor
Contributor

/etc/vmware/hostd/hostsvc.xml is stored in /vmfs/Hypervisor1/state.tgz.

If you know a way to save the state, your problem is fixed.

0 Kudos
Dave_Mishchenko
Immortal
Immortal

The file has the sticky bit enabled to it will be backed up as part of the system backup that runs when the host shuts down or every hour at 1 minute past.




Dave

VMware Communities User Moderator

Now available - vSphere Quick Start Guide

Do you have a system or PCI card working with VMDirectPath? Submit your specs to the Unofficial VMDirectPath HCL.

0 Kudos
mossko
Contributor
Contributor

I can confirm that when updating the hostsvc.xml file in the way I described earlier does keep the settings through reboots, and the "Management Traffic" tickbox in the vSphere client remains ticked. This would obviously also apply to lamw's post also

Hope this helps!

0 Kudos