Public/Invoke-IBCLISetMembership.ps1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
function Invoke-IBCLISetMembership { [CmdletBinding()] param( [Parameter( ParameterSetName='NewStream', Mandatory=$true, Position=0, HelpMessage='Enter the Hostname or IP Address of an Infoblox appliance.' )] [ValidateNotNullOrEmpty()] [string] $ComputerName, [Parameter( ParameterSetName='ExistingStream', Mandatory=$true, Position=0, HelpMessage='Enter the ShellStream object returned by Connect-IBCLI.' )] [ValidateNotNull()] [Renci.SshNet.ShellStream] $ShellStream, [Parameter( ParameterSetName='NewStream', Mandatory=$true, Position=1, HelpMessage='Enter the credentials for the appliance.' )] [PSCredential] $Credential, [Parameter( ParameterSetName='NewStream', Mandatory=$true, Position=2, HelpMessage='Enter the Hostname or IP Address of the grid master.' )] [Parameter( ParameterSetName='ExistingStream', Mandatory=$true, Position=1, HelpMessage='Enter the Hostname or IP Address of the grid master.' )] [string] $GridMaster, [Parameter( ParameterSetName='NewStream', Mandatory=$true, Position=3, HelpMessage='Enter the name of the grid.' )] [Parameter( ParameterSetName='ExistingStream', Mandatory=$true, Position=2, HelpMessage='Enter the name of the grid.' )] [string] $GridName, [Parameter( ParameterSetName='NewStream', Mandatory=$true, Position=4, HelpMessage='Enter grid shared secret.' )] [Parameter( ParameterSetName='ExistingStream', Mandatory=$true, Position=3, HelpMessage='Enter grid shared secret.' )] [string] $GridSecret, [Parameter( ParameterSetName='NewStream' )] [Switch] $Force ) if ($PSCmdlet.ParameterSetName -eq 'NewStream') { $ShellStream = Connect-IBCLI $ComputerName $Credential -Force:$Force -ErrorAction Stop } Write-Verbose "Joining $($ShellStream.Session.ConnectionInfo.Host) to $GridName grid on master $GridMaster." try { # call set membership $output = Invoke-IBCLICommand 'set membership' $ShellStream # enter grid master if ($output[-1] -ne 'Enter new Grid Master VIP:') { $output | ForEach-Object { Write-Verbose $_ } throw "Unexpected output during 'set membership'" } $output = Invoke-IBCLICommand $GridMaster $ShellStream # enter grid name if ($output[-1] -ne 'Enter Grid Name [Default Infoblox]:') { $output | ForEach-Object { Write-Verbose $_ } throw "Unexpected output during 'set membership'" } $output = Invoke-IBCLICommand $GridName $ShellStream # enter grid secret if ($output[-1] -ne 'Enter Grid Shared Secret:') { $output | ForEach-Object { Write-Verbose $_ } throw "Unexpected output during 'set membership'" } $output = Invoke-IBCLICommand $GridSecret $ShellStream # confirmation 1 if ($output[-1] -ne 'Is this correct? (y or n):') { $output | ForEach-Object { Write-Verbose $_ } throw "Unexpected output during 'set membership'" } $output = Invoke-IBCLICommand 'y' $ShellStream # confirmation 2 if ($output[-1] -ne 'Are you sure? (y or n):') { $output | ForEach-Object { Write-Verbose $_ } throw "Unexpected output during 'set membership'" } $output = Invoke-IBCLICommand 'y' $ShellStream 2 "until it has been configured on the grid master.`r`n" if ($output[-1] -eq 'until it has been configured on the grid master.') { Write-Verbose "Join complete. Member restarting." return $true } else { $output | ForEach-Object { Write-Verbose $_ } throw "Unexpected output during 'set membership'" } } finally { # disconnect if we initiated the connection here if ($PSCmdlet.ParameterSetName -eq 'NewStream') { Disconnect-IBCLI $ShellStream } } <# .SYNOPSIS Join an Infoblox appliance to a grid. .DESCRIPTION Runs the 'set membership' command and answers the follow up prompts in order to join the target appliance to a grid. .PARAMETER ComputerName Hostname or IP Address of the Infoblox appliance. .PARAMETER ShellStream A Renci.SshNet.ShellStream object that was returned from Connect-IBCLI. .PARAMETER Credential Username and password for the Infoblox appliance. .PARAMETER GridMaster Hostname or IP Address of the grid master. .PARAMETER GridName The cosmetic name of the grid. 'Infoblox' is the default value on a new appliance. .PARAMETER GridSecret The grid's shared secret value used to join new members. .PARAMETER Force Disable SSH host key checking .OUTPUTS $true if the join was successful. .EXAMPLE Invoke-IBCLISetMembership 'ns2.example.com' (get-credential) 'ns1.example.com' 'MyGrid' 'MySecret' Joins the ns2.example.com appliance to the grid called MyGrid running on ns1.example.com. .EXAMPLE $ShellStream = Connect-IBCLI 'ns2.example.com' (Get-Credential) PS C:\>Invoke-IBCLISetMembership $ShellStream 'ns1.example.com' 'MyGrid' 'MySecret' Joins the ns2.example.com appliance to the grid called MyGrid running on ns1.example.com. .LINK Project: https://github.com/rmbolger/Posh-IBCLI .LINK Connect-IBCLI .LINK Disconnect-IBCLI #> } |