Database Reference
In-Depth Information
Listing 6-17.
The
__loadtargobjects( )
of the
updateProps( )
class reloads the EM targets when necessary
def __loadtargobjects(self):
if self.reloadtargs == True:
self.reloadtargs = False
self.fulltargs = \
emcli.list(resource='Targets').out()['data']
self.targprops = \
emcli.list(resource='TargetProperties'
).out()['data']
The
props()
function shown in Listing 6-18 sets or modifies the
propsdict
variable, which holds the key value
dictionary that is used to set the target properties. This was turned into a function rather than just setting the parameter
directly, mainly because it can be called multiple times and includes the
assert
statement for error checking.
Listing 6-18.
The
props( )
function of the
updateProps( )
class updates the
propsdict
properties dictionary
def props(self, propdict):
assert isinstance(propdict, dict), \
'propdict parameter must be ' + \
'a dictionary of ' + \
'{"property_name":"property_value"}'
self.propdict = propdict
Listing 6-19 shows the
filt()
function, which defines the scope of targets to which the defined properties will
be applied for this instance. Even after the filter is applied, it can be queried or changed. The first three parameters
(
agentfilter, typefilter,
and
namefilter
) are compiled as regular expressions so as to include or exclude targets
for this instance. If the parameters are not defined when the
filt()
function is called, they are defined implicitly
to include all targets. The
sort
parameter defines how the filtered targets should be sorted, and, finally, the
show
parameter determines if the output of the filtered target list will be printed to screen.
Listing 6-19.
The
filt( )
function of the
updateProps( )
class creates and manages the filtered list of targets
def filt(self, agentfilter='.*', typefilter='.*',
namefilter='.*',
sort=('TARGET_TYPE','TARGET_NAME'), show=False):
self.targs = []
__agentcompfilt = re.compile(agentfilter)
__typecompfilt = re.compile(typefilter)
__namecompfilt = re.compile(namefilter)
self.__loadtargobjects()
for __inttarg in self.fulltargs:
if __typecompfilt.search(__inttarg['TARGET_TYPE']) \
and __namecompfilt.search(
__inttarg['TARGET_NAME']) \
and (__inttarg['EMD_URL'] == None or \
__agentcompfilt.search(__inttarg['EMD_URL'])):
self.targs.append(__inttarg)
__myoperator = operator
for __myop in sort:
__myoperator = operator.itemgetter(__myop)
self.targssort = sorted(self.targs, key=__myoperator)
if show == True:
self.show()
Search WWH ::
Custom Search