Skip to content

Commit cf7cf12

Browse files
Merge pull request #36 from VeritasOS/redacted_mammoth_go_scripts
NetBackup 8.2 API golang scripts for config, admin APIs
2 parents fb3a4cd + 89870fb commit cf7cf12

File tree

9 files changed

+509
-47
lines changed

9 files changed

+509
-47
lines changed

recipes/go/admin/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 administration 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.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 ./get_processes.go -nbmaster <masterServer> -username <username> -password <password> [-domainName <domainName>] [-domainType <domainType>] -client <client>`
18+
- `go run ./get_services.go -nbmaster <masterServer> -username <username> -password <password> [-domainName <domainName>] [-domainType <domainType>] -client <client>`

recipes/go/admin/get_processes.go

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.2 and higher.
2+
//It gets all NetBackup processes running on the given host.
3+
4+
package main
5+
6+
import (
7+
"flag"
8+
"fmt"
9+
"log"
10+
"os"
11+
"apihelper"
12+
)
13+
14+
//###################
15+
// Global Variables
16+
//###################
17+
var (
18+
nbmaster = flag.String("nbmaster", "", "NetBackup Master Server")
19+
username = flag.String("username", "", "User name to log into the NetBackup webservices")
20+
password = flag.String("password", "", "Password for the given user")
21+
domainName = flag.String("domainName", "", "Domain name of the given user")
22+
domainType = flag.String("domainType", "", "Domain type of the given user")
23+
client = flag.String("client", "", "NetBackup host name")
24+
)
25+
26+
const usage = "\n\nUsage: go run ./get_processes.go -nbmaster <masterServer> -username <username> -password <password> [-domainName <domainName>] [-domainType <domainType>] -client <client>\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+
if len(*client) == 0 {
48+
log.Fatalf("Please specify the name of a NetBackup host using the -client parameter.\n")
49+
}
50+
51+
httpClient := apihelper.GetHTTPClient()
52+
jwt := apihelper.Login(*nbmaster, httpClient, *username, *password, *domainName, *domainType)
53+
hostUuid := apihelper.GetHostUUID(*nbmaster, httpClient, jwt, *client);
54+
filter := "";
55+
apihelper.GetProcesses(*nbmaster, httpClient, jwt, *client, hostUuid, filter);
56+
}

recipes/go/admin/get_services.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
//This script can be run using NetBackup 8.2 and higher.
2+
//It gets all NetBackup services available on the given host.
3+
4+
package main
5+
6+
import (
7+
"flag"
8+
"fmt"
9+
"log"
10+
"os"
11+
"apihelper"
12+
)
13+
14+
//###################
15+
// Global Variables
16+
//###################
17+
var (
18+
nbmaster = flag.String("nbmaster", "", "NetBackup Master Server")
19+
username = flag.String("username", "", "User name to log into the NetBackup webservices")
20+
password = flag.String("password", "", "Password for the given user")
21+
domainName = flag.String("domainName", "", "Domain name of the given user")
22+
domainType = flag.String("domainType", "", "Domain type of the given user")
23+
client = flag.String("client", "", "NetBackup host name")
24+
)
25+
26+
const usage = "\n\nUsage: go run ./get_services.go -nbmaster <masterServer> -username <username> -password <password> [-domainName <domainName>] [-domainType <domainType>] -client <client>\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+
if len(*client) == 0 {
48+
log.Fatalf("Please specify the name of a NetBackup host using the -client parameter.\n")
49+
}
50+
51+
httpClient := apihelper.GetHTTPClient()
52+
jwt := apihelper.Login(*nbmaster, httpClient, *username, *password, *domainName, *domainType)
53+
hostUuid := apihelper.GetHostUUID(*nbmaster, httpClient, jwt, *client);
54+
apihelper.GetServices(*nbmaster, httpClient, jwt, *client, hostUuid);
55+
}

recipes/go/config/README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
### NetBackup API Code Samples for go (often referred to as golang)
2+
3+
This directory contains code samples to invoke NetBackup configuration 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.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 ./get_set_host_config.go -nbmaster <masterServer> -username <username> -password <password> [-domainName <domainName>] [-domainType <domainType>] -client <client>`
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
//This script can be run using NetBackup 8.2 and higher.
2+
//It sets exclude list for the given host and reads exclude list to confirm the value was set correctly.
3+
4+
package main
5+
6+
import (
7+
"flag"
8+
"fmt"
9+
"log"
10+
"os"
11+
"apihelper"
12+
)
13+
14+
//###################
15+
// Global Variables
16+
//###################
17+
var (
18+
nbmaster = flag.String("nbmaster", "", "NetBackup Master Server")
19+
username = flag.String("username", "", "User name to log into the NetBackup webservices")
20+
password = flag.String("password", "", "Password for the given user")
21+
domainName = flag.String("domainName", "", "Domain name of the given user")
22+
domainType = flag.String("domainType", "", "Domain type of the given user")
23+
client = flag.String("client", "", "NetBackup host name")
24+
)
25+
26+
const usage = "\n\nUsage: go run ./get_set_host_config.go -nbmaster <masterServer> -username <username> -password <password> [-domainName <domainName>] [-domainType <domainType>] -client <client>\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+
if len(*client) == 0 {
48+
log.Fatalf("Please specify the name of a NetBackup host using the -client parameter.\n")
49+
}
50+
51+
httpClient := apihelper.GetHTTPClient()
52+
jwt := apihelper.Login(*nbmaster, httpClient, *username, *password, *domainName, *domainType)
53+
hostUuid := apihelper.GetHostUUID(*nbmaster, httpClient, jwt, *client);
54+
apihelper.GetExcludeLists(*nbmaster, httpClient, jwt, hostUuid);
55+
apihelper.SetExcludeLists(*nbmaster, httpClient, jwt, hostUuid);
56+
apihelper.GetExcludeLists(*nbmaster, httpClient, jwt, hostUuid);
57+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
### NetBackup API Code Samples for go (often referred to as golang)
22

3-
This directory contains code samples to invoke NetBackup REST APIs using go.
3+
This directory contains code samples to invoke NetBackup policies REST APIs using go.
44

55
#### Disclaimer
66

recipes/go/create_policy_in_one_step.go renamed to recipes/go/policies/create_policy_in_one_step.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"fmt"
1010
"log"
1111
"os"
12-
"policies/apihelper"
12+
"apihelper"
1313
)
1414

1515
//###################

recipes/go/create_policy_step_by_step.go renamed to recipes/go/policies/create_policy_step_by_step.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"fmt"
1010
"log"
1111
"os"
12-
"policies/apihelper"
12+
"apihelper"
1313
)
1414

1515
//###################

0 commit comments

Comments
 (0)