|
| 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 | +} |
0 commit comments