Skip to content

Commit b16c0ea

Browse files
authored
Merge pull request #17 from chkp-shakedme/master
Gaia examples added
2 parents 7508cd0 + e2b9731 commit b16c0ea

File tree

5 files changed

+267
-1
lines changed

5 files changed

+267
-1
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#
2+
# modify_hostname.py
3+
# version 1.0
4+
#
5+
# The purpose of this script is to modify server hostname
6+
#
7+
# written by: Check Point software technologies inc.
8+
# APRIL 2019
9+
#
10+
11+
# A package for reading passwords without displaying them on the console.
12+
from __future__ import print_function
13+
14+
import getpass
15+
import os
16+
import sys
17+
18+
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
19+
20+
# cpapi is a library that handles the communication with the Check Point
21+
# management server.
22+
from cpapi import APIClient, APIClientArgs
23+
24+
25+
def main():
26+
# getting details from the user
27+
api_server = raw_input("Enter server IP address or hostname:")
28+
username = raw_input("Enter username: ")
29+
if sys.stdin.isatty():
30+
password = getpass.getpass("Enter password: ")
31+
else:
32+
print("Attention! Your password will be shown on the screen!")
33+
password = raw_input("Enter password: ")
34+
35+
hostname = raw_input("hostname value to be defined:")
36+
37+
client_args = APIClientArgs(server=api_server,
38+
api_version="1",
39+
unsafe=True,
40+
context="gaia_api")
41+
42+
with APIClient(client_args) as client:
43+
44+
# login to server:
45+
login_res = client.login(username, password)
46+
47+
if login_res.success is False:
48+
print("Login failed: {}".format(login_res.error_message))
49+
exit(1)
50+
51+
# request to show hostname
52+
api_res = client.api_call("show-hostname", {})
53+
if api_res.success:
54+
print("Hostname is '{}'".format(api_res.data["name"]))
55+
else:
56+
print("Failed to get hostname '{}'".format(api_res.data))
57+
58+
# request to set hostname
59+
api_res = client.api_call("set-hostname", {"name": hostname})
60+
if api_res.success:
61+
print("Hostname name changed to '{}'".format(api_res.data["name"]))
62+
else:
63+
print("Failed to get hostname '{}'".format(api_res.data))
64+
65+
66+
if __name__ == "__main__":
67+
main()
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#
2+
# show physical interface.py
3+
# version 1.0
4+
#
5+
# The purpose of this script is to show a server's physical interfaces
6+
#
7+
# written by: Check Point software technologies inc.
8+
# April 2019
9+
#
10+
11+
# A package for reading passwords without displaying them on the console.
12+
from __future__ import print_function
13+
14+
import getpass
15+
import os
16+
import sys
17+
18+
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
19+
20+
# lib is a library that handles the communication with the Check Point
21+
# management server.
22+
from cpapi import APIClient, APIClientArgs
23+
24+
25+
def main():
26+
# getting details from the user
27+
api_server = raw_input("Enter server IP address or hostname:")
28+
username = raw_input("Enter username: ")
29+
if sys.stdin.isatty():
30+
password = getpass.getpass("Enter password: ")
31+
else:
32+
print("Attention! Your password will be shown on the screen!")
33+
password = raw_input("Enter password: ")
34+
35+
client_args = APIClientArgs(server=api_server, api_version="1",
36+
unsafe=True, context="gaia_api")
37+
38+
with APIClient(client_args) as client:
39+
40+
# login to server:
41+
login_res = client.login(username, password)
42+
43+
if login_res.success is False:
44+
print("Login failed: {}".format(login_res.error_message))
45+
exit(1)
46+
interface_name = raw_input("Enter interface name: ")
47+
48+
api_res = client.api_call("show-physical-interface", {
49+
"name": interface_name
50+
})
51+
if api_res.success:
52+
# in order to access any field within the data that had
53+
# returned, simple use api_res.data["field name"] or refer to
54+
# the documentation page -
55+
# https://sc1.checkpoint.com/documents/latest/GaiaAPIs/
56+
print(
57+
"Physical interface name is '{}' , ipv4 address is '{}', "
58+
"interface mtu is '{}' ".format(api_res.data["name"],
59+
api_res.data["ipv4-address"],
60+
api_res.data["mtu"]))
61+
else:
62+
print("Failed to get physical interface data '{}'".format(
63+
api_res.data))
64+
65+
66+
if __name__ == "__main__":
67+
main()
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#
2+
# modify_hostname.py
3+
# version 1.0
4+
#
5+
# The purpose of this script is to modify server hostname
6+
#
7+
# written by: Check Point software technologies inc.
8+
# APRIL 2019
9+
#
10+
11+
# A package for reading passwords without displaying them on the console.
12+
from __future__ import print_function
13+
14+
import getpass
15+
import os
16+
import sys
17+
18+
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
19+
20+
# lib is a library that handles the communication with the Check Point
21+
# management server.
22+
from cpapi import APIClient, APIClientArgs
23+
24+
25+
def main():
26+
# getting details from the user
27+
api_server = input("Enter server IP address or hostname:")
28+
username = input("Enter username: ")
29+
if sys.stdin.isatty():
30+
password = getpass.getpass("Enter password: ")
31+
else:
32+
print("Attention! Your password will be shown on the screen!")
33+
password = input("Enter password: ")
34+
35+
hostname = input("hostname value to be defined:")
36+
37+
client_args = APIClientArgs(server=api_server, api_version="1",
38+
unsafe=True, context="gaia_api")
39+
40+
with APIClient(client_args) as client:
41+
42+
# login to server:
43+
login_res = client.login(username, password)
44+
45+
if login_res.success is False:
46+
print("Login failed: {}".format(login_res.error_message))
47+
exit(1)
48+
49+
# request to show hostname
50+
api_res = client.api_call("show-hostname", {})
51+
if api_res.success:
52+
print("Hostname is '{}'".format(api_res.data["name"]))
53+
else:
54+
print("Failed to get hostname '{}'".format(api_res.data))
55+
56+
# request to set hostname
57+
api_res = client.api_call("set-hostname", {"name": hostname})
58+
if api_res.success:
59+
print("Hostname name changed to '{}'".format(api_res.data["name"]))
60+
else:
61+
print("Failed to get hostname '{}'".format(api_res.data))
62+
63+
64+
if __name__ == "__main__":
65+
main()
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#
2+
# show physical interface.py
3+
# version 1.0
4+
#
5+
# The purpose of this script is to show a server's physical interfaces
6+
#
7+
# written by: Check Point software technologies inc.
8+
# April 2019
9+
#
10+
11+
# A package for reading passwords without displaying them on the console.
12+
from __future__ import print_function
13+
14+
import getpass
15+
import os
16+
import sys
17+
18+
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
19+
20+
# lib is a library that handles the communication with the Check Point
21+
# management server.
22+
from cpapi import APIClient, APIClientArgs
23+
24+
25+
def main():
26+
# getting details from the user
27+
api_server = input("Enter server IP address or hostname:")
28+
username = input("Enter username: ")
29+
if sys.stdin.isatty():
30+
password = getpass.getpass("Enter password: ")
31+
else:
32+
print("Attention! Your password will be shown on the screen!")
33+
password = input("Enter password: ")
34+
35+
client_args = APIClientArgs(server=api_server, api_version="1",
36+
unsafe=True, context="gaia_api")
37+
38+
with APIClient(client_args) as client:
39+
40+
# login to server:
41+
login_res = client.login(username, password)
42+
43+
if login_res.success is False:
44+
print("Login failed: {}".format(login_res.error_message))
45+
exit(1)
46+
47+
interface_name = input("Enter interface name: ")
48+
api_res = client.api_call("show-physical-interface", {
49+
"name": interface_name
50+
})
51+
if api_res.success:
52+
# in order to access any field within the data that had
53+
# returned, simple use api_res.data["field name"] or refer to
54+
# the documentation page -
55+
# https://sc1.checkpoint.com/documents/latest/GaiaAPIs/
56+
print(
57+
"Physical interface name is '{}' , ipv4 address is '{}', "
58+
"interface mtu is '{}' ".format(api_res.data["name"],
59+
api_res.data["ipv4-address"],
60+
api_res.data["mtu"]))
61+
else:
62+
print("Failed to get physical interface data '{}'".format(
63+
api_res.data))
64+
65+
66+
if __name__ == "__main__":
67+
main()

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
setup(
55
name="cpapi",
6-
version="1.0.2",
6+
version="1.0.3",
77
author="API team",
88
author_email="[email protected]",
99
description="Check Point Management API SDK",

0 commit comments

Comments
 (0)