Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update NetBackup Documentation #89

Open
wants to merge 135 commits into
base: create-branch
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
135 commits
Select commit Hold shift + click to select a range
04a6034
NetBackup module in go and its example
sgupta03 Jun 20, 2018
e57fba2
deleted binary file that was uploaded by mistake
sgupta03 Jun 20, 2018
8460615
go samples for netbackup image and jobs list
Sep 15, 2018
7889a21
change in README and rename get_nb_mappings
Sep 15, 2018
63e4355
NetBackup Config Management and Admin APIs code samples
santhosh-vrts Jun 28, 2019
e0013a8
NetBackup 8.2 API Perl scripts
srnavale Jun 28, 2019
89870fb
NetBackup 8.2 API Golang scripts
srnavale Jun 28, 2019
2a44f38
Update README.md (#28)
santhosh-vrts Jun 28, 2019
8e678e6
Merge pull request #34 from VeritasOS/sample/configapi-pyscripts
santhosh-vrts Jun 28, 2019
1ac3e5f
Update README.md
santhosh-vrts Jun 28, 2019
67f1d91
Update README.md
santhosh-vrts Jun 28, 2019
a5f6a18
Update README.md
santhosh-vrts Jun 28, 2019
a9a934a
Policy API samples update
santhosh-vrts Jul 1, 2019
fb3a4cd
Merge pull request #35 from VeritasOS/redacted_mammoth_perl_scripts
santhosh-vrts Jul 1, 2019
cf7cf12
Merge pull request #36 from VeritasOS/redacted_mammoth_go_scripts
santhosh-vrts Jul 1, 2019
7502e35
Merge pull request #38 from VeritasOS/policyapi-samples
santhosh-vrts Jul 1, 2019
94f609a
Update README.md
santhosh-vrts Jul 1, 2019
68b9819
Config and Admin API powershell scripts
kcvemula Jul 1, 2019
76a663e
Sample codes to expire images (#25)
YaredE Jul 8, 2019
f3a4799
Added perl scripts for all GET APIs for VM server credentials and res…
Apr 17, 2019
d693578
Merge pull request #29 from VeritasOS/vmserver_resource_limits_APIs
santhosh-vrts Jul 11, 2019
f8435b9
Recipe in Go to set up AIR relationship on MSDP or Cloud Catalyst sto…
akashvrts Jul 11, 2019
944f595
Sample code for NetBackup Storage APIs (#30)
suruchimalewar Jul 12, 2019
8a72764
Python script demonstrating VMware agentless restore APIs
t-r Aug 15, 2019
ae62d52
Condition set for adding TLS12 will always be true (#42)
poojaVeritas Oct 7, 2019
b60f82b
GET, POST and DELETE operation script for the AccessHost APIs.
adi-bhardwaj Oct 15, 2019
8b73c6c
Python script for Cloud Assets Cleanup
sourabhedake Dec 5, 2019
7441d7d
inital ansible
Dec 12, 2019
785f548
Merge pull request #48 from VeritasOS/feature/ism_cloud_asset_cleanup
sourabhedake-zz Dec 13, 2019
cd17c13
Update msdp_create.yml
Dec 15, 2019
ce0853a
Update vmware_resourcelimits.yml
Dec 15, 2019
20ceedc
Curl --data-urlencode does not encode name of the data of the form na…
Feb 18, 2020
e4b3562
little correction
Feb 18, 2020
1c017bd
removed echo
Feb 18, 2020
c850f79
Merge pull request #52 from VeritasOS/curl_issue_urlencode
Mar 5, 2020
96e0bbf
Create get_nb_vmservers.sh
gautam-shantanu May 9, 2020
bf85ec4
How to create, delete and use NetBackup API Key sample snippets
riteshopsranjan May 11, 2020
6c0b29d
Changed SecurityProtocol assignment from "+=" to Bitwise OR
kenogden May 21, 2020
6294614
Changed SecurityProtocol assignment from "+=" to Bitwise OR
kenogden May 21, 2020
686c198
Changed SecurityProtocol assignment from "+=" to Bitwise OR
kenogden May 21, 2020
6a04da4
Changed SecurityProtocol assignment from "+=" to Bitwise OR
kenogden May 21, 2020
1d5f83d
Changed SecurityProtocol assignment from "+=" to Bitwise OR
kenogden May 21, 2020
6d55f70
Changed SecurityProtocol assignment from "+=" to Bitwise OR
kenogden May 21, 2020
7d46715
Changed SecurityProtocol assignment from "+=" to Bitwise OR
kenogden May 21, 2020
e906c44
Changed SecurityProtocol assignment from "+=" to Bitwise OR
kenogden May 21, 2020
c714ce3
Changed SecurityProtocol assignment from "+=" to Bitwise OR
kenogden May 21, 2020
f000ef7
Changed SecurityProtocol assignment from "+=" to Bitwise OR
kenogden May 21, 2020
0472325
Changed SecurityProtocol assignment from "+=" to Bitwise OR
kenogden May 21, 2020
9ec46c1
Changed SecurityProtocol assignment from "+=" to Bitwise OR
kenogden May 21, 2020
03ccb96
Changed SecurityProtocol assignment from "+=" to Bitwise OR
kenogden May 21, 2020
1f59504
Changed SecurityProtocol assignment from "+=" to Bitwise OR
kenogden May 21, 2020
96d3cca
Changed SecurityProtocol assignment from "+=" to Bitwise OR
kenogden May 21, 2020
232525d
Changed SecurityProtocol assignment from "+=" to Bitwise OR
kenogden May 21, 2020
c93d1f2
Changed SecurityProtocol assignment from "+=" to Bitwise OR
kenogden May 21, 2020
928c51f
Changed SecurityProtocol assignment from "+=" to Bitwise OR
kenogden May 21, 2020
f47fe65
Changed SecurityProtocol assignment from "+=" to Bitwise OR
kenogden May 21, 2020
4b3c3a0
Changed SecurityProtocol assignment from "+=" to Bitwise OR
kenogden May 21, 2020
53d3949
Changed SecurityProtocol assignment from "+=" to Bitwise OR
kenogden May 21, 2020
f8b6f8f
Changed SecurityProtocol assignment from "+=" to Bitwise OR
kenogden May 21, 2020
d5845ce
Changed SecurityProtocol assignment from "+=" to Bitwise OR
kenogden May 21, 2020
2966eba
Update Post-NB-create-cloud-storage-unit.ps1
kenogden May 21, 2020
ae00060
Revert "Update Post-NB-create-cloud-storage-unit.ps1"
kenogden May 22, 2020
74699f3
Changed SecurityProtocol assignment from "+=" to Bitwise OR
kenogden May 22, 2020
8772d7f
Changed SecurityProtocol assignment from "+=" to Bitwise OR
kenogden May 22, 2020
11048c8
Changed SecurityProtocol assignment from "+=" to Bitwise OR
kenogden May 22, 2020
d80c4b0
Changed SecurityProtocol assignment from "+=" to Bitwise OR
kenogden May 22, 2020
e09016d
Sample Perl scripts for converting rbac principals behind registered …
hungtran-veritas May 18, 2020
bf694a4
Merge pull request #31 from VeritasOS/feature/apikeys
riteshopsranjan May 26, 2020
8947097
Create new sample Get_NB_ReissueToken
kenogden May 27, 2020
06dca47
Create new sample Get_NB_PolicyDetails
kenogden May 27, 2020
55e66c4
Rename Get_NB_ReissueToken to Get-NB-ReissueToken
kenogden May 27, 2020
73ac9f0
Rename Get_NB_PolicyDetails.ps1 to Get-NB-PolicyDetails.ps1
kenogden May 27, 2020
923df00
Update README.md
kenogden May 27, 2020
b8074f9
Rename Get-NB-ReissueToken to Get-NB-ReissueToken.ps1
kenogden May 27, 2020
cc68c60
Update README.md
kenogden May 27, 2020
0597ba5
Updated usage for -nbpolicy param
kenogden May 27, 2020
d1f4e43
Create rbac_role_templates.pl
kyleburling-veritas Jun 4, 2020
c86d766
Create rbac_user_migration.pl
kyleburling-veritas Jun 4, 2020
b44948e
new file added for vmware asset-groups
ntbritton Jun 5, 2020
762e16e
slo_post example
ntbritton Jun 5, 2020
b7aff31
Merge pull request #2 from ntbritton/ntbritton-slo-post
ntbritton Jun 5, 2020
259213b
Merge pull request #1 from ntbritton/ntbritton-patch-1
ntbritton Jun 5, 2020
bdc3697
Added new sample CRUD on policies
YaredE Jul 29, 2020
5cc8a88
Get VMware assets API script
santhosh-vrts Jul 30, 2020
bbf5ddb
Merge pull request #69 from VeritasOS/SampleAPI
YaredE Jul 30, 2020
3e7fcbe
Merge pull request #60 from kenogden/Issue/AppendVsBitwiseOr
rkennedy Jul 30, 2020
51ea86e
Asset service VMware assets API sample script
santhosh-vrts Jul 31, 2020
52410a0
Merge pull request #62 from kenogden/feature/PowerShell-Sample-Get-Re…
jaya-korlepara Jul 31, 2020
51c4ff7
Adding RBAC design change information warning users that some scripts…
jeffcjames Jul 30, 2020
257d9aa
Merge pull request #56 from VeritasOS/feature/convert-principal-behin…
rkennedy Jul 31, 2020
fa62a51
Merge pull request #66 from kyleburling-veritas/feature/rbac_roles
rkennedy Jul 31, 2020
79c8af3
Merge pull request #72 from VeritasOS/feature/rbac-design-change-warning
rkennedy Jul 31, 2020
4efd392
Get VMware assets API py script enhancements. Updated script to get V…
Aug 3, 2020
e868a2c
Asset Service VMware Assets API script
santhosh-vrts Aug 3, 2020
244a807
Added perl scripts for GET and POST notifications APIs.
aayush13890 Aug 3, 2020
b7a7244
Merge pull request #43 from VeritasOS/accessHostsApi_golang_scripts
rkennedy Aug 4, 2020
b75ce85
Merge pull request #16 from VeritasOS/feature/netbackup-go-module
rkennedy Aug 4, 2020
2dd9a05
Vmware assets ps scripts
ssuresh91 Aug 19, 2020
04d26ca
Moving the scripts located under /recipes/perl/rbac_roles to /recipes…
jeffcjames Aug 19, 2020
42f701b
Update snippets/curl/get_nb_vmservers.sh
gautam-shantanu Aug 21, 2020
2c8139a
Update snippets/curl/get_nb_vmservers.sh
gautam-shantanu Aug 21, 2020
2f855d1
Open source API code of single and group VM backup and restore
ashviniwaghmode Aug 25, 2020
a8c7c77
Removed unwanted code
ashviniwaghmode Aug 25, 2020
fe61c7c
ed f string format and added documentation
ashviniwaghmode Aug 28, 2020
0afd2a7
curl to get assets
gautam-shantanu Sep 1, 2020
4bcb9cc
Updated script
santhosh-vrts Sep 1, 2020
8a0748d
Used with statement to open the file
ashviniwaghmode Sep 2, 2020
c2e48f9
Get VMware assets API script
santhosh-vrts Sep 3, 2020
19ad33f
Sample perl script for VMware assets API
kcvemula Sep 3, 2020
7cace45
Sample perl script for VMware assets API
santhosh-vrts Sep 3, 2020
ba583e8
Corrected the description
ashviniwaghmode Sep 4, 2020
df3aa18
Take stu_name as input paramer and corrected typos
ashviniwaghmode Sep 9, 2020
648662a
Merge pull request #79 from ashviniwaghmode/feature/backup_restore_ap…
jaya-korlepara Sep 9, 2020
f00082a
Merge pull request #54 from gautam-shantanu/patch-1
rkennedy Sep 21, 2020
509508e
Merge pull request #50 from ntbritton/master
rkennedy Sep 22, 2020
dc9911b
Modified to use Python3 print statements
jpummill Oct 12, 2020
8a9e9b5
Merge pull request #82 from VeritasOS/fix_python_snippets
rkennedy Oct 23, 2020
2d83610
Clientbackup script
tcsimerson Sep 4, 2020
fcc1cd8
Address review comments & add Python version
tcsimerson Oct 25, 2020
5d5ab0c
Merge branch 'master' into feature/PowerShell-Sample-Get_NB_PolicyDet…
rkennedy Oct 26, 2020
6f8283a
Merge pull request #63 from kenogden/feature/PowerShell-Sample-Get_NB…
rkennedy Oct 26, 2020
5de3584
Merge pull request #81 from VeritasOS/clientbackup
rkennedy Oct 26, 2020
2d886de
Mssql workload API workflow for NetBackup 8.3+
pdamodha Nov 20, 2020
834904b
readme edited cosmetically
pdamodha Nov 21, 2020
43fc7b0
Update README.md
pdamodha Dec 2, 2020
2409a2a
Update README.md
pdamodha Dec 2, 2020
113c698
Merge pull request #83 from VeritasOS/feature/mssql-dsp-api-workflow
rkennedy Dec 12, 2020
bb2086c
Adding in samples on how to do a restore of a singular copy of a backup
alexoelke Dec 18, 2020
9287b2a
Update README.md
alexoelke Jan 19, 2021
6dc77d2
Update README.md
alexoelke Jan 19, 2021
8900df5
Merge pull request #84 from VeritasOS/feature/mssql_recover_from_copy…
rkennedy Apr 29, 2021
1d822a4
Invoking oracle clone using NetBackup APIs.
rushmeetbahra Apr 12, 2023
0f32c1c
Merge pull request #90 from rushmeetbahra/oracleclonescripts
rkennedy Oct 14, 2023
7a444a1
Adding in script for Oracle RBAC work
alexoelke Dec 18, 2023
29749ab
Merge pull request #91 from VeritasOS/oracleExamples
rkennedy Mar 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 34 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
### NetBackup API Code Samples

Contains code samples to invoke NetBackup REST API using different programming languages.
Contains code samples of using NetBackup REST APIs in different scripting/programming languages.

#### Disclaimer
These scripts are only meant to be used as a reference. Please do not use these in production.
##### Disclaimer
These samples are only meant to be used as a reference. Please do not use these in production.

#### Executing the snippets for different programming languages
##### Executing the 'snippets'

The `snippets` folder contains code samples to invoke NetBackup REST API using different programming languages.
The `snippets` folder contains code samples to invoke NetBackup APIs using different scripting/programming languages.
These are usually simple examples that demonstrate specific API.

Pre-requisites:

- NetBackup 8.1.1 or higher
- See the script's README for the corresponding requirements and usage


#### Executing the recipes for different programming languages
##### Executing the 'recipes'

The `recipes` folder contains code samples to invoke NetBackup REST API using different programming languages.
The `recipes` folder contains code samples to invoke NetBackup APIs using different scripting/programming languages.
These are usually examples of usage of multiple APIs covering specific use-cases.

Pre-requisites:

Expand All @@ -26,8 +28,29 @@ Pre-requisites:



#### Tools
The `tools` folder contains utilities that have proven useful in the development of projects using
NetBackup REST APIs, but do not provide any API usage examples. Again, these tools are not for
production use, but they may be of some use in your work.
##### Tools
The `tools` folder contains utilities that have proven useful in the development of projects using NetBackup APIs, but do not provide any API usage examples. Again, these tools are not for production use, but they may be of some use in your work.

#### NetBackup 8.3 RBAC Design Shift
NetBackup 8.3 introduced a major change in its RBAC configuration and enforcement design.

RBAC was introduced to NetBackup in the 8.1.2 release, offering access control for a limited number of security settings and workloads. That access control configuration was based on a dynamic object-level enforcement model using “Access Rules”.

With the NetBackup 8.3 release, RBAC has moved away from the dynamic access rule design.
The new RBAC allows more granular permissions, improved flexibility and greater control. The RBAC design is now based on Access Control Lists (ACLs) and closely follows the ANSI INCITS 359-2004. While the earlier design of RBAC enforcement was dynamic in nature, the new RBAC is static in its configuration.

The system-defined roles shipped with NetBackup also changed from 8.1.2 to the 8.3 release. In 8.1.2, there were three system-defined roles available for RBAC configuration. In the 8.3 release, this was simplified to offer a single “Administrator” role which has all privileges for RBAC.

Due to the significant design shift, automatic upgrade conversion of 8.1.2 RBAC roles to the new 8.3 roles is not feasible. However, tools are available to migrate the Backup administrator role and create a new Security administrator role for the users that had the old RBAC Security administrator role.
Other roles must be reconfigured manually.
There is also a script in this repository available to generate templated NetBackup roles.
See **/recipes/perl/access-control/rbac_role_templates.pl**


Any API keys in use prior to upgrade will still be valid, however, the underlying access granted those API keys must
be reconfigured using the new RBAC configuration, after which any active user sessions must be removed.
A utility script exists in this repository to help convert active API keys after upgrade to NetBackup 8.3.
See **/recipes/perl/access-control/access_control_api_requests.pl**

Most of the API examples in this repository assume a valid JWT (Json Web Token) or API Key issued by NetBackup and do
not incorporate role configuration as part of the script. However, there may be some examples which do configure RBAC as part of the script and have not yet been updated to use the RBAC design.
18 changes: 18 additions & 0 deletions recipes/go/admin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
### NetBackup API Code Samples for go (often referred to as golang)

This directory contains code samples to invoke NetBackup administration REST APIs using go.

#### 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
- go1.10.2 or higher

#### Executing the recipes using go

Use the following commands to run the go samples.
- `go run ./get_processes.go -nbmaster <masterServer> -username <username> -password <password> [-domainName <domainName>] [-domainType <domainType>] -client <client>`
- `go run ./get_services.go -nbmaster <masterServer> -username <username> -password <password> [-domainName <domainName>] [-domainType <domainType>] -client <client>`
56 changes: 56 additions & 0 deletions recipes/go/admin/get_processes.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
//This script can be run using NetBackup 8.2 and higher.
//It gets all NetBackup processes running on the given host.

package main

import (
"flag"
"fmt"
"log"
"os"
"apihelper"
)

//###################
// Global Variables
//###################
var (
nbmaster = flag.String("nbmaster", "", "NetBackup Master Server")
username = flag.String("username", "", "User name to log into the NetBackup webservices")
password = flag.String("password", "", "Password for the given user")
domainName = flag.String("domainName", "", "Domain name of the given user")
domainType = flag.String("domainType", "", "Domain type of the given user")
client = flag.String("client", "", "NetBackup host name")
)

const usage = "\n\nUsage: go run ./get_processes.go -nbmaster <masterServer> -username <username> -password <password> [-domainName <domainName>] [-domainType <domainType>] -client <client>\n\n"

func main() {
// Print usage
flag.Usage = func() {
fmt.Fprintf(os.Stderr, usage)
os.Exit(1)
}

// Read command line arguments
flag.Parse()

if len(*nbmaster) == 0 {
log.Fatalf("Please specify the name of the NetBackup Master Server using the -nbmaster parameter.\n")
}
if len(*username) == 0 {
log.Fatalf("Please specify the username using the -username parameter.\n")
}
if len(*password) == 0 {
log.Fatalf("Please specify the password using the -password parameter.\n")
}
if len(*client) == 0 {
log.Fatalf("Please specify the name of a NetBackup host using the -client parameter.\n")
}

httpClient := apihelper.GetHTTPClient()
jwt := apihelper.Login(*nbmaster, httpClient, *username, *password, *domainName, *domainType)
hostUuid := apihelper.GetHostUUID(*nbmaster, httpClient, jwt, *client);
filter := "";
apihelper.GetProcesses(*nbmaster, httpClient, jwt, *client, hostUuid, filter);
}
55 changes: 55 additions & 0 deletions recipes/go/admin/get_services.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
//This script can be run using NetBackup 8.2 and higher.
//It gets all NetBackup services available on the given host.

package main

import (
"flag"
"fmt"
"log"
"os"
"apihelper"
)

//###################
// Global Variables
//###################
var (
nbmaster = flag.String("nbmaster", "", "NetBackup Master Server")
username = flag.String("username", "", "User name to log into the NetBackup webservices")
password = flag.String("password", "", "Password for the given user")
domainName = flag.String("domainName", "", "Domain name of the given user")
domainType = flag.String("domainType", "", "Domain type of the given user")
client = flag.String("client", "", "NetBackup host name")
)

const usage = "\n\nUsage: go run ./get_services.go -nbmaster <masterServer> -username <username> -password <password> [-domainName <domainName>] [-domainType <domainType>] -client <client>\n\n"

func main() {
// Print usage
flag.Usage = func() {
fmt.Fprintf(os.Stderr, usage)
os.Exit(1)
}

// Read command line arguments
flag.Parse()

if len(*nbmaster) == 0 {
log.Fatalf("Please specify the name of the NetBackup Master Server using the -nbmaster parameter.\n")
}
if len(*username) == 0 {
log.Fatalf("Please specify the username using the -username parameter.\n")
}
if len(*password) == 0 {
log.Fatalf("Please specify the password using the -password parameter.\n")
}
if len(*client) == 0 {
log.Fatalf("Please specify the name of a NetBackup host using the -client parameter.\n")
}

httpClient := apihelper.GetHTTPClient()
jwt := apihelper.Login(*nbmaster, httpClient, *username, *password, *domainName, *domainType)
hostUuid := apihelper.GetHostUUID(*nbmaster, httpClient, jwt, *client);
apihelper.GetServices(*nbmaster, httpClient, jwt, *client, hostUuid);
}
27 changes: 27 additions & 0 deletions recipes/go/assets/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
### NetBackup API Code Samples in go

This directory contains code samples in golang for NetBackup Asset Service APIs.

#### Disclaimer

The scripts are provided only for reference and not meant for production use.

#### Pre-requisites:

- NetBackup 8.3 or higher
- go1.10.2 or higher

#### Executing the script

- get_vmware_assets:
`go run ./get_vmware_assets.go -nbserver <NetBackup server> -username <username> -password <password> [-domainName <domainName>] [-domainType <domainType>] [-assetsFilter <filter>]`

The script invokes the NetBackup VMware Asset Service API to get the VMware workload assets (filtered by the given filter criteria if specified). It prints the asset details (delimited by tab) such as asset display name, instance Id, vCenter and the protection plan names that the asset is protected by.

Note: The _assetsFilter_ option can be used to filter the assets returned. It should be in OData format (refer to the NetBackup API documentation for more details). It is optional; if not specified the script will return all VM assets. Redirect the script output to a file to avoid printing the details on terminal.

Examples:

- List all VMs: `go run ./get_vmware_assets.go -nbserver localhost -username user -password password -domainName domain -domainType NT > vm_assets.txt`

- List VMs with filter condition: `go run ./get_vmware_assets.go -nbserver localhost -username user -password password -domainName domain -domainType NT -assetsFilter "contains(commonAssetAttributes/displayName, 'backup')"`
136 changes: 136 additions & 0 deletions recipes/go/assets/get_vmware_assets.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
//This script can be run using NetBackup 8.3 and higher.
//It gets the list of VMware assets in NetBackup (based on the given filter if specified, else returns all the VMware assets).

package main

import (
"flag"
"fmt"
"log"
"os"
"strconv"
"net/url"
"net/http"
"io/ioutil"
"encoding/json"
"utils"
)

var (
nbserver = flag.String("nbserver", "", "NetBackup Server")
username = flag.String("username", "", "User name for NetBackup API login")
password = flag.String("password", "", "Password for the given user")
domainName = flag.String("domainName", "", "Domain name")
domainType = flag.String("domainType", "", "Domain type")
assetsFilter = flag.String("assetsFilter", "", "Filter string (odata format) to filter the assets")
)

const usage = "\n\nUsage: go run ./get_vmware_assets.go -nbserver <NetBackup server> -username <username> -password <password> [-domainName <domainName>] [-domainType <domainType>] [-assetsFilter <filter>]\n\n"

func main() {
// Print usage
flag.Usage = func() {
fmt.Fprintf(os.Stderr, usage)
os.Exit(1)
}

// Read command line arguments
flag.Parse()

if len(*nbserver) == 0 {
log.Fatalf("Please specify the name of the NetBackup Server using the -nbserver option.\n")
}
if len(*username) == 0 {
log.Fatalf("Please specify the username using the -username option.\n")
}
if len(*password) == 0 {
log.Fatalf("Please specify the password using the -password option.\n")
}

httpClient := apihelper.GetHTTPClient()
jwt := apihelper.Login(*nbserver, httpClient, *username, *password, *domainName, *domainType)

vmwareAssetsApiUrl := "https://" + *nbserver + "/netbackup/asset-service/workloads/vmware/assets"
defaultSort := "commonAssetAttributes.displayName"
assetTypeFilter := "(assetType eq 'vm')"

req, err := http.NewRequest("GET", vmwareAssetsApiUrl, nil)

if err != nil {
fmt.Printf("Making new HTTP request failed with error: %s\n", err)
panic("Script failed.")
}

req.Header.Add("Authorization", jwt)
pageLimit := 100
offset := 0
next := true
params := url.Values{}

if assetsFilter != nil {
filter := ""
if *assetsFilter != "" {
filter = *assetsFilter + " and " + assetTypeFilter
} else {
filter = assetTypeFilter
}
params.Add("filter", filter)
}

params.Add("sort", defaultSort)
params.Add("page[offset]", strconv.Itoa(offset))
params.Add("page[limit]", strconv.Itoa(pageLimit))

fmt.Println("\nGetting VMware assets...")
fmt.Println("Printing the following asset details: Display Name, VM InstanceId, vCenter, Protection Plan Names\n")

for next {
req.URL.RawQuery = params.Encode()
resp, err := httpClient.Do(req)

if err != nil {
fmt.Printf("Get VMware Assets failed with error: %s\n", err)
panic("Script failed.")
} else {
respJson, _ := ioutil.ReadAll(resp.Body)
if resp.StatusCode == 200 {
var respPayload interface{}
json.Unmarshal(respJson, &respPayload)
respData := respPayload.(map[string]interface{})
assetsData := respData["data"].([]interface{})
printAssetDetails(assetsData)
next = respData["meta"].(map[string]interface{})["pagination"].
(map[string]interface{})["hasNext"].(bool)
} else {
fmt.Println(string(respJson))
next = false
}
}
offset, _ = strconv.Atoi(params["page[offset]"][0])
params["page[offset]"][0] = strconv.Itoa(offset + pageLimit)
}

fmt.Println("\nScript completed.\n")
}

func printAssetDetails(assets []interface{}) {
for _, asset := range assets {
assetAttrs := asset.(map[string]interface{})["attributes"].(map[string]interface{})
assetCommonAttrs := assetAttrs["commonAssetAttributes"].(map[string]interface{})
displayName := assetCommonAttrs["displayName"]
instanceId := assetAttrs["instanceUuid"]
vCenter := assetAttrs["vCenter"]

var protectionPlans []string
if activeProtections, protected := assetCommonAttrs["activeProtection"]; protected {
protectionDetailsList := activeProtections.(map[string]interface{})["protectionDetailsList"].([]interface{})

for _, protectionDetails := range protectionDetailsList {
protectionPlans = append(protectionPlans, protectionDetails.
(map[string]interface{})["protectionPlanName"].(string))
}
}
fmt.Printf("%s\t%s\t%s\t%v\n", displayName, instanceId, vCenter, protectionPlans)
}

}
18 changes: 18 additions & 0 deletions recipes/go/config/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
### NetBackup API Code Samples for go (often referred to as golang)

This directory contains code samples to invoke NetBackup configuration REST APIs using go.

#### 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
- go1.10.2 or higher

#### Executing the recipes using go

Use the following commands to run the go samples.
- `go run ./get_set_host_config.go -nbmaster <masterServer> -username <username> -password <password> [-domainName <domainName>] [-domainType <domainType>] -client <client>`
- `go run ./manage_access_hosts.go -nbmaster <masterServer> -username <username> -password <password> [-domainName <domainName>] [-domainType <domainType>] [-accessHost <accessHost>]`
Loading