def zmanage_importObjects(self, context=None, REQUEST=None): """Import an XML file as the Zenoss objects and properties it represents. """ # XXX # for right now, we're only using this through the web, so a REQUEST is # always define; when we have a use-case for imports via command line, # we will add that code here if not context: context = self.getPhysicalRoot() # get the submitted data filenames = REQUEST.form.get('filenames') urlnames = REQUEST.form.get('urlnames') doDelete = REQUEST.form.get('dodelete') xmlfiles = [] for collection in [filenames, urlnames]: if collection: if isinstance(collection, list): xmlfiles.extend(collection) else: xmlfiles.append(collection) # load the objects into Zenoss im = ImportRM(noopts=True, app=self.getPhysicalRoot()) for xmlfile in xmlfiles: im.loadObjectFromXML(context, xmlfile) if doDelete and xmlfile in filenames: os.unlink(xmlfile) if REQUEST: messaging.IMessageSender(self).sendToBrowser( 'Import Objects', 'Objects imported') return self.callZenScreen(REQUEST)
def zmanage_importObjects(self, context=None, REQUEST=None): """Import an XML file as the Zenoss objects and properties it represents. """ # XXX # for right now, we're only using this through the web, so a REQUEST is # always define; when we have a use-case for imports via command line, # we will add that code here if not context: context = self.getPhysicalRoot() # get the submitted data filenames = REQUEST.form.get("filenames") urlnames = REQUEST.form.get("urlnames") doDelete = REQUEST.form.get("dodelete") xmlfiles = [] for collection in [filenames, urlnames]: if collection: if isinstance(collection, list): xmlfiles.extend(collection) else: xmlfiles.append(collection) # load the objects into Zenoss im = ImportRM(noopts=True, app=self.getPhysicalRoot()) for xmlfile in xmlfiles: im.loadObjectFromXML(context, xmlfile) if doDelete and xmlfile in filenames: os.unlink(xmlfile) if REQUEST: messaging.IMessageSender(self).sendToBrowser("Import Objects", "Objects imported") return self.callZenScreen(REQUEST)
def cutover(self, dmd): dmd.buildMenus({ 'PerformanceMonitor_list': [ { 'action': 'performanceTemplates', 'description': 'Templates', 'id': 'performanceTemplates', 'ordering': 16.0, 'permissions': ('View Device',), }], 'StatusMonitor_list': [ { 'action': 'performanceTemplates', 'description': 'Templates', 'id': 'performanceTemplates', 'ordering': 16.0, 'permissions': ('View Device',), }], }) for c in dmd.Monitors.objectValues(spec='MonitorClass'): c.buildRelations() for c in dmd.Monitors.objectValues(spec='Monitor'): c.buildRelations() dmd.Monitors.buildRelations() if len(dmd.Monitors.rrdTemplates()) == 0: from Products.ZenRelations.ImportRM import ImportRM from Products.ZenUtils.Utils import zenPath template = zenPath('Products/ZenModel/migrate/monitorTemplate.xml') im = ImportRM(noopts=True, app=dmd.zport) im.loadObjectFromXML(xmlfile=template)
def doImport(self): from Products.ZenRelations.ImportRM import ImportRM im = ImportRM(noopts=True, app=self.dmd.zport) f = None try: f = open(self.options.file, 'r') except: print >> sys.stderr, 'Error reading from %s.' % self.options.file sys.exit(2) print "Importing objects from %s." % self.options.file im.loadObjectFromXML(xmlfile=f) from transaction import commit commit() f.close()