Using REST to deploy an SBA on Sonus SBC1000/2000

Summary

This is a guide writes for the Sonus SBC1000/2000 with SBA. It may sometime be needed to deploy the SBA using scripting. To do it, the REST API is available and allow us to have a dynamic script that will start all the action and wait for their completion. This article contains all the steps required one by one then a script that is completely deploying the SBA in 30 min without human interaction.

Prerequisite

  1. Make sure you loaded 3.x base licenses into the SBC to have the REST license as “unlimited
  2. You need to have an SBC account with REST or Administrator access level
  3. Windows Management Framework 3.0: http://www.microsoft.com/en-us/download/details.aspx?id=34595 (Windows 7 download: Windows6.1-KB2506143-x64.msu)
  4. To Check your Version:
    1
    
    $host.version

Step by Step

Login

Defines the Login resource used to login to the Sonus SBC REST API. This is the first request that needs to be made before you can access any of the other REST Resources on the Sonus SBC 1000/2000 system. Using Resource – login.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
### Allow self Sign Cert
add-type @"
    using System.Net;
    using System.Security.Cryptography.X509Certificates;
 
    public class IDontCarePolicy : ICertificatePolicy {
        public IDontCarePolicy() {}
        public bool CheckValidationResult(
            ServicePoint sPoint, X509Certificate cert,
            WebRequest wRequest, int certProb) {
            return true;
        }
    }
"@
[System.Net.ServicePointManager]::CertificatePolicy = new-object IDontCarePolicy
 
### Login
$BodyValue = "Username=restuser&Password=restpass"
 
$url = "https://192.168.1.15/rest/login"
$Result = Invoke-RestMethod -Uri $url -Method Post -Body $BodyValue -SessionVariable ps

Update the recovery partition with a new ASM image (Optional)

This operation allows to load new software into the Recovery partition of the ASM through USB. Using Resource – sbaconfig.

Query

1
2
$url = "https://192.168.1.15/rest/sbaconfig?action=asmupdaterecoverypartition"
Invoke-RestMethod -Uri $url -Method POST -Body "" -WebSession $ps

Response

1
2
3
4
5
6
<?xml version="1.0"?>
<root>
 <status>
  <http_code>200</http_code>
 </status>
</root>

Action end on status

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
$url = "https://192.168.1.15/rest/sbaactionstatus"
Invoke-RestMethod -Uri $url -Method GET -WebSession $MyPs
 
<?xml version="1.0"?>
<root>
 <status>
  <http_code>200</http_code>
 </status>
 <sbaactionstatus href="https://192.168.1.15/rest/sbaactionstatus">
  <rt_Success>1</rt_Success>
  <rt_ActionType>28</rt_ActionType>
  <rt_PercentComplete>100</rt_PercentComplete>
  <rt_Duration>271</rt_Duration>
  <rt_StatusText>Image installation complete. If you need to apply this image, please remove the USB flash drive and perform the 'Reinitialize' action now</rt_StatusText>
  <rt_AllActionsBitmap>127</rt_AllActionsBitmap>
  <rt_ActionStartTime>0</rt_ActionStartTime>
 </sbaactionstatus>
</root>

Re-initialize the ASM (Optional)

Command to get the ASM images available

Retrieves the information of the factory image available on ASM. Using Resource – asmfactoryimage.

Query

1
2
$url = "https://192.168.1.15/rest/asmfactoryimage"
Invoke-RestMethod -Uri $url -Method GET  -WebSession $ps

Response

1
2
3
4
5
6
7
8
9
10
11
<?xml version="1.0"?>
<root>
 <status>
  <http_code>200</http_code>
</status>
 <asmfactoryimage_list count="3">
  <asmfactoryimage_pk id="1" href="https://192.168.1.15/rest/asmfactoryimage/1"/>
  <asmfactoryimage_pk id="3" href="https://192.168.1.15/rest/asmfactoryimage/3"/>
  <asmfactoryimage_pk id="2" href="https://192.168.1.15/rest/asmfactoryimage/2"/>
 </asmfactoryimage_list>
