def handleHost(self,hosttree): """ We can't load dates (created/modified) of elements because these are set automatically by Django <host docpage="None" origin="explorer2hostinfo.py by w86765" modified="2008-03-20" created="2008-03-20" > <hostname>zone_161.117.101.190</hostname> <data> <confitem key="os" origin="w86765" modified="2008-08-19" created="2008-08-19">solaris</confitem> <confitem key="type" origin="explorer2hostinfo.py by w86765" modified="2008-07-02" created="2008-03-20">virtual</confitem> <confitem key="virtualmaster" origin="explorer2hostinfo.py by w86765" modified="2008-03-20" created="2008-03-20">idmsvrqv01d</confitem> <confitem key="zonename" origin="explorer2hostinfo.py by w86765" modified="2008-03-20" created="2008-03-20">app04</confitem> </data> </host> """ hostname=hosttree.find('hostname').text verbose(hostname) try: host=Host.objects.get(hostname=hostname) except ObjectDoesNotExist: host=Host(hostname=hostname, docpage=hosttree.attrib.get('docpage', None), origin=hosttree.attrib.get('origin',None)) verbose("New host %s" % `host`) if not kiddingFlag: host.save() for data in hosttree.find('data').findall('confitem'): key=data.attrib['key'] if 'origin' in data.attrib: origin=data.attrib['origin'] else: origin='unknown' value=data.text try: self.handleValue(host, key, origin, value) except RestrictedValueException: sys.stderr.write("Trying to change a restricted value: %s:%s=%s - ignoring\n" % (hostname, key, value))
def handle(self, namespace): origin=getOrigin(namespace.origin) for host in namespace.host: host=host.lower() if self.checkHost(host): raise HostinfoException("Host %s already exists" % host) if host[0] in ('-',): raise HostinfoException("Host begins with a forbidden character ('%s') - not adding" % host[0]) hobj=Host(hostname=host, origin=origin) hobj.save() return None,0