diff --git a/recipes/powershell/config/Config_trust_management_crud_operation.ps1 b/recipes/powershell/config/Config_trust_management_crud_operation.ps1 new file mode 100644 index 0000000..b4f4e50 --- /dev/null +++ b/recipes/powershell/config/Config_trust_management_crud_operation.ps1 @@ -0,0 +1,239 @@ +<# +.SYNOPSIS +This sample script demonstrates the use of NetBackup Trust Management APIs. + +.DESCRIPTION +The script can be run using NetBackup 8.2 or higher. +It updates the exclude list configuration on the specified client. The exclude list is specified within the script below. + +.EXAMPLE +./Config_trust_management_crud_operation.ps1 -MasterServer -UserName -Password -TrustedMasterServerName [-DomainName -DomainType ] +#> + +#Requires -Version 4.0 + +Param ( + [string]$MasterServer = $(Throw "Please specify the name of the NetBackup Master Server using the -MasterServer parameter."), + [string]$UserName = $(Throw "Please specify the user name using the -UserName parameter."), + [string]$Password = $(Throw "Please specify the password using the -Password parameter."), + [string]$TrustedMasterServerName = $(Throw "Please specify the name of the NetBackup remote Master Server using the -TrustedMasterServerName parameter."), + [string]$DomainName, + [string]$DomainType +) + + +############################################################### +# Setup to allow self-signed certificates and enable TLS v1.2 +############################################################### +Function Setup() +{ + # Allow self-signed certificates + if ([System.Net.ServicePointManager]::CertificatePolicy -notlike 'TrustAllCertsPolicy') + { + Add-Type -TypeDefinition @" + using System.Net; + using System.Security.Cryptography.X509Certificates; + public class TrustAllCertsPolicy : ICertificatePolicy { + public bool CheckValidationResult( + ServicePoint srvPoint, X509Certificate certificate, + WebRequest request, int certificateProblem) { + return true; + } + } +"@ + [System.Net.ServicePointManager]::CertificatePolicy = New-Object -TypeName TrustAllCertsPolicy + } + + # Force TLS v1.2 + try { + if ([Net.ServicePointManager]::SecurityProtocol -notcontains 'Tls12') { + [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 + } + } + catch { + Write-Host "`n"$_.Exception.InnerException.Message + } +} + +#################### +# Global Variables +#################### + +$port = 1556 +$basepath = "https://" + $MasterServer + ":" + $port + "/netbackup" +$contentType = "application/vnd.netbackup+json;version=4.0" +$hostName = $client + +###################################### +# Login to the NetBackup webservices +###################################### +Function Login() +{ + + $uri = $basepath + "/login" + + $body = @{ + userName=$UserName + password=$Password + } + if ($DomainName -ne "") { + $body.add("domainName", $DomainName) + } + if ($DomainType -ne "") { + $body.add("domainType", $DomainType) + } + Write-Host "`nSending a POST request to login to the NetBackup webservices...`n" + + $response = Invoke-WebRequest ` + -Uri $uri ` + -Method POST ` + -Body (ConvertTo-Json -InputObject $body) ` + -ContentType $contentType + + if ($response.StatusCode -ne 201) + { + throw "Unable to connect to the NetBackup Master Server" + } + + Write-Host "Login successful.`n" + $content = (ConvertFrom-Json -InputObject $response) + return $content +} +##################################################################### +# POST NetBackup Storage server +##################################################################### +Function CreateTrust() +{ + $base_uri = $basepath + "/config/servers/trusted-master-servers" + + $json = '{ + "data": { + "type": "trustedMasterServer", + "attributes": { + "trustedMasterServerName": "'+$TrustedMasterServerName+'", + "rootCAType": "NBCA", + "authenticationType": "CREDENTIAL", + "domainName": "DOMAIN", + "userName": "USER", + "password": "PASSWORD", + "fingerprint": "FINGERPRINT" + } + } + } + ' + $response_create_trust = Invoke-WebRequest ` + -Uri $base_uri ` + -Method POST ` + -Body ($json) ` + -ContentType $contentType ` + -Headers $headers + + if ($response_create_trust.StatusCode -ne 201) + { + throw "Unable to create trust between master servers." + } + + Write-Host "Trust between master servers created successfully.`n" + echo $response_create_trust + Write-Host $response_create_trust + + $response_create_trust = (ConvertFrom-Json -InputObject $response_create_trust) +} +##################################################################### +# GET NetBackup Trusted Master Server +##################################################################### +Function GetTrustedMaster() +{ + + $base_uri = $basepath + "/config/servers/trusted-master-servers/" + $TrustedMasterServerName + + + $response_get = Invoke-WebRequest ` + -Uri $base_uri ` + -Method GET ` + -ContentType $contentType ` + -Headers $headers + + if ($response_get.StatusCode -ne 200) + { + throw "Unable to fetch scpecified trusted master server" + } + + Write-Host "Scpecified trusted master server fetched successfully.`n" + Write-Host $response_get + + $response_get = (ConvertFrom-Json -InputObject $response_get) +} +##################################################################### +# PATCH NetBackup trust between master servers +##################################################################### +Function UpdateTrust() +{ + $base_uri = $basepath + "/config/servers/trusted-master-servers/" + $TrustedMasterServerName + + $json = '{ + "data": { + "type": "trustedMasterServer", + "attributes": { + "trustedMasterServerName": "'+$TrustedMasterServerName+'", + "rootCAType": "ECA" + } + } + } + ' + + $response_update = Invoke-WebRequest ` + -Uri $base_uri ` + -Method PATCH ` + -Body ($json) ` + -ContentType $contentType ` + -Headers $headers + + if ($response_update.StatusCode -ne 200) + { + throw "Unable to update trust between masters." + } + + Write-Host "Trust between masters updated successfully.`n" + echo $response_update + Write-Host $response_update + + $response_update = (ConvertFrom-Json -InputObject $response_update) + +} + + +##################################################################### +# Delete NetBackup Trust between master Server +##################################################################### +Function DeleteTrust() +{ + $base_uri = $basepath + "/config/servers/trusted-master-servers/" + $TrustedMasterServerName + + + $response_delete = Invoke-WebRequest ` + -Uri $base_uri ` + -Method DELETE ` + -ContentType $contentType ` + -Headers $headers + + if ($response_delete.StatusCode -ne 204 ) + { + throw "Unable to delete trust between masters." + } + + Write-Host "Trust between masters deleted successfully.`n" + Write-Host $response_delete + + $response_delete = (ConvertFrom-Json -InputObject $response_delete) +} + +########################################################################### + +Setup +$loginResponse = Login +$headers = @{"Authorization" = $loginResponse.token} +CreateTrust +GetTrustedMaster +UpdateTrust +DeleteTrust \ No newline at end of file diff --git a/recipes/powershell/config/README.md b/recipes/powershell/config/README.md index 8ec6979..160f18a 100644 --- a/recipes/powershell/config/README.md +++ b/recipes/powershell/config/README.md @@ -1,4 +1,4 @@ -### NetBackup API Code Samples for PowerShell +#### NetBackup API Code Samples for PowerShell This directory contains code samples to invoke NetBackup config APIs using PowerShell. @@ -14,3 +14,4 @@ Pre-requisites: Use the following commands to run the PowerShell samples. - `./configManagement_curd_operations.ps1 -MasterServer -UserName -Password -Client [-DomainName -DomainType ]` +- `./Config_trust_management_crud_operation.ps1 -MasterServer -UserName -Password -TrustedMasterServerName [-DomainName -DomainType ]` \ No newline at end of file diff --git a/recipes/python/config/README.md b/recipes/python/config/README.md index bcce2bb..11120d6 100644 --- a/recipes/python/config/README.md +++ b/recipes/python/config/README.md @@ -1,4 +1,4 @@ -### NetBackup Hosts Configuration Management API Code Samples +#### NetBackup Hosts Configuration Management API Code Samples This directory contains Python scripts demonstrating the use of NetBackup Hosts Configuration Management APIs to update exclude list on a NetBackup host. @@ -18,4 +18,5 @@ Use the following command to run the script. The command should be run from the `python -W ignore -m config.hosts_exclude_list -hostName -nbmaster -username -password [-domainName ] [-domainType ]` +`python -W ignore configure_storage_unit_end_to_end.py -nbmaster -username -password -trust_payload -trusted_master_server_name [-domainname ] [-domaintype ]` `Note: hostName is the name of the NetBackup host to set the exclude configuration. The exclude list is specified in the config/exclude_list file.` diff --git a/recipes/python/config/config.py b/recipes/python/config/config.py new file mode 100644 index 0000000..3a61e81 --- /dev/null +++ b/recipes/python/config/config.py @@ -0,0 +1,74 @@ +import requests + +content_type = "application/vnd.netbackup+json; version=4.0" + + +def perform_login(username, password, base_url, domain_name, domain_type): + url = base_url + "/login" + + if domain_name != "" and domain_type != "": + req_body = {"userName": username, "password": password, "domainName": domain_name, "domainType": domain_type} + else: + req_body = {"userName": username, "password": password} + + headers = {'Content-Type': content_type} + + print("performing POST on {} for user '{}'\n".format(url, req_body['userName'])) + + resp = requests.post(url, headers=headers, json=req_body, verify=False) + + if resp.status_code != 201: + raise Exception('Login API failed with status code {} and {}'.format(resp.status_code, resp.json())) + + return resp.json()['token'] + + +def get_trusted_master_server_by_name(jwt, base_url, trustedmasterservername): + url = base_url + "/config/servers/trusted-master-servers/" + trustedmasterservername + headers = {'Content-Type': content_type, 'Authorization': jwt} + query_params = { + # "page[limit]": 100, #This changes the default page size to 100 + # "filter": "jobType eq 'RESTORE'" #This adds a filter to only show RESTORE Jobs + } + + print("performing GET on {}\n".format(url)) + + resp = requests.get(url, headers=headers, params=query_params, verify=False) + + if resp.status_code != 200: + raise Exception('GET Trusted master server with specific name failed with status code {} and {}'.format(resp.status_code, resp.json())) + + return resp.json() + +def delete_trust(jwt, base_url, trustedmasterservername): + url = base_url + "/config/servers/trusted-master-servers/" +trustedmasterservername + headers = {'Content-Type': content_type, 'Authorization': jwt} + query_params = { + # "page[limit]": 100, #This changes the default page size to 100 + # "filter": "jobType eq 'RESTORE'" #This adds a filter to only show RESTORE Jobs + } + + print("performing DELETE on {}\n".format(url)) + + resp = requests.delete(url, headers=headers, verify=False) + if resp.status_code != 204: + raise Exception('DELETE trust with specific trusted master failed with status code {} and {}'.format(resp.status_code, resp.json())) + + print("\nThe Trust is deleted with status code: {}\n".format(resp.status_code)) + +def create_trusted_master_server(jwt, base_url, file_name): + url = base_url + "/config/servers/trusted-master-servers" + headers = {'Content-Type': content_type, 'Authorization': jwt} + + path = file_name + + req_body = open(path, 'r').read() + + print("performing POST on {}\n".format(url)) + + resp = requests.post(url, headers=headers, data=req_body, verify=False) + + if resp.status_code != 201: + raise Exception('Create trust between master servers API failed with status code {} and {}'.format(resp.status_code, resp.json())) + + return resp.json() diff --git a/recipes/python/config/trust_management_crud_operation.py b/recipes/python/config/trust_management_crud_operation.py new file mode 100644 index 0000000..1c309b2 --- /dev/null +++ b/recipes/python/config/trust_management_crud_operation.py @@ -0,0 +1,89 @@ +import sys +import config +import json +import texttable as tt + +# This script consists of the helper functions to excute NetBackup APIs for trust management crud operations. +# 1) Login to Netbackup +# 2) Create Trust between masters +# 3) Get Trusted master server +# 4) Delete Trust between master servers + +protocol = "https" +nbmaster = "" +username = "" +password = "" +domainname = "" +domaintype = "" + +port = 1556 + +def print_usage(): + print("Example:") + print("python -W ignore configure_storage_unit_end_to_end.py -nbmaster -username -password -trust_payload -trusted_master_server_name [-domainname ] [-domaintype ]\n\n\n") + +def read_command_line_arguments(): + if len(sys.argv)%2 == 0: + print_usage() + exit() + + global nbmaster + global username + global password + global domainname + global domaintype + global trust_payload + global trusted_master_server_name + + for i in range(1, len(sys.argv), 2): + if sys.argv[i] == "-nbmaster": + nbmaster = sys.argv[i + 1] + elif sys.argv[i] == "-username": + username = sys.argv[i + 1] + elif sys.argv[i] == "-password": + password = sys.argv[i + 1] + elif sys.argv[i] == "-trust_payload": + trust_payload = sys.argv[i + 1] + elif sys.argv[i] == "-trusted_master_server_name": + trusted_master_server_name = sys.argv[i + 1] + elif sys.argv[i] == "-domainname": + domainname = sys.argv[i + 1] + elif sys.argv[i] == "-domaintype": + domaintype = sys.argv[i + 1] + else: + print_usage() + exit() + + if nbmaster == "": + print("Please provide the value for 'nbmaster'") + exit() + elif username == "": + print("Please provide the value for 'username'") + exit() + elif password == "": + print("Please provide the value for 'password'") + exit() + elif trust_payload == "": + print("Please provide the value for 'trust_payload'") + exit() + elif trusted_master_server_name == "": + print("Please provide the value for 'trusted_master_server_name'") + exit() + + +print_usage() + +read_command_line_arguments() + +base_url = protocol + "://" + nbmaster + ":" + str(port) + "/netbackup" + +jwt = config.perform_login(username, password, base_url, domainname, domaintype) + +response_create_trust = config.create_trusted_master_server(jwt, base_url, trust_payload) +print(response_create_trust) + +response_get_trust = config.get_trusted_master_server_by_name(jwt, base_url, trusted_master_server_name) +print(response_get_trust) + +response_delete_trust = config.delete_trust(jwt, base_url, trusted_master_server_name) +print(response_delete_trust) diff --git a/snippets/powershell/config/Delete-NB-delete-trust.ps1 b/snippets/powershell/config/Delete-NB-delete-trust.ps1 new file mode 100644 index 0000000..cc8490d --- /dev/null +++ b/snippets/powershell/config/Delete-NB-delete-trust.ps1 @@ -0,0 +1,120 @@ +<# + +.SYNOPSIS +This sample script demonstrates the use of NetBackup REST API for deleting trust between masters. + +.DESCRIPTION +This script will delete trust between masters. + +.EXAMPLE +./Delete-NB-delete-trust.ps1 -nbmaster "nb-master.example.com" -username "administrator" -password "secret" -trustedmasterservername "Trusted Master Server Name" +#> + +param ( + [string]$nbmaster = $(throw "Please specify the name of NetBackup master server using -nbmaster parameter."), + [string]$username = $(throw "Please specify the user name using -username parameter."), + [string]$password = $(throw "Please specify the password using -password parameter."), + [string]$trustedmasterservername = $(throw "Please specify the trusted master server name using -trustedmasterservername parameter.") +) + +##################################################################### +# Initial Setup +# Note: This allows self-signed certificates and enables TLS v1.2 +##################################################################### + +function InitialSetup() +{ + + [Net.ServicePointManager]::SecurityProtocol = "Tls12" + + # Allow self-signed certificates + if ([System.Net.ServicePointManager]::CertificatePolicy -notlike 'TrustAllCertsPolicy') + { + Add-Type -TypeDefinition @" + using System.Net; + using System.Security.Cryptography.X509Certificates; + public class TrustAllCertsPolicy : ICertificatePolicy { + public bool CheckValidationResult( + ServicePoint srvPoint, X509Certificate certificate, + WebRequest request, int certificateProblem) { + return true; + } + } +"@ + [System.Net.ServicePointManager]::CertificatePolicy = New-Object -TypeName TrustAllCertsPolicy + [Net.ServicePointManager]::SecurityProtocol = "Tls12" + + # Force TLS v1.2 + try { + if ([Net.ServicePointManager]::SecurityProtocol -notcontains 'Tls12') { + [Net.ServicePointManager]::SecurityProtocol += [Net.SecurityProtocolType]::Tls12 + } + } + catch { + Write-Host $_.Exception.InnerException.Message + } + } +} + +InitialSetup +##################################################################### +# Global Variables +##################################################################### + +$port = 1556 +$basepath = "https://" + $nbmaster + ":" + $port + "/netbackup" +$content_type1 = "application/vnd.netbackup+json;version=1.0" +$content_type2 = "application/vnd.netbackup+json;version=2.0" +$content_type3 = "application/vnd.netbackup+json;version=3.0" +$content_type4 = "application/vnd.netbackup+json;version=4.0" + +##################################################################### +# Login +##################################################################### + +$uri = $basepath + "/login" + +$body = @{ + userName=$username + password=$password +} + +$response = Invoke-WebRequest ` + -Uri $uri ` + -Method POST ` + -Body (ConvertTo-Json -InputObject $body) ` + -ContentType $content_type1 + +if ($response.StatusCode -ne 201) +{ + throw "Unable to connect to the Netbackup master server!" +} +Write-Host "Login successful.`n" +$content = (ConvertFrom-Json -InputObject $response) + +##################################################################### +# Delete NetBackup Trust between master Server +##################################################################### + +$headers = @{ + "Authorization" = $content.token +} + +$base_uri = $basepath + "/config/servers/trusted-master-servers/" + $trustedmasterservername + + +$response_delete = Invoke-WebRequest ` + -Uri $base_uri ` + -Method DELETE ` + -ContentType $contentType ` + -Headers $headers + +if ($response_delete.StatusCode -ne 204 ) +{ + throw "Unable to delete trust between masters." +} + +Write-Host "Trust between masters deleted successfully.`n" +Write-Host $response_delete + +$response_delete = (ConvertFrom-Json -InputObject $response_delete) \ No newline at end of file diff --git a/snippets/powershell/config/Get-NB-get-media-server-by-name.ps1 b/snippets/powershell/config/Get-NB-get-media-server-by-name.ps1 new file mode 100644 index 0000000..b4aa66c --- /dev/null +++ b/snippets/powershell/config/Get-NB-get-media-server-by-name.ps1 @@ -0,0 +1,120 @@ +<# + +.SYNOPSIS +This sample script demonstrates the use of NetBackup REST API for fetching scpecified media server details. + +.DESCRIPTION +This script will fetch scpecified media server. + +.EXAMPLE +./Get-NB-get-media-server-by-name.ps1 -nbmaster "nb-master.example.com" -username "administrator" -password "secret" -medianame "Media Server Name" +#> + +param ( + [string]$nbmaster = $(throw "Please specify the name of NetBackup master server using -nbmaster parameter."), + [string]$username = $(throw "Please specify the user name using -username parameter."), + [string]$password = $(throw "Please specify the password using -password parameter."), + [string]$medianame = $(throw "Please specify the media name using -medianame parameter.") +) + +##################################################################### +# Initial Setup +# Note: This allows self-signed certificates and enables TLS v1.2 +##################################################################### + +function InitialSetup() +{ + + [Net.ServicePointManager]::SecurityProtocol = "Tls12" + + # Allow self-signed certificates + if ([System.Net.ServicePointManager]::CertificatePolicy -notlike 'TrustAllCertsPolicy') + { + Add-Type -TypeDefinition @" + using System.Net; + using System.Security.Cryptography.X509Certificates; + public class TrustAllCertsPolicy : ICertificatePolicy { + public bool CheckValidationResult( + ServicePoint srvPoint, X509Certificate certificate, + WebRequest request, int certificateProblem) { + return true; + } + } +"@ + [System.Net.ServicePointManager]::CertificatePolicy = New-Object -TypeName TrustAllCertsPolicy + [Net.ServicePointManager]::SecurityProtocol = "Tls12" + + # Force TLS v1.2 + try { + if ([Net.ServicePointManager]::SecurityProtocol -notcontains 'Tls12') { + [Net.ServicePointManager]::SecurityProtocol += [Net.SecurityProtocolType]::Tls12 + } + } + catch { + Write-Host $_.Exception.InnerException.Message + } + } +} + +InitialSetup +##################################################################### +# Global Variables +##################################################################### + +$port = 1556 +$basepath = "https://" + $nbmaster + ":" + $port + "/netbackup" +$content_type1 = "application/vnd.netbackup+json;version=1.0" +$content_type2 = "application/vnd.netbackup+json;version=2.0" +$content_type3 = "application/vnd.netbackup+json;version=3.0" +$content_type4 = "application/vnd.netbackup+json;version=4.0" + +##################################################################### +# Login +##################################################################### + +$uri = $basepath + "/login" + +$body = @{ + userName=$username + password=$password +} + +$response = Invoke-WebRequest ` + -Uri $uri ` + -Method POST ` + -Body (ConvertTo-Json -InputObject $body) ` + -ContentType $content_type1 + +if ($response.StatusCode -ne 201) +{ + throw "Unable to connect to the Netbackup master server!" +} +Write-Host "Login successful.`n" +$content = (ConvertFrom-Json -InputObject $response) + +##################################################################### +# GET NetBackup Media Server +##################################################################### + +$headers = @{ + "Authorization" = $content.token +} + +$base_uri = $basepath + "/config/media-servers/" + $medianame + + +$response_get = Invoke-WebRequest ` + -Uri $base_uri ` + -Method GET ` + -ContentType $contentType ` + -Headers $headers + +if ($response_get.StatusCode -ne 200) +{ + throw "Unable to fetch media server." +} + +Write-Host "Media server fetched successfully.`n" +Write-Host $response_get + +$response_get = (ConvertFrom-Json -InputObject $response_get) \ No newline at end of file diff --git a/snippets/powershell/config/Get-NB-get-media-server.ps1 b/snippets/powershell/config/Get-NB-get-media-server.ps1 new file mode 100644 index 0000000..9343a27 --- /dev/null +++ b/snippets/powershell/config/Get-NB-get-media-server.ps1 @@ -0,0 +1,119 @@ +<# + +.SYNOPSIS +This sample script demonstrates the use of NetBackup REST API for fetching media server details configured with provided master. + +.DESCRIPTION +This script will fetch media server details configured with provided master. + +.EXAMPLE +./Get-NB-get-media-server.ps1 -nbmaster "nb-master.example.com" -username "administrator" -password "secret" +#> + +param ( + [string]$nbmaster = $(throw "Please specify the name of NetBackup master server using -nbmaster parameter."), + [string]$username = $(throw "Please specify the user name using -username parameter."), + [string]$password = $(throw "Please specify the password using -password parameter.") +) + +##################################################################### +# Initial Setup +# Note: This allows self-signed certificates and enables TLS v1.2 +##################################################################### + +function InitialSetup() +{ + + [Net.ServicePointManager]::SecurityProtocol = "Tls12" + + # Allow self-signed certificates + if ([System.Net.ServicePointManager]::CertificatePolicy -notlike 'TrustAllCertsPolicy') + { + Add-Type -TypeDefinition @" + using System.Net; + using System.Security.Cryptography.X509Certificates; + public class TrustAllCertsPolicy : ICertificatePolicy { + public bool CheckValidationResult( + ServicePoint srvPoint, X509Certificate certificate, + WebRequest request, int certificateProblem) { + return true; + } + } +"@ + [System.Net.ServicePointManager]::CertificatePolicy = New-Object -TypeName TrustAllCertsPolicy + [Net.ServicePointManager]::SecurityProtocol = "Tls12" + + # Force TLS v1.2 + try { + if ([Net.ServicePointManager]::SecurityProtocol -notcontains 'Tls12') { + [Net.ServicePointManager]::SecurityProtocol += [Net.SecurityProtocolType]::Tls12 + } + } + catch { + Write-Host $_.Exception.InnerException.Message + } + } +} + +InitialSetup +##################################################################### +# Global Variables +##################################################################### + +$port = 1556 +$basepath = "https://" + $nbmaster + ":" + $port + "/netbackup" +$content_type1 = "application/vnd.netbackup+json;version=1.0" +$content_type2 = "application/vnd.netbackup+json;version=2.0" +$content_type3 = "application/vnd.netbackup+json;version=3.0" +$content_type4 = "application/vnd.netbackup+json;version=4.0" + +##################################################################### +# Login +##################################################################### + +$uri = $basepath + "/login" + +$body = @{ + userName=$username + password=$password +} + +$response = Invoke-WebRequest ` + -Uri $uri ` + -Method POST ` + -Body (ConvertTo-Json -InputObject $body) ` + -ContentType $content_type1 + +if ($response.StatusCode -ne 201) +{ + throw "Unable to connect to the Netbackup master server!" +} +Write-Host "Login successful.`n" +$content = (ConvertFrom-Json -InputObject $response) + +##################################################################### +# GET NetBackup Media Servers +##################################################################### + +$headers = @{ + "Authorization" = $content.token +} + +$base_uri = $basepath + "/config/media-servers" + + +$response_getAll = Invoke-WebRequest ` + -Uri $base_uri ` + -Method GET ` + -ContentType $contentType ` + -Headers $headers + +if ($response_getAll.StatusCode -ne 200) +{ + throw "Unable to fetch media servers." +} + +Write-Host "Media servers fetched successfully.`n" +Write-Host $response_getAll + +$response_getAll = (ConvertFrom-Json -InputObject $response_getAll) \ No newline at end of file diff --git a/snippets/powershell/config/Get-NB-get-remote-master-server-cacert-by-name.ps1 b/snippets/powershell/config/Get-NB-get-remote-master-server-cacert-by-name.ps1 new file mode 100644 index 0000000..da6ee24 --- /dev/null +++ b/snippets/powershell/config/Get-NB-get-remote-master-server-cacert-by-name.ps1 @@ -0,0 +1,120 @@ +<# + +.SYNOPSIS +This sample script demonstrates the use of NetBackup REST API for fetching scpecified remote master server cacert details. + +.DESCRIPTION +This script will fetch scpecified remote master server cacert details. + +.EXAMPLE +./Get-NB-get-remote-master-server-cacert-by-name.ps1 -nbmaster "nb-master.example.com" -username "administrator" -password "secret" -remotemasterserver "Remote Master Server Name" +#> + +param ( + [string]$nbmaster = $(throw "Please specify the name of NetBackup master server using -nbmaster parameter."), + [string]$username = $(throw "Please specify the user name using -username parameter."), + [string]$password = $(throw "Please specify the password using -password parameter."), + [string]$remotemasterserver = $(throw "Please specify the remote master server name using -remotemasterserver parameter.") +) + +##################################################################### +# Initial Setup +# Note: This allows self-signed certificates and enables TLS v1.2 +##################################################################### + +function InitialSetup() +{ + + [Net.ServicePointManager]::SecurityProtocol = "Tls12" + + # Allow self-signed certificates + if ([System.Net.ServicePointManager]::CertificatePolicy -notlike 'TrustAllCertsPolicy') + { + Add-Type -TypeDefinition @" + using System.Net; + using System.Security.Cryptography.X509Certificates; + public class TrustAllCertsPolicy : ICertificatePolicy { + public bool CheckValidationResult( + ServicePoint srvPoint, X509Certificate certificate, + WebRequest request, int certificateProblem) { + return true; + } + } +"@ + [System.Net.ServicePointManager]::CertificatePolicy = New-Object -TypeName TrustAllCertsPolicy + [Net.ServicePointManager]::SecurityProtocol = "Tls12" + + # Force TLS v1.2 + try { + if ([Net.ServicePointManager]::SecurityProtocol -notcontains 'Tls12') { + [Net.ServicePointManager]::SecurityProtocol += [Net.SecurityProtocolType]::Tls12 + } + } + catch { + Write-Host $_.Exception.InnerException.Message + } + } +} + +InitialSetup +##################################################################### +# Global Variables +##################################################################### + +$port = 1556 +$basepath = "https://" + $nbmaster + ":" + $port + "/netbackup" +$content_type1 = "application/vnd.netbackup+json;version=1.0" +$content_type2 = "application/vnd.netbackup+json;version=2.0" +$content_type3 = "application/vnd.netbackup+json;version=3.0" +$content_type4 = "application/vnd.netbackup+json;version=4.0" + +##################################################################### +# Login +##################################################################### + +$uri = $basepath + "/login" + +$body = @{ + userName=$username + password=$password +} + +$response = Invoke-WebRequest ` + -Uri $uri ` + -Method POST ` + -Body (ConvertTo-Json -InputObject $body) ` + -ContentType $content_type1 + +if ($response.StatusCode -ne 201) +{ + throw "Unable to connect to the Netbackup master server!" +} +Write-Host "Login successful.`n" +$content = (ConvertFrom-Json -InputObject $response) + +##################################################################### +# GET NetBackup Remote Master Server Cacert Details +##################################################################### + +$headers = @{ + "Authorization" = $content.token +} + +$base_uri = $basepath + "/config/remote-master-server-cacerts/" + $remotemasterserver + + +$response_get = Invoke-WebRequest ` + -Uri $base_uri ` + -Method GET ` + -ContentType $contentType ` + -Headers $headers + +if ($response_get.StatusCode -ne 200) +{ + throw "Unable to Master server cacert details." +} + +Write-Host "Master server cacert details fetched successfully.`n" +Write-Host $response_get + +$response_get = (ConvertFrom-Json -InputObject $response_get) \ No newline at end of file diff --git a/snippets/powershell/config/Get-NB-get-trusted-master-server-by-name.ps1 b/snippets/powershell/config/Get-NB-get-trusted-master-server-by-name.ps1 new file mode 100644 index 0000000..7055a3c --- /dev/null +++ b/snippets/powershell/config/Get-NB-get-trusted-master-server-by-name.ps1 @@ -0,0 +1,120 @@ +<# + +.SYNOPSIS +This sample script demonstrates the use of NetBackup REST API for fetching scpecified trusted master server. + +.DESCRIPTION +This script will fetch scpecified scpecified trusted master server. + +.EXAMPLE +./Get-NB-get-trusted-master-server-by-name.ps1 -nbmaster "nb-master.example.com" -username "administrator" -password "secret" -trustedmasterservername "Trusted master Server Name" +#> + +param ( + [string]$nbmaster = $(throw "Please specify the name of NetBackup master server using -nbmaster parameter."), + [string]$username = $(throw "Please specify the user name using -username parameter."), + [string]$password = $(throw "Please specify the password using -password parameter."), + [string]$trustedmasterservername = $(throw "Please specify the trusted master server name using -trustedmasterservername parameter.") +) + +##################################################################### +# Initial Setup +# Note: This allows self-signed certificates and enables TLS v1.2 +##################################################################### + +function InitialSetup() +{ + + [Net.ServicePointManager]::SecurityProtocol = "Tls12" + + # Allow self-signed certificates + if ([System.Net.ServicePointManager]::CertificatePolicy -notlike 'TrustAllCertsPolicy') + { + Add-Type -TypeDefinition @" + using System.Net; + using System.Security.Cryptography.X509Certificates; + public class TrustAllCertsPolicy : ICertificatePolicy { + public bool CheckValidationResult( + ServicePoint srvPoint, X509Certificate certificate, + WebRequest request, int certificateProblem) { + return true; + } + } +"@ + [System.Net.ServicePointManager]::CertificatePolicy = New-Object -TypeName TrustAllCertsPolicy + [Net.ServicePointManager]::SecurityProtocol = "Tls12" + + # Force TLS v1.2 + try { + if ([Net.ServicePointManager]::SecurityProtocol -notcontains 'Tls12') { + [Net.ServicePointManager]::SecurityProtocol += [Net.SecurityProtocolType]::Tls12 + } + } + catch { + Write-Host $_.Exception.InnerException.Message + } + } +} + +InitialSetup +##################################################################### +# Global Variables +##################################################################### + +$port = 1556 +$basepath = "https://" + $nbmaster + ":" + $port + "/netbackup" +$content_type1 = "application/vnd.netbackup+json;version=1.0" +$content_type2 = "application/vnd.netbackup+json;version=2.0" +$content_type3 = "application/vnd.netbackup+json;version=3.0" +$content_type4 = "application/vnd.netbackup+json;version=4.0" + +##################################################################### +# Login +##################################################################### + +$uri = $basepath + "/login" + +$body = @{ + userName=$username + password=$password +} + +$response = Invoke-WebRequest ` + -Uri $uri ` + -Method POST ` + -Body (ConvertTo-Json -InputObject $body) ` + -ContentType $content_type1 + +if ($response.StatusCode -ne 201) +{ + throw "Unable to connect to the Netbackup master server!" +} +Write-Host "Login successful.`n" +$content = (ConvertFrom-Json -InputObject $response) + +##################################################################### +# GET NetBackup Trusted Master Server +##################################################################### + +$headers = @{ + "Authorization" = $content.token +} + +$base_uri = $basepath + "/config/servers/trusted-master-servers/" + $trustedmasterservername + + +$response_get = Invoke-WebRequest ` + -Uri $base_uri ` + -Method GET ` + -ContentType $contentType ` + -Headers $headers + +if ($response_get.StatusCode -ne 200) +{ + throw "Unable to fetch scpecified trusted master server" +} + +Write-Host "Scpecified trusted master server fetched successfully.`n" +Write-Host $response_get + +$response_get = (ConvertFrom-Json -InputObject $response_get) \ No newline at end of file diff --git a/snippets/powershell/config/Get-NB-get-trusted-master-server-list.ps1 b/snippets/powershell/config/Get-NB-get-trusted-master-server-list.ps1 new file mode 100644 index 0000000..8be212b --- /dev/null +++ b/snippets/powershell/config/Get-NB-get-trusted-master-server-list.ps1 @@ -0,0 +1,118 @@ +<# + +.SYNOPSIS +This sample script demonstrates the use of NetBackup REST API for fetching trusted master server list. + +.DESCRIPTION +This script will fetch trusted master server list. + +.EXAMPLE +./Get-NB-get-trusted-master-server-list.ps1 -nbmaster "nb-master.example.com" -username "administrator" -password "secret" +#> + +param ( + [string]$nbmaster = $(throw "Please specify the name of NetBackup master server using -nbmaster parameter."), + [string]$username = $(throw "Please specify the user name using -username parameter."), + [string]$password = $(throw "Please specify the password using -password parameter.") +) + +##################################################################### +# Initial Setup +# Note: This allows self-signed certificates and enables TLS v1.2 +##################################################################### + +function InitialSetup() +{ + + [Net.ServicePointManager]::SecurityProtocol = "Tls12" + + # Allow self-signed certificates + if ([System.Net.ServicePointManager]::CertificatePolicy -notlike 'TrustAllCertsPolicy') + { + Add-Type -TypeDefinition @" + using System.Net; + using System.Security.Cryptography.X509Certificates; + public class TrustAllCertsPolicy : ICertificatePolicy { + public bool CheckValidationResult( + ServicePoint srvPoint, X509Certificate certificate, + WebRequest request, int certificateProblem) { + return true; + } + } +"@ + [System.Net.ServicePointManager]::CertificatePolicy = New-Object -TypeName TrustAllCertsPolicy + [Net.ServicePointManager]::SecurityProtocol = "Tls12" + + # Force TLS v1.2 + try { + if ([Net.ServicePointManager]::SecurityProtocol -notcontains 'Tls12') { + [Net.ServicePointManager]::SecurityProtocol += [Net.SecurityProtocolType]::Tls12 + } + } + catch { + Write-Host $_.Exception.InnerException.Message + } + } +} + +InitialSetup +##################################################################### +# Global Variables +##################################################################### + +$port = 1556 +$basepath = "https://" + $nbmaster + ":" + $port + "/netbackup" +$content_type1 = "application/vnd.netbackup+json;version=1.0" +$content_type2 = "application/vnd.netbackup+json;version=2.0" + + +##################################################################### +# Login +##################################################################### + +$uri = $basepath + "/login" + +$body = @{ + userName=$username + password=$password +} + +$response = Invoke-WebRequest ` + -Uri $uri ` + -Method POST ` + -Body (ConvertTo-Json -InputObject $body) ` + -ContentType $content_type1 + +if ($response.StatusCode -ne 201) +{ + throw "Unable to connect to the Netbackup master server!" +} +Write-Host "Login successful.`n" +$content = (ConvertFrom-Json -InputObject $response) + +##################################################################### +# GET NetBackup Trusted master Server List +##################################################################### + +$headers = @{ + "Authorization" = $content.token +} + +$base_uri = $basepath + "/config/servers/trusted-master-servers" + + +$response_getAll = Invoke-WebRequest ` + -Uri $base_uri ` + -Method GET ` + -ContentType $contentType ` + -Headers $headers + +if ($response_getAll.StatusCode -ne 200) +{ + throw "Unable to fetch trusted master server list." +} + +Write-Host "Trusted master server list fetched successfully.`n" +Write-Host $response_getAll + +$response_getAll = (ConvertFrom-Json -InputObject $response_getAll) \ No newline at end of file diff --git a/snippets/powershell/config/Patch-NB-update-trusted-master-server.ps1 b/snippets/powershell/config/Patch-NB-update-trusted-master-server.ps1 new file mode 100644 index 0000000..5428f90 --- /dev/null +++ b/snippets/powershell/config/Patch-NB-update-trusted-master-server.ps1 @@ -0,0 +1,133 @@ +<# + +.SYNOPSIS +This sample script demonstrates the use of NetBackup REST API for updating trust between masters. + +.DESCRIPTION +This script will update trust between masters. + +.EXAMPLE +./Patch-NB-update-trusted-master-server.ps1 -nbmaster "nb-master.example.com" -username "administrator" -password "secret" -trustedmasterservername "Trusted Master Server Name" +#> + +param ( + [string]$nbmaster = $(throw "Please specify the name of NetBackup master server using -nbmaster parameter."), + [string]$username = $(throw "Please specify the user name using -username parameter."), + [string]$password = $(throw "Please specify the password using -password parameter."), + [string]$trustedmasterservername = $(throw "Please specify the trusted master server name using -trustedmasterservername parameter.") + +) + +##################################################################### +# Initial Setup +# Note: This allows self-signed certificates and enables TLS v1.2 +##################################################################### + +function InitialSetup() +{ + + [Net.ServicePointManager]::SecurityProtocol = "Tls12" + + # Allow self-signed certificates + if ([System.Net.ServicePointManager]::CertificatePolicy -notlike 'TrustAllCertsPolicy') + { + Add-Type -TypeDefinition @" + using System.Net; + using System.Security.Cryptography.X509Certificates; + public class TrustAllCertsPolicy : ICertificatePolicy { + public bool CheckValidationResult( + ServicePoint srvPoint, X509Certificate certificate, + WebRequest request, int certificateProblem) { + return true; + } + } +"@ + [System.Net.ServicePointManager]::CertificatePolicy = New-Object -TypeName TrustAllCertsPolicy + [Net.ServicePointManager]::SecurityProtocol = "Tls12" + + # Force TLS v1.2 + try { + if ([Net.ServicePointManager]::SecurityProtocol -notcontains 'Tls12') { + [Net.ServicePointManager]::SecurityProtocol += [Net.SecurityProtocolType]::Tls12 + } + } + catch { + Write-Host $_.Exception.InnerException.Message + } + } +} + +InitialSetup +##################################################################### +# Global Variables +##################################################################### + +$port = 1556 +$basepath = "https://" + $nbmaster + ":" + $port + "/netbackup" +$content_type1 = "application/vnd.netbackup+json;version=1.0" +$content_type2 = "application/vnd.netbackup+json;version=2.0" +$content_type3 = "application/vnd.netbackup+json;version=3.0" +$content_type4 = "application/vnd.netbackup+json;version=4.0" + +##################################################################### +# Login +##################################################################### + +$uri = $basepath + "/login" + +$body = @{ + userName=$username + password=$password +} + +$response = Invoke-WebRequest ` + -Uri $uri ` + -Method POST ` + -Body (ConvertTo-Json -InputObject $body) ` + -ContentType $content_type1 + +if ($response.StatusCode -ne 201) +{ + throw "Unable to connect to the Netbackup master server!" +} +Write-Host "Login successful.`n" +$content = (ConvertFrom-Json -InputObject $response) + +##################################################################### +# PATCH NetBackup trust between master servers +##################################################################### + +$headers = @{ + "Authorization" = $content.token +} + +$base_uri = $basepath + "/config/servers/trusted-master-servers/" + $trustedmasterservername + +$json = '{ + "data": { + "type": "trustedMasterServer", + "attributes": { + "trustedMasterServerName": "TRUSTED_MASTER_SERVER_NAME", + "rootCAType": "ECA" + } + } +} +' + +$response_update = Invoke-WebRequest ` + -Uri $base_uri ` + -Method PATCH ` + -Body ($json) ` + -ContentType $content_type3 ` + -Headers $headers + +if ($response_update.StatusCode -ne 200) +{ + throw "Unable to update trust between masters." +} + +Write-Host "Trust between masters updated successfully.`n" +echo $response_update +Write-Host $response_update + +$response_update = (ConvertFrom-Json -InputObject $response_update) \ No newline at end of file diff --git a/snippets/powershell/config/Post-NB-create-trusted-master-server.ps1 b/snippets/powershell/config/Post-NB-create-trusted-master-server.ps1 new file mode 100644 index 0000000..7d4ee3a --- /dev/null +++ b/snippets/powershell/config/Post-NB-create-trusted-master-server.ps1 @@ -0,0 +1,135 @@ +<# + +.SYNOPSIS +This sample script demonstrates the use of NetBackup REST API for adding trust between masters. + +.DESCRIPTION +This script will create adding trust between masters. + +.EXAMPLE +./Post-NB-create-trusted-master-server.ps1 -nbmaster "nb-master.example.com" -username "administrator" -password "secret" +#> + +param ( + [string]$nbmaster = $(throw "Please specify the name of NetBackup master server using -nbmaster parameter."), + [string]$username = $(throw "Please specify the user name using -username parameter."), + [string]$password = $(throw "Please specify the password using -password parameter.") +) + +##################################################################### +# Initial Setup +# Note: This allows self-signed certificates and enables TLS v1.2 +##################################################################### + +function InitialSetup() +{ + + [Net.ServicePointManager]::SecurityProtocol = "Tls12" + + # Allow self-signed certificates + if ([System.Net.ServicePointManager]::CertificatePolicy -notlike 'TrustAllCertsPolicy') + { + Add-Type -TypeDefinition @" + using System.Net; + using System.Security.Cryptography.X509Certificates; + public class TrustAllCertsPolicy : ICertificatePolicy { + public bool CheckValidationResult( + ServicePoint srvPoint, X509Certificate certificate, + WebRequest request, int certificateProblem) { + return true; + } + } +"@ + [System.Net.ServicePointManager]::CertificatePolicy = New-Object -TypeName TrustAllCertsPolicy + [Net.ServicePointManager]::SecurityProtocol = "Tls12" + + # Force TLS v1.2 + try { + if ([Net.ServicePointManager]::SecurityProtocol -notcontains 'Tls12') { + [Net.ServicePointManager]::SecurityProtocol += [Net.SecurityProtocolType]::Tls12 + } + } + catch { + Write-Host $_.Exception.InnerException.Message + } + } +} + +InitialSetup +##################################################################### +# Global Variables +##################################################################### + +$port = 1556 +$basepath = "https://" + $nbmaster + ":" + $port + "/netbackup" +$content_type1 = "application/vnd.netbackup+json;version=1.0" +$content_type2 = "application/vnd.netbackup+json;version=2.0" +$content_type3 = "application/vnd.netbackup+json;version=3.0" +$content_type4 = "application/vnd.netbackup+json;version=4.0" + +##################################################################### +# Login +##################################################################### + +$uri = $basepath + "/login" + +$body = @{ + userName=$username + password=$password +} + +$response = Invoke-WebRequest ` + -Uri $uri ` + -Method POST ` + -Body (ConvertTo-Json -InputObject $body) ` + -ContentType $content_type1 + +if ($response.StatusCode -ne 201) +{ + throw "Unable to connect to the Netbackup master server!" +} +Write-Host "Login successful.`n" +$content = (ConvertFrom-Json -InputObject $response) + +##################################################################### +# POST NetBackup Storage server +##################################################################### + +$headers = @{ + "Authorization" = $content.token +} + +$base_uri = $basepath + "/config/servers/trusted-master-servers" + +$json = '{ + "data": { + "type": "trustedMasterServer", + "attributes": { + "trustedMasterServerName": "remote.master.com", + "rootCAType": "NBCA", + "authenticationType": "CREDENTIAL", + "domainName": "DOMAIN", + "userName": "USER", + "password": "PASSWORD", + "fingerprint": "FINGERPRINT" + } + } +} +' +$response_create_trust = Invoke-WebRequest ` + -Uri $base_uri ` + -Method POST ` + -Body ($json) ` + -ContentType $content_type3 ` + -Headers $headers + +if ($response_create_trust.StatusCode -ne 201) +{ + throw "Unable to create trust between master servers." +} + +Write-Host "Trust between master servers created successfully.`n" +echo $response_create_trust +Write-Host $response_create_trust + +$response_create_trust = (ConvertFrom-Json -InputObject $response_create_trust) \ No newline at end of file diff --git a/snippets/powershell/config/README.md b/snippets/powershell/config/README.md new file mode 100644 index 0000000..673b44e --- /dev/null +++ b/snippets/powershell/config/README.md @@ -0,0 +1,24 @@ +#### NetBackup API Code Samples for PowerShell + +This directory contains code samples to invoke NetBackup REST APIs using PowerShell. + +#### Disclaimer + +These scripts are only meant to be used as a reference. If you intend to use them in production, use it at your own risk. + +#### Pre-requisites: + +- NetBackup 8.2 or higher +- PowerShell 5.0 or higher + +#### Executing the snippets in PowerShell + +Use the following commands to run the PowerShell samples. +- `./Get-NB-get-media-server.ps1 -nbmaster "nb-master.example.com" -username "administrator" -password "secret"` +- `./Get-NB-get-media-server-by-name.ps1 -nbmaster "nb-master.example.com" -username "administrator" -password "secret" -medianame "Media Server Name"` +- `./Get-NB-get-remote-master-server-cacert-by-name.ps1 -nbmaster "nb-master.example.com" -username "administrator" -password "secret" -remotemasterserver "remote Master Server Name"` +- `./Get-NB-get-trusted-master-server-list.ps1 -nbmaster "nb-master.example.com" -username "administrator" -password "secret"` +- `./Get-NB-get-trusted-master-server-by-name.ps1 -nbmaster "nb-master.example.com" -username "administrator" -password "secret" -trustedmasterservername "Trusted master Server Name"` +- `./Post-NB-create-trusted-master-server.ps1 -nbmaster "nb-master.example.com" -username "administrator" -password "secret"` +- `./Patch-NB-update-trusted-master-server.ps1 -nbmaster "nb-master.example.com" -username "administrator" -password "secret" -trustedmasterservername "Trusted Master Server Name"` +- `./Delete-NB-delete-trust.ps1 -nbmaster "nb-master.example.com" -username "administrator" -password "secret" -trustedmasterservername "Trusted Master Server Name"` \ No newline at end of file diff --git a/snippets/python/config/README.md b/snippets/python/config/README.md new file mode 100644 index 0000000..43aa8ba --- /dev/null +++ b/snippets/python/config/README.md @@ -0,0 +1,27 @@ +#### NetBackup API Code Samples for Python + +This directory contains code samples to invoke NetBackup REST APIs using Python. + +#### Disclaimer + +These scripts are only meant to be used as a reference. If you intend to use them in production, use it at your own risk. + +#### Pre-requisites: + +- NetBackup 8.2 or higher +- python 3.5 or higher +- python modules: `requests, texttable` + +#### NOTE - Sample payloads from the snippets\sample-payloads\config-samples location can be used as input to run the scripts. + +#### Executing the snippets in Python + +Use the following commands to run the python samples. +- `python -W ignore get_trusted_master_server_list.py -nbmaster -username -password [-domainname ] [-domaintype ]` +- `python -W ignore get_trusted_master_server_by_name.py -nbmaster -username -password -trustedmasterservername [-domainname ] [-domaintype ]` +- `python -W ignore get_remote_master_server_cacert_by_name.py -nbmaster -username -password -remotemasterserver [-domainname ] [-domaintype ]` +- `python -W ignore get_media_server_by_name.py -nbmaster -username -password -medianame [-domainname ] [-domaintype ]` +- `python -W ignore get_media_server.py -nbmaster -username -password [-domainname ] [-domaintype ]` +- `python -W ignore delete_trust.py -nbmaster -username -password -trustedmasterservername [-domainname ] [-domaintype ]` +- `python -W ignore create_trusted_master_server.py -nbmaster -username -password -payload [-domainname ] [-domaintype ]` +- `python -W ignore patch_trusted_master_server.py -nbmaster -username -password -payload -trustedmasterservername [-domainname ] [-domaintype ]` \ No newline at end of file diff --git a/snippets/python/config/config.py b/snippets/python/config/config.py new file mode 100644 index 0000000..856b161 --- /dev/null +++ b/snippets/python/config/config.py @@ -0,0 +1,158 @@ +import requests + +content_type = "application/vnd.netbackup+json; version=4.0" + + +def perform_login(username, password, base_url, domain_name, domain_type): + url = base_url + "/login" + + if domain_name != "" and domain_type != "": + req_body = {"userName": username, "password": password, "domainName": domain_name, "domainType": domain_type} + else: + req_body = {"userName": username, "password": password} + + headers = {'Content-Type': content_type} + + print("performing POST on {} for user '{}'\n".format(url, req_body['userName'])) + + resp = requests.post(url, headers=headers, json=req_body, verify=False) + + if resp.status_code != 201: + raise Exception('Login API failed with status code {} and {}'.format(resp.status_code, resp.json())) + + return resp.json()['token'] + +def get_media_servers(jwt, base_url): + url = base_url + "/config/media-servers" + headers = {'Content-Type': content_type, 'Authorization': jwt} + query_params = { + # "page[limit]": 100, #This changes the default page size to 100 + # "filter": "jobType eq 'RESTORE'" #This adds a filter to only show RESTORE Jobs + } + + print("performing GET on {}\n".format(url)) + + resp = requests.get(url, headers=headers, params=query_params, verify=False) + + if resp.status_code != 200: + raise Exception('GET Media server API failed with status code {} and {}'.format(resp.status_code, resp.json())) + + return resp.json() + +def get_media_server_by_name(jwt, base_url, medianame): + url = base_url + "/config/media-servers/" + medianame + headers = {'Content-Type': content_type, 'Authorization': jwt} + query_params = { + # "page[limit]": 100, #This changes the default page size to 100 + # "filter": "jobType eq 'RESTORE'" #This adds a filter to only show RESTORE Jobs + } + + print("performing GET on {}\n".format(url)) + + resp = requests.get(url, headers=headers, params=query_params, verify=False) + + if resp.status_code != 200: + raise Exception('GET Media server with specific name failed with status code {} and {}'.format(resp.status_code, resp.json())) + + return resp.json() + +def get_remote_master_server_cacert_by_name(jwt, base_url, remotemasterserver): + url = base_url + "/config/remote-master-server-cacerts/" + remotemasterserver + headers = {'Content-Type': content_type, 'Authorization': jwt} + query_params = { + # "page[limit]": 100, #This changes the default page size to 100 + # "filter": "jobType eq 'RESTORE'" #This adds a filter to only show RESTORE Jobs + } + + print("performing GET on {}\n".format(url)) + + resp = requests.get(url, headers=headers, params=query_params, verify=False) + + if resp.status_code != 200: + raise Exception('GET Remote master server cacert info with specific name failed with status code {} and {}'.format(resp.status_code, resp.json())) + + return resp.json() + +def get_trusted_master_server_list(jwt, base_url): + url = base_url + "/config/servers/trusted-master-servers" + headers = {'Content-Type': content_type, 'Authorization': jwt} + query_params = { + # "page[limit]": 100, #This changes the default page size to 100 + # "filter": "jobType eq 'RESTORE'" #This adds a filter to only show RESTORE Jobs + } + + print("performing GET on {}\n".format(url)) + + resp = requests.get(url, headers=headers, params=query_params, verify=False) + + if resp.status_code != 200: + raise Exception('GET trusted master server list API failed with status code {} and {}'.format(resp.status_code, resp.json())) + + return resp.json() + +def get_trusted_master_server_by_name(jwt, base_url, trustedmasterservername): + url = base_url + "/config/servers/trusted-master-servers/" + trustedmasterservername + headers = {'Content-Type': content_type, 'Authorization': jwt} + query_params = { + # "page[limit]": 100, #This changes the default page size to 100 + # "filter": "jobType eq 'RESTORE'" #This adds a filter to only show RESTORE Jobs + } + + print("performing GET on {}\n".format(url)) + + resp = requests.get(url, headers=headers, params=query_params, verify=False) + + if resp.status_code != 200: + raise Exception('GET trusted master server with specific name failed with status code {} and {}'.format(resp.status_code, resp.json())) + + return resp.json() + +def delete_trust(jwt, base_url, trustedmasterservername): + url = base_url + "/config/servers/trusted-master-servers/" +trustedmasterservername + headers = {'Content-Type': content_type, 'Authorization': jwt} + query_params = { + # "page[limit]": 100, #This changes the default page size to 100 + # "filter": "jobType eq 'RESTORE'" #This adds a filter to only show RESTORE Jobs + } + + print("performing DELETE on {}\n".format(url)) + + resp = requests.delete(url, headers=headers, verify=False) + if resp.status_code != 204: + raise Exception('DELETE trust with specific trusted master failed with status code {} and {}'.format(resp.status_code, resp.json())) + + print("\nThe Trust is deleted with status code: {}\n".format(resp.status_code)) + +def create_trusted_master_server(jwt, base_url, file_name): + url = base_url + "/config/servers/trusted-master-servers" + headers = {'Content-Type': content_type, 'Authorization': jwt} + + path = file_name + + req_body = open(path, 'r').read() + + print("performing POST on {}\n".format(url)) + + resp = requests.post(url, headers=headers, data=req_body, verify=False) + + if resp.status_code != 201: + raise Exception('Create trust between master servers API failed with status code {} and {}'.format(resp.status_code, resp.json())) + + return resp.json() + +def patch_trusted_master_server(jwt, base_url, file_name, trustedmasterservername): + url = base_url + "/config/servers/trusted-master-servers/" +trustedmasterservername + headers = {'Content-Type': content_type, 'Authorization': jwt} + + path = file_name + + req_body = open(path, 'r').read() + + print("performing PATCH on {}\n".format(url)) + + resp = requests.patch(url, headers=headers, data=req_body, verify=False) + + if resp.status_code != 200: + raise Exception('Update trust between masters API failed with status code {} and {}'.format(resp.status_code, resp.json())) + print("\nThe Trust is Upadated with status code: {}\n".format(resp.status_code)) + return resp.json() diff --git a/snippets/python/config/create_trusted_master_server.py b/snippets/python/config/create_trusted_master_server.py new file mode 100644 index 0000000..2a68f4b --- /dev/null +++ b/snippets/python/config/create_trusted_master_server.py @@ -0,0 +1,71 @@ +import sys +import config +import json +import texttable as tt + +protocol = "https" +nbmaster = "" +username = "" +password = "" +domainname = "" +domaintype = "" + +port = 1556 + +def print_usage(): + print("Example:") + print("python -W ignore create_trusted_master_server.py -nbmaster -username -password -payload [-domainname ] [-domaintype ]\n\n\n") + +def read_command_line_arguments(): + if len(sys.argv)%2 == 0: + print_usage() + exit() + + global nbmaster + global username + global password + global domainname + global domaintype + global payload + + for i in range(1, len(sys.argv), 2): + if sys.argv[i] == "-nbmaster": + nbmaster = sys.argv[i + 1] + elif sys.argv[i] == "-username": + username = sys.argv[i + 1] + elif sys.argv[i] == "-password": + password = sys.argv[i + 1] + elif sys.argv[i] == "-payload": + payload = sys.argv[i + 1] + elif sys.argv[i] == "-domainname": + domainname = sys.argv[i + 1] + elif sys.argv[i] == "-domaintype": + domaintype = sys.argv[i + 1] + else: + print_usage() + exit() + + if nbmaster == "": + print("Please provide the value for 'nbmaster'") + exit() + elif username == "": + print("Please provide the value for 'username'") + exit() + elif password == "": + print("Please provide the value for 'password'") + elif payload == "": + print("Please provide the value for 'payload'") + exit() + + +print_usage() + +read_command_line_arguments() + +base_url = protocol + "://" + nbmaster + ":" + str(port) + "/netbackup" + +jwt = config.perform_login(username, password, base_url, domainname, domaintype) + +reponse = config.create_trusted_master_server(jwt, base_url, payload) + +print(reponse) diff --git a/snippets/python/config/delete_trust.py b/snippets/python/config/delete_trust.py new file mode 100644 index 0000000..fd4fa55 --- /dev/null +++ b/snippets/python/config/delete_trust.py @@ -0,0 +1,69 @@ +import sys +import config +import json +import texttable as tt + +protocol = "https" +nbmaster = "" +username = "" +password = "" +domainname = "" +domaintype = "" + +port = 1556 + +def print_usage(): + print("Example:") + print("python -W ignore delete_trust.py -nbmaster -username -password -trustedmasterservername [-domainname ] [-domaintype ]\n\n\n") + +def read_command_line_arguments(): + if len(sys.argv)%2 == 0: + print_usage() + exit() + + global nbmaster + global username + global password + global domainname + global domaintype + global trustedmasterservername + +for i in range(1, len(sys.argv), 2): + if sys.argv[i] == "-nbmaster": + nbmaster = sys.argv[i + 1] + elif sys.argv[i] == "-username": + username = sys.argv[i + 1] + elif sys.argv[i] == "-password": + password = sys.argv[i + 1] + elif sys.argv[i] == "-trustedmasterservername": + trustedmasterservername = sys.argv[i + 1] + elif sys.argv[i] == "-domainname": + domainname = sys.argv[i + 1] + elif sys.argv[i] == "-domaintype": + domaintype = sys.argv[i + 1] + else: + print_usage() + exit() + +if nbmaster == "": + print("Please provide the value for 'nbmaster'") + exit() +elif username == "": + print("Please provide the value for 'username'") + exit() +elif password == "": + print("Please provide the value for 'password'") +elif trustedmasterservername == "": + print("Please provide the value for 'trustedmasterservername'") + exit() + + +print_usage() + +read_command_line_arguments() + +base_url = protocol + "://" + nbmaster + ":" + str(port) + "/netbackup" + +jwt = config.perform_login(username, password, base_url, domainname, domaintype) + +config.delete_trust(jwt, base_url, trustedmasterservername) \ No newline at end of file diff --git a/snippets/python/config/get_media_server.py b/snippets/python/config/get_media_server.py new file mode 100644 index 0000000..7d895ba --- /dev/null +++ b/snippets/python/config/get_media_server.py @@ -0,0 +1,66 @@ +import sys +import config +import json +import texttable as tt + +protocol = "https" +nbmaster = "" +username = "" +password = "" +domainname = "" +domaintype = "" + +port = 1556 + +def print_usage(): + print("Example:") + print("python -W ignore get_media_server.py -nbmaster -username -password [-domainname ] [-domaintype ]\n\n\n") + +def read_command_line_arguments(): + if len(sys.argv)%2 == 0: + print_usage() + exit() + + global nbmaster + global username + global password + global domainname + global domaintype + + for i in range(1, len(sys.argv), 2): + if sys.argv[i] == "-nbmaster": + nbmaster = sys.argv[i + 1] + elif sys.argv[i] == "-username": + username = sys.argv[i + 1] + elif sys.argv[i] == "-password": + password = sys.argv[i + 1] + elif sys.argv[i] == "-domainname": + domainname = sys.argv[i + 1] + elif sys.argv[i] == "-domaintype": + domaintype = sys.argv[i + 1] + else: + print_usage() + exit() + + if nbmaster == "": + print("Please provide the value for 'nbmaster'") + exit() + elif username == "": + print("Please provide the value for 'username'") + exit() + elif password == "": + print("Please provide the value for 'password'") + exit() + + +print_usage() + +read_command_line_arguments() + +base_url = protocol + "://" + nbmaster + ":" + str(port) + "/netbackup" + +jwt = config.perform_login(username, password, base_url, domainname, domaintype) + +jobs = config.get_media_servers(jwt, base_url) + +print(jobs) \ No newline at end of file diff --git a/snippets/python/config/get_media_server_by_name.py b/snippets/python/config/get_media_server_by_name.py new file mode 100644 index 0000000..240d61c --- /dev/null +++ b/snippets/python/config/get_media_server_by_name.py @@ -0,0 +1,71 @@ +import sys +import config +import json +import texttable as tt + +protocol = "https" +nbmaster = "" +username = "" +password = "" +domainname = "" +domaintype = "" + +port = 1556 + +def print_usage(): + print("Example:") + print("python -W ignore get_media_server_by_name.py -nbmaster -username -password -medianame [-domainname ] [-domaintype ]\n\n\n") + +def read_command_line_arguments(): + if len(sys.argv)%2 == 0: + print_usage() + exit() + + global nbmaster + global username + global password + global domainname + global domaintype + global medianame + +for i in range(1, len(sys.argv), 2): + if sys.argv[i] == "-nbmaster": + nbmaster = sys.argv[i + 1] + elif sys.argv[i] == "-username": + username = sys.argv[i + 1] + elif sys.argv[i] == "-password": + password = sys.argv[i + 1] + elif sys.argv[i] == "-medianame": + medianame = sys.argv[i + 1] + elif sys.argv[i] == "-domainname": + domainname = sys.argv[i + 1] + elif sys.argv[i] == "-domaintype": + domaintype = sys.argv[i + 1] + else: + print_usage() + exit() + +if nbmaster == "": + print("Please provide the value for 'nbmaster'") + exit() +elif username == "": + print("Please provide the value for 'username'") + exit() +elif password == "": + print("Please provide the value for 'password'") +elif medianame == "": + print("Please provide the value for 'medianame'") + exit() + + +print_usage() + +read_command_line_arguments() + +base_url = protocol + "://" + nbmaster + ":" + str(port) + "/netbackup" + +jwt = config.perform_login(username, password, base_url, domainname, domaintype) + +jobs = config.get_media_server_by_name(jwt, base_url, medianame) + +print(jobs) \ No newline at end of file diff --git a/snippets/python/config/get_remote_master_server_cacert_by_name.py b/snippets/python/config/get_remote_master_server_cacert_by_name.py new file mode 100644 index 0000000..392c466 --- /dev/null +++ b/snippets/python/config/get_remote_master_server_cacert_by_name.py @@ -0,0 +1,71 @@ +import sys +import config +import json +import texttable as tt + +protocol = "https" +nbmaster = "" +username = "" +password = "" +domainname = "" +domaintype = "" + +port = 1556 + +def print_usage(): + print("Example:") + print("python -W ignore get_remote_master_server_cacert_by_name.py -nbmaster -username -password -remotemasterserver [-domainname ] [-domaintype ]\n\n\n") + +def read_command_line_arguments(): + if len(sys.argv)%2 == 0: + print_usage() + exit() + + global nbmaster + global username + global password + global domainname + global domaintype + global remotemasterserver + +for i in range(1, len(sys.argv), 2): + if sys.argv[i] == "-nbmaster": + nbmaster = sys.argv[i + 1] + elif sys.argv[i] == "-username": + username = sys.argv[i + 1] + elif sys.argv[i] == "-password": + password = sys.argv[i + 1] + elif sys.argv[i] == "-remotemasterserver": + remotemasterserver = sys.argv[i + 1] + elif sys.argv[i] == "-domainname": + domainname = sys.argv[i + 1] + elif sys.argv[i] == "-domaintype": + domaintype = sys.argv[i + 1] + else: + print_usage() + exit() + +if nbmaster == "": + print("Please provide the value for 'nbmaster'") + exit() +elif username == "": + print("Please provide the value for 'username'") + exit() +elif password == "": + print("Please provide the value for 'password'") +elif remotemasterserver == "": + print("Please provide the value for 'remotemasterserver'") + exit() + + +print_usage() + +read_command_line_arguments() + +base_url = protocol + "://" + nbmaster + ":" + str(port) + "/netbackup" + +jwt = config.perform_login(username, password, base_url, domainname, domaintype) + +jobs = config.get_remote_master_server_cacert_by_name(jwt, base_url, remotemasterserver) + +print(jobs) diff --git a/snippets/python/config/get_trusted_master_server_by_name.py b/snippets/python/config/get_trusted_master_server_by_name.py new file mode 100644 index 0000000..805823f --- /dev/null +++ b/snippets/python/config/get_trusted_master_server_by_name.py @@ -0,0 +1,71 @@ +import sys +import config +import json +import texttable as tt + +protocol = "https" +nbmaster = "" +username = "" +password = "" +domainname = "" +domaintype = "" + +port = 1556 + +def print_usage(): + print("Example:") + print("python -W ignore get_trusted_master_server_by_name.py -nbmaster -username -password -trustedmasterservername [-domainname ] [-domaintype ]\n\n\n") + +def read_command_line_arguments(): + if len(sys.argv)%2 == 0: + print_usage() + exit() + + global nbmaster + global username + global password + global domainname + global domaintype + global trustedmasterservername + +for i in range(1, len(sys.argv), 2): + if sys.argv[i] == "-nbmaster": + nbmaster = sys.argv[i + 1] + elif sys.argv[i] == "-username": + username = sys.argv[i + 1] + elif sys.argv[i] == "-password": + password = sys.argv[i + 1] + elif sys.argv[i] == "-trustedmasterservername": + trustedmasterservername = sys.argv[i + 1] + elif sys.argv[i] == "-domainname": + domainname = sys.argv[i + 1] + elif sys.argv[i] == "-domaintype": + domaintype = sys.argv[i + 1] + else: + print_usage() + exit() + +if nbmaster == "": + print("Please provide the value for 'nbmaster'") + exit() +elif username == "": + print("Please provide the value for 'username'") + exit() +elif password == "": + print("Please provide the value for 'password'") +elif trustedmasterservername == "": + print("Please provide the value for 'trustedmasterservername'") + exit() + + +print_usage() + +read_command_line_arguments() + +base_url = protocol + "://" + nbmaster + ":" + str(port) + "/netbackup" + +jwt = config.perform_login(username, password, base_url, domainname, domaintype) + +jobs = config.get_trusted_master_server_by_name(jwt, base_url, trustedmasterservername) + +print(jobs) \ No newline at end of file diff --git a/snippets/python/config/get_trusted_master_server_list.py b/snippets/python/config/get_trusted_master_server_list.py new file mode 100644 index 0000000..e509305 --- /dev/null +++ b/snippets/python/config/get_trusted_master_server_list.py @@ -0,0 +1,66 @@ +import sys +import config +import json +import texttable as tt + +protocol = "https" +nbmaster = "" +username = "" +password = "" +domainname = "" +domaintype = "" + +port = 1556 + +def print_usage(): + print("Example:") + print("python -W ignore get_trusted_master_server_list.py -nbmaster -username -password [-domainname ] [-domaintype ]\n\n\n") + +def read_command_line_arguments(): + if len(sys.argv)%2 == 0: + print_usage() + exit() + + global nbmaster + global username + global password + global domainname + global domaintype + + for i in range(1, len(sys.argv), 2): + if sys.argv[i] == "-nbmaster": + nbmaster = sys.argv[i + 1] + elif sys.argv[i] == "-username": + username = sys.argv[i + 1] + elif sys.argv[i] == "-password": + password = sys.argv[i + 1] + elif sys.argv[i] == "-domainname": + domainname = sys.argv[i + 1] + elif sys.argv[i] == "-domaintype": + domaintype = sys.argv[i + 1] + else: + print_usage() + exit() + + if nbmaster == "": + print("Please provide the value for 'nbmaster'") + exit() + elif username == "": + print("Please provide the value for 'username'") + exit() + elif password == "": + print("Please provide the value for 'password'") + exit() + + +print_usage() + +read_command_line_arguments() + +base_url = protocol + "://" + nbmaster + ":" + str(port) + "/netbackup" + +jwt = config.perform_login(username, password, base_url, domainname, domaintype) + +jobs = config.get_trusted_master_server_list(jwt, base_url) + +print(jobs) diff --git a/snippets/python/config/patch_trusted_master_server.py b/snippets/python/config/patch_trusted_master_server.py new file mode 100644 index 0000000..7424ed3 --- /dev/null +++ b/snippets/python/config/patch_trusted_master_server.py @@ -0,0 +1,77 @@ +import os +import sys +import config +import json +import texttable as tt + +protocol = "https" +nbmaster = "" +username = "" +password = "" +domainname = "" +domaintype = "" + +port = 1556 + +def print_usage(): + print("Example:") + print("python -W ignore patch_trusted_master_server.py -nbmaster -username -password -payload -trustedmasterservername [-domainname ] [-domaintype ]\n\n\n") + +def read_command_line_arguments(): + if len(sys.argv)%2 == 0: + print_usage() + exit() + + global nbmaster + global username + global password + global domainname + global domaintype + global payload + global trustedmasterservername + + for i in range(1, len(sys.argv), 2): + if sys.argv[i] == "-nbmaster": + nbmaster = sys.argv[i + 1] + elif sys.argv[i] == "-username": + username = sys.argv[i + 1] + elif sys.argv[i] == "-password": + password = sys.argv[i + 1] + elif sys.argv[i] == "-payload": + payload = sys.argv[i + 1] + elif sys.argv[i] == "-trustedmasterservername": + trustedmasterservername = sys.argv[i + 1] + elif sys.argv[i] == "-domainname": + domainname = sys.argv[i + 1] + elif sys.argv[i] == "-domaintype": + domaintype = sys.argv[i + 1] + else: + print_usage() + exit() + + if nbmaster == "": + print("Please provide the value for 'nbmaster'") + exit() + elif username == "": + print("Please provide the value for 'username'") + exit() + elif password == "": + print("Please provide the value for 'password'") + elif payload == "": + print("Please provide the value for 'payload'") + elif trustedmasterservername == "": + print("Please provide the value for 'trustedmasterservername'") + exit() + + +print_usage() + +read_command_line_arguments() + +base_url = protocol + "://" + nbmaster + ":" + str(port) + "/netbackup" + +jwt = config.perform_login(username, password, base_url, domainname, domaintype) + +reponse = config.patch_trusted_master_server(jwt, base_url, payload, trustedmasterservername) + +print(reponse) diff --git a/snippets/sample-payloads/config-samples/patch_trusted_master_server.json b/snippets/sample-payloads/config-samples/patch_trusted_master_server.json new file mode 100644 index 0000000..b938367 --- /dev/null +++ b/snippets/sample-payloads/config-samples/patch_trusted_master_server.json @@ -0,0 +1,9 @@ +{ + "data": { + "type": "trustedMasterServer", + "attributes": { + "trustedMasterServerName": "TRUSTED_MASTER_SERVER_NAME", + "rootCAType": "ECA" + } + } +} \ No newline at end of file diff --git a/snippets/sample-payloads/config-samples/post_trusted_master_server.json b/snippets/sample-payloads/config-samples/post_trusted_master_server.json new file mode 100644 index 0000000..74dde60 --- /dev/null +++ b/snippets/sample-payloads/config-samples/post_trusted_master_server.json @@ -0,0 +1,14 @@ +{ + "data": { + "type": "trustedMasterServer", + "attributes": { + "trustedMasterServerName": "remote.master.com", + "rootCAType": "NBCA", + "authenticationType": "CREDENTIAL", + "domainName": "DOMAIN", + "userName": "USER", + "password": "PASSWORD", + "fingerprint": "FINGERPRINT" + } + } +} \ No newline at end of file