</root>

Command to get the ASM image details based on the ID:

Retrieves the detailed information of the factory image on ASM. Using Resource – asmfactoryimage.

Query

1
2
3
4
5
6
7
8
$url = "https://192.168.1.15/rest/asmfactoryimage/1"
Invoke-RestMethod -Uri $url -Method GET  -WebSession $ps
 
$url = "https://192.168.1.15/rest/asmfactoryimage/2"
Invoke-RestMethod -Uri $url -Method GET  -WebSession $ps
 
$url = "https://192.168.1.15/rest/asmfactoryimage/3"
Invoke-RestMethod -Uri $url -Method GET  -WebSession $ps

Response

1
2
3
4
5
6
7
8
9
10
11
<?xml version="1.0"?>
<root>
 <status>
  <http_code>200</http_code>
</status>
 <asmfactoryimage id="1" href="https://192.168.1.15/rest/asmfactoryimage/1">
  <Description>Lync 2013 SBA with SBC Comms 2.2.0b175</Description>
  <ImageDirectoryName>2013-05-02_10-08-26</ImageDirectoryName>
  <IsDefault>1</IsDefault>
 </asmfactoryimage>
</root>

Command to apply a new ASM image based on the ASM Image details

This action re-initializes the ASM and puts it in default factory state. Using Resource – sbaconfig.

Query

1
2
3
4
5
6
7
##########
$dirNam = "2013-05-02_10-08-26"
##########
 
$BodyValue = "dirName=$dirName"
$url = "https://192.168.1.15/rest/sbaconfig?action=asmreinitialize"
Invoke-RestMethod -Uri $url -Method POST -Body $BodyValue -WebSession $ps

Response

1
2
3
4
5
6
<?xml version="1.0"?>
<root>
 <status>
  <http_code>200</http_code>
 </status>
</root>

Action end on status

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
$url = "https://192.168.1.15/rest/sbaactionstatus"
Invoke-RestMethod -Uri $url -Method GET -WebSession $MyPs
 
<?xml version="1.0"?>
<root>
 <status>
  <http_code>200</http_code>
 </status>
 <sbaactionstatus href="https://192.168.1.15/rest/sbaactionstatus">
  <rt_Success>1</rt_Success>
  <rt_ActionType>9</rt_ActionType>
  <rt_PercentComplete>100</rt_PercentComplete>
  <rt_Duration>0</rt_Duration>
  <rt_StatusText>Re-initialization complete</rt_StatusText>
  <rt_AllActionsBitmap>0</rt_AllActionsBitmap>
  <rt_ActionStartTime>0</rt_ActionStartTime>
 </sbaactionstatus>
</root>

Configuring the ASM IP Settings

Modifies the SBA configuration resource. This is the first step in setting up the SBA. Using Resource – sbaconfig.

Query

1
2
3
4
5
6
7
8
9
10
11
12
13
$DHCPEnabled = 0
$ipv4Address = "192.168.1.14"
$ipv4Netmask = "255.255.255.0"
$ipv4Gateway = "192.168.1.1"
$RemoteDesktopEnabled = 1
$DNSServer1 = "192.168.1.100"
$DNSServer2 = "192.168.1.101"
$AclEnable = 1
##########
 
$BodyValue = "DHCPEnabled=$DHCPEnabled&ipv4Address=$ipv4Address&ipv4Netmask=$ipv4Netmask&ipv4Gateway=$ipv4Gateway&RemoteDesktopEnabled=$RemoteDesktopEnabled&DNSServer1=$DNSServer1&DNSServer2=$DNSServer2&AclEnable=$AclEnable"
$url = "https://192.168.1.15/rest/sbaconfig"
Invoke-RestMethod -Uri $url -Method POST -Body $BodyValue -WebSession $ps

Response

1
2
3
4
5
6
<?xml version="1.0"?>
<root>
 <status>
  <http_code>200</http_code>
 </status>
</root>

Action end on status

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
$url = "https://192.168.1.15/rest/sbaactionstatus"
Invoke-RestMethod -Uri $url -Method GET -WebSession $MyPs
 
<?xml version="1.0"?>
<root>
 <status>
  <http_code>200</http_code>
 </status>
 <sbaactionstatus href="https://192.168.1.15/rest/sbaactionstatus">
  <rt_Success>1</rt_Success>
  <rt_ActionType>31</rt_ActionType>
  <rt_PercentComplete>100</rt_PercentComplete>
  <rt_Duration>0</rt_Duration>
  <rt_StatusText>ASM Configuration successfully applied</rt_StatusText>
  <rt_AllActionsBitmap>0</rt_AllActionsBitmap>
  <rt_ActionStartTime>0</rt_ActionStartTime>
 </sbaactionstatus>
</root>

Joining the ASM to the domain

This action configures the domain that the SBA will connect to. Using Resource – sbaconfig.

Query

1
2
3
4
5
6
7
8
9
$hostName = "sba2013"
$domainName = "MyDomain.COM"
$userName = "MyDomain\administrator"
$userPassword = "Password"
##########
 
$BodyValue = "hostName=$hostName&domainName=$domainName&userName=$userName&userPassword=$userPassword"
$url = "https://192.168.1.15/rest/sbaconfig?action=joindomain"
Invoke-RestMethod -Uri $url -Method POST -Body $BodyValue -WebSession $ps

Response

1
2
3
4
5
6
<?xml version="1.0"?>
<root>
 <status>
  <http_code>200</http_code>
 </status>
</root>

Action end on status

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
$url = "https://192.168.1.15/rest/sbaactionstatus"
Invoke-RestMethod -Uri $url -Method GET -WebSession $MyPs
 
<?xml version="1.0"?>
<root>
 <status>
  <http_code>200</http_code>
 </status>
 <sbaactionstatus href="https://192.168.1.15/rest/sbaactionstatus">
  <rt_Success>1</rt_Success>
  <rt_ActionType>4</rt_ActionType>
  <rt_PercentComplete>100</rt_PercentComplete>
  <rt_Duration>107</rt_Duration>
  <rt_StatusText>join complete</rt_StatusText>
  <rt_AllActionsBitmap>1</rt_AllActionsBitmap>
  <rt_ActionStartTime>0</rt_ActionStartTime>
 </sbaactionstatus>
</root>

Deploying the SBA

Command to prepare the SBA bits

This action performs a number of low-level steps necessary to deploy the ASM packages. Using Resource – sbaconfig.

Query

1
2
$url = "https://192.168.1.15/rest/sbaconfig?action=deploy"
Invoke-RestMethod -Uri $url -Method POST -Body "" -WebSession $ps

Response

1
2
3
4
5
6
<?xml version="1.0"?>
<root>
 <status>
  <http_code>200</http_code>
 </status>
</root>

Action end on status

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
$url = "https://192.168.1.15/rest/sbaactionstatus"
Invoke-RestMethod -Uri $url -Method GET -WebSession $MyPs
 
<?xml version="1.0"?>
<root>
 <status>
  <http_code>200</http_code>
 </status>
 <sbaactionstatus href="https://192.168.1.15/rest/sbaactionstatus">
  <rt_Success>1</rt_Success>
  <rt_ActionType>22</rt_ActionType>
  <rt_PercentComplete>100</rt_PercentComplete>
  <rt_Duration>1502</rt_Duration>
  <rt_StatusText>Complete</rt_StatusText>
  <rt_AllActionsBitmap>3</rt_AllActionsBitmap>
  <rt_ActionStartTime>0</rt_ActionStartTime>
 </sbaactionstatus>
</root>

Command to start the replication with Lync Server:

This action causes the Communications Server to begin configuration replication with the domain. This is a necessary step for bringing up the CS configuration as well as receiving updates from the domain. Using Resource – sbaconfig.

