Skip to content

Commit 4da0a4e

Browse files
committed
resolve conflict
2 parents 6e9a77b + 723c5a9 commit 4da0a4e

File tree

20 files changed

+949
-85
lines changed

20 files changed

+949
-85
lines changed

README.md

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,17 @@ Contains code samples to invoke NetBackup REST API using different programming l
55
#### Disclaimer
66
These scripts are only meant to be used as a reference. Please do not use these in production.
77

8-
#### Executing the snippets in PowerShell
9-
Pre-requisites:
10-
- NetBackup 8.1.1 or higher
11-
- Powershell 5.0 or higher
8+
#### Executing the snippets for different programming languages
129

13-
Use the following commands to run the powershell samples.
14-
- `.\Get-NB-Images.ps1 -nbmaster <masterServer> -username <username> -password <password>`
15-
- `.\Get-NB-Jobs.ps1 -nbmaster <masterServer> -username <username> -password <password>`
10+
The `snippets` folder contains code samples to invoke NetBackup REST API using different programming languages.
1611

17-
#### Executing the snippets in Python
1812
Pre-requisites:
19-
- NetBackup 8.1.1 or higher
20-
- python 3.5 or higher
21-
- python modules: `requests, texttable`
2213

23-
Use the following commands to run the python samples.
24-
- `python -W ignore get_nb_images.py -nbmaster <masterServer> -username <username> -password <password>`
25-
- `python -W ignore get_nb_jobs.py -nbmaster <masterServer> -username <username> -password <password>`
14+
- NetBackup 8.1.1 or higher
15+
- See the script's README for the corresponding requirements and usage
2616

2717
#### Executing the recipes in Python
18+
2819
Pre-requisites:
2920
- NetBackup 8.1.2 or higher
3021
- python 3.5 or higher
@@ -34,21 +25,6 @@ Use the following commands to run the python samples.
3425
- `python -W ignore create_policy_step_by_step.py -nbmaster <masterServer> -username <username> -password <password> [-domainName <domainName>] [-domainType <domainType>]`
3526
- `python -W ignore create_policy_in_one_step.py -nbmaster <masterServer> -username <username> -password <password> [-domainName <domainName>] [-domainType <domainType>]`
3627

37-
#### Executing the snippets in Perl
38-
Pre-requisites:
39-
- NetBackup 8.1.1 or higher
40-
- See script README for perl requirements and usage
41-
42-
#### Executing the snippets using curl
43-
Pre-requisites:
44-
- NetBackup 8.1.1 or higher
45-
- curl 7.51.0 or higher
46-
- jq command-line parser (https://github.com/stedolan/jq/releases)
47-
48-
Use the following commands to run the curl samples.
49-
- `./get_nb_jobs.sh -master <master_server> -username <username> -password <password>`
50-
- `./get_nb_images.sh -master <master_server> -username <username> -password <password>`
51-
5228
#### Tools
5329
The `tools` folder contains utilities that have proven useful in the development of projects using
5430
NetBackup REST APIs, but do not provide any API usage examples. Again, these tools are not for

snippets/curl/README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
### NetBackup API Code Samples for curl
2+
3+
This directory contains code samples to invoke NetBackup REST APIs using curl.
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+
- NetBackup 8.1.1 or higher
12+
- curl 7.51.0 or higher
13+
- jq command-line parser (https://github.com/stedolan/jq/releases)
14+
15+
#### Executing the snippets in curl
16+
17+
Use the following commands to run the curl samples.
18+
- `./get_nb_jobs.sh -nbmaster <master_server> -username <username> -password <password> -domainname <dname> -domaintype <unixpwd/nt>`
19+
- `./get_nb_images.sh -nbmaster <master_server> -username <username> -password <password> -domainname <dname> -domaintype <unixpwd/nt>`

snippets/curl/get_nb_images.sh

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
#####################n#####################################################
44

5-
# This script demonstrates the usage of netbackup REST API for listing
5+
# This script demonstrates the usage of netbackup REST API for listing
66
# the backup images
77

8-
# This script requires jq command-line JSON parser
8+
# This script requires jq command-line JSON parser
99
# if your system does not have jq installed, this will not work
1010
# jq can be downloaded from here: https://github.com/stedolan/jq/releases
1111

@@ -23,7 +23,7 @@ showHelp()
2323
echo ""
2424
echo "Invalid command parameters"
2525
echo "Usage:"
26-
echo "./get_nb_images.sh -master <master_server> -username <username> -password <password> -domainname <dname> -domaintype <unixpwd/nt>"
26+
echo "./get_nb_images.sh -nbmaster <master_server> -username <username> -password <password> -domainname <dname> -domaintype <unixpwd/nt>"
2727
echo ""
2828
exit 1
2929
}
@@ -33,10 +33,10 @@ parseArguments()
3333
if [ $# -lt 6 ]; then
3434
showHelp
3535
fi
36-
36+
3737
while [ "$1" != "" ]; do
3838
case $1 in
39-
-master)
39+
-nbmaster)
4040
master_server=$2
4141
;;
4242
-username)
@@ -57,7 +57,7 @@ parseArguments()
5757
esac
5858
shift 2
5959
done
60-
60+
6161
if [ -z "$master_server" ] || [ -z "$username" ] || [ -z "$password" ] || [ -z "$domainname" ] || [ -z "$domaintype" ]; then
6262
showhelp
6363
fi
@@ -98,4 +98,3 @@ curl --insecure --request GET --globoff --get $uri -H $content_header -H $auth
9898
jq '[.data[]|{IMAGE_ID: .id, POLICY: .attributes.policyName, CLIENT: .attributes.clientName, BACKUP_TIME: .attributes.backupTime}]'
9999

