UCS CLI & PowerShell Scripts

Adding VLAN’s and updating the vNIC templates is straightforward in the GUI; But if you have a lot of VLAN’s and vNIC templates to update then it quicker to add them via some kind of script. There are a number of ways to ways to script the UCS platform using the API.

  • The CLI is one of the ways we can manipulate the objects.
  • Another way is via Cisco’s UCS PowerTool, a Microsoft PowerShell add-on.

We will look at the CLI option first as it’s also useful if you don’t have PowerShell access.

Firstly you should download and take a look at the Cisco UCS Manager CLI Configuration Guide from Cisco website. This details all of the commands required to read/write/delete and manipulate the objects. After you have read the introduction section you should be ready to login to the UCS and start working with the CLI.  The CLI is a powerful tool and should be used with caution especially in production environments. I would highly recommend you download the free UCS emulator from Cisco website before entering the commands on a production environment.

Login to the UCS manager via SSH; you should see something similar to the output below.

Cisco UCS 6200 Series Fabric Interconnect
Using keyboard-interactive authentication.
Password:
Cisco Nexus Operating System (NX-OS) Software
TAC support: http://www.cisco.com/tac
Copyright (c) 2009, Cisco Systems, Inc. All rights reserved.
The copyrights to certain works contained in this software are
owned by other third parties and used and distributed under
license. Certain components of this software are licensed under
the GNU General Public License (GPL) version 2.0 or the GNU
Lesser General Public License (LGPL) Version 2.1. A copy of each
such license is available at
http://www.opensource.org/licenses/gpl-2.0.php and
http://www.opensource.org/licenses/lgpl-2.1.php

UCS-A#

For our example we are going to create a couple of VLAN’s and attach them to a vNIC template.

Firstly we need to determine the scope of our change, the list can be found in the configuration guide;

We will be making changes to the following scope/mode “Ethernet uplink” to change to this mode enter the following command on the command line “scope eth-uplink ” the prompt should change to /eth-uplink # to indicate the mode has changed.

To create a VLAN we now just issue the following commands;

  1. UCS-A# scope eth-uplink
  2. UCS-A /eth-uplink # create vlan MY_VLAN 1234
  3. UCS-A /eth-uplink/vlan* # (Press Crtl-Z)
  4. UCS-A* # show configuration pending
    scope eth-uplink
    +    enter vlan MY_VLAN 1234
    +        set mcastpolicy “”
    +        set native no
    +        set pubnwname “”
    +        set sharing none
    +        set vlan-comp-type included
    +        set vlan-id 1234
    +    exit
    exit
  5. UCS-A* # commit-buffer

To undo any changes before they are committed you can use issue the following command “discard-buffer”

To remove a VLAN you would issue the following commands:

  1. UCS-A# scope eth-uplink
  2. UCS-A /eth-uplink # delete vlan MY_VLAN
  3. UCS-A /eth-uplink/vlan* # commit-buffer

Warring: do not delete any vlans that are attached to vNIC templates before you have removed them from the templates otherwise you will be left with orphaned objects under the vNIC template network objects.

To view a list of the vNIC templates currently created issue the following command:

UCS-A /org # show vnic-templ

vNIC Template:
Name                 Type              Fabric ID
——————– —————– ———
vNIC-0-Fbc-A-DMZ     Updating Template A
vNIC-1-Fbc-B-DMZ     Updating Template B
UCS-A /org #

You can issue the “show vnic-templ vNIC-0-Fbc-A-DMZ expand” to view a list of attached VLAN’s

To Associate a VLAN with a vNIC template use the following commands:

UCS-A # scope org /
UCS-A /org # enter vnic-templ vNIC-0-Fbc-A-DMZ eth-if MY_VLAN

 

Now lets do the same using the Cisco UCS PowerTool.

The Cisco UCS PowerTool is not installed by default and will need to be downloaded and installed from Cisco’s Website before continuing;

I also recommend downloading a copy of the Cisco UCS PowerTool Userguide to get started, this is a very powerful tool that can be used to automate many if not all tasks performed within the Cisco UCS Manager.  If you are familiar with PowerShell scripts you should quickly be able to generate a few basic scripts.

To login to the UCS Manager from the PowerShell (PS) issue the following command “Connect-Ucs ip-address-of-ucs” this can be automated but for this example we will just be prompted for the Username and Password.

