Update 'freenas_network_unlock.py'

This commit is contained in:
2019-11-11 22:05:02 -05:00
parent 6b47231fbb
commit 48685b693e

View File

@@ -1,8 +1,22 @@
import requests # For the api calls
import platform # For getting the operating system name
import subprocess # For executing a shell command
import yaml # For parsing the yaml config file
import config # configuration file
import logging
#try:
# import http.client as http_client
#except ImportError:
# Python 2
# import httplib as http_client
#http_client.HTTPConnection.debuglevel = 1
# You must initialize logging, otherwise you'll not see debug output.
#logging.basicConfig()
#logging.getLogger().setLevel(logging.DEBUG)
#requests_log = logging.getLogger("requests.packages.urllib3")
#requests_log.setLevel(logging.DEBUG)
#requests_log.propagate = True
def ping(host):
"""
@@ -18,24 +32,25 @@ def ping(host):
return subprocess.call(command) == 0
#if ping(FREENAS_HOST):
#if ping(config.HOSTNAME):
VOLUMES = requests.get(
'https://{}/api/v1.0/storage/volume/'.format(config.HOSTNAME),
auth=('root', '{}'.format(config.ROOT_PASSWORD)),
verify='{}'.format(config.CA_CERT_PATH),
).json()
)
for volume in VOLUMES:
for volume in VOLUMES.json():
if volume['is_decrypted'] == False:
response = request.post(
response = requests.post(
'https://{}/api/v1.0/storage/volume/{}/unlock/'.format(config.HOSTNAME,volume['name']),
data={'passphrase': '{}'.format(config.POOLS[volume['name']])},
json={'passphrase': '{}'.format(config.POOLS[volume['name']])},
auth=('root', '{}'.format(config.ROOT_PASSWORD)),
verify='{}'.format(config.CA_CERT_PATH),
).json()
print(response)
)
print(response.status_code)
print(response.text)
#else:
#print("Host,{}, is not online".format(FREENAS_HOST))
#print("Host,{}, is not online".format(config.HOSTNAME))