Skip to content

Commit 5d5ab0c

Browse files
authored
Merge branch 'master' into feature/PowerShell-Sample-Get_NB_PolicyDetails
2 parents 0597ba5 + 8a9e9b5 commit 5d5ab0c

File tree

97 files changed

+7531
-53
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+7531
-53
lines changed

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,26 @@ Pre-requisites:
3131
##### Tools
3232
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.
3333

34+
#### NetBackup 8.3 RBAC Design Shift
35+
NetBackup 8.3 introduced a major change in its RBAC configuration and enforcement design.
36+
37+
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”.
38+
39+
With the NetBackup 8.3 release, RBAC has moved away from the dynamic access rule design.
40+
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.
41+
42+
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.
43+
44+
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.
45+
Other roles must be reconfigured manually.
46+
There is also a script in this repository available to generate templated NetBackup roles.
47+
See **/recipes/perl/access-control/rbac_role_templates.pl**
48+
49+
50+
Any API keys in use prior to upgrade will still be valid, however, the underlying access granted those API keys must
51+
be reconfigured using the new RBAC configuration, after which any active user sessions must be removed.
52+
A utility script exists in this repository to help convert active API keys after upgrade to NetBackup 8.3.
53+
See **/recipes/perl/access-control/access_control_api_requests.pl**
54+
55+
Most of the API examples in this repository assume a valid JWT (Json Web Token) or API Key issued by NetBackup and do
56+
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.

