用于创建新资源的 Python 示例代码:
>>> action = {'category': 'network'}
>>> post_data = json.dumps(action)
>>> request = urllib2.Request("https://zfssa:215/api/alert/v1/actions", post_data)
>>> request.add_header('Content-Type', 'application/json')
>>> response = opener.open(request)
>>> response.getcode()
201
>>> response.info().getheader('Location')
'/api/alert/v1/actions/actions-001'
>>> body = json.loads(response.read())
>>> print json.dumps(body, sort_keys=True, indent=4)
{
"actions": {
"category": "network",
"datalink_failed": true,
"datalink_ok": true,
"href":
"/api/alert/v1/actions/actions-001",
"ip_address_conflict": true,
"ip_address_conflict_resolved": true,
"ip_interface_degraded": true,
"ip_interface_failed":
true,
"ip_interface_ok": true,
"network_port_down": true,
"network_port_up":
true
}
}