PowerCLI

 View Only
  • 1.  How to add multiple iSCSI targets with static discovery

    Posted Oct 27, 2014 05:01 PM

    Trying to add multiple static discovery entries for a set of cluster hosts. I can add the first entry by running the following PowerCLI

    get-vmhost “vdi1.vdi.sf.local" | Get-VMHostHba -Type iScsi | New-IScsiHbaTarget -Address "172.27.32.30" -IScsiName iqn.2010-01.com.solidfire:bbup.desktop01.2514 -ChapName VDI-Desktops -ChapPassword j0iT18i17Vp4su>r -ChapType Required -type static

    However, whenever I try to add subsequent static discovery entries (I have 22 to add to the same discovery IP) I receive the following error:

    New-IScsiHbaTarget : 10/27/2014 9:17:28 AM    New-IScsiHbaTarget        The specified target

    '172.27.32.30:3260' already exists.

    At line:1 char:62

    + get-vmhost "vdi1.vdi.sf.local" | Get-VMHostHba -Type iScsi | New-IScsiHbaTarget  ...

    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

        + CategoryInfo          : InvalidArgument: (:) [New-IScsiHbaTarget], VimException

        + FullyQualifiedErrorId : Client20_StorageServiceImpl_TryValidateUniqueIScisTargetAddress_NonU

       niqueAddress,VMware.VimAutomation.ViCore.Cmdlets.Commands.Host.Storage.NewIScsiHbaTarget

    I can add multiple static targets to a single iSCSI server IP just fine with esxcli, but would prefer to have this done directly in PowerCLI without using $esxcli if possible.

    esxcli iscsi adapter discovery statictarget add -A vmhba38 -a 172.27.32.30:3260 -n iqn.2010-01.com.solidfire:bbup.desktop01.2514

    esxcli iscsi adapter target portal auth chap set -A vmhba38 -a 172.27.32.30 -d uni -N VDI-Desktops -l required -n iqn.2010-01.com.solidfire:bbup.desktop01.2514 -S j0iT18i17Vp4su>r

    esxcli iscsi adapter discovery statictarget add -A vmhba38 -a 172.27.32.30:3260 -n iqn.2010-01.com.solidfire:bbup.desktop02.2515

    esxcli iscsi adapter target portal auth chap set -A vmhba38 -a 172.27.32.30 -d uni -N VDI-Desktops -l required -n iqn.2010-01.com.solidfire:bbup.desktop02.2515 -S j0iT18i17Vp4su>r

    I must be missing something simple. Any help is much appreciated.



  • 2.  RE: How to add multiple iSCSI targets with static discovery
    Best Answer

    Posted Oct 27, 2014 07:40 PM

    Afaik it's not possible with current PowerCLI build to define multiple iScsiNames on the same target.

    You'll have to use the $esxcli I'm afraid.



  • 3.  RE: How to add multiple iSCSI targets with static discovery

    Posted Oct 28, 2014 06:32 PM

    Here is what I ended up cobbling together to get this done with $esxcli. It's ugly, but gets the job done :-)

    #Add static iSCSI targets to hosts

    Connect-VIServer -Server view-vcenter.vdi.sf.local -User vdi\administrator -Password P@ssw0rd

    $hosts = get-vmhost

    #Define the IQNs to add

    #Set $iqnprefix to cut down on length of commands

    $iqnprefix = "iqn.2010-01.com.solidfire:bbup."

    $volumeNames = @("desktop01","desktop02","desktop03","desktop04","desktop05","desktop06","desktop07","desktop08","desktop09","desktop10","desktop11","desktop12","desktop13","desktop14","desktop15","desktop16","desktop17","desktop18","desktop19","desktop20")

    $volumeIDs = @(2514..2530 + 2535..2537)

    #Storage virtual IP for the SolidFire system

    $svip = "172.27.32.30"

    $chapsecret = "j0iT18i17Vp4su>r"

    $account = "VDI-Desktops"

    foreach ($esx in $hosts) {

      write-host "Getting iSCSI adapter for host $esx"

      $hba = get-vmhost $esx | Get-VMHostHba -Type iScsi | Where {$_.Model -eq "iSCSI Software Adapter"}

      write-host "Setting up esxcli"

      $esxcli = get-esxcli -vmhost $esx

      write-host "Configuring targets on host $esx"

      for ($i = 0; $i -le 19; $i++) {

     

      $target = $iqnprefix + $volumeNames[$i] + "." + $volumeIDs[$i]

      write-host "Adding static target $target"

      $esxcli.iscsi.adapter.discovery.statictarget.add($hba, $svip, $target)

      $esxcli.iscsi.adapter.target.portal.auth.chap.set($hba, $svip, $account, $null, "uni", $false, "required", $target, $chapsecret)

      }

    }

    #Disconnect-VIServer -Server * -Force -Confirm:$false

    Write-Host "Done adding static targets" -ForegroundColor Green



  • 4.  RE: How to add multiple iSCSI targets with static discovery

    Posted Oct 28, 2014 06:47 PM

    Thanks for sharing that