-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathrefreshSource.py
52 lines (41 loc) · 1.75 KB
/
refreshSource.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env python
"""refresh protection source"""
### import pyhesity wrapper module
from pyhesity import *
### command line arguments
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('-v', '--vip', type=str, required=True) # cluster to connect to
parser.add_argument('-u', '--username', type=str, default='helios') # username
parser.add_argument('-d', '--domain', type=str, default='local') # domain - defaults to local
parser.add_argument('-i', '--useApiKey', action='store_true') # use API key authentication
parser.add_argument('-pwd', '--password', type=str, default=None) # optional password
parser.add_argument('-n', '--sourcename', type=str, action='append') # optional name of vcenter
args = parser.parse_args()
vip = args.vip
username = args.username
domain = args.domain
password = args.password
useApiKey = args.useApiKey
sourceNames = args.sourcename
# authenticate
apiauth(vip=vip, username=username, domain=domain, password=password, useApiKey=useApiKey)
if sourceNames is None:
print('No sources specified')
exit()
sources = api('get', 'protectionSources/registrationInfo?allUnderHierarchy=false')
if 'rootNodes' not in sources:
print('No sources found')
exit()
def getObjectId(sourcename):
for source in sources['rootNodes']:
if source['rootNode']['name'].lower() == sourcename.lower():
return source['rootNode']['id']
return None
for sourcename in sourceNames:
objectId = getObjectId(sourcename)
if objectId is not None:
print('refreshing %s...' % sourcename)
result = api('post', 'protectionSources/refresh/%s' % objectId)
else:
print('%s not found' % sourcename)