Skip to content

NetBackup 8.2 API Golang scripts #36

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

Merged
merged 1 commit into from
Jul 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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);
}
17 changes: 17 additions & 0 deletions recipes/go/config/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
### 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>`
57 changes: 57 additions & 0 deletions recipes/go/config/get_set_host_config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//This script can be run using NetBackup 8.2 and higher.
//It sets exclude list for the given host and reads exclude list to confirm the value was set correctly.

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_set_host_config.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.GetExcludeLists(*nbmaster, httpClient, jwt, hostUuid);
apihelper.SetExcludeLists(*nbmaster, httpClient, jwt, hostUuid);
apihelper.GetExcludeLists(*nbmaster, httpClient, jwt, hostUuid);
}
2 changes: 1 addition & 1 deletion recipes/go/README.md → recipes/go/policies/README.md
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
### NetBackup API Code Samples for go (often referred to as golang)

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

#### Disclaimer

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"fmt"
"log"
"os"
"policies/apihelper"
"apihelper"
)

//###################
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"fmt"
"log"
"os"
"policies/apihelper"
"apihelper"
)

//###################
Expand Down
Loading