Database Reference
In-Depth Information
Listing 6-8. start.py not in the Jython search path
emcli>import start
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named start
The JYTHONPATH environment variable tells Jython the additional directories in which to search for modules
to be imported. Set this variable before executing emcli . In Listing 6-9, the start module can now be successfully
imported, either directly from the interactive mode command line or within a script in scripting mode.
Listing 6-9. Successful execution of the start.py script
[oracle@server ]$ export JYTHONPATH=/home/oracle/scripts
[oracle@server ]$ emcli
emcli>import start
Login successful
If you are not comfortable with including your password in the script (you shouldn't be) and only specify the
username parameter with the login function, you will be prompted for the password:
Enter password : **********
Listing 6-10 shows an alternative method of authenticating that affords one the security of not including the
password in the script while at the same time not requiring one to enter the password every time the script is invoked.
The password in this example would be contained in the .secret file, which should have permissions set such that it
can be read only by the operating system user invoking EM CLI.
Listing 6-10. start.py logon script using a password read from an external file
from emcli import *
set_client_property('EMCLI_OMS_URL', ' https://em12cr3.example.com:7802/em ' )
set_client_property('EMCLI_TRUSTALL', 'true')
set_client_property('EMCLI_OUTPUT_TYPE', 'JSON')
f = open('/home/oracle/.secret','r')
pwd = f.read()
print(login(username='sysman', password=pwd))
The steps included in the start.py script need to be executed every time EM CLI is invoked in scripted or
interactive mode, which is why it is important to script the login process. Any script called directly should invoke the
import start command before doing anything else.
Python Scripting with EM CLI to Set Target Properties
EM CLI includes a function to change the properties of a target. If the properties of a small number of targets need to
be updated, it is easy to simply execute the set_target_property_value() function for each of those targets. When
the need arises to update the properties of tens or even hundreds of targets, executing the function for each target is
not efficient. Fortunately, with EM CLI we can take advantage of the full scripting functionality of Python.
A for loop can be used to iterate through any object and perform any task on each one of those object pieces.
For example, it is common to add or update target properties after a target has been added. Any task involving changing
target properties for more than a couple of targets in the GUI is tedious and time-consuming. There is more than one
way to accomplish this task within EM CLI, but all of them are easier and more efficient than the GUI can offer.
 
Search WWH ::




Custom Search