100100
exit 0
101-

snippets/curl/get_nb_jobs.sh

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
# This script demonstrates the usage of netbackup REST API for listing the jobs
77

8-
# This script requires jq command-line JSON parser
8+
# This script requires jq command-line JSON parser
99
# if your system does not have jq installed, this will not work
1010
# jq can be downloaded from here: https://github.com/stedolan/jq/releases
1111

@@ -23,7 +23,7 @@ showHelp()
2323
echo ""
2424
echo "Invalid command parameters"
2525
echo "Usage:"
26-
echo "./get_nb_jobs.sh -master <master_server> -username <username> -password <password> -domainname <dname> -domaintype <unixpwd/nt>"
26+
echo "./get_nb_jobs.sh -nbmaster <master_server> -username <username> -password <password> -domainname <dname> -domaintype <unixpwd/nt>"
2727
echo ""
2828
exit 1
2929
}
@@ -33,10 +33,10 @@ parseArguments()
3333
if [ $# -lt 10 ]; then
3434
showHelp
3535
fi
36-
36+
3737
while [ "$1" != "" ]; do
3838
case $1 in
39-
-master)
39+
-nbmaster)
4040
master_server=$2
4141
;;
4242
-username)
@@ -57,7 +57,7 @@ parseArguments()
5757
esac
5858
shift 2
5959
done
60-
60+
6161
if [ -z "$master_server" ] || [ -z "$username" ] || [ -z "$password" ] || [ -z "$domainname" ] || [ -z "$domaintype" ]; then
6262
showhelp
6363
fi
@@ -97,4 +97,3 @@ curl --insecure --request GET --globoff --get $uri -H $content_header -H $auth_
9797
| \
9898
jq '[.data[]|{JOBID: .id, TYPE: .attributes.jobType, STATE: .attributes.state, STATUS: .attributes.status}]'
9999
exit 0
100-

snippets/nodejs/README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
### NetBackup API Code Samples for Node.js
2+
3+
This directory contains code samples to invoke NetBackup REST APIs using node.js.
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+
- NetBackup 8.1.1 or higher
12+
- node.js v8.9.4 or higher
13+
- node.js modules: `https, fs, stdio, pem`
14+
- openssl and openssl path should be configured in system path.
15+
16+
* To install node.js module, Run `npm install <module_name>`.
17+
18+
#### Executing the snippets in Node.js
19+
20+
Before running API samples, run following command to store CA certificate.
21+
- `node get_ca_cert.js --nbmaster <master_server> [--port <port_number>] [--verbose]`
22+
or
23+
- `node get_ca_cert.js -n<master_server> [-pr <port_number>] [-v]`
24+
25+
Use the following commands to run the node.js samples.
26+
- `node get_nb_images.js --nbmaster <master_server> [--port <port_number>] --username <username> --password <password> [--domainname <domain_name>] [--domaintype <domain_type>] [--verbose]`
27+
or
28+
- `node get_nb_hosts.js -n<master_server> [-pr <port_number>] -u <username> -p <password> [-d <domain_name>] [-t <domain_type>] [-v]`

snippets/nodejs/get_ca_cert.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
var netbackup = require("./netbackup-module/netbackup.js");
2+
// including stdio just for creating help
3+
var stdio = require('stdio');
4+
var parms = stdio.getopt({
5+
'nbmaster' : { key: 'n', args: 1, description: 'Master server name', mandatory: true },
6+
'port' : { key: 'pr', args: 1, default: '1556', description: 'Port number' },
7+
'verbose' : { key: 'v', args: 1, description: 'Verbose statements' }
8+
});
9+
10+
var contentType = "application/vnd.netbackup+json;version=1.0";
11+
var verbose;
12+
13+
function main() {
14+
verbose = (parms.verbose === undefined) ? false: true;
15+
16+
netbackup.printOnConsole('\nDeploying CA certificate...', verbose);
17+
netbackup.getCACertificate(parms.nbmaster, parms.port, contentType, verbose);
18+
19+
}
20+
21+
main();

