Database Reference
In-Depth Information
Simple Logon Script (start.py)
The code sample below can be copied directly into a text file. It is used to set some important session properties and
to establish a secure connection between the EM CLI client and the OMS to which it is connecting. Before using this
script, the variables myurl , myuser , and mypass will need to be updated for your environment:
from emcli import *
myurl = ' https://em12cr3.example.com:7802/em '
mytrustall = 'TRUE'
myoutput = 'JSON'
myuser = 'sysman'
mypass = 'foobar'
set_client_property('EMCLI_OMS_URL', myurl)
set_client_property('EMCLI_TRUSTALL', mytrustall)
set_client_property('EMCLI_OUTPUT_TYPE', myoutput)
print(login(username=myuser, password=mypass))
The start.py script can be used in both scripting and interactive modes. In scripting mode, the script could
be executed directly from EM CLI using the command emcli @start.py. The result would either succeed or fail in
establishing a connection between EM CLI and an OMS. Using this script alone would not be very useful unless you
just wanted to see the confirmation that the connection can be made.
start.py is commonly called from other scripts, or when in interactive mode, from the EM CLI Jython command-
line interface (not to be confused with command-line mode). Calling start.py from another script is done by
importing the script as a module.
For example, a script called sync.py is called in scripting mode with the command emcli @sync.py. Before the
commands can be executed, a connection must be established between EM CLI and an OMS. If the start.py script is in
a directory that is included in JYTHONPATH, the logon script can be called as the first command with import start.
JYTHONPATH is a shell environment variable that will be used by em ClI to establish all of the directories to be
searched when importing modules. to add a directory, supplement the variable according to the shell standards, similar
to how a directory would be added to the PATH environment variable.
Note
An alternative would be to execute the start.py in scripting mode using the command emcli @start.py and then
call the sync.py (import sync) script as the last line in start.py. This method would assume that sync.py is located
within the searchable path of the JYTHONPATH environment variable.
When using interactive mode, the start.py script must be in the searchable path of JYTHONPATH and be called
with import start. The logon is now established for the life of the current interactive session or until the logon is
implicitly (expired timeout) or explicitly (using the logout() function) dissolved.
Many Enterprise environments discourage or do not allow scripts to contain credential passwords. The start.py
script can be slightly modified to take advantage of Python's capability to read external files, as shown in the
next example.
 
 
Search WWH ::




Custom Search