Query

1
2
$url = "https://192.168.1.15/rest/sbaconfig?action=startreplication"
Invoke-RestMethod -Uri $url -Method POST -Body "" -WebSession $ps

Response

1
2
3
4
5
6
<?xml version="1.0"?>
<root>
 <status>
  <http_code>200</http_code>
 </status>
</root>

Action end on status

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
$url = "https://192.168.1.15/rest/sbaactionstatus"
Invoke-RestMethod -Uri $url -Method GET -WebSession $MyPs
 
<?xml version="1.0"?>
<root>
 <status>
  <http_code>200</http_code>
 </status>
 <sbaactionstatus href="https://192.168.1.15/rest/sbaactionstatus">
  <rt_Success>1</rt_Success>
  <rt_ActionType>20</rt_ActionType>
  <rt_PercentComplete>100</rt_PercentComplete>
  <rt_Duration>268</rt_Duration>
  <rt_StatusText>replication started</rt_StatusText>
  <rt_AllActionsBitmap>7</rt_AllActionsBitmap>
  <rt_ActionStartTime>0</rt_ActionStartTime>
 </sbaactionstatus>
</root>

Command to activate SBA with Lync Server:

This action activates the Communications Server and must be done before the certificates are installed. Using Resource – sbaconfig.

Query

1
2
$url = "https://192.168.1.15/rest/sbaconfig?action=activatewithlync"
Invoke-RestMethod -Uri $url -Method POST -Body "" -WebSession $ps

Response

1
2
3
4
5
6
<?xml version="1.0"?>
<root>
 <status>
  <http_code>200</http_code>
 </status>
</root>

Action end on status

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
:
$url = "https://192.168.1.15/rest/sbaactionstatus"
Invoke-RestMethod -Uri $url -Method GET -WebSession $MyPs
 
<?xml version="1.0"?>
<root>
 <status>
  <http_code>200</http_code>
 </status>
 <sbaactionstatus href="https://192.168.1.15/rest/sbaactionstatus">
  <rt_Success>1</rt_Success>
  <rt_ActionType>7</rt_ActionType>
  <rt_PercentComplete>100</rt_PercentComplete>
  <rt_Duration>12</rt_Duration>
  <rt_StatusText>Activation Complete</rt_StatusText>
  <rt_AllActionsBitmap>15</rt_AllActionsBitmap>
  <rt_ActionStartTime>0</rt_ActionStartTime>
 </sbaactionstatus>
</root>

Generate and Import an SBA Certificate

This resource defines the generatecsr action on the SBA CSR Resource . It returns the CSR as the Response.It also able to auto-submit the request. Using Resource – sbacsr.

Query

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
$CA = "RDC.MyDomain.COM\MyDomain-DC-CA"
$CALogin = "MyDomain\Administrator"
$CAPassword = "Password"
$Domain = "MyDomain.com"
$Email = "Adrien@MyDomain.com"
$Organization = "MyOrg"
$OU = "AUTO"
$City = "Paris"
$State = "FR"
$Country = "FR"
$CsrTemplate = "WebServer"
$KeySize = 2048
##########
 
$BodyValue = "CA=$CA&CALogin=$CALogin&CAPassword=$CAPassword&Domain=$Domain&Email=$Email&Organization=$Organization&OU=$OU&City=$City&State=$State&Country=$Country&CsrTemplate=$CsrTemplate&KeySize=$KeySize"
$url = "https://192.168.1.15/rest/sbacsr?action=generatecsr"
$Result = Invoke-RestMethod -Uri $url -Method POST -Body $BodyValue -WebSession $ps

Response

1
2
3
4
5
6
<?xml version="1.0"?>
<root>
 <status>
  <http_code>200</http_code>
 </status>
</root>

Action end on status

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
$url = "https://192.168.1.15/rest/sbaactionstatus"
Invoke-RestMethod -Uri $url -Method GET -WebSession $MyPs
 
<?xml version="1.0"?>
<root>
 <status>
  <http_code>200</http_code>
 </status>
 <sbaactionstatus href="https://192.168.1.15/rest/sbaactionstatus">
  <rt_Success>1</rt_Success>
  <rt_ActionType>14</rt_ActionType>
  <rt_PercentComplete>100</rt_PercentComplete>
  <rt_Duration>11</rt_Duration>
  <rt_StatusText>Certificate successfully applied</rt_StatusText>
  <rt_AllActionsBitmap>31</rt_AllActionsBitmap>
  <rt_ActionStartTime>0</rt_ActionStartTime>
 </sbaactionstatus>
</root>

Starting the SBA Services

This action starts the network daemons for the services indicated. Using Resource – sbaconfig.

Query

1
2
3
4
$BodyValue = "serviceName=16"
 
$url = "https://192.168.1.15/rest/sbaconfig?action=enablesvc"
Invoke-RestMethod -Uri $url -Method POST -Body $BodyValue -WebSession $ps

Response

1
2
3
4
5
<?xml version="1.0"?><root>
 <status>
  <http_code>200</http_code>
 </status>
</root>

Action end on status

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
$url = "https://192.168.1.15/rest/sbaactionstatus"
Invoke-RestMethod -Uri $url -Method GET -WebSession $MyPs
 
<?xml version="1.0"?>
<root>
 <status>
  <http_code>200</http_code>
 </status>
 <sbaactionstatus href="https://192.168.1.15/rest/sbaactionstatus">
  <rt_Success>1</rt_Success>
  <rt_ActionType>1</rt_ActionType>
  <rt_PercentComplete>100</rt_PercentComplete>
  <rt_Duration>139</rt_Duration>
  <rt_StatusText>Services successfully started (16)</rt_StatusText>
  <rt_AllActionsBitmap>63</rt_AllActionsBitmap>
  <rt_ActionStartTime>0</rt_ActionStartTime>
 </sbaactionstatus>
</root>

Applying an SBA Security Template

This action applies a security template to the node to prevent unauthorized changes from being made to the system. Using Resource – sbaconfig.

Query

1
2
3
4
$BodyValue = "templateType=0&sbaInstallFilename=0"
 
$url = "https://192.168.1.15/rest/sbaconfig?action=applysectemplate"
$Result = Invoke-RestMethod -Uri $url -Method POST -Body $BodyValue -WebSession $ps

Response

1
2
3
4
5
<?xml version="1.0"?><root>
 <status>
  <http_code>200</http_code>
 </status>
</root>

Action end on status

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
$url = "https://192.168.1.15/rest/sbaactionstatus"
Invoke-RestMethod -Uri $url -Method GET -WebSession $MyPs
 
<?xml version="1.0"?>
<root>
 <status>
  <http_code>200</http_code>
 </status>
 <sbaactionstatus href="https://192.168.1.15/rest/sbaactionstatus">
  <rt_Success>1</rt_Success>
  <rt_ActionType>21</rt_ActionType>
  <rt_PercentComplete>100</rt_PercentComplete>
  <rt_Duration>1</rt_Duration>
  <rt_StatusText>Security Template Applied</rt_StatusText>
  <rt_AllActionsBitmap>127</rt_AllActionsBitmap>
  <rt_ActionStartTime>0</rt_ActionStartTime>
 </sbaactionstatus>
</root>

Checking the SBA Status

To confirm that all the SBA services are running properly, check the status by Viewing the SBA Operational Status.

1
2
$url = "https://192.168.1.15/rest/asmfactoryimage/1"
$Result = Invoke-RestMethod -Uri $url -Method GET  -WebSession $ps

All in One

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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
### 1. Login
$NodeUrl = "192.168.1.15"
$NodeLogin = "restuser"
$NodePassword = "restpass"
 
### 2. Re-initialize the ASM
$LyncVersion = "Lync 2013"
 
