This repository has been archived by the owner on Jul 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
REST-CreatePoolInPartition.ps1
executable file
·127 lines (117 loc) · 4.62 KB
/
REST-CreatePoolInPartition.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
#----------------------------------------------------------------------------
# The contents of this file are subject to the "END USER LICENSE AGREEMENT
# FOR F5 Software Development Kit for iControl"; you may not use this file
# except in compliance with the License. The License is included in the
# iControl Software Development Kit.
#
# Software distributed under the License is distributed on an "AS IS"
# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
# the License for the specific language governing rights and limitations
# under the License.
#
# The Original Code is iControl Code and related documentation
# distributed by F5.
#
# The Initial Developer of the Original Code is F5 Networks,
# Inc. Seattle, WA, USA. Portions created by F5 are Copyright (C) 1996-2009
# F5 Networks, Inc. All Rights Reserved. iControl (TM) is a registered
# trademark of F5 Networks, Inc.
#
# Alternatively, the contents of this file may be used under the terms
# of the GNU General Public License (the "GPL"), in which case the
# provisions of GPL are applicable instead of those above. If you wish
# to allow use of your version of this file only under the terms of the
# GPL and not to allow others to use your version of this file under the
# License, indicate your decision by deleting the provisions above and
# replace them with the notice and other provisions required by the GPL.
# If you do not delete the provisions above, a recipient may use your
# version of this file under either the License or the GPL.
#----------------------------------------------------------------------------
param(
[string]$Bigip = "",
[string]$User = "",
[string]$Pass = "",
[string]$Pool = "",
[string]$Partition = ""
);
#----------------------------------------------------------------------------
function Get-PoolList()
#----------------------------------------------------------------------------
{
$uri = "/mgmt/tm/ltm/pool";
$link = "https://$Bigip$uri";
$headers = @{};
$headers.Add("ServerHost", $Bigip);
$secpasswd = ConvertTo-SecureString $Pass -AsPlainText -Force
$mycreds = New-Object System.Management.Automation.PSCredential ($User, $secpasswd)
$obj = Invoke-RestMethod -Method GET -Headers $headers -Uri $link -Credential $mycreds
$items = $obj.items;
Write-Host "POOL NAMES";
Write-Host "----------";
for($i=0; $i -lt $items.length; $i++) {
$name = $items[$i].fullPath;
Write-Host " $name";
}
}
#----------------------------------------------------------------------------
function Create-Pool()
#
# Description:
# This function creates a new pool if the given pool name doesn't
# already exist.
#
# Parameters:
# Name - The Name of the pool you wish to create.
# Partition - The name of the partition to place the pool in.
#----------------------------------------------------------------------------
{
param(
[string]$Name,
[string]$Partition
);
$uri = "/mgmt/tm/ltm/pool";
$link = "https://$Bigip$uri";
$headers = @{};
$headers.Add("ServerHost", $Bigip);
$headers.Add("Content-Type", "application/json");
$obj = @{
name=$Name
partition=$Partition
};
$body = $obj | ConvertTo-Json
$secpasswd = ConvertTo-SecureString $Pass -AsPlainText -Force
$mycreds = New-Object System.Management.Automation.PSCredential ($User, $secpasswd)
$obj = Invoke-RestMethod -Method POST -Uri $link -Headers $headers -Credential $mycreds -Body $body;
Write-Host "Pool ${Name} created in partition ${Partition}"
}
#----------------------------------------------------------------------------
function Show-Usage()
#
# Description:
# This function will print the script usage information.
#
#----------------------------------------------------------------------------
{
Write-Host @"
Usage: CreatePoolInPartition.ps1 Arguments
Argument - Description
---------- -----------
Bigip - The ip/hostname of your BIG-IP.
User - The Managmenet username for your BIG-IP.
Pass - The Management password for your BIG-IP.
Pool - The Name of the pool to create.
Partition - The Partition to place the pool in.
"@;
}
#============================================================================
# Main application logic
#============================================================================
if ( ($Bigip.Length -eq 0) -or ($User.Length -eq 0) -or ($Pass.Length -eq 0) ) {
Show-Usage;
} else {
if ( ($Pool.Length -eq 0) -or ($Partition.Length -eq 0) ) {
Get-PoolList;
} else {
Create-Pool -Name $Pool -Partition $Partition;
}
}