Add_workflow_for_techpubs |
---|
AUTH1 | |
---|
JIRAIDAUTH | SYM-22656 |
---|
REV5 | |
---|
REV6 | |
---|
REV3 | |
---|
REV1 | |
---|
|
Summary
...
Getting Started
Info |
---|
Starting with Release 3.0 of firmware, the |
...
REST license is free of charge and you can use it for multiple scenarios. |
REST APIs are provided for developers who want to programmatically integrate the Sonus SBC 1000/2000 the
into their applications, and for administrators who want to script interactions with the
Sonus SBC 1000/2000..An example One of these scenarios is scripting provisioning, that which allows you to program multiple SBCs with the same parameters, in a one shot execution instead of having to program manually programming each one by one each SBCs. This is often the case when you need to deploy multiple SBCs in a the same countrycounty, creating and must create the same routing and transformation tables manually each time.
Here are some quick start tips to let you easily jump into This article outlines tips for accessing REST programming through Microsoft Powershell 3.
http://fiddler2.com/
Prerequisite
Prerequisites
Your system must include the following:
- Make sure you loaded 3.x base licenses loaded into the SBC to have ; this will define the REST license as “unlimited"
- You need to have an SBC account with REST or Administrator access level
- Windows Management Framework 3.0: http://www.microsoft.com/en-us/download/details.aspx?id=34595 (Windows 7 download: Windows6.1-KB2506143-x64.msu)To Check your Version:
Verify the Version
Verify the version of the host using the following command.
Login
Login using a public signed certificate (never tested)
...
Log into REST
Login without certificate
Code Block |
---|
### 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://134.56.226.215/rest/login"
Invoke-RestMethod -Uri $url -Method Post -Body $BodyValue -SessionVariable ps |
Basic REST requests - Samples
Create resources (PUT)
Code Block |
---|
$BodyValue = "Description=Default SIP Server"
$url = "https://134.56.226.215/rest/sipservertable/8"
Invoke-RestMethod -Uri $url -Method PUT -Body $BodyValue -WebSession $ps |
...
Code Block |
---|
$url = "https://134.56.226.215/rest/sipservertable/8"
Invoke-RestMethod -Uri $url -Method DELETE -Body "" -WebSession $ps |
Advanced REST Requests
Backup Configuration
Code Block |
---|
$DestFile = "C:\Users\plessisa\Desktop\Rest\backup.tar.gz"
$url = "https://134.56.226.215/rest/system?action=backup"
Invoke-RestMethod -Uri $url -Method POST -Body "" -WebSession $ps -OutFile $DestFile |
Restore Configuration
Code Block |
---|
$url= "https://134.56.226.215/rest/system?action=importconfig"
$body = "--MyBoundary`n"
$body += 'Content-Disposition: form-data; name="Filename"; filename="symphonyconfig.xml"'
$body += "`nContent-Type: application/xml`n`n"
$body += $(get-content symphonyconfig.xml -raw)
$body += "`n--MyBoundary--"
Invoke-RestMethod -uri $url -method POST -ContentType "multipart/form-data; boundary=MyBoundary" -body $body -WebSession $ps |
Upload new Sbc Firmware (Does not work)
Log in with cURL
This operation allows login to the
with cURL, and stores the PHP Session ID into Powershell for reuse later. Code Block |
---|
$login = ./curl.exe -k --data "Username=restuser&Password=restpass" -i -v |
Code Block |
---|
$url= "https://134192.56168.226123.21553/rest/partition/1?action=upgrade"
$body = "--MyBoundary`n"
$body += 'Content-Disposition: form-data; name="Filename"; filename="sbc1000-release-3.1.0.img"'
$body += "`nContent-Type: application/octet-stream`n`n"
$body += $(get-content sbc1000-release-3.1.0.img -raw)
$body += "`n--MyBoundary--"
Invoke-RestMethod -uri $url -method POST -ContentType "multipart/form-data; boundary=MyBoundary" -body $body -WebSession $ps
|
Upload new SbcComms (Does not work)
...
login
$PHPSESSID = 0
foreach ($line in $login) {
if ($line.contains("PHPSESSID=")) {
$correctline = $line.split(";")
$splitedline = $correctline.split("=")
$PHPSESSID = $splitedline[1]
}
} |
Update SbcComms
This operation allows installation of Communication service updates on the ASM. Refer to Resource - sbaconfig.
Query
Code Block |
---|
curl.exe --cookie PHPSESSID=$PHPSESSID -k -i https://134.56.226.215/rest/sbaconfig?action=sbaupgrade |
...
...
-F sbaInstallFilename=@setup.msi |
Response
Code Block |
---|
<?xml version="1.0"?>
<root>
<status>
<http_code>200</http_code>
</status>
</root> |
Action end on status
Code Block |
---|
$url = "https://134.56.226.215/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://134.56.226.215/rest/sbaactionstatus">
<rt_Success>1</rt_Success>
<rt_ActionType>15</rt_ActionType>
<rt_PercentComplete>100</rt_PercentComplete>
<rt_Duration>5</rt_Duration>
<rt_StatusText>setup.msi: Update Complete</rt_StatusText>
<rt_AllActionsBitmap>0</rt_AllActionsBitmap>
<rt_ActionStartTime>0</rt_ActionStartTime>
</sbaactionstatus>
</root> |
Scripting with REST
Basic Handler (PUT, POST, GET, DELETE)
Code Block |
---|
Function BasicHandler {
Param($ResultIn)
[xml]$XmlResultIn = $ResultIn.Substring(5)
if($XmlResultIn.root.status.http_code.contains("200")) {
return "Success"
} else {
return "Error Code:<"+$XmlResultIn.root.status.app_status.app_status_entry.code+"> Param:<"+$XmlResultIn.root.status.app_status.app_status_entry.params+">"
}
}
####### Expected
PS C:> BasicHandler $Result
Success
or
Error Code:<20013> Param:<8|SIPServerTable> |
Content Handler (GET)
Code Block |
---|
[xml]$FinalResult= $Result.Substring(5)
####### Expected Result
PS C:> $FinalResult.root.sipservertable.Description
Default SIP TOTO |
...