snippets/nodejs/get_nb_hosts.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
var netbackup = require("./netbackup-module/netbackup.js");
2+
// including stdio just for creating help
3+
var stdio = require('stdio');
4+
var parms = stdio.getopt({
5+
'nbmaster' : { key: 'n', args: 1, description: 'Master server name', mandatory: true },
6+
'port' : { key: 'pr', args: 1, default: '1556', description: 'Port number' },
7+
'username' : { key: 'u', args: 1, description: 'User name', mandatory: true },
8+
'password' : { key: 'p', args: 1, description: 'Password of a user', mandatory: true },
9+
'domainname' : { key: 'd', args: 1, default: '', description: 'Domain name (empty by default)' },
10+
'domaintype' : { key: 't', args: 1, default: '', description: 'Domain type (empty by default)' },
11+
'verbose' : { key: 'v', args: 1, description: 'Verbose statements' }
12+
});
13+
14+
var contentType = "application/vnd.netbackup+json;version=1.0";
15+
var jwt;
16+
var verbose;
17+
18+
function main() {
19+
verbose = (parms.verbose === undefined) ? false: true;
20+
21+
netbackup.printOnConsole('\nMaking call to login API...', verbose);
22+
netbackup.loginWithUser(parms.nbmaster, parms.port, parms.username, parms.password,
23+
parms.domainname, parms.domaintype, contentType, verbose, loginResponse);
24+
}
25+
26+
function loginResponse(data) {
27+
if (typeof data.errorCode != 'undefined') {
28+
console.info("\nError:\n " + JSON.stringify(data, null, 4));
29+
} else {
30+
netbackup.printOnConsole('\nLogin completed!', verbose);
31+
jwt = data.token;
32+
netbackup.printOnConsole('\nJWT token : ' + jwt, verbose);
33+
34+
netbackup.getHostDetails(parms.nbmaster, parms.port, jwt, contentType, verbose, hostsListResponse);
35+
}
36+
}
37+
38+
function hostsListResponse(data) {
39+
if (typeof data.errorCode != 'undefined') {
40+
console.info("\nError:\n " + JSON.stringify(data, null, 4));
41+
} else {
42+
console.info("\nHosts:\n " + JSON.stringify(data, null, 4));
43+
netbackup.printOnConsole('\nDone!!!');
44+
}
45+
}
46+
47+
main();

snippets/nodejs/get_nb_images.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
var netbackup = require("./netbackup-module/netbackup.js");
2+
// including stdio just for creating help
3+
var stdio = require('stdio');
4+
var parms = stdio.getopt({
5+
'nbmaster' : { key: 'n', args: 1, description: 'Master server name', mandatory: true },
6+
'port' : { key: 'pr', args: 1, default: '1556', description: 'Port number' },
7+
'username' : { key: 'u', args: 1, description: 'User name', mandatory: true },
8+
'password' : { key: 'p', args: 1, description: 'Password of a user', mandatory: true },
9+
'domainname' : { key: 'd', args: 1, default: '', description: 'Domain name (empty by default)' },
10+
'domaintype' : { key: 't', args: 1, default: '', description: 'Domain type (empty by default)' },
11+
'verbose' : { key: 'v', args: 1, description: 'Verbose statements' }
12+
});
13+
14+
var contentType = "application/vnd.netbackup+json;version=1.0";
15+
var jwt;
16+
var verbose;
17+
18+
function main() {
19+
verbose = (parms.verbose === undefined) ? false: true;
20+
21+
netbackup.printOnConsole('\nMaking call to login API...', verbose);
22+
netbackup.loginWithUser(parms.nbmaster, parms.port, parms.username, parms.password,
23+
parms.domainname, parms.domaintype, contentType, verbose, loginResponse);
24+
}
25+
26+
function loginResponse(data) {
27+
if (typeof data.errorCode != 'undefined') {
28+
console.info("\nError:\n "+ JSON.stringify(data, null, 4));
29+
} else {
30+
netbackup.printOnConsole('\nLogin completed!', verbose);
31+
jwt = data.token;
32+
netbackup.printOnConsole('\nJWT token : ' + jwt, verbose);
33+
34+
netbackup.getNBImages(parms.nbmaster, parms.port, jwt, contentType, verbose, nbImages);
35+
}
36+
}
37+
38+
function nbImages(data) {
39+
if (typeof data.errorCode != 'undefined') {
40+
console.info("\nError:\n "+ JSON.stringify(data, null, 4));
41+
} else {
42+
console.info("\nNB Images:\n "+ JSON.stringify(data, null, 4));
43+
netbackup.printOnConsole('\nDone!!!');
44+
}
45+
}
46+
47+
main();

0 commit comments

Comments
 (0)