OpenLM 2.0 API Python script example: Closing ArcGIS โ€˜Editorโ€™ sessions

Facebook
X
LinkedIn

Subscribe to our blog

Loading

OpenLM frequently receives requests for OpenLM API usage examples. Here is one that a client of ours has written, and was kind enough to share with us. Please note that the example is provided as is, and should be used at the customerโ€™s discretion.

Thanks Nat.

The example was implemented in Python, and takes advantage of the โ€˜GetActiveProductsโ€™ and โ€˜CloseApplicationโ€™ APIs, to obtain a list of ArcGIS Editor users and actively shut down these sessions as a batch job. The โ€˜CloseApplicationโ€™ API requires the installation of the OpenLM Agent and OpenLM Agent extension on the end users workstation. It is currently applicable to ESRI ArcGIS , Autodesk (AutoCAD) and Matlab.

ย 

import urllib2
from xml.etree.ElementTree import fromstring, ElementTree

# GetActiveProducts API request parameters
# Please replace OpenLM_Server_Hostname with your actual hostname.
xml_string = '<ULM><MESSAGE type="GetActiveProducts" /><SESSION sessionid="0" /></ULM>'
url = 'http://OpenLM_Server_Hostname:7014/OpenLMServer'

# compile the GetActiveProducts request: Obtain a list of currently consumed licenses
req = urllib2.Request(url=url,
ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย data=xml_string,
ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย headers={'Content-Type': 'application/xml'})
ย 
# Send the request, and obtain a response ย 
response = urllib2.urlopen(req)
readResponse = response.read()
ET_xml = ElementTree(fromstring(readResponse))

# Initialize the standardLicense as False. This variable will flag each 'Editor' license.
standardLicense = False
for node in ET_xml.iter('PRODUCT'):
ย ย ย product = node.attrib.get('product')

# Identify 'Editor' license usage, and the respective workstation and user name.
ย ย ย if(product=="Editor"):
ย ย ย ย ย ย ย standardLicense
ย ย ย ย ย ย ย username = node.attrib.get('username')
ย ย ย ย ย ย ย workstation = node.attrib.get('workstation')
ย ย ย ย ย ย ย #print(username, workstation)

# Compile the CloseApplication to be sent to the OpenLM Agent on the specific workstation.
# Please replace License_Server_Descriptive_Name with the descriptive name configured on the OpenLM Server configuration tool.
ย ย ย ย ย ย ย xmlCommand = '<ULM><MESSAGE type="CloseApplication" /><PARAMETERS><PARAM name="username">%s</PARAM><PARAM name="workstation">%s</PARAM><PARAM name="server">License_Server_Descriptive_Name</PARAM><PARAM name="vendor">ARCGIS</PARAM><PARAM name="feature">Editor</PARAM></PARAMETERS></ULM>' %(username, workstation)
ย ย ย ย ย ย ย print(xmlCommand)
ย ย ย ย ย ย ย req2 = urllib2.Request(url=url,
ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย data=xmlCommand,
ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย headers={'Content-Type': 'application/xml'})

# Send the request, and obtain a response ย 
ย ย ย ย ย ย ย response = urllib2.urlopen(req2)
ย ย ย ย ย ย ย print(response.read())

# Print a summary.
if(standardLicense):
ย ย ย print('The user has been removed')
else:
ย ย ย print('No one is currently using the standard Editor license')

		
Skip to content