Charles Currier total respect mate. BTW exactly how idempotent is ansible in practice when used against checkpoint? This sounds awesome for my story of applying staging and test firewall playbooks.
BTW I found a typo in line 4 and hacked it about a bit, used a main function and removed the tag function for me(also being a bit naughty and disabling verification, yeah but I'm testing etc i ran with 2.7.15... omg when will the world move to v3?
Obviously argpass or somehting is better than static def's of uid and pw, sorry if obvious
import requests
import json
mgmt_username = 'some_username'
mgmt_password = 'some_password'
mgmt_server = 'some_mgmt_ipaddress'
def api_call(ip_addr, port, command, json_payload, sid):
url = 'https://' + ip_addr + ':' + str(port) + '/web_api/' + command
if sid == '':
request_headers = {'Content-Type' : 'application/json'}
else:
request_headers = {'Content-Type' : 'application/json', 'X-chkp-sid' : sid}
r = requests.post(url,data=json.dumps(json_payload), headers=request_headers, verify=False)
return r.json()
def login(user,password):
payload = {'user':user, 'password' : password}
response = api_call(mgmt_server, 443, 'login',payload, '')
return response["sid"]
def get_tag_uid(sid):
payload = {'type':'tag'}
response = api_call(mgmt_server, 443, 'show-objects', payload, sid)
return response["sid"]
def main():
sid = login(mgmt_username,mgmt_password)
print("session id: " + sid)
logout_result = api_call(mgmt_server, 443,"logout", {},sid)
print("logout result: " + json.dumps(logout_result))
if __name__ == '__main__':
main()