### 3. Configuring the ASM IP Settings
$DHCPEnabled = 0
$ipv4Address = "192.168.1.14"
$ipv4Netmask = "255.255.255.0"
$ipv4Gateway = "192.168.1.1"
$RemoteDesktopEnabled = 1
$DNSServer1 = "192.168.1.100"
$DNSServer2 = "192.168.1.101"
$AclEnable = 1
 
### 4. Update SbcComms
 
### 5. Joining the ASM to a Domain
$hostName = "SBA2013"
$domainName = "MyDomain.COM"
$userName = "MyDomain\administrator"
$userPassword = "Password"
 
### 7. Generate and Import an SBA Certificate
$CA = "RDC.MyDomain.COM\MyDomain-RDC-CA"
$CALogin = "MyDomain\Administrator"
$CAPassword = "Password"
$Domain = "MyDomain.com"
$Email = "Adrien@MyDomain.com"
$Organization = "MyOrg"
$OU = "AUTO"
$City = "Paris"
$State = "FR"
$Country = "FR"
$CsrTemplate = "WebServer"
$KeySize = 2048
 
### 10. Install the Latest Lync SBA Cumulative Update (CU)
 
 
###################################
#### Define some function Helper
###################################
 
### Re-initialize the ASM with the correct ASM Image
function SearchImageDirectoryName {
    Param($MyLyncVersion, $MyNodeUrl, $MyPs)
    $url = "https://$MyNodeUrl/rest/asmfactoryimage"
    $ImageCmd = Invoke-RestMethod -Uri $url -Method GET  -WebSession $MyPs
    if ((BasicHandler $ImageCmd) -ne 1) {
        write-host "Failed on SearchImageDirectoryName: "(BasicHandler $ImageCmd)
        return 0
    }
    [xml]$ImageCmdXml= $ImageCmd.Substring(5)
    foreach ($image in $ImageCmdXml.root.asmfactoryimage_list.asmfactoryimage_pk.href) {
        $url = $image
        $ImageDetail = Invoke-RestMethod -Uri $url -Method GET -WebSession $MyPs
        [xml]$ImageDetailXml= $ImageDetail.Substring(5)
        if($ImageDetailXml.root.asmfactoryimage.Description.contains($MyLyncVersion)) { return $ImageDetailXml.root.asmfactoryimage.ImageDirectoryName}
    }
    return 0
}
 
### Return the result of the request
Function BasicHandler {
    Param($MyResult)
 
    [xml]$XmlResult = $MyResult.Substring(5)
    if($XmlResult.root.status.http_code.contains("200")) {
        return 1
    } else {
        return "Error Code:<"+$XmlResult.root.status.app_status.app_status_entry.code+"> Param:<"+$XmlResult.root.status.app_status.app_status_entry.params+">"
    }
}
 
### Return the result of the request
Function BasicHandlerCurl {
    Param($MyResult)
    $FiltredMyResult = ""
    foreach ($line in $MyResult) {
        if ($line.StartsWith("<")) {
            $FiltredMyResult += $line
        } elseif ($line.StartsWith(" ")) {
            $FiltredMyResult += $line
        }
    }
    [xml]$XmlResult = $FiltredMyResult
    if($XmlResult.root.status.http_code.contains("200")) {
        return 1
    } else {
        return "Error Code:<"+$XmlResult.root.status.app_status.app_status_entry.code+"> Param:<"+$XmlResult.root.status.app_status.app_status_entry.params+">"
    }
}
 
### Return the result of the last action
function LookCompletionStatus {
    Param($MyNodeUrl, $MyPs)
    $url = "https://$MyNodeUrl/rest/sbaactionstatus"
    $timer = 0
    while($timer -lt 3600) {
        $Result = Invoke-RestMethod -Uri $url -Method GET -WebSession $MyPs
        if ((BasicHandler $Result) -ne 1) { return 0}
        [xml]$FinalResult= $Result.Substring(5)
        if ($FinalResult.root.sbaactionstatus.rt_Success -eq 1) {
            if ($FinalResult.root.sbaactionstatus.rt_PercentComplete -eq 100) { return 1 }
        } else {
            return $FinalResult.root.sbaactionstatus.rt_StatusText
        }
        sleep 10
        $timer += 10
        write-host "- "$FinalResult.root.sbaactionstatus.rt_PercentComplete"% "$FinalResult.root.sbaactionstatus.rt_StatusText
    }
    return "Timout out"
}
 
