Database Reference
In-Depth Information
The commands are again printed to the screen. The properties for the TEST_em12cr3.example.com target have
already been updated, so only the command to change the TEST_em12cr3.example.com:3872 target needs to be
copied and pasted:
emcli>set_target_property_value(subseparator="property_records=@",
property_records="TEST_em12cr3.example.com:3872@oracle_emd@LifeCycle Status@Development")
Properties updated successfully
The example we just looked at hardcodes the properties. This will work fine if the properties never change, but
at the beginning of this exercise we created the myprops dictionary so we could easily change the property keys and
values:
emcli>myprops = {'LifeCycle Status':'Development', 'Location':'COLO'}
Now let's change the code we just created to take advantage of this variable. We'll continue to use the debugging
mode we included in the code to print the commands to screen and then add a nested for loop inside the existing for
loop; we'll then iterate through the items of the myprops dictionary. There is also an additional change here by adding
the mydelim variable. By now you should be noticing a pattern; the more you parameterize, the easier your code is to
read, change, troubleshoot, etc. Now if we decided to change the subseparator from an @ sign to something else, we
would change it in one place, not four:
emcli>for targ in myobj:
... if myreg.search(targ['Target Name']):
... mydelim = '@'
... mysubsep = 'property_records=' + mydelim
... myproprecs = targ['Target Name'] + \
... mydelim + targ['Target Type'] + mydelim
... for propkey, propvalue in myprops.items():
... myproprecprops = propkey + mydelim + propvalue
... mycommand = 'set_target_property_value(' + \
... 'subseparator="' + \
... mysubsep + '", property_records="' + \
... myproprecs + \
... myproprecprops + '")'
... print(mycommand)
These commands should work great for copy and paste, but we want to automate it further to skip the copy and
paste and run the commands automatically in the code. However, when problems arise later, we don't want to lose
the ability to look at this verbose output again, so we'll leave the debug in place and supplement it with the ability to
choose whether we want to see the command printed to the screen or have it be run automatically by the script.
Adding a debug variable at the beginning of the script and checking for the value of that variable within the script
is an easy way to enable or disable a “testing” mode. By default the debug variable will be false unless it is assigned a
value, in which case it becomes true:
emcli>debug = ''
emcli>if debug:
... print('True')
... else:
... print('False')
...
False
Search WWH ::




Custom Search