Package schrodinger :: Package application :: Package licensing :: Module licadmin
[hide private]
[frames] | no frames]

Module licadmin

Classes [hide private]
  Status
A Status object represents the "health" of a license resource.
  stat_info
stat_info(total, used)
  LicenseFeature
A LicenseFeature object represents a particular license feature provided by a LicenseResource.
  LicenseResource
A LicenseResource object represents a single license file or license server (port@host).
  ServerInfo
A ServerInfo object represents the information reported in the lmgrd log when a license server is started.
  UsageError
This exception is thrown when unrecognized ior incompatible commandline options are used.
Functions [hide private]
 
_single_job_capacity(reqs, tokens)
Calculate the number of jobs that can be run, for a job with the given token requirements and the given set of available tokens.
 
healthier(health1, health2)
Return True if health1 is healthier than health2.
 
tokens(licenses)
Report number of tokens provided by and currently available from the given license resources.
 
job_capacity(resources)
Report number of jobs that can be run with the tokens available on the given license resources.
 
get_hostid()
Get the hostid for the current machine using "lmutil lmhostid".
 
execute_lmutil(args)
Execute the lmutil program with the given commandline arguments.
 
execute_lictest(args)
Execute the lictest program with the given commandline arguments.
 
parse_lmhostid_output(lines)
Parse the output from "lmutil lmhostid", provided as a list of output lines.
 
run_lmstat(hostport)
Get license usage information from a server via "lmutil lmstat".
 
parse_lmstat_output(lines)
Parse the output from "lmutil lmstat", provided as a list of output lines.
 
run_lmdiag(locations)
Get diagnostic information regarding one or more license resources via "lmutil lmdiag".
 
parse_lmdiag_output(lines)
Parse the output from "lmutil lmdiag", provided as a list of output lines.
 
join_cont_lines(lines)
Returns the input list of lines, after joining any logical lines that were split across two (or more) physical lines, and stripping leading and trailing whitespace.
 
parse_lmdiag_entry(lines)
Returns a LicenseFeature object, representing the information reported by lmdiag for that feature.
 
load_job_reqs(filename='')
Read a json document describing the license requirements for each job that a user could launch.
 
load_job_products(filename='')
Read a json document listing the product names under which job types should be grouped.
 
_require_job_reqs()
Return the table of license requirements for each job.
 
find_license_resources()
Returns a list of lists of all license resources (license files or servers) that would be available to a job trying to check out a license.
 
_unique_resources(lics)
Filter the given list of LicenseResources to remove redundant resources.
 
resources_from_path(search_path, source='')
Parse the given search path (PATH-style) into components and return a list with the LicenseResource object for each item.
 
resources_from_list(license_list, source)
Return a list with the LicenseResource object for each item (server hostport, license file or license directory) in the given list.
 
resource_summary(resources)
Provide a condensed list of license resources.
 
hostid_is_local(lic_hostid)
Returns True if the given hostid matches the local hostid.
 
hostname_is_local(hostname)
Determine whether the given hostname refers to the current host.
 
is_ipv4_addr(addr)
Determine whether the given string is an IPv4 address.
 
server_log(licfile)
Return the standard pathname for the lmgrd log file associated with the given license file.
 
writable_server_log(licfile, prefer_logfile='')
Return the pathname for the log file to use when launching a server for the given license file.
 
can_write_file(pathname)
Returns true if the filesystem permissions appear to allow the specified file to be written.
 
start_server(licfile, logfile='', append=True)
Start a license server for the given license file.
 
stop_server(licfile)
Stop the license server for the given license file.
 
create_stub_license(host, port='')
Create a stub license license file, which points to a remote license server.
 
parse_lmgrd_log(filename, after=None)
 
parse_lmgrd_lines(lines, after=None)
Parse an lmgrd log file for messages related to the health of the lmgrd and SCHROD daemons.
 
version_uptodate(version)
Returns True unless the given lmgrd version number is older than v11.12.
 
parse_lmgrd_event(eventdict, line)
 
lmgrd_lines(lines)
A generator to perform initial parsing of lmgrd logfile lines.
 
resources()
Return a list of all license resources found.
 
refresh()
Force license-resource info to be re-loaded.
 
hostid()
Return the hostid for the current host.
 
local_server()
Returns the license resource representing the local license server, if any.
 
job_capacity_by_product(res_list=None)
Return a dict of lists of tuples, reporting the number of jobs of each type that can be run, grouped by product.
 
license_directory()
Return the pathname of the directory into which license files should be installed.
 
