Source code for schrodinger.application.licensing.licerror

"""
Provide information about FlexNet error codes to python programs.
"""

import functools
import sys

LMGRD_DOWN_ERROR_CODE = -15


@functools.total_ordering
class _ErrorLevel(object):
    """
    An _ErrorLevel is an ordered type that represents the severity
    of a license error.
    """

    def __init__(self, level, tag=""):
        if not hasattr(self, "_level"):
            self._level = level
            self._tag = tag

    def __repr__(self):
        return self._tag

    def __index__(self):
        return self._level

    def __lt__(self, other):
        return self._level < other._level


IGNORE = _ErrorLevel(0, "IGNORE")  # an unimportant error condition
WARNING = _ErrorLevel(1, "WARNING")  # an error that may not be serious
ERROR = _ErrorLevel(2, "ERROR")  # an error preventing use of the license

# Interested SCHROD daemon exit codes
if sys.platform == "win32":
    SCHROD_NO_FEATURES_CODE = 27
else:
    SCHROD_NO_FEATURES_CODE = 36

#######################################################################
# Exceptions
#######################################################################


[docs]class LicenseException(Exception): """ A LicenseException delivers a LicenseError up the call chain. """
[docs] def __init__(self, error): assert type(error) == LicenseError self.error = error
def __str__(self): return str(self.error)
[docs]class LicenseError(object): """ A LicenseError represents a license-related error. This includes errors reported by Flexnet Publisher (aka "FLEXlm") and more general errors. Many errors will be standard FLEXlm errors, with standard error codes, but this class is intended to represent more general errors, as well. FlexNet errors all have error codes. """
[docs] def __init__(self, errcode, msg, level=None, count=1, tag="", output="", cmd=""): errcode = str(errcode) self._errcode = errcode if "," in errcode: code, subcode = errcode.split(",", 1) code = int(code) else: code = int(errcode) self._code = code self._message = msg self._level = level self._tag = tag self._count = count self._output = output self._cmd = cmd # set default description and advice? ("Contact Schrodinger"?) if code and code in _errcode: self._description = _errcode[code].get("description", "") self._advice = _errcode[code].get("advice", "") if level is None: self._level = _errcode[code].get("level", ERROR) if msg == "": self._message = _errcode[code]["msg"] elif msg and msg in _errmsg: self._description = _errmsg[msg].get("description", "") self._advice = _errmsg[msg].get("advice", "") if level is None: self._level = _errmsg[msg].get("level", ERROR) if errcode == 0: self._code = _errmsg[msg]["code"] self._errcode = self._code else: self._description = "" self._advice = "" self.unreachable_hostname = False
def __unicode__(self): return self._message def __repr__(self): result = "%s: %s" % (self._level, self._message) if self._code != 0: result += " (%s)" % self._errcode elif self._output: cmd = "" if self._cmd: cmd = f"{self._cmd}:\n" result += f" {cmd}({self._output}" return result @property def code(self): return self._code @property def message(self): if self._message: msg = self._message else: msg = "FlexNet Error " + self._errcode if self._count > 1: msg += " (%d errors)" % self._count return msg @property def count(self): return self._count @property def advice(self): return self._advice @property def description(self): if self._description: return self._description else: return self._message @property def level(self): return self._level @property def tag(self): return self._tag @property def output(self): return self._output @output.setter def output(self, output): self._output = output @property def cmd(self): return self._cmd @cmd.setter def cmd(self, cmd): self._cmd = cmd
[docs] def add_output(self, text): if self._output: self._output += "\n" + text else: self._output = text
####################################################################### # Error info ####################################################################### _errcode = {} # error info, indexed by error code _errmsg = {} # error info, indexed by error message def _define(code, level, msg, description="", advice=""): """ Add info about the given error to the "database". If some parameter isn't defined, or if a code of zero is given, it's ignored. If the database already has a value for some error attribute, conflicting values for that attribute are ignored. For example, a number of errors have more than one message for the same error code; the first message added to the db will be the one associated with that error. The error level should be an instance of _ErrorLevel. """ info = {} if code: info["code"] = code if level: info["level"] = level if msg: info["msg"] = msg if description: info["description"] = description if advice: info["advice"] = advice if msg and msg in _errmsg: info.update(_errmsg[msg]) if code in _errcode: info.update(_errcode[code]) if msg: _errmsg[msg] = info if code: _errcode[code] = info ####################################################################### # # The following definitions describe the most common FLEXlm errors, # along with our own verbose descripton (where we have one) and (in some # cases) advice on what to do about it. Defining the license-error data # this way is intended to keep the data in a form that's easy to maintain. # # The layout for each error is... # # _define(<flexlm_code>, <error_level>, <flexlm_message>, # <description>, # """ # <advice> # """ # ) # # If some error has no verbose description or no advice, enter the # empty string "" in its place. If an error message has no FLEXlm # error code, use an error code of zero. # ####################################################################### _define( 5, ERROR, "Unable to allocate resources", "", """ This error condition is usually caused by attempting to check out older-format licenses (pre-2013) with newer software. Please email 'help@schrodinger.com' to request an updated license file, attaching your current license file. """) _define( -1, ERROR, "Cannot find license file", "", """ When no env var set and no license file in default locations. For example, if license file incorrectly named 'license.txt.txt' """) _define( -2, ERROR, "Invalid license file syntax", "", """ Typically seen when only the stub license file is present. Can also be caused by a corrupted license file. Rare but recent. Example: License file in UTF-16 format. """) _define(-4, ERROR, "Licensed number of users already reached", "", """ """) _define(-5, ERROR, "No such feature exists", "", """ Maybe node-locked version of -18 error? """) _define( -9, ERROR, "Invalid host", "This feature can only be used on a different machine", """ If you have other licenses (node-locked or server-based) that can be used on the current machine, then this error can probably be ignored. This error can occur spuriously on Linux machines using the Consistent Network Device Naming scheme. See Knowledge Base Issue #1889 for more info about this at (http://www.schrodinger.com/kb/1889). """) _define(-10, ERROR, "Feature has expired", "", """ """) _define( -12, ERROR, "Invalid returned data from license server system", "", """ Maybe caused by connecting to port with non-lmgrd process listening """) _define( -13, ERROR, "No SERVER lines in license file", "", """ Trying to start license server with a node-locked or wide-open license. Can be caused by bad formatting in license file """) _define( -15, ERROR, "Cannot connect to license server system", "", """ The license server host is accessible, but no license server is listening at the expected port. This typically means the license server process is not running, but could also mean we are trying to access the wrong host or port. It's possible to get this error if the hostname is resolvable to an IP address, but a firewall is blocking access to server port. """) _define( -16, ERROR, "Cannot read data from license server system", "", """ lmgrd is running but not responding (e.g., orphan redundant server, or lmgrd in process of shutting down) """) _define(-18, ERROR, "License server system does not support this feature", "", """ """) _define(-21, ERROR, "License file does not support this version", "", """ Maybe node-locked version of -25 error? """) _define(-25, ERROR, "License server system does not support this version of this feature", "", """ """) _define( -31, ERROR, "Feature start date is in the future", "", """ For example, some renewal licenses, only a problem if current licenses replaced """) _define(-34, ERROR, "Clock difference too large between client and license server system", "", """ Security measure to check on back-dating of license server """) _define(-38, ERROR, "User/host on EXCLUDE list for feature", "", """ Seen when options file used """) _define(-39, ERROR, "User/host not on INCLUDE list for feature", "", """ Seen when options file used. """) _define( -73, ERROR, "Local checkout filter rejected request", "", """ Seen when running DIAG on file for inacessible remote server and both current and renewal licenses. Seen in license directory testing (increments with same parameters?). """) _define( -88, ERROR, "System clock has been set back", "", """ Security measure to check on back-dating of current machine (node-locked, client, or server) Refer to Knowledge Base Issue #1836 at (http://www.schrodinger.com/kb/1836). """) _define(-89, ERROR, "This platform not authorized by license", "", """ Now only seen with platform-restricted DESRES licenses. """) _define(-90, ERROR, "Future license file format or misspelling in license file", "", """ Usually indicates corruption of license file. """) _define( -95, ERROR, "Network connect to THIS_HOST failed", "", """ Seen when using 'this_host' for server name in license file, and server name changes while lmgrd is running """) _define( -96, ERROR, "License server machine is down or not responding", "", """ The license server machine is not accessible. Typically means there is a network issue (e.g., server machines name can't be resolved), but can also be caused by a firewall blocking access. Can be caused by the license server machine being shut down. """) _define( -97, ERROR, "The desired vendor daemon is down", "", """ The 'lmgrd' process is running, but the Schrodinger vendor daemon (SCHROD) is not. Common causes: (1) The license server machine not communicating with itself properly, due to an inability to resolve the machine name in the license file. (2) The port on which the vendor daemon runs was not free. (3) The license file is bad (e.g., all licenses are expired) and SCHROD shuts itself down because there are no licenses to serve. """) _define(-101, ERROR, "All licenses are reserved for others", "", """ Seen when options file is used. """) _define( -103, ERROR, "Terminal Server remote client not allowed", "", """ Requires new license with TS_OK added to features. We don't recommend running Maestro via remote login. """) _define(-114, ERROR, "SIGN = keyword required, but missing from license certificate", "", """ Usually means license file is corrupted. """) _define( -125, IGNORE, "A PACKAGE component must be specified", "", """ This is a meaningless error, reported when a suite token is checked out directly, rather than as part of the checkout of a regular token from the suite. """) _define( -139, WARNING, "Communications timeout", "", """ Caused by network communication problems (between lmgrd and SCHROD?) There is a FlexNet env var that can change the timeout period """) ####################################################################### # Other FLEXlm error messages # Taken from the lmclient.h header in the FlexNet Publisher SDK. # # NOTE: These definitions are for the cases where we haven't composed # a long description or formulated advice. They should FOLLOW the full # definitions. ####################################################################### _define(-1, ERROR, "Can't find license file") _define(-2, ERROR, "License file corrupted") _define(-3, ERROR, "Cannot connect to a license server") _define(-4, ERROR, "Maximum number of users reached") _define(-5, ERROR, "No such feature exists") _define(-6, ERROR, "No TCP/IP service") _define(-7, ERROR, "No socket to talk to server on") _define(-8, ERROR, "Bad encryption code") _define(-9, ERROR, "Hostid doesn't match license") _define(-10, ERROR, "Software Expired") _define(-11, ERROR, "Bad date in license file") _define(-12, ERROR, "Bad return from server") _define(-13, ERROR, "No servers specified in license file") _define(-14, ERROR, "Bad SERVER hostname in license file") _define(-15, ERROR, "Cannot connect to server") _define(-16, ERROR, "Cannot read from server") _define(-17, ERROR, "Cannot write to server") _define(-18, ERROR, "Server does not support this feature") _define(-19, ERROR, "Error in select system call") _define(-20, ERROR, "Application server busy (connecting)") _define(-21, ERROR, "Config file doesn't support this version") _define(-22, ERROR, "Feature checkin failed at daemon end") _define(-23, ERROR, "Server busy/new server connecting") _define(-24, ERROR, "Users already in queue for this feature") _define(-25, ERROR, "Version not supported at server end") _define(-26, ERROR, "Request for more licenses than supported") _define(-27, ERROR, "Cannot read /dev/kmem") _define(-28, ERROR, "Cannot read /vmunix") _define(-29, ERROR, "Cannot find ethernet device") _define(-30, ERROR, "Cannot read license file") _define(-31, ERROR, "Start date for feature not reached") _define(-32, ERROR, "No such attr for lm_set_attr/ls_get_attr") _define(-33, ERROR, "Bad encryption handshake with server") _define(-34, ERROR, "Clock difference too large between client/server") _define(-35, ERROR, "We are in the queue for this feature") _define(-36, ERROR, "Feature database corrupted in daemon") _define(-37, ERROR, "dup_select mismatch for this feature") _define(-38, ERROR, "User/host on EXCLUDE list for feature") _define(-39, ERROR, "User/host not in INCLUDE list for feature") _define(-40, ERROR, "Cannot allocate dynamic memory") _define(-41, ERROR, "Feature never checked out (lm_status())") _define(-42, ERROR, "Invalid parameter") _define(-43, ERROR, "No FLEXlm key data") _define(-44, ERROR, "Invalid FLEXlm key data") _define(-45, ERROR, "FLEXlm function not available") _define(-46, ERROR, "FLEXlm software is demonstration version") _define(-47, ERROR, "Clock check not available in daemon") _define(-48, ERROR, "FLEXlm platform not enabled") _define(-49, ERROR, "Date too late for binary format") _define(-50, ERROR, "FLEXlm key data has expired") _define(-51, ERROR, "FLEXlm not initialized") _define(-52, ERROR, "Server did not respond to message") _define(-53, ERROR, "Request rejected by vendor-defined filter") _define(-54, ERROR, "No FEATURESET line present in license file") _define(-55, ERROR, "Incorrect FEATURESET line in license file") _define(-56, ERROR, "Cannot compute FEATURESET line") _define(-57, ERROR, "socket() call failed") _define(-58, ERROR, "setsockopt() failed") _define(-59, ERROR, "message checksum failure") _define(-60, ERROR, "server message checksum failure") _define(-61, ERROR, "Cannot read license file from server") _define(-62, ERROR, "Network software (tcp/ip) not available") _define(-63, ERROR, "Not a license administrator") _define(-64, ERROR, "lmremove request too soon") _define(-65, ERROR, "Bad VENDORCODE struct passed to lm_init()") _define(-66, ERROR, "FLEXlm include file/library mismatch") _define(-67, ERROR, "No licenses to borrow") _define(-68, ERROR, "License BORROW support not enabled") _define(-69, ERROR, "FLOAT_OK can't run standalone on SERVER") _define(-70, ERROR, "Meter already being updated for another counter") _define(-71, ERROR, "Invalid TZ environment variable") _define(-72, ERROR, "Old-style vendor keys (3-word)") _define(-73, ERROR, "Local checkout filter requested request") _define(-74, ERROR, "Attempt to read beyond the end of LF path") _define(-75, ERROR, "VMS SYS$SETIMR call failed") _define(-76, ERROR, "Internal FLEXlm error -- Please report") _define(-77, ERROR, "Version number must be string of dec float") _define(-78, ERROR, "FLEXadmin API functions not available") _define(-79, ERROR, "FLEXlm internal error -79") _define(-80, ERROR, "FLEXlm internal error -80") _define(-81, ERROR, "FLEXlm internal error -81") _define(-82, ERROR, "Invalid PACKAGE line in license file") _define(-83, ERROR, "Server FLEXlm version older than client's") _define( -84, ERROR, "Incorrect number of USERS/HOSTS INCLUDED in options file -- see server log" ) _define(-85, ERROR, "Server doesn't support this request") _define(-86, ERROR, "This license object already in use (Java only)") _define(-87, ERROR, "Checkout exceeds MAX specified in options file") _define(-88, ERROR, "System clock has been set back") _define(-89, ERROR, "This platform not authorized by license") _define(-90, ERROR, "Future license file format or misspelling in license file") _define(-91, ERROR, "ENCRYPTION_SEEDs are non-unique") _define(-92, ERROR, "Server removed during reread, or server hostid mismatch with license") _define(-93, ERROR, "This feature is available in a different license pool") _define(-94, ERROR, "Attempt to generate license with incompatible attributes") _define(-95, ERROR, "Network connect to THIS_HOST failed") _define(-96, ERROR, "Server node is down or not responding") _define(-97, ERROR, "The desired vendor daemon is down") _define(-98, ERROR, "The FEATURE line can't be converted to decimal format") _define(-99, ERROR, "The decimal format license is typed incorrectly") _define(-100, ERROR, "Cannot remove a lingering license") _define(-101, ERROR, "All licenses are reserved for others") _define(-102, ERROR, "A FLEXid borrow error occurred") _define(-103, ERROR, "Terminal Server remote client not allowed") _define(-104, ERROR, "Cannot borrow that long") _define(-105, ERROR, "Feature already returned to server") _define(-106, ERROR, "License server out of network connections") _define(-107, ERROR, "Can't borrow a PACKAGE component") _define(-108, ERROR, "Licenses all borrowed or meter empty") _define(-109, ERROR, "No Borrow Meter Found") _define(-110, ERROR, "Dongle not attached, or can't read dongle") _define(-111, ERROR, "lmgr.res, Windows Resource file, not linked") _define(-112, ERROR, "Missing Dongle Driver") _define(-113, ERROR, "2 FLEXlock checkouts attempted") _define(-114, ERROR, "SIGN= attribute required, but missing from license") _define(-115, ERROR, "Error in Public Key package") _define(-116, ERROR, "TRL not supported for this platform") _define(-117, ERROR, "BORROW failed") _define(-118, ERROR, "BORROW period has expired") _define(-119, ERROR, "lmdown and lmreread must be run on license server node") _define(-120, ERROR, "Cannot lmdown the server when licenses are borrowed") _define(-121, ERROR, "FLOAT_OK license must have exactly one dongle hostid") _define(-122, ERROR, "Unable to delete local borrow info") _define(-123, ERROR, "Support for returning a borrowed license early is not enabled") _define(-124, ERROR, "Error returning borrowed license on server") _define(-125, IGNORE, "Error when trying to just checkout a PACKAGE(BUNDLE)") _define(-126, ERROR, "Composite Hostid not initialized") _define(-127, ERROR, "An item needed for Composite Hostid missing or invalid") _define(-128, ERROR, "Error, borrowed license doesn't match any known server license.") _define(-129, ERROR, "A null pointer was detected. @ref FLEX_ERROR") _define(-130, ERROR, "A bad handle was used. @ref FLEX_ERROR") _define(-131, ERROR, "An emptstring was detected. @ref FLEX_ERROR") _define(-132, ERROR, "Tried to asscess memory that we shouldn't have. @ref FLEX_ERROR") _define(-133, ERROR, "Operation is not supported yet. @ref FLEX_ERROR") _define(-134, ERROR, "The job handle was NULL. @ref FLEX_ERROR") _define(-135, ERROR, "Error enabling event log") _define(-136, ERROR, "Event logging is disabled") _define(-137, ERROR, "Error writing to event log") _define(-138, ERROR, "Internal error. An invalid array index was used.") _define(-139, WARNING, "a timeout has occured") _define(-140, ERROR, "A bad command was found in a message") _define(-141, ERROR, "Error writing to socket. Peer has closed socket") _define( -142, ERROR, "Attempting to generate version specific license tied to a single hostid, which is composite." ) _define( -143, ERROR, "Version specific signatures are not supported for uncounted licenses.") _define(-144, ERROR, "License template contains redundant signature specifiers.") _define(-145, ERROR, "Bad V71_LK signature.") _define(-146, ERROR, "Bad V71_SIGN signature") _define(-147, ERROR, "Bad V80_LK signature") _define(-148, ERROR, "Bad V80_SIGN signature") _define(-149, ERROR, "Bad V81_LK signature") _define(-150, ERROR, "Bad V81_SIGN signature") _define(-151, ERROR, "Bad V81_SIGN2 signature") _define(-152, ERROR, "Bad V84_LK signature") _define(-153, ERROR, "Bad V84_SIGN signature") _define(-154, ERROR, "Bad V84_SIGN2 signature") _define(-155, ERROR, "License key required but missing from the license certificate.") _define(-156, ERROR, "Bad AUTH={} signature") _define(-157, ERROR, "TS record invalid") _define(-158, ERROR, "Cannot open TS") _define(-159, ERROR, "Invalid Fulfillment record") _define(-160, ERROR, "Invalid activation request received") _define(-161, ERROR, "Invalid activation request received") _define(-162, ERROR, "Invalid activation response received") _define(-163, ERROR, "Can't return the fulfillment") _define(-164, ERROR, "Return would exceed max count(s)") _define(-165, ERROR, "Return would exceed max count(s)") _define(-166, ERROR, "Specified operation is not allowed") _define(-167, ERROR, "User/host on EXCLUDE list for entitlement") _define(-168, ERROR, "User/host not in INCLUDE list for entitlement") _define(-169, ERROR, "Activation error") _define(-170, ERROR, "Invalid date format in trusted storage") _define(-171, ERROR, "Encryption failed") _define(-172, ERROR, "Encryption failed") _define(-173, ERROR, "Bad filter context") _define(-174, ERROR, "SUPERSEDE and SUPERSEDE_SIGN can't be used at the same time") _define(-175, ERROR, "Invalid SUPERSEDE_SIGN syntax") _define(-176, ERROR, "SUPERSEDE_SIGN does not contain any license signature") _define(-177, ERROR, "ONE_TS_OK is not supported in this Windows Platform.") _define( -178, ERROR, "Failed to create or reopen the mutex. Terminal Server Remote Client checkout not allowed." ) _define( -179, ERROR, "Only One Terminal Server Remote Client checkout is allowed for this feature." ) _define(-180, ERROR, "Internal Error - 180. Please report to Flexera Software LLC.") _define(-181, ERROR, "Internal Error - 181. Please report to Flexera Software LLC.") _define(-182, ERROR, "Internal Error - 182. Please report to Flexera Software LLC.") _define( -183, ERROR, "More than one ethernet hostid not supported in composite hostid definition." ) _define( -184, ERROR, "The number of characters in the license file paths exceeds the permissible limit." ) _define(-185, ERROR, "Invalid TZ keyword syntax.") _define(-186, ERROR, "Invalid time zone override specification in the client.") _define(-187, ERROR, "The time zone information could not be obtained.") _define(-188, ERROR, "License client time zone not authorized for license rights.") _define(-189, ERROR, "Invalid VM_PLATFORMS syntax") _define(-190, ERROR, "Feature can be check-out from Physical machine only") _define(-191, ERROR, "Feature can be check-out from Virtual machine only") _define(-192, ERROR, "VM platform not authorized by license") _define(-193, ERROR, "FNP vendor keys do not support Virtualization feature") _define( -194, ERROR, "Checkout request denied as it exceeds the MAX limit specified in the options file." ) _define(-195, ERROR, "Binding agent API - Internal error") _define(-196, ERROR, "Binding agent communication error") _define(-197, ERROR, "Invalid Binding agent version") _define(-198, ERROR, "Unsupported hostid provided in feature line.") _define(-199, ERROR, "Failed to load ServerQuery request.") _define(-200, ERROR, "Failed to generate ServerQuery response.") _define(-201, ERROR, "Invalid IPaddress used while overriding.") _define( -202, ERROR, "Returning borrowed feature failed as same feature borrowed from different Vendor daemons." ) _define(-203, ERROR, "Failed to get the total feature count.") #######################################################################