VMware Cloud Community
kmarty009
Contributor
Contributor
Jump to solution

vMA Script Error for VMkernel Port

I've used this script in the past for various automated creations (thanks to Lamw).  But I seem to have an issue at line #32 (in bold and blue) in the script.  When I try to create the VMkernel port it errors out saying in the vMA "Failed to add vmkernel nic: A specified parameter was not correct."  "Vim.Host.VirtualNic.Specification.Ip".  Can  someone please look at what is wrong with m script?  Thanks in adavanced.

Here is my Config File

esxiserver.mydoamin.com:vSwitch1:ISCSI01:125:167.237.125.38:255.255.255.128

Here is the Script:

#!/bin/sh

if [ $# -ne 1 ]; then
         echo "Please provide configuration input file"
         exit 1
fi

CONFIG=$1

FIRST_HOST=$(head -1 ${CONFIG} | awk -F ":" '{print $1}')
source /opt/vmware/vma/bin/vifptarget -s ${FIRST_HOST} > /dev/null 2>&1

if [ $? -eq 0 ]; then
         IFS=$'\n'
         for LINE in $(cat ${CONFIG});
         do
                 VIHOST=$(echo ${LINE} | awk -F ":" '{print $1}')
                 VSWITCH=$(echo ${LINE} | awk -F ":" '{print $2}')
                 PORTGROUP=$(echo ${LINE} | awk -F ":" '{print $3}')
                 VLAN=$(echo ${LINE} | awk -F ":" '{print $4}')
                 IP=$(echo ${LINE} | awk -F ":" '{print $5}')
                 NETMASK=$(echo ${LINE} | awk -F ":" '{print $6}')
                 echo "Creating new vSwitch with Jumbo Frames ${VSWITCH} on target ${VIHOST}"
                 /usr/bin/esxcfg-vswitch --server ${VIHOST} -a ${VSWITCH}
                 /usr/bin/esxcfg-vswitch --server ${VIHOST} -m 9000 ${VSWITCH}
                 /usr/bin/esxcfg-vswitch --server ${VIHOST} -L vmnic2 ${VSWITCH}
                 /usr/bin/esxcfg-vswitch --server ${VIHOST} -L vmnic3 ${VSWITCH}
                 echo "Adding new portgroup ${PORTGROUP} with VLAN ${VLAN}"
                 /usr/bin/esxcfg-vswitch --server ${VIHOST} -A ${PORTGROUP} ${VSWITCH}
                 /usr/bin/esxcfg-vswitch --server ${VIHOST} -p ${PORTGROUP} -v ${VLAN} ${VSWITCH}
                  echo "Creating VMkernel Port ${PORTGROUP} with IP ${IP} on PORTGROUP ${PORTGROUP}"

               /usr/bin/esxcfg-vmknic --server ${VIHOST} -a -i ${IP} -n {NETMASK} -m 9000 ${PORTGROUP}  -- THIS IS THE ERROR IN THE SCRIPT

                echo
         done
         unset IFS
else
         echo "Unable to intialize vi-fastpass on target ${FIRST_HOST}"
         exit 1

0 Kudos
1 Solution

Accepted Solutions
lamw
Community Manager
Community Manager
Jump to solution

If you script is called blah.sh, instead of running it as ./blah.sh run it with sh -x blah.sh. This produces more output to see what the variables/etc. are getting as the script runs through it's logic. It's an easy way to debug

The error you're seeing is nothing with the script, I'm thinking that you're creating portgroup and then the interface back to back and it may be happening too quickly and hence you're getting an error with the input. Easy solution to verify this is add a sleep command before creating the VMkernel interface and see if that helps

View solution in original post

0 Kudos
6 Replies
lamw
Community Manager
Community Manager
Jump to solution

Are you able to manually run the esxcfg-vmknic with the parameters you're expecting

0 Kudos
kmarty009
Contributor
Contributor
Jump to solution

It does work if I create it manually from the CLI.  "esxcfg-vmknic -a -i 167.237.125.38 -n 255.255.255.128 -m 9000 ISCSI01"  Only in the script it errors.  Any thoughts?

0 Kudos
lamw
Community Manager
Community Manager
Jump to solution

Can you run sh -x when you run the script and also confirm that the VMkernel portgroup is in fact created before the VMkernel interface is created? Generally this error means something is not being passed correctly or does not exists

0 Kudos
kmarty009
Contributor
Contributor
Jump to solution

I apologize, I do not know what you mean by using sh -x.  Could you elaborate further on this to assist me please?  I appreciate all your help!

0 Kudos
lamw
Community Manager
Community Manager
Jump to solution

If you script is called blah.sh, instead of running it as ./blah.sh run it with sh -x blah.sh. This produces more output to see what the variables/etc. are getting as the script runs through it's logic. It's an easy way to debug

The error you're seeing is nothing with the script, I'm thinking that you're creating portgroup and then the interface back to back and it may be happening too quickly and hence you're getting an error with the input. Easy solution to verify this is add a sleep command before creating the VMkernel interface and see if that helps

0 Kudos
kmarty009
Contributor
Contributor
Jump to solution

lamw,

I found the error!!!  It was when using the sh -x myscript.sh I noticed that ${NETMASK} was the problem.  I setup the command in the script to look like this since they all use the same Netmask anyways.  I also added the "sleep 10" to slow it down.

/usr/bin/esxcfg-vmknic --server ${VIHOST} -a -i ${IP} -n 255.255.255.128 -m 9000 ${PORTGROUP}

Needless to say, I added this and now the script works fine.  Thanks for all you do to help us with automation.  You've help me save countless hours..... Smiley Happy

0 Kudos