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