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