Skip to content

Commit 5477b15

Browse files
Merge pull request #13 from VeritasOS/feature/policy_API_golang
Provide go scripts to create a policy
2 parents 4aebc25 + a2a10ea commit 5477b15

File tree

5 files changed

+709
-18
lines changed

5 files changed

+709
-18
lines changed

README.md

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,16 @@ Pre-requisites:
1414
- NetBackup 8.1.1 or higher
1515
- See the script's README for the corresponding requirements and usage
1616

17-
#### Executing the recipes in Perl
1817

19-
Pre-requisites:
20-
- NetBackup 8.1.2 or higher
21-
- Perl 5.20.2 or higher
22-
23-
Use the following commands to run the perl samples.
24-
- `perl create_policy_step_by_step.pl -nbmaster <masterServer> -username <username> -password <password> [-domainName <domainName>] [-domainType <domainType>]`
25-
- `perl create_policy_in_one_step.pl -nbmaster <masterServer> -username <username> -password <password> [-domainName <domainName>] [-domainType <domainType>]`
26-
- `perl rbac_filtering_in_policy.pl -nbmaster <masterServer> -username <username> -password <password> [-domainName <domainName>] [-domainType <domainType>]`
27-
- `perl api_requests_images.pl -nbmaster <masterServer> -username <username> -password <password> [-domainName <domainName>] [-domainType <domainType>]`
28-
- `perl api_requests_image_contents.pl -nbmaster <masterServer> -username <username> -password <password> [-domainName <domainName>] [-domainType <domainType>]`
18+
#### Executing the recipes for different programming languages
2919

30-
#### Executing the recipes in Python
20+
The `recipes` folder contains code samples to invoke NetBackup REST API using different programming languages.
3121

3222
Pre-requisites:
23+
3324
- NetBackup 8.1.2 or higher
34-
- python 3.5 or higher
35-
- python modules: `requests`
25+
- See the script's README for the corresponding requirements and usage
3626

37-
Use the following commands to run the python samples.
38-
- `python -W ignore create_policy_step_by_step.py -nbmaster <masterServer> -username <username> -password <password> [-domainName <domainName>] [-domainType <domainType>]`
39-
- `python -W ignore create_policy_in_one_step.py -nbmaster <masterServer> -username <username> -password <password> [-domainName <domainName>] [-domainType <domainType>]`
40-
- `python -W ignore rbac_filtering_in_policy.py -nbmaster <masterServer> -username <username> -password <password> [-domainName <domainName>] [-domainType <domainType>]`
4127

4228

4329
#### Tools

