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 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(config.HOSTNAME), auth=('root', '{}'.format(config.ROOT_PASSWORD)), verify='{}'.format(config.CA_CERT_PATH), ).json() for volume in VOLUMES: if volume['is_decrypted'] == False: #request.post( # 'https://{}/api/v1.0/storage/volume/{}/unlock/'.format(config.HOSTNAME,volume.name), # data={'passphrase': '{}'.format(config.POOLS[volume.name])}, # auth=('root', '{}'.format(config.ROOT_PASSWORD)), # verify='{}'.format(config.CA_CERT_PATH), #).json() print(config.POOLS[volume[name]]) #else: #print("Host,{}, is not online".format(FREENAS_HOST))