- Community Home
- >
- Storage
- >
- HPE Nimble Storage
- >
- Array Setup and Networking
- >
- PowerCLI to setup hosts networking and storage rea...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-26-2016 01:40 PM
тАО01-26-2016 01:40 PM
PowerCLI to setup hosts networking and storage ready for iSCSI LUNS
Hey,
I am by no means a scripting person, but the other day I had quite a few greenfield hosts to deploy, so I decided to use powercli to make life easier, and do the job quicker. Admittedly it took longer for me to actually find all the commands, but still, they can be used in the future.
Where in red you need to edit to fit your environment
#Setup which host to target
$VMhost = 'hostname'
#create vSwitch2 for storage, add vmnics, add two vmkernels with Storage IPs, setup NIC teaming (based on the fact you probably have vSwitch0 for mgmt and vSwitch1 for VM traffic)
$vs2 = get-vmhost $VMhost | new-virtualswitch -Name vSwitch2 -Nic 'vmnic2','vmnic5' -Mtu 9000 -NumPorts 120
New-VMHostNetworkAdapter -VMhost $VMhost -virtualswitch $vs2 -portgroup iSCSI_ESX_01 -ip IP_ADDR -subnetmask SUBNET_MASK -Mtu 9000
New-VMHostNetworkAdapter -VMhost $VMhost -virtualswitch $vs2 -portgroup iSCSI_ESX_02 -ip IP_ADDR -subnetmask SUBNET_MASK -Mtu 9000
Get-VirtualPortGroup -VMhost $host -virtualswitch $vs2 -Name iSCSI_ESX_01 | Get-NicTeamingPolicy | Set-NicTeamingPolicy -MakeNicActive vmnic2 -MakeNicUnused vmnic5
Get-VirtualPortGroup -VMhost $host -virtualswitch $vs2 -Name iSCSI_ESX_02 | Get-NicTeamingPolicy | Set-NicTeamingPolicy -MakeNicActive vmnic5 -MakeNicUnused vmnic2
#Create Software iSCSI Adapter
get-vmhoststorage $VMhost | set-vmhoststorage -softwareiscsienabled $True
#Get Software iSCSI adapter HBA number and put it into an array
$HBA = Get-VMHostHba -VMHost $VMHost -Type iSCSI | %{$_.Device}
#Set your VMKernel numbers, Use ESXCLI to create the iSCSI Port binding in the iSCSI Software Adapter,
$vmk1number = 'vmk1'
$vmk2number = 'vmk2'
$esxcli = Get-EsxCli -VMhost $VMhost
$Esxcli.iscsi.networkportal.add($HBA, $Null, $vmk1number)
$Esxcli.iscsi.networkportal.add($HBA, $Null, $vmk2number)
#Setup the Discovery iSCSI IP addresses on the iSCSI Software Adapter
$hbahost = get-vmhost $VMhost | get-vmhosthba -type iscsi
new-iscsihbatarget -iscsihba $hbahost -address IP_ADDR
#Rescan the HBA to discover any storage
get-vmhoststorage $VMhost -rescanallhba -rescanvmfs
If anyone wants to improve the above, reach out, I put this together in an afternoon/evening during the install I was on. So it was rushed and best effort.
This will also appear on my blog as well www.educationalcentre.co.uk.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-27-2016 01:20 PM
тАО01-27-2016 01:20 PM
Re: PowerCLI to setup hosts networking and storage ready for iSCSI LUNS
G'day Dean,
I wrote a similar script a few months back, so I'll put a couple of comments below as to where mine differed
I think you get the iSCSI HBA settings twice, which probably isn't needed
$HBA = Get-VMHostHba -VMHost $VMHost -Type iSCSI | %{$_.Device}
$hbahost = get-vmhost $VMhost | get-vmhosthba -type iscsi
With this particular line, the server could have additional hardware iSCSI HBAs, so I there in a where-object to make sure it was the software adapter:
$hbahost = Get-VMHostHba -VMHost $VMHost -Type iScsi | Where-Object {$_.Model -eq "iSCSI Software Adapter"}
I can't recall if Nimble Connection Manager (NCM) automatically adjusts the timeout values on the iSCSI software Adapter. In our environment (long story), some of our hosts connecting to Nimble Storage are using hardware adapter and some are using software adapter. Nimble best practice is to set the iSCSI Login Timeout, Noop Timout and Noop Interval to 30 seconds each, which can be done with the following as you have already imported esxcli:
$esxcli.iscsi.adapter.param.set($hbahost.device,$false,'LoginTimeout','30')
$esxcli.iscsi.adapter.param.set($hbahost.device,$false,'NoopOutTimeout','30')
$esxcli.iscsi.adapter.param.set($hbahost.device,$false,'NoopOutInterval','30')
As I was making this change to production servers as we were migrating from an old SAN to the Nimble storage, I also decided to place the host into maintenance mode before making these changes (just in case). Also I believe that the changes to the timeouts above require a reboot to apply, so I incorporated a host reboot into the script as well.
The other thing I did, was instead of having to modify the values below, I created a CSV file where I could put the values, and then just import the CSV at the start of the script and run a foreach loop to modify each host.
I've taken your script and added my suggestions above, as well as placed it in a foreach.
The CSV would look something like this, obviously with extra rows with specific info per host
hostname | Portgroup1 | Portgroup2 | Uplink1 | Uplink2 | IP1 | IP2 | VMK1Number | VMK2Number | iSCSITarget |
Server1 | iSCSI-Nimble1 | iSCSI-Nimble2 | vmnic6 | vmnic7 | 172.17.248.18 | 172.17.248.19 | vmk1 | vmk2 | 172.17.248.249 |
And the script is below. I haven't actually tested it but I've read over it and I think I have all of the variables lined up correctly
$HostData = import-csv C:\Scripts\Nimble_vSwitch.csv
foreach ($Host in $HostData){
#Place Host in maintenance mode
Set-VMHost -VMHost $Host.hostname -State Maintenance
#create vSwitch2 for storage, add vmnics, add two vmkernels with Storage IPs, setup NIC teaming (based on the fact you probably have vSwitch0 for mgmt and vSwitch1 for VM traffic)
$vs2 = New-VirtualSwitch -VMHost $Host.hostname -Name vSwitch2 -Nic $Host.Uplink1,$Host.Uplink2 -Mtu 9000 -NumPorts 120
New-VMHostNetworkAdapter -VMhost $Host.hostname -virtualswitch $vs2 -portgroup $host.Portgroup1 -ip $Host.IP1 -subnetmask 255.255.255.0 -Mtu 9000
New-VMHostNetworkAdapter -VMhost $Host.hostname -virtualswitch $vs2 -portgroup $host.Portgroup2 -ip $Host.IP2 -subnetmask 255.255.255.0 -Mtu 9000
Get-VirtualPortGroup -VMhost $Host.hostname -virtualswitch $vs2 -Name $Host.IP1 | Get-NicTeamingPolicy | Set-NicTeamingPolicy -MakeNicActive $Host.Uplink1 -MakeNicUnused $Host.Uplink2
Get-VirtualPortGroup -VMhost $Host.hostname -virtualswitch $vs2 -Name $Host.IP2 | Get-NicTeamingPolicy | Set-NicTeamingPolicy -MakeNicActive $Host.Uplink2 -MakeNicUnused $Host.Uplink1
#Create Software iSCSI Adapter
get-vmhoststorage $Host.hostname | set-vmhoststorage -softwareiscsienabled $True
#Get Software iSCSI adapter HBA number and put it into an array
$hbahost = Get-VMHostHba -VMHost $Host.hostname -Type iScsi | Where {$_.Model -eq "iSCSI Software Adapter"}
#Use ESXCLI to create the iSCSI Port binding in the iSCSI Software Adapter
$esxcli = Get-EsxCli -VMhost $Host.hostname
$Esxcli.iscsi.networkportal.add($hbahost.device, $Null, $Host.vmk1number)
$Esxcli.iscsi.networkportal.add($hbahost.device, $Null, $Host.vmk2number)
#Using esxcli, configure the LoginTimeout, NoopTimeout and NoopInterval values in seconds
$esxcli.iscsi.adapter.param.set($hbahost.device,$false,'LoginTimeout','30')
$esxcli.iscsi.adapter.param.set($hbahost.device,$false,'NoopOutTimeout','30')
$esxcli.iscsi.adapter.param.set($hbahost.device,$false,'NoopOutInterval','30')
#Setup the Discovery iSCSI IP addresses on the iSCSI Software Adapter
new-iscsihbatarget -iscsihba $hbahost -address $Host.iSCSITarget
#Restart the ESXi Host
Restart-VMHost -VMHost $Host.hostname -Confirm:$false
}
If time permits I was hoping to build this into a function so then someone could just run a cmdlet such as Create-NimblevSwitch with the various parameters.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-27-2016 02:18 PM
тАО01-27-2016 02:18 PM
Re: PowerCLI to setup hosts networking and storage ready for iSCSI LUNS
Wow Matt!
Cheers
So I knew I put it into a CSV file, but time meant it was quicker for me to just change the script for each host,
Thanks for the other information however, I'll look to incorporate that if the NCM doesn't do it already, and thanks for pointing out the duplicated effort. The great thing is, I understand the changes you've made, which shows my powershell knowledge is somewhat improving. Hopefully by the end of the year I'm creating proper toolkits
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-28-2016 01:03 PM
тАО01-28-2016 01:03 PM
Re: PowerCLI to setup hosts networking and storage ready for iSCSI LUNS
No worries Dean - thank you for originally sharing! I was meant to before Christmas but got tied up with some other stuff.
I've got a few hosts to build soon so I'll find some time to make a proper powershell function and publish it. I'll also check whether the modifications to the timeouts are required after NCM is installed (I think it is).
Powershell is a wonderful platform, I'm nowhere near skilled in it as I want to be, but I know enough to usually make my job a lot simpler or in some cases such as this, just automate the configuration if other tools aren't available in the environment such as host profiles.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-31-2016 08:46 PM
тАО01-31-2016 08:46 PM
Re: PowerCLI to setup hosts networking and storage ready for iSCSI LUNS
So, I got around to creating a powershell script for this task.
Decided it was probably easier to blog about it, so head on over to PowerCLI Function тАУ Configure ESXi Host for Connectivity to Nimble iSCSI SAN | Matt Alllford's Blog for some information.
As noted, it is a v1.0 script. Happy to accept feedback, good or bad. Hopefully this helps automate some of the work that might come up for those that don't have host profiles within the VMWare environment.
Example of the script:
Create-NimbleVSwitch.ps1 -HostMaintenanceMode -Hostname ESXi1 -Uplink1 vmnic1 -Uplink2 vmnic2 -vSwitchName iSCSIVSwitch -PortGroup1Name iSCSIPG1 -PortGroup2Name iSCSIPG2 -iSCSIAddress1 192.168.0.10 -iSCSIAddress2 192.168.0.11 -iSCSITargetAddress 192.168.0.250 -iSCSIVLAN 800 -MTU 9000 -RebootHost