Skip to content

Commit f00082a

Browse files
authored
Merge pull request VeritasOS#54 from gautam-shantanu/patch-1
Get a list of VMware vmServers
2 parents 648662a + 2c8139a commit f00082a

File tree

1 file changed

+111
-0
lines changed

1 file changed

+111
-0
lines changed

snippets/curl/get_nb_vmservers.sh

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
#!/bin/sh
2+
3+
#####################n#####################################################
4+
5+
# This script demonstrates the usage of netbackup REST API for listing
6+
# the vmservers
7+
8+
# This script requires jq command-line JSON parser
9+
# if your system does not have jq installed, this will not work
10+
# jq can be downloaded from here: https://github.com/stedolan/jq/releases
11+
12+
###########################################################################
13+
14+
port=1556
15+
master_server=""
16+
username=""
17+
password=""
18+
domainname=""
19+
domaintype=""
20+
21+
showHelp()
22+
{
23+
echo ""
24+
echo "Invalid command parameters"
25+
echo "Usage:"
26+
echo "./get_nb_vmservers.sh -nbmaster <master_server> -username <username> -password <password> -domainname <dname> -domaintype <unixpwd/nt>"
27+
echo ""
28+
exit 1
29+
}
30+
31+
parseArguments()
32+
{
33+
if [ $# -lt 6 ]; then
34+
showHelp
35+
fi
36+
37+
while [ "$1" != "" ]; do
38+
case $1 in
39+
-nbmaster)
40+
master_server=$2
41+
;;
42+
-username)
43+
username=$2
44+
;;
45+
-password)
46+
password=$2
47+
;;
48+
-domainname)
49+
domainname=$2
50+
;;
51+
-domaintype)
52+
domaintype=$2
53+
;;
54+
*)
55+
showHelp
56+
;;
57+
esac
58+
shift 2
59+
done
60+
61+
if [ -z "$master_server" ] || [ -z "$username" ] || [ -z "$password" ] || [ -z "$domainname" ] || [ -z "$domaintype" ]; then
62+
showhelp
63+
fi
64+
65+
if [ "${domaintype^^}" = "WINDOWS" ] || [ "${domaintype^^}" = "NT" ]; then
66+
domaintype="nt"
67+
fi
68+
}
69+
70+
uriencode()
71+
{
72+
jq -nr --arg v "$1" '$v|@uri';
73+
}
74+
###############main############
75+
76+
parseArguments "$@"
77+
78+
master_server=$master_server.$domainname
79+
basepath="https://$master_server:$port/netbackup"
80+
content_header='content-type:application/json'
81+
82+
##############login#############
83+
84+
uri="$basepath/login"
85+
echo $uri
86+
87+
data=$(jq --arg name "$username" --arg pass "$password" --arg dname "$domainname" --arg dtype "$domaintype" \
88+
--null-input '{userName: $name, password: $pass}')
89+
90+
jwt=$(curl -k -X POST $uri -H $content_header -d "$data" | jq --raw-output '.token')
91+
92+
### To use filter page[limit] in URI, The key 'page[limit]' must be url encoded already. ###
93+
### Curl --data-urlencode encodes only the content part of the data of the form 'name=content' ###
94+
param1="$(uriencode 'page[limit]')=10" #op: page%5Blimit%5D=10
95+
param2="$(uriencode 'page[offset]')=0"
96+
97+
98+
##############jobs##############
99+
auth_header="authorization:$jwt"
100+
uri="$basepath/config/servers/vmservers"
101+
102+
curl --insecure --request GET --globoff --get $uri -H $content_header -H $auth_header \
103+
--data-urlencode "$param1" \
104+
--data-urlencode "$param2" \
105+
| \
106+
jq '[.data[]|{Type: .type, ID: .id,
107+
ServerName: .attributes.vmServer.serverName,
108+
VmType: .attributes.vmServer.vmType,
109+
UserId: .attributes.vmServer.userId}]'
110+
111+
exit 0

0 commit comments

Comments
 (0)