###################################
#### Main Code
###################################
 
$ActualStep = 0
 
### 1. Login
$ActualStep = "1. Login"
add-type @"
    using System.Net;
    using System.Security.Cryptography.X509Certificates;
 
    public class IDontCarePolicy : ICertificatePolicy {
        public IDontCarePolicy() {}
        public bool CheckValidationResult(
            ServicePoint sPoint, X509Certificate cert,
            WebRequest wRequest, int certProb) {
            return true;
        }
    }
"@
[System.Net.ServicePointManager]::CertificatePolicy = new-object IDontCarePolicy                                         
 
$BodyValue = "Username=$NodeLogin&Password=$NodePassword"
$url = "https://$NodeUrl/rest/login"
$Result = Invoke-RestMethod -Uri $url -Method Post -Body $BodyValue -SessionVariable ps
if ((BasicHandler $Result) -ne 1) {
    write-host "Failed on "$ActualStep": "(BasicHandler $Result)
    return 0
}
 
### 2. Re-initialize the ASM
$ActualStep = "2. Re-initialize the ASM"
$dirName = SearchImageDirectoryName $LyncVersion $NodeUrl $ps
if ($dirName -eq 0) {
    write-host $ActualStep" Failed: Unable to find the proper ASM Image"
    return 0
}
$BodyValue = "dirName=$dirName"
$url = "https://$NodeUrl/rest/sbaconfig?action=asmreinitialize"
$Result = Invoke-RestMethod -Uri $url -Method POST -Body $BodyValue -WebSession $ps
if ((BasicHandler $Result) -ne 1) {
    write-host $ActualStep" Failed: "(BasicHandler $Result)
    return 0
}
if ((LookCompletionStatus $NodeUrl $ps) -ne 1) {
    write-host $ActualStep" Failed: "(BasicHandler $Result)
    return 0
}
 
 
### 3. Configuring the ASM IP Settings
$ActualStep = "3. Configuring the ASM IP Settings"
$BodyValue = "DHCPEnabled=$DHCPEnabled&ipv4Address=$ipv4Address&ipv4Netmask=$ipv4Netmask&ipv4Gateway=$ipv4Gateway&RemoteDesktopEnabled=$RemoteDesktopEnabled&DNSServer1=$DNSServer1&DNSServer2=$DNSServer2&AclEnable=$AclEnable"
$url = "https://$NodeUrl/rest/sbaconfig"
$Result = Invoke-RestMethod -Uri $url -Method POST -Body $BodyValue -WebSession $ps
if ((BasicHandler $Result) -ne 1) {
    write-host $ActualStep" Failed: "(BasicHandler $Result)
    return 0
}
if ((LookCompletionStatus $NodeUrl $ps) -ne 1) {
    write-host $ActualStep" Failed: "(BasicHandler $Result)
    return 0
}
 
### 4. Update SbcComms
 
### 5. Joining the ASM to a Domain
$ActualStep = "5. Joining the ASM to a Domain"
$BodyValue = "hostName=$hostName&domainName=$domainName&userName=$userName&userPassword=$userPassword"
$url = "https://$NodeUrl/rest/sbaconfig?action=joindomain"
$Result = Invoke-RestMethod -Uri $url -Method POST -Body $BodyValue -WebSession $ps
if ((BasicHandler $Result) -ne 1) {
    write-host $ActualStep" Failed: "(BasicHandler $Result)
    return 0
}
if ((LookCompletionStatus $NodeUrl $ps) -ne 1) {
    write-host $ActualStep" Failed: "(BasicHandler $Result)
    return 0
}
 
