This repository has been archived on 2020-09-24. You can view files and clone it, but cannot push or open issues or pull requests.
Files
FreeNAS-Network-Unlock/freenas_network_unlock.py

47 lines
1.1 KiB
Python

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
with open("config.yml", 'r') as ymlfile:
cfg = yaml.safe_load(ymlfile)
for section in cfg:
print(section)
exit()
def ping(host):
"""
Returns True if host (str) responds to a ping request.
Remember that a host may not respond to a ping (ICMP) request even if the host name is valid.
"""
# Option for the number of packets as a function of
param = '-n' if platform.system().lower()=='windows' else '-c'
# Building the command. Ex: "ping -c 1 google.com"
command = ['ping', param, '1', host]
return subprocess.call(command) == 0
#if ping(FREENAS_HOST):
VOLUMES = requests.get(
'https://{}/api/v1.0/storage/volume/'.format(FREENAS_HOST),
auth=('root', '{}'.format(ROOT_PASSWORD)),
verify='{}'.format(CA_CERT),
).json()
for volume in VOLUMES:
if volume['is_decrypted'] == False:
print(volume['vol_guid'])
#else:
#print("Host,{}, is not online".format(FREENAS_HOST))