Package Products :: Package ZenRelations :: Module ImportRM :: Class ImportRM |
[hide private]
[frames] | no frames]

# Class ImportRM

source code

                  object --+
                           |
    ZenUtils.CmdBase.CmdBase --+
                               |
    ZenUtils.ZenDaemon.ZenDaemon --+
                                   |
          ZenUtils.ZCmdBase.ZCmdBase --+
                                       |
      xml.sax.handler.ContentHandler --+
                                       |
                                      ImportRM

Known Subclasses:
  - NoLoginImportRM
  - , ZenModel.XmlDataLoader.XmlDataLoader

        Wrapper module to interface between Zope and the Python SAX XML library.
    The xml.sax.parse() calls different routines depending on what it finds.

    A simple example of a valid XML file can be found in the objects.xml file
    for a ZenPack.

     <?xml version="1.0"?>
     <objects>
       <!-- ('', 'zport', 'dmd', 'Devices', 'rrdTemplates', 'HelloWorld') -->
       <object id='/zport/dmd/Devices/rrdTemplates/HelloWorld' module='Products.ZenModel.RRDTemplate' class='RRDTemplate'>
         <property type="text" id="description" mode="w" > This is the glorious description that shows up when we click on our RRD template </property>
       <tomanycont id='datasources'>
         <object id='hello' module='Products.ZenModel.BasicDataSource' class='BasicDataSource'>
           <property select_variable="sourcetypes" type="selection" id="sourcetype" mode="w" > SNMP </property>
           <property type="boolean" id="enabled" mode="w" > True </property>
           <property type="string" id="eventClass" mode="w" > /Cmd/Fail </property>
           <property type="int" id="severity" mode="w" > 3 </property>
           <property type="int" id="cycletime" mode="w" > 300 </property>
           <property type="boolean" id="usessh" mode="w" > False </property>
         <tomanycont id='datapoints'>
           <object id='hello' module='Products.ZenModel.RRDDataPoint' class='RRDDataPoint'>
               <property select_variable="rrdtypes" type="selection" id="rrdtype" mode="w" > GAUGE </property>
               <property type="boolean" id="isrow" mode="w" > True </property>
           </object>
         </tomanycont>
      </object>

     <!--    snip  -->

     </objects>

Instance Methods | [hide private]
__init__(self, noopts=0, app=None, keeproot=False) Initializer | source code
object |
context(self) Return the bottom object in the stack | source code
list |
cleanattrs(self, attrs) Convert all attributes to string values | source code
startElement(self, name, attrs) Function called when the parser finds the starting element in the XML file. | source code
endElement(self, name) Function called when the parser finds the starting element in the XML file. | source code
characters(self, chars) Called by xml.sax.parse() with data found in an element eg <object>my characters stuff</object> | source code
object |
createObject(self, attrs) Create an object and set it into its container | source code
setZendoc(self, obj, value) | source code
setProperty(self, obj, attrs, value) Set the value of a property on an object. | source code
addLink(self, rel, objid) Build list of links to form after all objects have been created make sure that we don't add other side of a bidirectional relation | source code
processLinks(self) Walk through all the links that we saved and link them up | source code
buildOptions(self) Command-line options specific to this command | source code
loadObjectFromXML(self, xmlfile='') This method can be used to load data for the root of Zenoss (default behavior) or it can be used to operate on a specific point in the Zenoss hierarchy (ZODB). | source code
loadDatabase(self) The default behavior of loadObjectFromXML() will be to use the Zope app object, and thus operatate on the whole of Zenoss. | source code
commit(self) Wrapper around the Zope database commit() | source code
Inherited from `ZenUtils.ZCmdBase.ZCmdBase`: `closeAll`, `closedb`, `findDevice`, `getConnection`, `getContext`, `getDataRoot`, `getDmdObj`, `login`, `logout`, `opendb`, `sigTerm`, `syncdb`, `zodbConnect` Inherited from `ZenUtils.ZenDaemon.ZenDaemon`: `audit`, `becomeDaemon`, `becomeWatchdog`, `changeUser`, `convertSocketOption`, `logname`, `niceDoggie`, `openPrivilegedPort`, `setupLogging`, `sighandler_USR1`, `watchdogCycleTime`, `watchdogMaxRestartTime`, `watchdogStartTimeout`, `writePidFile` Inherited from `ZenUtils.ZenDaemon.ZenDaemon` (private): `_sigUSR1_called` Inherited from `ZenUtils.CmdBase.CmdBase`: `buildParser`, `checkLogpath`, `generate_configs`, `generate_xml_configs`, `generate_xml_table`, `getConfigFileDefaults`, `getGlobalConfigFileDefaults`, `getParamatersFromConfig`, `loadConfigFile`, `parseOptions`, `pretty_print_config_comment`, `validateConfigFile` Inherited from `xml.sax.handler.ContentHandler`: `endDocument`, `endElementNS`, `endPrefixMapping`, `ignorableWhitespace`, `processingInstruction`, `setDocumentLocator`, `skippedEntity`, `startDocument`, `startElementNS`, `startPrefixMapping`

Class Variables | [hide private]
| rootpath = `''`
| skipobj = `0`
Inherited from `ZenUtils.ZenDaemon.ZenDaemon`: `pidfile` Inherited from `ZenUtils.CmdBase.CmdBase`: `doesLogging`

Method Details | [hide private]

### __init__(self, noopts=0, app=None, keeproot=False) (Constructor) | source code
Initializer Parameters: `noopts` (boolean) - don't use sys.argv for command-line options `app` (object) - app `keeproot` (boolean) - keeproot Overrides: xml.sax.handler.ContentHandler.__init__

### context(self) | source code
Return the bottom object in the stack Returns: object

### cleanattrs(self, attrs) | source code
Convert all attributes to string values Parameters: `attrs` (list) - (key,val) pairs Returns: list same list, but with all values as strings

### startElement(self, name, attrs) | source code
Function called when the parser finds the starting element in the XML file. Parameters: `name` (string) - name of the element `attrs` (list) - list of (key, value) tuples Overrides: xml.sax.handler.ContentHandler.startElement

### endElement(self, name) | source code
Function called when the parser finds the starting element in the XML file. Parameters: `name` (string) - name of the ending element Overrides: xml.sax.handler.ContentHandler.endElement

### characters(self, chars) | source code
Called by xml.sax.parse() with data found in an element eg <object>my characters stuff</object> Note that this can be called character by character. Parameters: `chars` (string) - chars Overrides: xml.sax.handler.ContentHandler.characters

### createObject(self, attrs) | source code
Create an object and set it into its container Parameters: `attrs` (string) - attrs Returns: object newly created object

### setProperty(self, obj, attrs, value) | source code
Set the value of a property on an object. Parameters: `obj` (string) - obj `attrs` (string) - attrs `value` (string) - value

### addLink(self, rel, objid) | source code
Build list of links to form after all objects have been created make sure that we don't add other side of a bidirectional relation Parameters: `rel` (relation object) - relationship object `objid` (string) - objid

### buildOptions(self) | source code
Command-line options specific to this command Overrides: ZenUtils.CmdBase.CmdBase.buildOptions

### loadObjectFromXML(self, xmlfile='') | source code
This method can be used to load data for the root of Zenoss (default behavior) or it can be used to operate on a specific point in the Zenoss hierarchy (ZODB). Upon loading the XML file to be processed, the content of the XML file is handled by the methods in this class when called by xml.sax.parse(). Reads from a file if xmlfile is specified, otherwise reads from the command-line option --infile. If no files are found from any of these places, read from standard input. Parameters: `xmlfile` (string or file-like object) - Name of XML file to load, or file-like object