Skip to content

Commit c4e1e59

Browse files
committed
Added LLS ForceLicenseCheck
1 parent 4b05f3d commit c4e1e59

2 files changed

Lines changed: 35 additions & 6 deletions

File tree

kepconfig/admin/lls.py

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@
77
r"""`lls` exposes an API to allow modifications to Local License Server parameters in
88
the Kepware Administration through the Kepware Configuration API
99
"""
10+
from .. import connection
1011
from typing import Union
1112
from ..error import KepHTTPError, KepError
13+
import inspect
1214

1315

1416
LLS_ROOT = '/admin'
17+
FORCE_CHECK_URL = '/project/services/ForceLicenseCheck'
1518
LICENSING_SERVER_PORT = "libadminsettings.LICENSING_SERVER_PORT"
1619
LICENSING_SERVER_NAME = "libadminsettings.LICENSING_SERVER_NAME"
1720
LICENSING_SERVER_ENABLE = "libadminsettings.LICENSING_SERVER_ENABLE"
@@ -59,7 +62,7 @@ def _get_dict(self):
5962
def __str__(self) -> str:
6063
return "{}".format(self._get_dict())
6164

62-
def get_lls_config(server) -> lls_config:
65+
def get_lls_config(server: connection.server) -> lls_config:
6366
'''Returns the properties of the Local License server properties. Returned object is lls_config class object.
6467
6568
INPUTS:
@@ -76,7 +79,7 @@ def get_lls_config(server) -> lls_config:
7679
r = server._config_get(server.url + LLS_ROOT)
7780
return lls_config(r.payload)
7881

79-
def update_lls_config(server, config: lls_config) -> bool:
82+
def update_lls_config(server: connection.server, config: lls_config) -> bool:
8083
'''Updates the Local License Server admin properties for Kepware.
8184
8285
INPUTS:
@@ -96,7 +99,7 @@ def update_lls_config(server, config: lls_config) -> bool:
9699
if r.code == 200: return True
97100
else: raise KepHTTPError(r.url, r.code, r.msg, r.hdrs, r.payload)
98101

99-
def enable_lls(server) -> bool:
102+
def enable_lls(server: connection.server) -> bool:
100103
'''Enables the Local License Server connection for Kepware.
101104
102105
INPUTS:
@@ -114,7 +117,7 @@ def enable_lls(server) -> bool:
114117
if r.code == 200: return True
115118
else: raise KepHTTPError(r.url, r.code, r.msg, r.hdrs, r.payload)
116119

117-
def disable_lls(server) -> bool:
120+
def disable_lls(server: connection.server) -> bool:
118121
'''Disables the Local License Server connection for Kepware.
119122
120123
INPUTS:
@@ -131,3 +134,25 @@ def disable_lls(server) -> bool:
131134
r = server._config_update(server.url + LLS_ROOT, {LICENSING_SERVER_ENABLE: False})
132135
if r.code == 200: return True
133136
else: raise KepHTTPError(r.url, r.code, r.msg, r.hdrs, r.payload)
137+
138+
def force_license_check(server: connection.server, job_ttl: int = None):
139+
'''Executes a ForceLicenseCheck call to the Kepware instance. This triggers the server to verify the
140+
license state of the license received from the Local License Server.
141+
142+
INPUTS:
143+
"server" - instance of the "server" class
144+
145+
"job_ttl" (optional) - Determines the number of seconds a job instance will exist following completion.
146+
147+
RETURNS:
148+
KepServiceResponse instance with job information
149+
150+
EXCEPTIONS (If not HTTP 200 or 429 returned):
151+
152+
KepHTTPError - If urllib provides an HTTPError
153+
KepURLError - If urllib provides an URLError
154+
'''
155+
156+
url = f'{server.url}{FORCE_CHECK_URL}'
157+
job = server._kep_service_execute(url, None, job_ttl)
158+
return job

tests/admin_test.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ def test_users(server):
220220
assert admin.users.del_user(server, user2['common.ALLTYPES_NAME'])
221221

222222
def test_LLS(server):
223-
223+
if server_type == 'TKS': pytest.skip("LLS not configurable in {}.".format(server_type))
224224
assert type(admin.lls.get_lls_config(server)) == admin.lls.lls_config
225225

226226
lls_config = {"libadminsettings.LICENSING_SERVER_PORT": 80,
@@ -238,4 +238,8 @@ def test_LLS(server):
238238

239239
assert admin.lls.enable_lls(server)
240240

241-
assert admin.lls.disable_lls(server)
241+
assert admin.lls.disable_lls(server)
242+
243+
assert type(admin.lls.force_license_check(server)) == kepconfig.connection.KepServiceResponse
244+
245+
assert type(admin.lls.force_license_check(server, 10)) == kepconfig.connection.KepServiceResponse

0 commit comments

Comments
 (0)