Skip to content

Commit f8435b9

Browse files
akashvrtssanthosh-vrts
authored andcommitted
Recipe in Go to set up AIR relationship on MSDP or Cloud Catalyst storage server (#39)
* Go scripts for AIR Apis
1 parent d693578 commit f8435b9

File tree

4 files changed

+517
-0
lines changed

4 files changed

+517
-0
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
//This script can be run using NetBackup 8.2 and higher.
2+
3+
package main
4+
5+
import (
6+
"flag"
7+
"fmt"
8+
"log"
9+
"os"
10+
"storageHelper"
11+
)
12+
13+
//###################
14+
// Global Variables
15+
//###################
16+
var (
17+
nbmaster = flag.String("nbmaster", "", "NetBackup Master Server")
18+
username = flag.String("username", "", "User name to log into the NetBackup webservices")
19+
password = flag.String("password", "", "Password for the given user")
20+
domainName = flag.String("domainName", "", "Domain name of the given user")
21+
domainType = flag.String("domainType", "", "Domain type of the given user")
22+
)
23+
24+
const usage = "\n\nUsage: go run ./AIRAPIs.go -nbmaster <masterServer> -username <username> -password <password> [-domainName <domainName>] [-domainType <domainType>]\n\n"
25+
26+
func main() {
27+
// Print usage
28+
flag.Usage = func() {
29+
fmt.Fprintf(os.Stderr, usage)
30+
os.Exit(1)
31+
}
32+
33+
// Read command line arguments
34+
flag.Parse()
35+
36+
if len(*nbmaster) == 0 {
37+
log.Fatalf("Please specify the name of the NetBackup Master Server using the -nbmaster parameter.\n")
38+
}
39+
if len(*username) == 0 {
40+
log.Fatalf("Please specify the username using the -username parameter.\n")
41+
}
42+
if len(*password) == 0 {
43+
log.Fatalf("Please specify the password using the -password parameter.\n")
44+
}
45+
46+
httpClient := storageHelper.GetHTTPClient()
47+
jwt := storageHelper.Login(*nbmaster, httpClient, *username, *password, *domainName, *domainType)
48+
49+
status, stsName := storageHelper.CreateMSDPStorageServer(*nbmaster, httpClient, jwt)
50+
if( status != 201){
51+
panic("CreateMSDPStorageServer Failed. Exiting.\n")
52+
}
53+
54+
candInx, candId := storageHelper.GetReplicationCandidates(*nbmaster, httpClient, jwt)
55+
if ( candInx == 0 ) {
56+
fmt.Println("Exiting")
57+
os.Exit(0)
58+
}
59+
60+
if ( storageHelper.AddReplicationTarget(*nbmaster, httpClient, jwt, stsName, candId) != 201 ) {
61+
panic("AddReplicationTarget Failed. Exiting.\n")
62+
}
63+
64+
tarInx, tarId := storageHelper.GetReplicationTargets(*nbmaster, httpClient, jwt, stsName)
65+
if ( tarInx == 0 ) {
66+
fmt.Println("Exiting")
67+
os.Exit(0)
68+
}
69+
storageHelper.DeleteReplicationTargets(*nbmaster, httpClient, jwt, stsName, tarId)
70+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
//This script consists of the helper functions to read and process user inpus
2+
3+
package apiUtil
4+
5+
import (
6+
"bufio"
7+
"os"
8+
"strings"
9+
"io"
10+
"fmt"
11+
"bytes"
12+
)
13+
14+
func TakeInput(displayStr string)(string) {
15+
16+
reader := bufio.NewReader(os.Stdin)
17+
fmt.Print(displayStr)
18+
output, _ := reader.ReadString('\n')
19+
// convert CRLF to LF
20+
output = strings.Replace(output, "\r\n", "", -1)
21+
output = strings.Replace(output, "\n", "", -1)
22+
return output
23+
}
24+
25+
func AskForResponseDisplay(response io.ReadCloser) {
26+
if strings.Compare(TakeInput("Show response? (Yes/No)"), "Yes") == 0 {
27+
buf := new(bytes.Buffer)
28+
buf.ReadFrom(response)
29+
responseStr := buf.String()
30+
responseStr = strings.Replace(responseStr, "}", "}\r\n", -1)
31+
responseStr = strings.Replace(responseStr, ",", ",\r\n", -1)
32+
responseStr = strings.Replace(responseStr, "]", "]\r\n", -1)
33+
34+
fmt.Print(responseStr)
35+
} else {
36+
fmt.Println("Response is not Yes!!")
37+
}
38+
}
39+
40+
func AskForGETResponseDisplay(response []byte) {
41+
if strings.Compare(TakeInput("Show response? (Yes/No)"), "Yes") == 0 {
42+
responseStr := string(response)
43+
responseStr = strings.Replace(responseStr, "}", "}\r\n", -1)
44+
responseStr = strings.Replace(responseStr, ",", ",\r\n", -1)
45+
responseStr = strings.Replace(responseStr, "]", "]\r\n", -1)
46+
47+
fmt.Print(responseStr)
48+
} else {
49+
fmt.Println("Response is not Yes!!")
50+
}
51+
}

recipes/go/storage/README.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Run the AIRAPIs.go file using Go.
2+
3+
Prerequisites
4+
1. Atleast a couple of NBU master servers.
5+
2. MSDP or CC storage server created on one of them. (Use the nbmaster as the other master server for the script execution)
6+
3. Trust relationship established between the two NBU masters.
7+
8+
Run cli in AIRAPIs directory
9+
Go run AIRAPIs.go -nbmaster <master server name> -username <username> -password <passwd>
10+
11+
The script can also create new MSDP storage server (with creds as a/a) depending on user inputs.
12+
Further lists the replication candidates based on the no of trusted master servers and storage server (MSDP and CC) on them.
13+
User need to select one of the replication candidate to create AIR relationship on the earlier created MSDP/CC sts or existing one.
14+
User can delete any existing AIR relationship as well.
15+

0 commit comments

Comments
 (0)