recipes/go/assets/README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
### NetBackup API Code Samples in go
2+
3+
This directory contains code samples in golang for NetBackup Asset Service APIs.
4+
5+
#### Disclaimer
6+
7+
The scripts are provided only for reference and not meant for production use.
8+
9+
#### Pre-requisites:
10+
11+
- NetBackup 8.3 or higher
12+
- go1.10.2 or higher
13+
14+
#### Executing the script
15+
16+
- get_vmware_assets:
17+
`go run ./get_vmware_assets.go -nbserver <NetBackup server> -username <username> -password <password> [-domainName <domainName>] [-domainType <domainType>] [-assetsFilter <filter>]`
18+
19+
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.
20+
21+
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.
22+
23+
Examples:
24+
25+
- List all VMs: `go run ./get_vmware_assets.go -nbserver localhost -username user -password password -domainName domain -domainType NT > vm_assets.txt`
26+
27+
- 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')"`
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
//This script can be run using NetBackup 8.3 and higher.
2+
//It gets the list of VMware assets in NetBackup (based on the given filter if specified, else returns all the VMware assets).
3+
4+
package main
5+
6+
import (
7+
"flag"
8+
"fmt"
9+
"log"
10+
"os"
11+
"strconv"
12+
"net/url"
13+
"net/http"
14+
"io/ioutil"
15+
"encoding/json"
16+
"utils"
17+
)
18+
19+
var (
20+
nbserver = flag.String("nbserver", "", "NetBackup Server")
21+
username = flag.String("username", "", "User name for NetBackup API login")
22+
password = flag.String("password", "", "Password for the given user")
23+
domainName = flag.String("domainName", "", "Domain name")
24+
domainType = flag.String("domainType", "", "Domain type")
25+
assetsFilter = flag.String("assetsFilter", "", "Filter string (odata format) to filter the assets")
26+
)
27+
28+
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"
29+
30+
func main() {
31+
// Print usage
32+
flag.Usage = func() {
33+
fmt.Fprintf(os.Stderr, usage)
34+
os.Exit(1)
35+
}
36+
37+
// Read command line arguments
38+
flag.Parse()
39+
40+
if len(*nbserver) == 0 {
41+
log.Fatalf("Please specify the name of the NetBackup Server using the -nbserver option.\n")
42+
}
43+
if len(*username) == 0 {
44+
log.Fatalf("Please specify the username using the -username option.\n")
45+
}
46+
if len(*password) == 0 {
47+
log.Fatalf("Please specify the password using the -password option.\n")
48+
}
49+
50+
httpClient := apihelper.GetHTTPClient()
51+
jwt := apihelper.Login(*nbserver, httpClient, *username, *password, *domainName, *domainType)
52+
53+
vmwareAssetsApiUrl := "https://" + *nbserver + "/netbackup/asset-service/workloads/vmware/assets"
54+
defaultSort := "commonAssetAttributes.displayName"
55+
assetTypeFilter := "(assetType eq 'vm')"
56+
57+
req, err := http.NewRequest("GET", vmwareAssetsApiUrl, nil)
58+
59+
if err != nil {
60+
fmt.Printf("Making new HTTP request failed with error: %s\n", err)
61+
panic("Script failed.")
62+
}
63+
64+
req.Header.Add("Authorization", jwt)
65+
pageLimit := 100
66+
offset := 0
67+
next := true
68+
params := url.Values{}
69+
70+
if assetsFilter != nil {
71+
filter := ""
72+
if *assetsFilter != "" {
73+
filter = *assetsFilter + " and " + assetTypeFilter
74+
} else {
75+
filter = assetTypeFilter
76+
}
77+
params.Add("filter", filter)
78+
}
79+
80+
params.Add("sort", defaultSort)
81+
params.Add("page[offset]", strconv.Itoa(offset))
82+
params.Add("page[limit]", strconv.Itoa(pageLimit))
83+
84+
fmt.Println("\nGetting VMware assets...")
85+
fmt.Println("Printing the following asset details: Display Name, VM InstanceId, vCenter, Protection Plan Names\n")
86+
87+
for next {
88+
req.URL.RawQuery = params.Encode()
89+
resp, err := httpClient.Do(req)
90+
91+
if err != nil {
92+
fmt.Printf("Get VMware Assets failed with error: %s\n", err)
93+
panic("Script failed.")
94+
} else {
95+
respJson, _ := ioutil.ReadAll(resp.Body)
96+
if resp.StatusCode == 200 {
97+
var respPayload interface{}
98+
json.Unmarshal(respJson, &respPayload)
99+
respData := respPayload.(map[string]interface{})
100+
assetsData := respData["data"].([]interface{})
101+
printAssetDetails(assetsData)
102+
next = respData["meta"].(map[string]interface{})["pagination"].
103+
(map[string]interface{})["hasNext"].(bool)
104+
} else {
105+
fmt.Println(string(respJson))
106+
next = false
107+
}
108+
}
109+
offset, _ = strconv.Atoi(params["page[offset]"][0])
110+
params["page[offset]"][0] = strconv.Itoa(offset + pageLimit)
111+
}
112+
113+
fmt.Println("\nScript completed.\n")
114+
}
115+
116+
func printAssetDetails(assets []interface{}) {
117+
for _, asset := range assets {
118+
assetAttrs := asset.(map[string]interface{})["attributes"].(map[string]interface{})
119+
assetCommonAttrs := assetAttrs["commonAssetAttributes"].(map[string]interface{})
120+
displayName := assetCommonAttrs["displayName"]
121+
instanceId := assetAttrs["instanceUuid"]
122+
vCenter := assetAttrs["vCenter"]
123+
124+
var protectionPlans []string
125+
if activeProtections, protected := assetCommonAttrs["activeProtection"]; protected {
126+
protectionDetailsList := activeProtections.(map[string]interface{})["protectionDetailsList"].([]interface{})
127+
128+
for _, protectionDetails := range protectionDetailsList {
129+
protectionPlans = append(protectionPlans, protectionDetails.
130+
(map[string]interface{})["protectionPlanName"].(string))
131+
}
132+
}
133+
fmt.Printf("%s\t%s\t%s\t%v\n", displayName, instanceId, vCenter, protectionPlans)
134+
}
135+
136+
}

recipes/go/config/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ These scripts are only meant to be used as a reference. If you intend to use the
1515

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

0 commit comments

Comments
 (0)