Skip to content

Commit 382fc23

Browse files
committed
Add Examples for LLS parameters
1 parent 220f7d6 commit 382fc23

1 file changed

Lines changed: 77 additions & 0 deletions

File tree

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# -------------------------------------------------------------------------
2+
# Copyright (c) PTC Inc. and/or all its affiliates. All rights reserved.
3+
# See License.txt in the project root for
4+
# license information.
5+
# --------------------------------------------------------------------------
6+
7+
# Kepware LLS Config Example - Simple example on how to manage properties of a Kepware instance
8+
# to connect to a Local License Server through the Kepware Configuration API
9+
10+
from kepconfig import connection, error
11+
from kepconfig.admin import lls
12+
13+
def ErrorHandler(err):
14+
# Generic Handler for exception errors
15+
if err.__class__ is error.KepError:
16+
print(err.msg)
17+
elif err.__class__ is error.KepHTTPError:
18+
print(err.code)
19+
print(err.msg)
20+
print(err.url)
21+
print(err.hdrs)
22+
print(err.payload)
23+
elif err.__class__ is error.KepURLError:
24+
print(err.url)
25+
print(err.reason)
26+
else:
27+
print('Different Exception Received: {}'.format(err))
28+
29+
# This creates a server reference that is used to target all modifications of
30+
# the Kepware configuration
31+
server = connection.server(host = '127.0.0.1', port = 57412, user = 'Administrator', pw = '')
32+
33+
34+
35+
# Retreive the LLS properties from a Kepware instance and return a lls_config class object
36+
try:
37+
LLSconfig = lls.get_lls_config(server)
38+
print("{} - {}".format("Get Local License Server parameters for Kepware instance",LLSconfig))
39+
except Exception as err:
40+
ErrorHandler(err)
41+
42+
43+
# Create a lls_config class object from Dict parameters
44+
JSON_lls_config = {
45+
"libadminsettings.LICENSING_SERVER_PORT": 80,
46+
"libadminsettings.LICENSING_SERVER_NAME": "test_host",
47+
"libadminsettings.LICENSING_CHECK_PERIOD_MINS": 20,
48+
"libadminsettings.LICENSING_SERVER_SSL_PORT": 7777,
49+
"libadminsettings.LICENSING_SERVER_ALLOW_INSECURE_COMMS": True,
50+
"libadminsettings.LICENSING_SERVER_ALLOW_SELF_SIGNED_CERTS": True,
51+
"libadminsettings.LICENSING_CLIENT_ALIAS": "TestAliasName"
52+
}
53+
54+
try:
55+
print("{} - {}".format("Create Local License Server parameters object from Dict", lls.lls_config(JSON_lls_config)))
56+
except Exception as err:
57+
ErrorHandler(err)
58+
59+
60+
# Update lls_config object with new values and update the Kepware instance with new parameters
61+
LLSconfig.server_name = 'HOSTNAME'
62+
try:
63+
print("{} - {}".format("Update Local License Server parameters for Kepware instance",lls.update_lls_config(server, LLSconfig)))
64+
except Exception as err:
65+
ErrorHandler(err)
66+
67+
# Enable the LLS connection for the Kepware instance
68+
try:
69+
print("{} - {}".format("Enable Local License Server connection for Kepware instance",lls.enable_lls(server)))
70+
except Exception as err:
71+
ErrorHandler(err)
72+
73+
# Disable the LLS connection for the Kepware instance
74+
try:
75+
print("{} - {}".format("Disable Local License Server connection for Kepware instance",lls.disable_lls(server)))
76+
except Exception as err:
77+
ErrorHandler(err)

0 commit comments

Comments
 (0)