Skip to content

Instantly share code, notes, and snippets.

@fracai
Created February 20, 2016 04:15
Show Gist options
  • Save fracai/cbb61974a04ac4f1e7d5 to your computer and use it in GitHub Desktop.
Save fracai/cbb61974a04ac4f1e7d5 to your computer and use it in GitHub Desktop.
A short script using the FreeNAS API to cycle the AFP service off and back on. Just replace your root password and hostname in the script.
#!/usr/bin/env python
import requests, json, time
password='root_password'
host='freenas_hostname'
login = ('root', password)
headers = {'Content-Type': "application/json"}
url = 'http://'+host+'/api/v1.0/services/services/afp/'
result = requests.put(
url,
headers=headers,
auth=login,
data=json.dumps({'srv_enable': 'False'})
)
print result.json()
time.sleep(1)
result = requests.put(
url,
headers=headers,
auth=login,
data=json.dumps({'srv_enable': 'True'})
)
print result.json()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment