Skip to content

Commit 692597e

Browse files
committed
name improvement for new hosts
If a name already exists but does not have the needed initiators a new host will be created with a UUID in the name
1 parent 10491b3 commit 692597e

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

PureStorage.FlashArray.VMware.Configuration/PureStorage.FlashArray.VMware.Configuration.psd1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Created by: Cody Hosterman
55
Organization: Pure Storage, Inc.
66
Filename: PureStorage.FlashArray.VMware.Configuration.psd1
7-
Version: 2.0.0.0
7+
Version: 2.0.0.1
88
Copyright: 2020 Pure Storage, Inc.
99
-------------------------------------------------------------------------
1010
Module Name: PureStorageFlashArrayVMwareConfigurationPowerShell
@@ -29,7 +29,7 @@
2929
RootModule = 'PureStorage.FlashArray.VMware.Configuration.psm1'
3030

3131
# Version number of this module; major.minor[.build[.revision]]
32-
ModuleVersion = '2.0.0.0'
32+
ModuleVersion = '2.0.0.1'
3333

3434
# ID used to uniquely identify this module
3535
GUID = '8f427302-6faf-42de-9f58-09276c3343cb'

PureStorage.FlashArray.VMware.Configuration/PureStorage.FlashArray.VMware.Configuration.psm1

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,19 @@ function New-PfaHostFromVmHost {
590590
$iqnJson = ("[" + ($iqn |ConvertTo-Json) + "]")
591591
}
592592
Write-debug $iqnJson
593-
$newFaHost = New-PfaRestOperation -resourceType host/$($esxi.NetworkInfo.HostName) -restOperationType POST -flasharray $fa -SkipCertificateCheck -jsonBody "{`"iqnlist`":$($iqnJson)}" -ErrorAction Stop
593+
try {
594+
$newFaHost = New-PfaRestOperation -resourceType host/$($esxi.NetworkInfo.HostName) -restOperationType POST -flasharray $fa -SkipCertificateCheck -jsonBody "{`"iqnlist`":$($iqnJson)}" -ErrorAction Stop
595+
}
596+
catch {
597+
if (($PSItem.ToString() |convertfrom-json).msg -eq "Host already exists.")
598+
{
599+
$randName = $esxi.NetworkInfo.HostName + (Get-Random -Maximum 99999 -Minimum 10000).ToString()
600+
$newFaHost = New-PfaRestOperation -resourceType host/$($randName) -restOperationType POST -flasharray $fa -SkipCertificateCheck -jsonBody "{`"iqnlist`":$($iqnJson)}" -ErrorAction Stop
601+
}
602+
else {
603+
throw ($PSItem.ToString()|convertfrom-json).msg
604+
}
605+
}
594606
$majorVersion = ((New-PfaRestOperation -resourceType array -restOperationType GET -flasharray $fa -SkipCertificateCheck).version[0])
595607
if ($majorVersion -ge 5)
596608
{
@@ -622,10 +634,24 @@ function New-PfaHostFromVmHost {
622634
$wwnsJson = ("[" + ($wwns |ConvertTo-Json) + "]")
623635
}
624636
Write-debug $wwnsJson
625-
$newFaHost = New-PfaRestOperation -resourceType host/$($esxi.NetworkInfo.HostName) -restOperationType POST -flasharray $fa -SkipCertificateCheck -jsonBody "{`"wwnlist`":$($wwnsJson)}" -ErrorAction Stop
637+
try {
638+
Write-Debug -Message "test1"
639+
$newFaHost = New-PfaRestOperation -resourceType host/$($esxi.NetworkInfo.HostName) -restOperationType POST -flasharray $fa -SkipCertificateCheck -jsonBody "{`"wwnlist`":$($wwnsJson)}" -ErrorAction Stop
640+
}
641+
catch {
642+
if (($PSItem.ToString() |convertfrom-json).msg -eq "Host already exists.")
643+
{
644+
$randName = $esxi.NetworkInfo.HostName + (Get-Random -Maximum 99999 -Minimum 10000).ToString()
645+
$newFaHost = New-PfaRestOperation -resourceType host/$($randName) -restOperationType POST -flasharray $fa -SkipCertificateCheck -jsonBody "{`"wwnlist`":$($wwnsJson)}" -ErrorAction Stop
646+
}
647+
else {
648+
throw ($PSItem.ToString() |convertfrom-json).msg
649+
}
650+
}
626651
$majorVersion = ((New-PfaRestOperation -resourceType array -restOperationType GET -flasharray $fa -SkipCertificateCheck).version[0])
627652
if ($majorVersion -ge 5)
628653
{
654+
Write-Debug -Message "test3"
629655
New-PfaRestOperation -resourceType host/$($newFaHost.name) -restOperationType PUT -flasharray $fa -SkipCertificateCheck -jsonBody "{`"personality`":`"esxi`"}" |Out-Null
630656
}
631657
$vmHosts += $newFaHost

0 commit comments

Comments
 (0)