Database Reference
In-Depth Information
For demonstration purposes, we'll use the interactive mode, but all of these commands will also work in
scripting mode:
emcli>import start
Enter password : **********
Login successful
Create an object containing all of the targets. Don't worry about filtering out targets yet. That part will be done
further down in the script:
emcli>myobj = get_targets().out()['data']
emcli>len(myobj)
29
In this case, I know I have 29 targets in my repository. We want to update the Lifecycle Status and Location
properties of the targets we just added that have the prefix of TEST_ with Development and COLO , respectively. Since we
may want to add to or change this list of properties in the future, we'll put these into a dictionary as keys and values:
emcli>myprops = {'LifeCycle Status':'Development', 'Location':'COLO'}
We want to make sure we choose the correct targets for this update, so we will use regular expressions to filter the
target names. Using regular expressions within Jython requires that we import another module:
emcli>import re
Now we can create the regular expression that we will use to filter the target names. This filter will be applied to
each target name to determine if the target properties will be applied to that target:
emcli>filtermatch = '^TEST_'
emcli>myreg = re.compile(filtermatch)
Create a for loop to iterate through the targets. When writing programs like this, it is a good idea to write a little
code and then test, especially when just getting started. Once the loop is created, we'll run it with a simple print
command to make sure we are iterating through the appropriate information.
Make sure the lines shown in the example preceded by three dots are indented properly. An indentation in
Python is four spaces:
emcli>for targ in myobj:
... print(targ['Target Name'])
This shows us that we are able to see all of the target names in our repository. Now we can apply the filter so we
are only seeing the targets that start with TEST_ :
emcli>for targ in myobj:
... if myreg.search(targ['Target Name']):
... print(targ['Target Name'] + \
... ' - ' + targ['Target Type'])
Search WWH ::




Custom Search