Some time ago I have blogged about perl scripts emulating well known physical network switch CLI commands (show mac-address-table and show interface status) for VMware Distributed Virtual Switch (aka VDS). See the blog post here "CLI for VMware Virtual Distributed Switch".
Now is the time to operationalize it. My scripts are written in Perl leveraging vSphere Perl SDK which is distributed by VMware as vCLI. vCLI is available for Linux and Windows OS. I personally prefer Linux over Windows, therefore, the implementation procedure below is for Centos 7.
Implementation procedure for Centos 7
1/ Install Centos 7 minimal OS installation
2/ Install Perl
yum install perl
3/ Install vCLI Prerequisite Software for Linux Systems with Internet Access
yum install e2fsprogs-devel libuuid-devel openssl-devel perl-devel
yum install glibc.i686 zlib.i686
yum install perl-XML-LibXML libncurses.so.5 perl-Crypt-SSLeay
4/ Install the vCLI Package on a Linux System with Internet Access
Download vSphere Perl SDK (Use link here)
tar –zxvf VMware-vSphere-CLI-6.X.X-XXXXX.x86_64.tar.gz
sudo vmware-vsphere-cli-distrib/vmware-install.pl
5/ Install VDSCLI scripts
# Create directory for vdscli
mkdir vdscli
# Change directory to vdscli
cd vdscli
# Install wget to be able to download VDSCLI files
yum install wget
# Download vdscli.pl
wget https://raw.githubusercontent.com/davidpasek/vdscli/master/vdscli.pl
# Download supporting shell wraper for show mac-address-table
wget https://raw.githubusercontent.com/davidpasek/vdscli/master/show-mac-address-table.sh
# Download supporting shell wraper for show interface status
wget https://raw.githubusercontent.com/davidpasek/vdscli/master/show-interface-status.sh
# Change mod of all files in VDSCLI directory to allow execution
chmod 755 *
# Edit shell wrappers with your specific vCenter hostname and credentials
It is highly recommended to create a specific readonly (AD or vSphere SSO) account for VDSCLI as depicted on screenshot below
6/ VDSCLI validation
# You must be in vdscli directory
# Run command below
./show-mac-address-table.sh
You should get mac address table for VMware distributed virtual switch. Something like on screenshot below
So now we have Perl scripts to get information from VMware Distributed Virtual Switch. So far so good. However, we would like to have Interactive CLI to have the same user experience as we have on physical switches CLI, right? For Interactive CLI I have decided to use Python ishell (https://github.com/italorossi/ishell).
7/ iShell installation
# Install python
yum install python
# Install and upgrade pip which is Python package manager
yum install epel-release
yum install python-pip
pip install --upgrade pip
# We need gcc therefore we install all development tools
yum group install "Development Tools"
yum install python-devel
yum install ncurses-devel
# Now we can finally install ishell
pip install ishell
8/ Interactive VDSCLI validation
# You must be in vdscli directory
# Run command bellow
./vdscli-ishell.py
You should be able to use an interactive shell with just two show commands. See. the screenshot below to get the impression how it works.
9/ Remote SSH or Telnet
The last step is to expose VDSCLI interactive shell over SSH or Telnet. I will show you how to do it for SSH but if you enable Telnet on your linux server it will work as well.
Let's add specific OS user
adduser admin
passwd admin
You have to copy all vdscli scripts to home dir of the newly created user (/home/admin). It is user admin in our case but you can create any username you want.
We have to add our interactive shell /home/admin/vdscli-ishell.py into /etc/shells because only programs configred there can be used as shells.
chsh admin
and use /home/vdscli/vdscli-ishell.py as a shell
CONCLUSION
So at the end you can simply ssh to Linux system we have build and immediately use CLI to VMware Distributed Switch as depicted on screenshot below
And that was the goal. Hope somebody else in VMware community will find it useful.
Now is the time to operationalize it. My scripts are written in Perl leveraging vSphere Perl SDK which is distributed by VMware as vCLI. vCLI is available for Linux and Windows OS. I personally prefer Linux over Windows, therefore, the implementation procedure below is for Centos 7.
Implementation procedure for Centos 7
1/ Install Centos 7 minimal OS installation
2/ Install Perl
yum install perl
3/ Install vCLI Prerequisite Software for Linux Systems with Internet Access
yum install e2fsprogs-devel libuuid-devel openssl-devel perl-devel
yum install glibc.i686 zlib.i686
yum install perl-XML-LibXML libncurses.so.5 perl-Crypt-SSLeay
4/ Install the vCLI Package on a Linux System with Internet Access
Download vSphere Perl SDK (Use link here)
tar –zxvf VMware-vSphere-CLI-6.X.X-XXXXX.x86_64.tar.gz
sudo vmware-vsphere-cli-distrib/vmware-install.pl
5/ Install VDSCLI scripts
# Create directory for vdscli
mkdir vdscli
# Change directory to vdscli
cd vdscli
# Install wget to be able to download VDSCLI files
yum install wget
# Download vdscli.pl
wget https://raw.githubusercontent.com/davidpasek/vdscli/master/vdscli.pl
# Download supporting shell wraper for show mac-address-table
wget https://raw.githubusercontent.com/davidpasek/vdscli/master/show-mac-address-table.sh
# Download supporting shell wraper for show interface status
wget https://raw.githubusercontent.com/davidpasek/vdscli/master/show-interface-status.sh
# Change mod of all files in VDSCLI directory to allow execution
chmod 755 *
# Edit shell wrappers with your specific vCenter hostname and credentials
It is highly recommended to create a specific readonly (AD or vSphere SSO) account for VDSCLI as depicted on screenshot below
vSphere SSO account for VDSCLI |
6/ VDSCLI validation
# You must be in vdscli directory
# Run command below
./show-mac-address-table.sh
You should get mac address table for VMware distributed virtual switch. Something like on screenshot below
Output from ./show-mac-address-table.sh |
So now we have Perl scripts to get information from VMware Distributed Virtual Switch. So far so good. However, we would like to have Interactive CLI to have the same user experience as we have on physical switches CLI, right? For Interactive CLI I have decided to use Python ishell (https://github.com/italorossi/ishell).
7/ iShell installation
# Install python
yum install python
# Install and upgrade pip which is Python package manager
yum install epel-release
yum install python-pip
pip install --upgrade pip
# We need gcc therefore we install all development tools
yum group install "Development Tools"
yum install python-devel
yum install ncurses-devel
# Now we can finally install ishell
pip install ishell
8/ Interactive VDSCLI validation
# You must be in vdscli directory
# Run command bellow
./vdscli-ishell.py
You should be able to use an interactive shell with just two show commands. See. the screenshot below to get the impression how it works.
VDSCLI Interactive Shell |
9/ Remote SSH or Telnet
The last step is to expose VDSCLI interactive shell over SSH or Telnet. I will show you how to do it for SSH but if you enable Telnet on your linux server it will work as well.
Let's add specific OS user
adduser admin
passwd admin
You have to copy all vdscli scripts to home dir of the newly created user (/home/admin). It is user admin in our case but you can create any username you want.
We have to add our interactive shell /home/admin/vdscli-ishell.py into /etc/shells because only programs configred there can be used as shells.
chsh admin
and use /home/vdscli/vdscli-ishell.py as a shell
CONCLUSION
So at the end you can simply ssh to Linux system we have build and immediately use CLI to VMware Distributed Switch as depicted on screenshot below
VDSCLI Interactive Shell over SSH |
No comments:
Post a Comment