47 lines
2.1 KiB
Python
47 lines
2.1 KiB
Python
#!/usr/bin/env python
|
|
import requests, platform, subprocess, config, logging, simplejson as json, argparse
|
|
|
|
# You must initialize logging, otherwise you'll not see debug output.
|
|
logging.basicConfig(level=logging.DEBUG,format='%(asctime)s - [%(levelname)s] %(message)s', datefmt='%Y-%m-%d %H:%M:%S')
|
|
#logging.getLogger().setLevel(logging.DEBUG)
|
|
#requests_log = logging.getLogger("requests.packages.urllib3")
|
|
#requests_log.setLevel(logging.DEBUG)
|
|
#requests_log.propagate = True
|
|
|
|
def request(resource, method='GET', data=None):
|
|
if data is None:
|
|
data = ''
|
|
url = 'https://{}/api/v1.0/{}'.format(config.HOSTNAME, resource)
|
|
logging.debug('Request URL: {}'.format(url))
|
|
logging.debug('Request Data: {}'.format(data))
|
|
logging.debug('CA Certificate Path: {}'.format(config.CA_CERT_PATH))
|
|
r = requests.request(
|
|
method,
|
|
url,
|
|
data=json.dumps(data),
|
|
headers={'Content-Type': "application/json"},
|
|
auth=('root', '{}'.format(config.ROOT_PASSWORD)),
|
|
verify='{}'.format(config.CA_CERT_PATH)
|
|
)
|
|
logging.debug('Request Status Code: {}'.format(r.status_code))
|
|
if r.ok:
|
|
try:
|
|
logging.debug('Request Returned JSON: {}'.format(r.json()))
|
|
return {'ok': r.ok, 'status_code': r.status_code, 'response': r.json()}
|
|
except:
|
|
logging.debug('Request Returned Text: {}'.format(r.text))
|
|
return {'ok': r.ok, 'status_code': r.status_code, 'response': r.text}
|
|
raise ValueError(r)
|
|
|
|
POOLS = request('storage/volume/', 'GET')
|
|
|
|
for pool in POOLS['response']:
|
|
if pool['is_decrypted'] == False:
|
|
logging.info('Pool {} is locked'.format(pool['name']))
|
|
response = request('storage/volume/{}/unlock/'.format(pool['name']), 'POST', {'passphrase': '{}'.format(config.ENCRYPTION_PASSPHRASES[pool['name']])})
|
|
if response['ok']:
|
|
logging.info('Pool {} was unlocked successfully'.format(pool['name']))
|
|
else:
|
|
logging.error('Pool {} was NOT unlocked successfully'.format(pool['name']))
|
|
else:
|
|
logging.debug('Pool {} is already unlocked'.format(pool['name'])) |