recipes/go/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
### NetBackup API Code Samples for go (often referred to as golang)
2+
3+
This directory contains code samples to invoke NetBackup REST APIs using go.
4+
5+
#### Disclaimer
6+
7+
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.
8+
9+
#### Pre-requisites:
10+
11+
- NetBackup 8.1.2 or higher
12+
- go1.10.2 or higher
13+
14+
#### Executing the recipes using go
15+
16+
Use the following commands to run the go samples.
17+
- `go run ./create_policy_step_by_step.go -nbmaster <master_server> -username <username> -password <password>`
18+
- `go run ./create_policy_in_one_step.go -nbmaster <master_server> -username <username> -password <password>`
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
//This script can be run using NetBackup 8.1.2 and higher.
2+
//It creates a VMware policy consisting of the specific attribute values, a client, a schedule, and a VIP query backup selection
3+
//and eventually deletes the policy.
4+
5+
package main
6+
7+
import (
8+
"flag"
9+
"fmt"
10+
"log"
11+
"os"
12+
"policies/apihelper"
13+
)
14+
15+
//###################
16+
// Global Variables
17+
//###################
18+
var (
19+
nbmaster = flag.String("nbmaster", "", "NetBackup Master Server")
20+
username = flag.String("username", "", "User name to log into the NetBackup webservices")
21+
password = flag.String("password", "", "Password for the given user")
22+
domainName = flag.String("domainName", "", "Domain name of the given user")
23+
domainType = flag.String("domainType", "", "Domain type of the given user")
24+
)
25+
26+
const usage = "\n\nUsage: go run ./create_policy_in_one_step.go -nbmaster <masterServer> -username <username> -password <password> [-domainName <domainName>] [-domainType <domainType>]\n\n"
27+
28+
func main() {
29+
// Print usage
30+
flag.Usage = func() {
31+
fmt.Fprintf(os.Stderr, usage)
32+
os.Exit(1)
33+
}
34+
35+
// Read command line arguments
36+
flag.Parse()
37+
38+
if len(*nbmaster) == 0 {
39+
log.Fatalf("Please specify the name of the NetBackup Master Server using the -nbmaster parameter.\n")
40+
}
41+
if len(*username) == 0 {
42+
log.Fatalf("Please specify the username using the -username parameter.\n")
43+
}
44+
if len(*password) == 0 {
45+
log.Fatalf("Please specify the password using the -password parameter.\n")
46+
}
47+
48+
httpClient := helper.GetHTTPClient()
49+
jwt := helper.Login(*nbmaster, httpClient, *username, *password, *domainName, *domainType)
50+
51+
helper.CreatePolicy(*nbmaster, httpClient, jwt)
52+
helper.ListPolicies(*nbmaster, httpClient, jwt)
53+
helper.ReadPolicy(*nbmaster, httpClient, jwt)
54+
helper.DeletePolicy(*nbmaster, httpClient, jwt)
55+
helper.ListPolicies(*nbmaster, httpClient, jwt)
56+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
//This script can be run using NetBackup 8.1.2 and higher.
2+
//It creates a VMware policy with the default attribute values, then adds a client, a schedule, and a VIP query backup selection to it.
3+
//It then delets the client, schedule from the policy and finally deletes the policy.
4+
5+
package main
6+
7+
import (
8+
"flag"
9+
"fmt"
10+
"log"
11+
"os"
12+
"policies/apihelper"
13+
)
14+
15+
//###################
16+
// Global Variables
17+
//###################
18+
var (
19+
nbmaster = flag.String("nbmaster", "", "NetBackup Master Server")
20+
username = flag.String("username", "", "User name to log into the NetBackup webservices")
21+
password = flag.String("password", "", "Password for the given user")
22+
domainName = flag.String("domainName", "", "Domain name of the given user")
23+
domainType = flag.String("domainType", "", "Domain type of the given user")
24+
)
25+
26+
const usage = "\n\nUsage: go run ./create_policy_step_by_step.go -nbmaster <masterServer> -username <username> -password <password> [-domainName <domainName>] [-domainType <domainType>]\n\n"
27+
28+
func main() {
29+
// Print usage
30+
flag.Usage = func() {
31+
fmt.Fprintf(os.Stderr, usage)
32+
os.Exit(1)
33+
}
34+
35+
// Read command line arguments
36+
flag.Parse()
37+
38+
if len(*nbmaster) == 0 {
39+
log.Fatalf("Please specify the name of the NetBackup Master Server using the -nbmaster parameter.\n")
40+
}
41+
if len(*username) == 0 {
42+
log.Fatalf("Please specify the username using the -username parameter.\n")
43+
}
44+
if len(*password) == 0 {
45+
log.Fatalf("Please specify the password using the -password parameter.\n")
46+
}
47+
48+
httpClient := helper.GetHTTPClient()
49+
jwt := helper.Login(*nbmaster, httpClient, *username, *password, *domainName, *domainType)
50+
51+
helper.CreatePolicyWithDefaults(*nbmaster, httpClient, jwt)
52+
helper.ListPolicies(*nbmaster, httpClient, jwt)
53+
helper.ReadPolicy(*nbmaster, httpClient, jwt)
54+
helper.AddClient(*nbmaster, httpClient, jwt)
55+
helper.AddSchedule(*nbmaster, httpClient, jwt)
56+
helper.AddBackupSelection(*nbmaster, httpClient, jwt)
57+
helper.ReadPolicy(*nbmaster, httpClient, jwt)
58+
helper.DeleteClient(*nbmaster, httpClient, jwt)
59+
helper.DeleteSchedule(*nbmaster, httpClient, jwt)
60+
helper.ReadPolicy(*nbmaster, httpClient, jwt)
61+
helper.DeletePolicy(*nbmaster, httpClient, jwt)
62+
helper.ListPolicies(*nbmaster, httpClient, jwt)
63+
}

0 commit comments

Comments
 (0)