kepconfig.admin.lls
lls exposes an API to allow modifications to Local License Server parameters in
the Kepware Administration through the Kepware Configuration API
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 7r"""`lls` exposes an API to allow modifications to Local License Server parameters in 8the Kepware Administration through the Kepware Configuration API 9""" 10from .. import connection 11from typing import Union 12from ..error import KepHTTPError, KepError 13 14 15 16LLS_ROOT = '/admin' 17FORCE_CHECK_URL = '/project/services/ForceLicenseCheck' 18LICENSING_SERVER_PORT = "libadminsettings.LICENSING_SERVER_PORT" 19LICENSING_SERVER_NAME = "libadminsettings.LICENSING_SERVER_NAME" 20LICENSING_SERVER_ENABLE = "libadminsettings.LICENSING_SERVER_ENABLE" 21LICENSING_CHECK_PERIOD_MINS = "libadminsettings.LICENSING_CHECK_PERIOD_MINS" 22LICENSING_SERVER_SSL_PORT = "libadminsettings.LICENSING_SERVER_SSL_PORT" 23LICENSING_SERVER_ALLOW_INSECURE_COMMS = "libadminsettings.LICENSING_SERVER_ALLOW_INSECURE_COMMS" 24LICENSING_SERVER_ALLOW_SELF_SIGNED_CERTS = "libadminsettings.LICENSING_SERVER_ALLOW_SELF_SIGNED_CERTS" 25LICENSING_CLIENT_ALIAS = "libadminsettings.LICENSING_CLIENT_ALIAS" 26 27class lls_config: 28 '''A class to represent a admin properties for the Local License Server connection from an instance of Kepware. 29 This object is used to easily manage the LLS parameters for a Kepware instance. 30 31 :param server_name: Host name or IP address of the LLS server 32 :param server_port: HTTP/non-SSL port to target for the LLS server 33 :param check_period: Period that Kepware checks licensing status 34 :param server_port_SSL: HTTPS/SSL port to target for the LLS server 35 :param allow_insecure_comms: When True, use HTTP/non-SSL connection to LLS 36 :param allow_self_signed_certs: Allow for self signed certificates to be used during HTTPS/SSL connections to the LLS 37 :param instance_alias_name: Alias name for LLS to use as reference to this Kepware instance 38 ''' 39 40 def __init__(self, config = {}): 41 self.server_name = config[LICENSING_SERVER_NAME] if LICENSING_SERVER_NAME in config else '' 42 self.server_port = config[LICENSING_SERVER_PORT] if LICENSING_SERVER_PORT in config else 7070 43 self.check_period = config[LICENSING_CHECK_PERIOD_MINS] if LICENSING_CHECK_PERIOD_MINS in config else 5 44 self.server_port_SSL = config[LICENSING_SERVER_SSL_PORT] if LICENSING_SERVER_SSL_PORT in config else 1883 45 self.allow_insecure_comms = config[LICENSING_SERVER_ALLOW_INSECURE_COMMS] if LICENSING_SERVER_ALLOW_INSECURE_COMMS in config else False 46 self.allow_self_signed_certs = config[LICENSING_SERVER_ALLOW_SELF_SIGNED_CERTS] if LICENSING_SERVER_ALLOW_SELF_SIGNED_CERTS in config else False 47 self.instance_alias_name = config[LICENSING_CLIENT_ALIAS] if LICENSING_CLIENT_ALIAS in config else '' 48 49 def _get_dict(self): 50 return { 51 LICENSING_SERVER_PORT: self.server_port, 52 LICENSING_SERVER_NAME: self.server_name, 53 LICENSING_CHECK_PERIOD_MINS: self.check_period, 54 LICENSING_SERVER_SSL_PORT: self.server_port_SSL, 55 LICENSING_SERVER_ALLOW_INSECURE_COMMS: self.allow_insecure_comms, 56 LICENSING_SERVER_ALLOW_SELF_SIGNED_CERTS: self.allow_self_signed_certs, 57 LICENSING_CLIENT_ALIAS: self.instance_alias_name 58 } 59 60 def __str__(self) -> str: 61 return "{}".format(self._get_dict()) 62 63def get_lls_config(server: connection.server) -> lls_config: 64 '''Returns the properties of the Local License server connection properties. Returned object is `lls_config` class object. 65 66 :param server: instance of the `server` class 67 68 :return: `lls_config` class object with lls connection configuration 69 70 :raises KepHTTPError: If urllib provides an HTTPError 71 :raises KepURLError: If urllib provides an URLError 72 ''' 73 74 r = server._config_get(server.url + LLS_ROOT) 75 return lls_config(r.payload) 76 77def update_lls_config(server: connection.server, config: lls_config) -> bool: 78 '''Updates the Local License Server connection properties for Kepware. 79 80 :param server: instance of the `server` class 81 :param config: `lls_config` class object with lls connection configuration 82 83 :return: True - If a "HTTP 200 - OK" is received from Kepware server 84 85 :raises KepHTTPError: If urllib provides an HTTPError 86 :raises KepURLError: If urllib provides an URLError 87 ''' 88 89 DATA = config._get_dict() 90 r = server._config_update(server.url + LLS_ROOT, DATA) 91 if r.code == 200: return True 92 else: raise KepHTTPError(r.url, r.code, r.msg, r.hdrs, r.payload) 93 94def enable_lls(server: connection.server) -> bool: 95 '''Enables the Local License Server connection for Kepware. 96 97 :param server: instance of the `server` class 98 99 :return: True - If a "HTTP 200 - OK" is received from Kepware server 100 101 :raises KepHTTPError: If urllib provides an HTTPError 102 :raises KepURLError: If urllib provides an URLError 103 ''' 104 105 r = server._config_update(server.url + LLS_ROOT, {LICENSING_SERVER_ENABLE: True}) 106 if r.code == 200: return True 107 else: raise KepHTTPError(r.url, r.code, r.msg, r.hdrs, r.payload) 108 109def disable_lls(server: connection.server) -> bool: 110 '''Disables the Local License Server connection for Kepware. 111 112 :param server: instance of the `server` class 113 114 :return: True - If a "HTTP 200 - OK" is received from Kepware server 115 116 :raises KepHTTPError: If urllib provides an HTTPError 117 :raises KepURLError: If urllib provides an URLError 118 ''' 119 120 r = server._config_update(server.url + LLS_ROOT, {LICENSING_SERVER_ENABLE: False}) 121 if r.code == 200: return True 122 else: raise KepHTTPError(r.url, r.code, r.msg, r.hdrs, r.payload) 123 124def force_license_check(server: connection.server, job_ttl: int = None): 125 '''Executes a ForceLicenseCheck service call to the Kepware instance. This triggers the server to verify the 126 license state of the license received from the Local License Server. 127 128 :param server: instance of the `server` class 129 :param job_ttl: *(optional)* Determines the number of seconds a job instance will exist following completion. 130 131 :return: `KepServiceResponse` instance with job information 132 133 :raises KepHTTPError: If urllib provides an HTTPError (If not HTTP code 202 [Accepted] or 429 [Too Busy] returned) 134 :raises KepURLError: If urllib provides an URLError 135 ''' 136 137 url = f'{server.url}{FORCE_CHECK_URL}' 138 job = server._kep_service_execute(url, None, job_ttl) 139 return job
28class lls_config: 29 '''A class to represent a admin properties for the Local License Server connection from an instance of Kepware. 30 This object is used to easily manage the LLS parameters for a Kepware instance. 31 32 :param server_name: Host name or IP address of the LLS server 33 :param server_port: HTTP/non-SSL port to target for the LLS server 34 :param check_period: Period that Kepware checks licensing status 35 :param server_port_SSL: HTTPS/SSL port to target for the LLS server 36 :param allow_insecure_comms: When True, use HTTP/non-SSL connection to LLS 37 :param allow_self_signed_certs: Allow for self signed certificates to be used during HTTPS/SSL connections to the LLS 38 :param instance_alias_name: Alias name for LLS to use as reference to this Kepware instance 39 ''' 40 41 def __init__(self, config = {}): 42 self.server_name = config[LICENSING_SERVER_NAME] if LICENSING_SERVER_NAME in config else '' 43 self.server_port = config[LICENSING_SERVER_PORT] if LICENSING_SERVER_PORT in config else 7070 44 self.check_period = config[LICENSING_CHECK_PERIOD_MINS] if LICENSING_CHECK_PERIOD_MINS in config else 5 45 self.server_port_SSL = config[LICENSING_SERVER_SSL_PORT] if LICENSING_SERVER_SSL_PORT in config else 1883 46 self.allow_insecure_comms = config[LICENSING_SERVER_ALLOW_INSECURE_COMMS] if LICENSING_SERVER_ALLOW_INSECURE_COMMS in config else False 47 self.allow_self_signed_certs = config[LICENSING_SERVER_ALLOW_SELF_SIGNED_CERTS] if LICENSING_SERVER_ALLOW_SELF_SIGNED_CERTS in config else False 48 self.instance_alias_name = config[LICENSING_CLIENT_ALIAS] if LICENSING_CLIENT_ALIAS in config else '' 49 50 def _get_dict(self): 51 return { 52 LICENSING_SERVER_PORT: self.server_port, 53 LICENSING_SERVER_NAME: self.server_name, 54 LICENSING_CHECK_PERIOD_MINS: self.check_period, 55 LICENSING_SERVER_SSL_PORT: self.server_port_SSL, 56 LICENSING_SERVER_ALLOW_INSECURE_COMMS: self.allow_insecure_comms, 57 LICENSING_SERVER_ALLOW_SELF_SIGNED_CERTS: self.allow_self_signed_certs, 58 LICENSING_CLIENT_ALIAS: self.instance_alias_name 59 } 60 61 def __str__(self) -> str: 62 return "{}".format(self._get_dict())
A class to represent a admin properties for the Local License Server connection from an instance of Kepware. This object is used to easily manage the LLS parameters for a Kepware instance.
Parameters
- server_name: Host name or IP address of the LLS server
- server_port: HTTP/non-SSL port to target for the LLS server
- check_period: Period that Kepware checks licensing status
- server_port_SSL: HTTPS/SSL port to target for the LLS server
- allow_insecure_comms: When True, use HTTP/non-SSL connection to LLS
- allow_self_signed_certs: Allow for self signed certificates to be used during HTTPS/SSL connections to the LLS
- instance_alias_name: Alias name for LLS to use as reference to this Kepware instance
41 def __init__(self, config = {}): 42 self.server_name = config[LICENSING_SERVER_NAME] if LICENSING_SERVER_NAME in config else '' 43 self.server_port = config[LICENSING_SERVER_PORT] if LICENSING_SERVER_PORT in config else 7070 44 self.check_period = config[LICENSING_CHECK_PERIOD_MINS] if LICENSING_CHECK_PERIOD_MINS in config else 5 45 self.server_port_SSL = config[LICENSING_SERVER_SSL_PORT] if LICENSING_SERVER_SSL_PORT in config else 1883 46 self.allow_insecure_comms = config[LICENSING_SERVER_ALLOW_INSECURE_COMMS] if LICENSING_SERVER_ALLOW_INSECURE_COMMS in config else False 47 self.allow_self_signed_certs = config[LICENSING_SERVER_ALLOW_SELF_SIGNED_CERTS] if LICENSING_SERVER_ALLOW_SELF_SIGNED_CERTS in config else False 48 self.instance_alias_name = config[LICENSING_CLIENT_ALIAS] if LICENSING_CLIENT_ALIAS in config else ''
64def get_lls_config(server: connection.server) -> lls_config: 65 '''Returns the properties of the Local License server connection properties. Returned object is `lls_config` class object. 66 67 :param server: instance of the `server` class 68 69 :return: `lls_config` class object with lls connection configuration 70 71 :raises KepHTTPError: If urllib provides an HTTPError 72 :raises KepURLError: If urllib provides an URLError 73 ''' 74 75 r = server._config_get(server.url + LLS_ROOT) 76 return lls_config(r.payload)
Returns the properties of the Local License server connection properties. Returned object is lls_config class object.
Parameters
- server: instance of the
serverclass
Returns
lls_configclass object with lls connection configuration
Raises
- KepHTTPError: If urllib provides an HTTPError
- KepURLError: If urllib provides an URLError
78def update_lls_config(server: connection.server, config: lls_config) -> bool: 79 '''Updates the Local License Server connection properties for Kepware. 80 81 :param server: instance of the `server` class 82 :param config: `lls_config` class object with lls connection configuration 83 84 :return: True - If a "HTTP 200 - OK" is received from Kepware server 85 86 :raises KepHTTPError: If urllib provides an HTTPError 87 :raises KepURLError: If urllib provides an URLError 88 ''' 89 90 DATA = config._get_dict() 91 r = server._config_update(server.url + LLS_ROOT, DATA) 92 if r.code == 200: return True 93 else: raise KepHTTPError(r.url, r.code, r.msg, r.hdrs, r.payload)
Updates the Local License Server connection properties for Kepware.
Parameters
- server: instance of the
serverclass - config:
lls_configclass object with lls connection configuration
Returns
True - If a "HTTP 200 - OK" is received from Kepware server
Raises
- KepHTTPError: If urllib provides an HTTPError
- KepURLError: If urllib provides an URLError
95def enable_lls(server: connection.server) -> bool: 96 '''Enables the Local License Server connection for Kepware. 97 98 :param server: instance of the `server` class 99 100 :return: True - If a "HTTP 200 - OK" is received from Kepware server 101 102 :raises KepHTTPError: If urllib provides an HTTPError 103 :raises KepURLError: If urllib provides an URLError 104 ''' 105 106 r = server._config_update(server.url + LLS_ROOT, {LICENSING_SERVER_ENABLE: True}) 107 if r.code == 200: return True 108 else: raise KepHTTPError(r.url, r.code, r.msg, r.hdrs, r.payload)
Enables the Local License Server connection for Kepware.
Parameters
- server: instance of the
serverclass
Returns
True - If a "HTTP 200 - OK" is received from Kepware server
Raises
- KepHTTPError: If urllib provides an HTTPError
- KepURLError: If urllib provides an URLError
110def disable_lls(server: connection.server) -> bool: 111 '''Disables the Local License Server connection for Kepware. 112 113 :param server: instance of the `server` class 114 115 :return: True - If a "HTTP 200 - OK" is received from Kepware server 116 117 :raises KepHTTPError: If urllib provides an HTTPError 118 :raises KepURLError: If urllib provides an URLError 119 ''' 120 121 r = server._config_update(server.url + LLS_ROOT, {LICENSING_SERVER_ENABLE: False}) 122 if r.code == 200: return True 123 else: raise KepHTTPError(r.url, r.code, r.msg, r.hdrs, r.payload)
Disables the Local License Server connection for Kepware.
Parameters
- server: instance of the
serverclass
Returns
True - If a "HTTP 200 - OK" is received from Kepware server
Raises
- KepHTTPError: If urllib provides an HTTPError
- KepURLError: If urllib provides an URLError
125def force_license_check(server: connection.server, job_ttl: int = None): 126 '''Executes a ForceLicenseCheck service call to the Kepware instance. This triggers the server to verify the 127 license state of the license received from the Local License Server. 128 129 :param server: instance of the `server` class 130 :param job_ttl: *(optional)* Determines the number of seconds a job instance will exist following completion. 131 132 :return: `KepServiceResponse` instance with job information 133 134 :raises KepHTTPError: If urllib provides an HTTPError (If not HTTP code 202 [Accepted] or 429 [Too Busy] returned) 135 :raises KepURLError: If urllib provides an URLError 136 ''' 137 138 url = f'{server.url}{FORCE_CHECK_URL}' 139 job = server._kep_service_execute(url, None, job_ttl) 140 return job
Executes a ForceLicenseCheck service call to the Kepware instance. This triggers the server to verify the license state of the license received from the Local License Server.
Parameters
- server: instance of the
serverclass - job_ttl: (optional) Determines the number of seconds a job instance will exist following completion.
Returns
KepServiceResponseinstance with job information
Raises
- KepHTTPError: If urllib provides an HTTPError (If not HTTP code 202 [Accepted] or 429 [Too Busy] returned)
- KepURLError: If urllib provides an URLError