After you have connected you are ready to start scripting.

Lets start with creating a new VLAN.

Get-UcsLanCloud | Add-UcsVlan -DefaultNet no -Id 200 -Name PG-SALES

If you have lots objects to create you can group the commands together and execute them as a batch with the Start-UcsTransaction and Complete-UcsTransaction.

Start-UcsTransaction
Get-UcsLanCloud | Add-UcsVlan -DefaultNet no -Id 200 -Name PG-SALES
Get-UcsLanCloud | Add-UcsVlan -DefaultNet no -Id 201 -Name PG-TRANING
Get-UcsLanCloud | Add-UcsVlan -DefaultNet no -Id 202 -Name PG-FINANCE
Complete-UcsTransaction

To associate the VLAN’s with a vNIC Templates issue the following commands.

Start-UcsTransaction
Get-UcsOrg -Level root  | Get-UcsVnicTemplate -Name vNIC-0-Fabric-A | Add-UcsVnicInterface -ModifyPresent -DefaultNet false -Name PG-SALES
Get-UcsOrg -Level root  | Get-UcsVnicTemplate -Name vNIC-0-Fabric-A | Add-UcsVnicInterface -ModifyPresent -DefaultNet false -Name PG-TRANING
Get-UcsOrg -Level root  | Get-UcsVnicTemplate -Name vNIC-0-Fabric-A | Add-UcsVnicInterface -ModifyPresent -DefaultNet false -Name PG-FINANCE
Get-UcsOrg -Level root  | Get-UcsVnicTemplate -Name vNIC-1-Fabric-B | Add-UcsVnicInterface -ModifyPresent -DefaultNet false -Name PG-SALES
Get-UcsOrg -Level root  | Get-UcsVnicTemplate -Name vNIC-1-Fabric-B | Add-UcsVnicInterface -ModifyPresent -DefaultNet false -Name PG-TRANING
Get-UcsOrg -Level root  | Get-UcsVnicTemplate -Name vNIC-1-Fabric-B | Add-UcsVnicInterface -ModifyPresent -DefaultNet false -Name PG-FINANCE
Complete-UcsTransaction

To remove the VLAN association from the vNIC Template issue the following commands; You will also be prompted before deleting the association.

Start-UcsTransaction
Get-UcsOrg -Level root  | Get-UcsVnicTemplate -Name vNIC-0-Fabric-A | Get-UcsVnicInterface -Name PG-SALES | Remove-UcsVnicInterface
Get-UcsOrg -Level root  | Get-UcsVnicTemplate -Name vNIC-0-Fabric-A | Get-UcsVnicInterface -Name PG-TRANING | Remove-UcsVnicInterface
Get-UcsOrg -Level root  | Get-UcsVnicTemplate -Name vNIC-0-Fabric-A | Get-UcsVnicInterface -Name PG-FINANCE | Remove-UcsVnicInterface
Get-UcsOrg -Level root  | Get-UcsVnicTemplate -Name vNIC-1-Fabric-B | Get-UcsVnicInterface -Name PG-SALES | Remove-UcsVnicInterface
Get-UcsOrg -Level root  | Get-UcsVnicTemplate -Name vNIC-1-Fabric-B | Get-UcsVnicInterface -Name PG-TRANING | Remove-UcsVnicInterface
Get-UcsOrg -Level root  | Get-UcsVnicTemplate -Name vNIC-1-Fabric-B | Get-UcsVnicInterface -Name PG-FINANCE | Remove-UcsVnicInterface
Complete-UcsTransaction

To remove the VLANS issue the following commands.

Start-UcsTransaction
Get-UcsLanCloud | Get-UcsVlan -Name “PG-SALES” -LimitScope | Remove-UcsVlan
Get-UcsLanCloud | Get-UcsVlan -Name “PG-TRANING” -LimitScope | Remove-UcsVlan
Get-UcsLanCloud | Get-UcsVlan -Name “PG-FINANCE” -LimitScope | Remove-UcsVlan
Complete-UcsTransaction

You can also use the ConvertTo-UcsCmdlet to help you script tasks you preform in the GUI, this will allow you to capture the commands using the GUI and convert into a PowerShell script.

 

Leave a Comment

*