Powershell – Automating HP c7000 Virtual Connect Domain Configuration

In preparation for private cloud deployment, our HP c7000 BladeSystem Virtual Connect domain needed configuration.  Of course, the VCEM modules allow CLI interaction, so I figured I could automate the process using a script.  Problem is, the SSH buffer maxes out after about 50-60 lines from the script, resulting in catastrophic configurations.  As always, PowerShell has come to the rescue.  After downloading and installing the SSH Sessions module for PowerShell, I was able to convert my script into PowerShell to deliver the script to the VC module in a controlled (and programmatic!) fashion.  In my experiences, the script I provide below took about 40 minutes to complete, with most of the time consumed by importing the enclosure and creating all the server profiles.

Some assumptions:

  1. The enclosure is not linked – we’re not currently linking our chasses, so the script assumes all ports begin with “enc0”
  2. The chassis this was tested against has the following layout; the script is designed to recognize the FC modules in bays 5-8, however, this layout has not been tested:
    Enet modules in bays 1,2
    FC modules in bays 3,4
    OA modules in bays 9,10
  3. The script is designed to recognize which ports in the Enet and FC modules are live, and will add them to UplinkSets and the fabric
  4. Server profiles are created for all 16 device bays
  5. Fault tolerance is built in through the use of two UplinkSets.  Each UplinkSet will contain identical networks (VLANs) that map to each Enet module.
  6. The server profiles have 6 Enet ports – 2 for management, 2 created for fault tolerant UplinkSets (see assumption #5 above), and two for VM migration (VMotion in this case because the blades are to have ESXi installed).  The order in which the Enet ports are added is important, so if you plan on customizing this script for fewer (or additional) ports, keep that in mind!
  7. VC Defined MAC addresses, serial numbers, and WWNs are used.

Keep in mind that you will need to determine the networks that will go into your domain, and add them to the script.  The network list below has been truncated in the interest of brevity.  In reality, your network list will probably be much longer (I have over 40 in production).  Any changes you make to the networks added to the UplinkSets will need to be mirrored in the server profile creation portion of the script

Use the script like so:

Config-VC.ps1 98KS8FG8 1 VCDomain-Name OAPassword

The variables are:

SSHTarget (IP/DNS of VC module)

VC module password (can be retrieved off the tag stuck to the front of the module)

PoolID (see assumption #7 above; don’t use the same pool ID for different enclosures; if you only have 1 enclosure, set this to 1)

VCDomainName (what you want your VC Domain name to be)

OAPassword (the password of your enclosure’s OA)

And below, I present the script:

  [Parameter(Mandatory=$True,Position=1)][string]$SSHTarget = "",
  [Parameter(Mandatory=$True,Position=2)][string]$PW = "98KS8FG8",
  [Parameter(Mandatory=$True,Position=3)][string]$PoolID = "1",
  [Parameter(Mandatory=$True,Position=4)][string]$domainName = "VCDomain-Name"
  [Parameter(Mandatory=$True,Position=5)][string]$OAPassword = "OAPassword"

Import-Module SSH-Sessions

New-SshSession -ComputerName $SSHTarget -Username Administrator -Password $PW

#Import OA enclosure
Invoke-SshCommand -ComputerName $SSHTarget -Command "import enclosure username=Administrator password=$OAPassword"

#Set domain name
Invoke-SshCommand -ComputerName $SSHTarget -Command "set domain name=$domainName"

#Set Admin PW
Invoke-SshCommand -ComputerName $SSHTarget -Command "set user Administrator password=NewPassword"

#Add uplink sets
Invoke-SshCommand -ComputerName $SSHTarget -Command "add uplinkset UplinkSet_A"
Invoke-SshCommand -ComputerName $SSHTarget -Command "add uplinkset UplinkSet_B"

#Add ports to uplink sets

$bays = Invoke-SshCommand -ComputerName $SSHTarget -Command "show uplinkport"
$ports = $bays.Split("`r`n")
$online = $ports | ? { $_.contains("Linked") -and -not $_.contains("Stacking Link") }
$online | % {
  $targetport = $_.substring(0,9).trim()

  if ($targetport.contains("enc0:1")) {
    Invoke-SshCommand -ComputerName $SSHTarget -Command "add uplinkport $targetport uplinkset=UplinkSet_A"
  } else {
    Invoke-SshCommand -ComputerName $SSHTarget -Command "add uplinkport $targetport uplinkset=UplinkSet_B"


#Add networks to uplinkports
Invoke-SshCommand -ComputerName $SSHTarget -Command "add network VMOTION_A"
Invoke-SshCommand -ComputerName $SSHTarget -Command "add network VMOTION_B"
Invoke-SshCommand -ComputerName $SSHTarget -Command "add network Messaging_A uplinkset=UplinkSet_A vlanid=100"
Invoke-SshCommand -ComputerName $SSHTarget -Command "add network Messaging_B uplinkset=UplinkSet_B vlanid=100"

#Set network speeds

#Set Fibre WWN
Invoke-SshCommand -ComputerName $SSHTarget -Command "set domain WwnType=VC-Defined WwnPool=$PoolID"

#Add Fabric

$a = @()
$b = @()
$ports = $bays.Split("`r`n")
$onlineFC = $ports | ? { $_.contains("Logged In") -and -not $_.contains("Not Logged In") }
$onlineFC | % {
  $targetport = $_.substring(0,8).trim().split(":")
  $test= $targetport[1] % 2

  if ($test -eq 0) { #even number
    $b += $targetport[2]
    $moduleB = $targetport[1]
  } else { #odd number
    $a += $targetport[2]
    $moduleA = $targetport[1]


$fabricA = $a -join ","
$fabricB = $B -join ","

Invoke-SshCommand -ComputerName $SSHTarget -Command "add fabric SAN_A Bay=$moduleA Ports=$fabricA"
Invoke-SshCommand -ComputerName $SSHTarget -Command "add fabric SAN_B Bay=$moduleB Ports=$fabricB"

#Power off servers before profile creation
Invoke-SshCommand -ComputerName $SSHTarget -Command "poweroff server *"

#Change server serial numbers
Invoke-SshCommand -ComputerName $SSHTarget -Command "set serverid Type=VC-Defined PoolId=$PoolID"
Invoke-SshCommand -ComputerName $SSHTarget -Command "set domain MacType=VC-Defined MacPool=$PoolID"

#Create Server Profiles - this is the section you will need to keep mirrored to your "Add networks to uplinkports" section above
1..16 | % {

  $Blade = $_.ToString("Blade_00")

  Invoke-SshCommand -ComputerName $SSHTarget -Command "add profile $($Blade) -nodefaultfcconn -nodefaultfcoeconn"
  Invoke-SshCommand -ComputerName $SSHTarget -Command "set enet-connection $($Blade) 1 Network=Management_VLAN_A"
  Invoke-SshCommand -ComputerName $SSHTarget -Command "set enet-connection $($Blade) 2 Network=Management_VLAN_B"
  Invoke-SshCommand -ComputerName $SSHTarget -Command "add enet-connection $($Blade)"
  Invoke-SshCommand -ComputerName $SSHTarget -Command "add server-port-map $($Blade):3 Messaging_A Uplinkset=UplinkSet_A"
  Invoke-SshCommand -ComputerName $SSHTarget -Command "add enet-connection $($Blade)"
  Invoke-SshCommand -ComputerName $SSHTarget -Command "add server-port-map $($Blade):4 Messaging_B Uplinkset=UplinkSet_B"
  Invoke-SshCommand -ComputerName $SSHTarget -Command "add enet-connection $($Blade) Network=VMOTION_A"
  Invoke-SshCommand -ComputerName $SSHTarget -Command "add enet-connection $($Blade) Network=VMOTION_B"
  Invoke-SshCommand -ComputerName $SSHTarget -Command "add fc-connection $($Blade) Fabric=SAN_A"
  Invoke-SshCommand -ComputerName $SSHTarget -Command "add fc-connection $($Blade) Fabric=SAN_B"


#Assign profiles to server bays
Invoke-SshCommand -ComputerName $SSHTarget -Command "assign profile Blade_01 enc0:1"
Invoke-SshCommand -ComputerName $SSHTarget -Command "assign profile Blade_02 enc0:2"
Invoke-SshCommand -ComputerName $SSHTarget -Command "assign profile Blade_03 enc0:3"
Invoke-SshCommand -ComputerName $SSHTarget -Command "assign profile Blade_04 enc0:4"
Invoke-SshCommand -ComputerName $SSHTarget -Command "assign profile Blade_05 enc0:5"
Invoke-SshCommand -ComputerName $SSHTarget -Command "assign profile Blade_06 enc0:6"
Invoke-SshCommand -ComputerName $SSHTarget -Command "assign profile Blade_07 enc0:7"
Invoke-SshCommand -ComputerName $SSHTarget -Command "assign profile Blade_08 enc0:8"
Invoke-SshCommand -ComputerName $SSHTarget -Command "assign profile Blade_09 enc0:9"
Invoke-SshCommand -ComputerName $SSHTarget -Command "assign profile Blade_10 enc0:10"
Invoke-SshCommand -ComputerName $SSHTarget -Command "assign profile Blade_11 enc0:11"
Invoke-SshCommand -ComputerName $SSHTarget -Command "assign profile Blade_12 enc0:12"
Invoke-SshCommand -ComputerName $SSHTarget -Command "assign profile Blade_13 enc0:13"
Invoke-SshCommand -ComputerName $SSHTarget -Command "assign profile Blade_14 enc0:14"
Invoke-SshCommand -ComputerName $SSHTarget -Command "assign profile Blade_15 enc0:15"
Invoke-SshCommand -ComputerName $SSHTarget -Command "assign profile Blade_16 enc0:16"

#Start servers
Invoke-SshCommand -ComputerName $SSHTarget -Command "poweron server enc0:1"
Invoke-SshCommand -ComputerName $SSHTarget -Command "poweron server enc0:2"
Invoke-SshCommand -ComputerName $SSHTarget -Command "poweron server enc0:3"
Invoke-SshCommand -ComputerName $SSHTarget -Command "poweron server enc0:4"
Invoke-SshCommand -ComputerName $SSHTarget -Command "poweron server enc0:5"
Invoke-SshCommand -ComputerName $SSHTarget -Command "poweron server enc0:6"
Invoke-SshCommand -ComputerName $SSHTarget -Command "poweron server enc0:7"
Invoke-SshCommand -ComputerName $SSHTarget -Command "poweron server enc0:8"
Invoke-SshCommand -ComputerName $SSHTarget -Command "poweron server enc0:9"
Invoke-SshCommand -ComputerName $SSHTarget -Command "poweron server enc0:10"
Invoke-SshCommand -ComputerName $SSHTarget -Command "poweron server enc0:11"
Invoke-SshCommand -ComputerName $SSHTarget -Command "poweron server enc0:12"
Invoke-SshCommand -ComputerName $SSHTarget -Command "poweron server enc0:13"
Invoke-SshCommand -ComputerName $SSHTarget -Command "poweron server enc0:14"
Invoke-SshCommand -ComputerName $SSHTarget -Command "poweron server enc0:15"
Invoke-SshCommand -ComputerName $SSHTarget -Command "poweron server enc0:16"

Leave a Reply