parse_args(args)
Parse the commandline arguments for the licadmin utility.
 
handle_start_action(opts)
Start a local license server.
 
handle_stop_action(opts)
Stop a local license server.
 
handle_stat_action(opts)
Execute "lmutil lmstat -a" for the specified license.
 
handle_diag_action(opts)
Execute "lmutil lmdiag -n" for the specified license.
 
handle_ver_action(opts)
Execute "lmutil lmver" for the specified executable.
 
handle_list_action(opts)
List all known license resources.
 
handle_check_action(opts)
Report the status of all known license resources.
 
handle_verify_action(opts)
Verify the signatures in the specified license file, using lictest.
 
handle_generic_action(action, opts)
Execute the lmutil subcommand for the given action.
 
working_directory(*args, **kwds)
Change the CWD within some limited context
 
handle_info_action(opts)
Create an archive of information for troubleshooting license issues.
 
options_file(licfile='')
Return the pathname of the FLEXlm options file associated with the given license.
 
system_hosts_file()
Return the pathname of the /etc/hosts file, or its equivalent.
 
get_machid_output()
Return the output of the machid utility
 
get_network_info()
Return network configuration info from ifconfig.
 
get_mmshare_listing()
Return info about the mmshare directory.
 
get_schrod_file_listing()
Return info about license-related files installed under $SCHRODINGER.
 
get_shared_file_listing()
Return info about files installed in the shared license directory.
 
get_server_processes()
Return info about any running lmgrd and SCHROD processes.
 
process_attributes(proc, attrs)
Return a dict containing the specified attributes for the given psutil.Process object.
 
copy_license_files(subdir='.')
Copy license files to the specified subdirectory.
 
copy_server_logs(subdir='.')
Copy license server logs to the current directory.
 
_find_server_logs(licenses)
Return a list of all server logfiles found on the standard search path.
 
create_archive_file(archive_file, archive_dir)
Create a zip archive with the contents of archive_dir
 
shorthost(hostname)
Return the short hostname for the given hostname, without the domain name.
 
get_flexlm_search_path()
Execute "lmutil lmpath" to determine the actual search path used for license checkouts.
 
main(args)
 
