Skip to content

Commit 76a663e

Browse files
YaredEsanthosh-vrts
authored andcommitted
Sample codes to expire images (#25)
1 parent 68b9819 commit 76a663e

File tree

7 files changed

+494
-0
lines changed

7 files changed

+494
-0
lines changed

recipes/go/images/README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
### NetBackup API Code Samples for go (often referred to as golang)
2+
3+
This directory contains code samples to invoke NetBackup Catalog (Image) 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+
- Image update related API samples will work on 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+
- The following assumes you set MASTERSERVER, USERID,PASSWORD, backupID, serverName, serverType and optionValue in your environment.
18+
- `go run ./update_nb_images.go -nbmaster ${MASTERSERVER} -username ${USERID} -password ${PASSWORD} -backupId ${backupID}`
19+
- `go run ./update_nb_images_by_server_name.go -nbmaster ${MASTERSERVER} -username ${USERID} -password ${PASSWORD} -serverName ${serverName}`
20+
- `go run ./update_nb_images_by_server_type.go -nbmaster ${MASTERSERVER} -username ${USERID} -password ${PASSWORD} -serverType ${serverType}`
21+
- `go run ./update_nb_images_primary_copy.go -nbmaster ${MASTERSERVER} -username ${USERID} -password ${PASSWORD} -optionValue ${optionValue}`
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"flag"
6+
"log"
7+
"os"
8+
"apihelper"
9+
"images"
10+
)
11+
12+
//###################
13+
// Global Variables
14+
//###################
15+
var (
16+
nbmaster = flag.String("nbmaster", "", "NetBackup Master Server")
17+
username = flag.String("username", "", "User name to log into the NetBackup webservices")
18+
password = flag.String("password", "", "Password for the given user")
19+
domainName = flag.String("domainName", "", "Domain name of the given user")
20+
domainType = flag.String("domainType", "", "Domain type of the given user")
21+
backupId = flag.String ("backupId","", "BackupId of the image for which expiration date needs update.")
22+
)
23+
24+
25+
26+
27+
const usage = "\n\nUsage: go run ./update_nb_images.go -nbmaster <masterServer> -username <username> -password <password> [-domainName <domainName>] [-domainType <domainType>] -backupId <backupId> n\n"
28+
29+
func main() {
30+
31+
// Print usage
32+
flag.Usage = func() {
33+
fmt.Fprintf(os.Stderr, usage)
34+
os.Exit(1)
35+
}
36+
37+
// Read command line arguments
38+
flag.Parse()
39+
40+
if len(*nbmaster) == 0 {
41+
log.Fatalf("Please specify the name of the NetBackup Master Server using the -nbmaster parameter.\n")
42+
}
43+
if len(*username) == 0 {
44+
log.Fatalf("Please specify the username using the -username parameter.\n")
45+
}
46+
if len(*password) == 0 {
47+
log.Fatalf("Please specify the password using the -password parameter.\n")
48+
}
49+
50+
if len(*backupId) == 0 {
51+
log.Fatalf("Please specify the backupId using the -backupId parameter.\n")
52+
}
53+
54+
httpClient := apihelper.GetHTTPClient()
55+
token := apihelper.Login(*nbmaster, httpClient, *username, *password, *domainName, *domainType)
56+
57+
images.UpdateImageExpirationDateByBackupId ( httpClient, *nbmaster, token, *backupId )
58+
images.UpdateImageExpirationDateByRecalculating ( httpClient, *nbmaster, token, *backupId )
59+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"flag"
6+
"log"
7+
"os"
8+
"apihelper"
9+
"images"
10+
)
11+
12+
//###################
13+
// Global Variables
14+
//###################
15+
var (
16+
nbmaster = flag.String("nbmaster", "", "NetBackup Master Server")
17+
username = flag.String("username", "", "User name to log into the NetBackup webservices")
18+
password = flag.String("password", "", "Password for the given user")
19+
domainName = flag.String("domainName", "", "Domain name of the given user")
20+
domainType = flag.String("domainType", "", "Domain type of the given user")
21+
serverName = flag.String ("serverName","", "Server name for the image to which expiration date needs update.")
22+
)
23+
24+
25+
26+
const usage = "\n\nUsage: go run ./update_nb_images_by_server_name.go -nbmaster <masterServer> -username <username> -password <password> [-domainName <domainName>] [-domainType <domainType>] -serverName <serverName> n\n"
27+
28+
func main() {
29+
30+
// Print usage
31+
flag.Usage = func() {
32+
fmt.Fprintf(os.Stderr, usage)
33+
os.Exit(1)
34+
}
35+
36+
// Read command line arguments
37+
flag.Parse()
38+
39+
if len(*nbmaster) == 0 {
40+
log.Fatalf("Please specify the name of the NetBackup Master Server using the -nbmaster parameter.\n")
41+
}
42+
if len(*username) == 0 {
43+
log.Fatalf("Please specify the username using the -username parameter.\n")
44+
}
45+
if len(*password) == 0 {
46+
log.Fatalf("Please specify the password using the -password parameter.\n")
47+
}
48+
49+
if len(*serverName) == 0 {
50+
log.Fatalf("Please specify the serverName using the -serverName parameter.\n")
51+
}
52+
53+
httpClient := apihelper.GetHTTPClient()
54+
token := apihelper.Login(*nbmaster, httpClient, *username, *password, *domainName, *domainType)
55+
56+
images.UpdateImageExpirationDateByServerName ( httpClient, *nbmaster, token, *serverName )
57+
58+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"flag"
6+
"log"
7+
"os"
8+
"apihelper"
9+
"images"
10+
)
11+
12+
//###################
13+
// Global Variables
14+
//###################
15+
var (
16+
nbmaster = flag.String("nbmaster", "", "NetBackup Master Server")
17+
username = flag.String("username", "", "User name to log into the NetBackup webservices")
18+
password = flag.String("password", "", "Password for the given user")
19+
domainName = flag.String("domainName", "", "Domain name of the given user")
20+
domainType = flag.String("domainType", "", "Domain type of the given user")
21+
serverType = flag.String ("serverType","", "Server type for the image to which expiration date needs update.")
22+
)
23+
24+
25+
26+
const usage = "\n\nUsage: go run ./update_nb_images_by_server_type.go -nbmaster <masterServer> -username <username> -password <password> [-domainName <domainName>] [-domainType <domainType>] -serverType <serverType> n\n"
27+
28+
func main() {
29+
30+
// Print usage
31+
flag.Usage = func() {
32+
fmt.Fprintf(os.Stderr, usage)
33+
os.Exit(1)
34+
}
35+
36+
// Read command line arguments
37+
flag.Parse()
38+
39+
if len(*nbmaster) == 0 {
40+
log.Fatalf("Please specify the name of the NetBackup Master Server using the -nbmaster parameter.\n")
41+
}
42+
if len(*username) == 0 {
43+
log.Fatalf("Please specify the username using the -username parameter.\n")
44+
}
45+
if len(*password) == 0 {
46+
log.Fatalf("Please specify the password using the -password parameter.\n")
47+
}
48+
49+
if len(*serverType) == 0 {
50+
log.Fatalf("Please specify the serverName using the -serverType parameter.\n")
51+
}
52+
53+
httpClient := apihelper.GetHTTPClient()
54+
token := apihelper.Login(*nbmaster, httpClient, *username, *password, *domainName, *domainType)
55+
56+
images.UpdateImageExpirationDateByServerType ( httpClient, *nbmaster, token, *serverType )
57+
58+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"flag"
6+
"log"
7+
"os"
8+
"apihelper"
9+
"images"
10+
)
11+
12+
//###################
13+
// Global Variables
14+
//###################
15+
var (
16+
nbmaster = flag.String("nbmaster", "", "NetBackup Master Server")
17+
username = flag.String("username", "", "User name to log into the NetBackup webservices")
18+
password = flag.String("password", "", "Password for the given user")
19+
domainName = flag.String("domainName", "", "Domain name of the given user")
20+
domainType = flag.String("domainType", "", "Domain type of the given user")
21+
optionValue = flag.String ("optionValue","", "The option value for updating primary copy of images.")
22+
)
23+
24+
25+
26+
const usage = "\n\nUsage: go run ./update_nb_images_primary_copy.go -nbmaster <masterServer> -username <username> -password <password> [-domainName <domainName>] [-domainType <domainType>] -optionValue <optionValue> n\n"
27+
28+
func main() {
29+
30+
// Print usage
31+
flag.Usage = func() {
32+
fmt.Fprintf(os.Stderr, usage)
33+
os.Exit(1)
34+
}
35+
36+
// Read command line arguments
37+
flag.Parse()
38+
39+
if len(*nbmaster) == 0 {
40+
log.Fatalf("Please specify the name of the NetBackup Master Server using the -nbmaster parameter.\n")
41+
}
42+
if len(*username) == 0 {
43+
log.Fatalf("Please specify the username using the -username parameter.\n")
44+
}
45+
if len(*password) == 0 {
46+
log.Fatalf("Please specify the password using the -password parameter.\n")
47+
}
48+
49+
if len(*optionValue) == 0 {
50+
log.Fatalf("Please specify the optionValue using the -optionValue parameter.\n")
51+
}
52+
53+
httpClient := apihelper.GetHTTPClient()
54+
token := apihelper.Login(*nbmaster, httpClient, *username, *password, *domainName, *domainType)
55+
56+
images.UpdateImagePrimaryCopy ( httpClient, *nbmaster, token, *optionValue )
57+
58+
}

0 commit comments

Comments
 (0)