### 6. Deploying the SBA
$ActualStep = "6. Deploying the SBA"
$url = "https://$NodeUrl/rest/sbaconfig?action=deploy"
$Result = Invoke-RestMethod -Uri $url -Method POST -Body "" -WebSession $ps
if ((BasicHandler $Result) -ne 1) {
    write-host $ActualStep" Failed: "(BasicHandler $Result)
    return 0
}
if ((LookCompletionStatus $NodeUrl $ps) -ne 1) {
    write-host $ActualStep" Failed: "(BasicHandler $Result)
    return 0
}
 
$url = "https://$NodeUrl/rest/sbaconfig?action=startreplication"
$Result = Invoke-RestMethod -Uri $url -Method POST -Body "" -WebSession $ps
if ((BasicHandler $Result) -ne 1) {
    write-host $ActualStep" Failed: "(BasicHandler $Result)
    return 0
}
if ((LookCompletionStatus $NodeUrl $ps) -ne 1) {
    write-host $ActualStep" Failed: "(BasicHandler $Result)
    return 0
}
 
$url = "https://$NodeUrl/rest/sbaconfig?action=activatewithlync"
$Result = Invoke-RestMethod -Uri $url -Method POST -Body "" -WebSession $ps
if ((BasicHandler $Result) -ne 1) {
    write-host $ActualStep" Failed: "(BasicHandler $Result)
    return 0
}
if ((LookCompletionStatus $NodeUrl $ps) -ne 1) {
    write-host $ActualStep" Failed: "(BasicHandler $Result)
    return 0
}
 
### 7. Generate and Import an SBA Certificate
$ActualStep = "7. Generate and Import an SBA Certificate"
$BodyValue = "CA=$CA&CALogin=$CALogin&CAPassword=$CAPassword&Domain=$Domain&Email=$Email&Organization=$Organization&OU=$OU&City=$City&State=$State&Country=$Country&CsrTemplate=$CsrTemplate&KeySize=$KeySize"
$url = "https://$NodeUrl/rest/sbacsr?action=generatecsr"
$Result = Invoke-RestMethod -Uri $url -Method POST -Body $BodyValue -WebSession $ps
if ((BasicHandler $Result) -ne 1) {
    write-host $ActualStep" Failed: "(BasicHandler $Result)
    return 0
}
if ((LookCompletionStatus $NodeUrl $ps) -ne 1) {
    write-host $ActualStep" Failed: "(BasicHandler $Result)
    return 0
}
 
### 8. Starting the SBA Services
$ActualStep = "8. Starting the SBA Services"
$BodyValue = "serviceName=16"
$url = "https://$NodeUrl/rest/sbaconfig?action=enablesvc"
$Result = Invoke-RestMethod -Uri $url -Method POST -Body $BodyValue -WebSession $ps
if ((BasicHandler $Result) -ne 1) {
    write-host $ActualStep" Failed: "(BasicHandler $Result)
    return 0
}
if ((LookCompletionStatus $NodeUrl $ps) -ne 1) {
    write-host $ActualStep" Failed: "(BasicHandler $Result)
    return 0
}
 
### 9. Applying an SBA Security Template
$ActualStep = "9. Applying an SBA Security Template"
$BodyValue = "templateType=0&sbaInstallFilename=0"
$url = "https://$NodeUrl/rest/sbaconfig?action=applysectemplate"
$Result = Invoke-RestMethod -Uri $url -Method POST -Body $BodyValue -WebSession $ps
if ((BasicHandler $Result) -ne 1) {
    write-host $ActualStep" Failed: "(BasicHandler $Result)
    return 0
}
if ((LookCompletionStatus $NodeUrl $ps) -ne 1) {
    write-host $ActualStep" Failed: "(BasicHandler $Result)
    return 0
}
 
### 10. Install the Latest Lync SBA Cumulative Update

One thought on “Using REST to deploy an SBA on Sonus SBC1000/2000

Leave a Reply

Your email address will not be published. Required fields are marked *