_run()
Variables [hide private]
  fmt = logging.Formatter('%(message)s')
  log = logging.getLogger("licadmin")
  console_handler = logging.StreamHandler(stream= sys.stdout)
  SCHRODINGER = '/nfs/builds/objects/NB/2015-3/Linux-x86_64/buil...
  MMSHARE_EXEC = '/nfs/builds/objects/NB/2015-3/Linux-x86_64/bui...
  MMSHARE_DATA = '/nfs/builds/objects/NB/2015-3/Linux-x86_64/bui...
  LICENSE_DIRNAME = 'licenses'
  LICENSE_FILENAME = 'license'
  LMGRD_LOG = 'lmgrd.log'
  LMGRD_ALTLOG = 'lmgrd.buildbot.log'
  SHARED_LICENSE_DIR = '/opt/schrodinger'
  JOB_REQS_FILE = '/nfs/builds/objects/NB/2015-3/Linux-x86_64/bu...
  JOB_PRODUCTS_FILE = '/nfs/builds/objects/NB/2015-3/Linux-x86_6...
  REQUIRED_MAJOR_VERSION = 11
  REQUIRED_MINOR_VERSION = 13
  UNCOUNTED = -1
  _resources = []
  _hostid = ''
  _job_reqs = {}
  _job_products = []
  RESOURCE_OK = License OK
  RESOURCE_PROBLEMS = License may have problems
  RESOURCE_UNAVAILABLE = License is unusable
  LMGRD_EVENTS = OrderedDict([('LMGRD_PRE_START', (0, <_sre.SRE_...
  SCHROD_EVENTS = OrderedDict([('SCHROD_START', (0, <_sre.SRE_Pa...
  parser = None
hash(x)
  GENERIC_ACTIONS = ('CKSUM', 'NEWLOG', 'REREAD', 'REMOVE', 'SWI...
  LICENSE_ACTIONS = ('CKSUM', 'DIAG', 'INFO', 'NEWLOG', 'REREAD'...
  GENERAL_INFO_FILE = 'general-info.txt'
  GENERAL_INFO_TEMPLATE = Template("""Gene...
  server_ps_attrs = ['pid', 'ppid', 'name', 'exe', 'memory_info'...
  server_ps_head_fmt = '%-6s %-8s %6s %6s %4s %4s %6s %4s %s'
  server_ps_body_fmt = '{name:<6s} {username:<8s} {pid:6d} {ppid...
  LMGRD_ERROR = 1
  LMGRD_INFO = 0
  SCHROD_ERROR = 1
  SCHROD_INFO = 0
  __package__ = 'schrodinger.application.licensing'
Function Details [hide private]

_single_job_capacity(reqs, tokens)

 

Calculate the number of jobs that can be run, for a job with the given token requirements and the given set of available tokens. Returns -1 if an unlimited number of jobs can be run.

The requirements are a dict, mapping token name to the number required. The tokens are also a dict, mapping token names to the number of available tokens. A token count of -1 indicates an unlimited number of tokens.

tokens(licenses)

 

Report number of tokens provided by and currently available from the given license resources. Returns a dict mapping token name to stat_info tuple for each token.

job_capacity(resources)

 

Report number of jobs that can be run with the tokens available on the given license resources.

Returns a dict mapping the jobtype to the number of jobs that can be run, with licenses available from the given resources.

get_hostid()

 

Get the hostid for the current machine using "lmutil lmhostid". Generally, this will be the MAC address(es) for the ethernet interface.

Returns the hostid string reported for the current host.

execute_lmutil(args)

 

Execute the lmutil program with the given commandline arguments. The arguments must be specified as list.

The raw output of the command is returned.

If the exit code is non-zero it raises a CalledProcessError. The CalledProcessError object will have the return code in the returncode attribute, the output in the output attribute, and the command in the cmd attribute.

execute_lictest(args)

 

Execute the lictest program with the given commandline arguments. The arguments must be specified as list.

The raw output of the command is returned.

If the exit code is non-zero it raises a CalledProcessError. The CalledProcessError object will have the return code in the returncode attribute, the output in the output attribute, and the command in the cmd attribute.

parse_lmhostid_output(lines)

 

Parse the output from "lmutil lmhostid", provided as a list of output lines.

Returns the hostid string for the current host.

run_lmstat(hostport)

 

Get license usage information from a server via "lmutil lmstat".

Returns a dict mapping the token name to a stat_info named tuple for that feature. A stat_info tuple has integer fields 'total' and 'used', recording the total tokens provided and the number in use.

parse_lmstat_output(lines)

 

Parse the output from "lmutil lmstat", provided as a list of output lines.

Returns a dict mapping the feature name to a stat_info named tuple for that feature. A stat_info tuple has integer fields 'total' and 'used', recording the total tokens provided and the number in use.

run_lmdiag(locations)

 

Get diagnostic information regarding one or more license resources via "lmutil lmdiag".

The argument 'locations' is a string representing a FLEXLM search path, such as $SCHROD_LICENSE_FILE.

Returns a dict with an entry for each license resource that was examined. For each resource, returns a dict mapping the feature name to a list of LicenseFeature objects, each representing the diag info for a single license line for that feature. (There may be more than one.)

parse_lmdiag_output(lines)

 

Parse the output from "lmutil lmdiag", provided as a list of output lines.

Returns a dict with an entry for each license resource that was examined. For each resource, returns a dict mapping the feature name to a list of LicenseFeature objects, each representing the diag info for a single license line for that feature. (There may be more than one.)

join_cont_lines(lines)

 

Returns the input list of lines, after joining any logical lines that were split across two (or more) physical lines, and stripping leading and trailing whitespace.

A continued line is indicated by a trailing comma.

load_job_reqs(filename='')

 

Read a json document describing the license requirements for each job that a user could launch.

The license requirements for a given job are represented as a dict, mapping the token name to the number of tokens required for that job. A job may accept more than one combination of tokens.

Return a dict mapping the job type to a list of dicts, each representing an acceptable set of licenses for that job.

If the file can't be loaded, an exception will be thrown.

load_job_products(filename='')

 

Read a json document listing the product names under which job types should be grouped.

Returns a list of product names.

If the file can't be loaded, an exception will be thrown.

_require_job_reqs()

 

Return the table of license requirements for each job.

The requirements are returned as a dict. The keys are the full internal job names. The license requirements for each job are recorded as a list of dicts, where each list item describes a set of requirements. A set of requirements is a dict mapping a license token name to the number of tokens required for that job.

find_license_resources()

 

Returns a list of lists of all license resources (license files or
servers) that would be available to a job trying to check out a license.

License resources may be specified using the environment variables

    $SCHROD_LICENSE_FILE
    $LM_LICENSE_FILE

... which can each specify a list of license files and/or license servers.

License resources will also be found automatically if installed in one of
the standard locations that mmlic3 is hard-wired to search.  These are 

    $SCHRODINGER/licenses/*.lic
    $SCHRODINGER/license{,.txt}

... and, depending on the platform,

    MacOSX:
    /Library/Application Support/Schrodinger/licenses/*.lic
    /Library/Application Support/Schrodinger/license{,.txt}

    Windows:
    C:\ProgramData\Schrodinger\licenses\*.lic
    C:\ProgramData\Schrodinger\license{,.txt}

    Linux
    /opt/schrodinger/licenses/*.lic
    /opt/schrodinger/license{,.txt}

Returns the tuple (license_file, source)

_unique_resources(lics)

 

Filter the given list of LicenseResources to remove redundant resources.

Rules:
1. If both a port@host reference and license file are found for the same
   server, we keep the license file.
2. If we have both a port@host and an @host reference to a server, keep
   the port@host reference.
3. If a stub license and a full license file are found, keep the full
   license file.
4. If there's more than one full license file for a given server, all
   are kept.

resource_summary(resources)

 

Provide a condensed list of license resources. Each license server is listed, but the existence of node-locked licenses. The health of each listed resource is indicated with a status code, which will be one of RESOURCE_OK, RESOURCE_PROBLEMS, RESOURCE_UNAVAILABLE.

server_log(licfile)

 

Return the standard pathname for the lmgrd log file associated with the given license file.

If the license is just a port@host server address, the empty string is returned, because we have no idea where the logs would be.

writable_server_log(licfile, prefer_logfile='')

 

Return the pathname for the log file to use when launching a server for the given license file. The returned pathname will be writable by the current user.

This differs from server_log() in that it will check for alternative locations and filenames if the standard lmgrd.log file can't be written.

A suggested logfile pathname can be specified. If this file is writable, it will be returned.

start_server(licfile, logfile='', append=True)

 

Start a license server for the given license file. If a logfile pathname isn't specified, the default location will be used. If the append option is False, the existing logfile (if any) will be overwritten.

The return value is the pathname of the logfile that was used.

If the exit code is non-zero it raises a CalledProcessError. The CalledProcessError object will have the return code in the returncode attribute and the command in the cmd attribute. This exception is only expected when there's a problem with the lmgrd executable, itself. License-related failures will be reported in the lmgrd log file.

If the lmgrd logfile can't be written a LicenseException is raised.

stop_server(licfile)

 

Stop the license server for the given license file.

The output from the command is returned.

If the exit code is non-zero it raises a CalledProcessError. The CalledProcessError object will have the return code in the returncode attribute and the command in the cmd attribute.

parse_lmgrd_lines(lines, after=None)

 

Parse an lmgrd log file for messages related to the health of the lmgrd and SCHROD daemons. The log file is supplied as a list of lines.

If an "after" datetime is specified, only logfile lines with timestamps after that time are considered.

A ServerInfo object is returned

lmgrd_lines(lines)

 

A generator to perform initial parsing of lmgrd logfile lines.

A sequence of tuples (timestamp, prog, text) is returned. Lines for any prog other than "lmgrd" or "SCHROD" are discarded.

local_server()

 

Returns the license resource representing the local license server, if any. There may be multiple license servers, but only one that can run on the current machine. Only a local license server can be started or stopped by the user. Returns None if no local license server is found.

job_capacity_by_product(res_list=None)

 

Return a dict of lists of tuples, reporting the number of
jobs of each type that can be run, grouped by product.

The structure of the return value is

{ <product1>: [ (<jobtype1>, <number of jobs>),
                (<jobtype2>, <number of jobs>),
              ... ],
  <product2>: [ (<jobtype1>, <number of jobs>),
                (<jobtype2>, <number of jobs>),
              ... ],
}

By default, checks all available resources, but the res_list parameter can
be used to restrict the report to a specified collection of resources.

license_directory()

 

Return the pathname of the directory into which license files
should be installed.

The first writable directory found among the following will be
returned:
1. the shared license directory,
2. $SCHRODINGER/licenses, and
3. $HOME/licenses

The returned license directory will be created, as a side effect, if it
doesn't already exist.

parse_args(args)

 

Parse the commandline arguments for the licadmin utility.

If incompatible options are specified a UsageError is thrown.

Returns a namespace object with the values of the commandline options. The subcommand ("START", "INFO", etc.) is returned as the "action" attribute of the namespace object.

handle_ver_action(opts)

 

Execute "lmutil lmver" for the specified executable. Lines containing "lmutil" are stripped from the result.

working_directory(*args, **kwds)

 

Change the CWD within some limited context

Decorators:
  • @contextmanager

process_attributes(proc, attrs)

 

Return a dict containing the specified attributes for the given psutil.Process object.

Make sure that filler values for unavailable data are of the correct type (LIC-548)

copy_license_files(subdir='.')

 

Copy license files to the specified subdirectory. All licenses found on the standard search path are copied.

If a subdir is specified, the files are copied to that subdirectory, which will be created if necessary.

copy_server_logs(subdir='.')

 

Copy license server logs to the current directory. All server logs found on the standard search path are copied.

If a subdir is specified, the files are copied to that subdirectory, which will be created if necessary.

_find_server_logs(licenses)

 

Return a list of all server logfiles found on the standard search path.

The standard search path includes...
1. Any directory in which a license is installed
2. The parent directory of a licenses/ directory in which a license is installed
3. The user's home directory
4. The current directory

shorthost(hostname)

 

Return the short hostname for the given hostname, without the domain name. If hostname is an IP address, it is returned unmodified.


Variables Details [hide private]

SCHRODINGER

Value:
'/nfs/builds/objects/NB/2015-3/Linux-x86_64/build-145'

MMSHARE_EXEC

Value:
'/nfs/builds/objects/NB/2015-3/Linux-x86_64/build-145/mmshare-v3.1/bin\
/Linux-x86_64'

MMSHARE_DATA

Value:
'/nfs/builds/objects/NB/2015-3/Linux-x86_64/build-145/mmshare-v3.1/dat\
a'

JOB_REQS_FILE

Value:
'/nfs/builds/objects/NB/2015-3/Linux-x86_64/build-145/mmshare-v3.1/dat\
a/license_reqs.json'

JOB_PRODUCTS_FILE

Value:
'/nfs/builds/objects/NB/2015-3/Linux-x86_64/build-145/mmshare-v3.1/dat\
a/job_products.json'

LMGRD_EVENTS

Value:
OrderedDict([('LMGRD_PRE_START', (0, <_sre.SRE_Pattern object at 0x10b\
24500>)), ('LMGRD_SYSDATE', (0, <_sre.SRE_Pattern object at 0x10b1f8c0\
>)), ('LMGRD_START', (0, <_sre.SRE_Pattern object at 0x10b1fad0>)), ('\
LMGRD_FILE', (0, <_sre.SRE_Pattern object at 0x10b1fd10>)), ('LMGRD_FI\
LE2', (0, <_sre.SRE_Pattern object at 0x10b1f530>)), ('LMGRD_PORT', (0\
, <_sre.SRE_Pattern object at 0xca32340>)), ('LMGRD_SCHROD_START', (0,\
 <_sre.SRE_Pattern object at 0x10b2ae10>)), ('LMGRD_SCHROD_EXIT', (1, \
<_sre.SRE_Pattern object at 0x10b2b080>)), ('LMGRD_BAD_HOST', (1, <_sr\
...

SCHROD_EVENTS

Value:
OrderedDict([('SCHROD_START', (0, <_sre.SRE_Pattern object at 0x10b219\
a0>)), ('SCHROD_HOST', (0, <_sre.SRE_Pattern object at 0x10b21b40>)), \
('SCHROD_BAD_KEY', (1, <_sre.SRE_Pattern object at 0x10af42c0>)), ('SC\
HROD_EXITING', (1, <_sre.SRE_Pattern object at 0x10abe4e0>)), ('SCHROD\
_SHUTDOWN', (1, <_sre.SRE_Pattern object at 0x10b22080>)), ('SCHROD_EX\
IT', (1, <_sre.SRE_Pattern object at 0x10b1f670>))])

GENERIC_ACTIONS

Value:
('CKSUM', 'NEWLOG', 'REREAD', 'REMOVE', 'SWITCHR')

LICENSE_ACTIONS

Value:
('CKSUM',
 'DIAG',
 'INFO',
 'NEWLOG',
 'REREAD',
 'REMOVE',
 'START',
 'STAT',
...

GENERAL_INFO_TEMPLATE

Value:
Template("""General
-------
hostname: $HOST
username: $USER
curdir:  $CWD

License
-------
...

server_ps_attrs

Value:
['pid',
 'ppid',
 'name',
 'exe',
 'memory_info',
 'memory_percent',
 'cpu_percent',
 'username',
...

server_ps_body_fmt

Value:
'{name:<6s} {username:<8s} {pid:6d} {ppid:6d} {cpu_percent:4.1f} {memo\
ry_percent:4.1f} {rss:>6s} {vms:>7s} {cmdstr}'