MisterE2002
Patron
- Joined
- Sep 5, 2015
- Messages
- 211
So i am using "http://<host>/api/docs/" to create a Python script to start a jail. The code works, but i like to know if it failed.
The correct name is 'rsync_backups' and i use 'rsync_backupss'
The API documentation only mentions 200 and 401.
But the middlewared.log is throwing. How do i catch those errors?
middlewared.service_exception.CallError: [ENOENT] 'rsync_backupss' jail does not exist
The correct name is 'rsync_backups' and i use 'rsync_backupss'
Code:
def start_jail(host, api_key):
global failure
api_call = 'http://{}/api/v2.0/jail/start'.format(host)
headers = {"Content-Type":"application/json", "Authorization": "Bearer " + api_key}
json_string = '"' + JAIL_NAME + '"'
try:
resp = requests.post(api_call, json=json.loads(json_string), headers=headers)
if resp.status_code != 200:
logger.error('Action "{}" on host "{}" failed with error: {}'.format('start', host, resp.status_code))
failure = True
else:
logger.info('Action "{}" on host "{}" successful'.format('start', host))
except Exception as e:
logger.error('Action "{}" on host "{}" failed with error: {}'.format('start', host, e))
failure = True
The API documentation only mentions 200 and 401.
But the middlewared.log is throwing. How do i catch those errors?
middlewared.service_exception.CallError: [ENOENT] 'rsync_backupss' jail does not exist