def handle(self, namespace):
     hostobj=getHost(namespace.srchost[0])
     if not hostobj:
         raise HostinfoException("There is no host called %s" % namespace.srchost[0])
     dsthostobj=getHost(namespace.dsthost[0])
     if dsthostobj:
         raise HostinfoException("A host already exists with the name %s" % namespace.dsthost[0])
     hostobj.hostname=namespace.dsthost[0]
     hostobj.save()
     return None,0
    def handle(self, namespace):
        host=namespace.host.lower()
        h=getHost(host)
        if not h:
            raise HostinfoException("Host %s doesn't exist" % host)

        if not namespace.lethal:
            raise HostinfoException("Didn't do delete as no --lethal specified")

        # Delete aliases
        aliases=HostAlias.objects.filter(hostid=h.id)
        for alias in aliases:
            if namespace.lethal:
                alias.delete()

        # Delete key/values
        kvs=KeyValue.objects.filter(hostid=h.id)    	
        for kv in kvs:
            if namespace.lethal:
                kv.delete(readonlychange=True)

        # Delete the host
        if namespace.lethal:
            h.delete()
        return None,0
 def handle(self, namespace):
     m=re.match("(?P<key>\w+)=(?P<value>.+)", namespace.keyvalue)
     if m:
         key=m.group('key').lower()
         value=m.group('value').lower()
     else:
         key=namespace.keyvalue.lower()
         value=''
     keyid=checkKey(key)
     for host in namespace.host:
         hostid=getHost(host)
         if not hostid:
             raise HostinfoException("Unknown host: %s" % host)
         if value:
             kvlist=KeyValue.objects.filter(hostid=hostid, keyid=keyid, value=value)
         else:
             kvlist=KeyValue.objects.filter(hostid=hostid, keyid=keyid)
         if not kvlist:
             raise HostinfoException("Host %s doesn't have key %s" % (host, key))
         else:
             for kv in kvlist:
                 try:
                     kv.delete(readonlychange=namespace.readonlyupdate)
                 except ReadonlyValueException:
                     raise HostinfoException("Cannot delete a readonly value")
     return None,0
예제 #4
0
    def handle(self, namespace):
        srchostobj=getHost(namespace.srchost[0])
        if not srchostobj:
            raise HostinfoException("Source host %s doesn't exist" % namespace.srchost[0])
        dsthostobj=getHost(namespace.dsthost[0])
        if not dsthostobj:
            raise HostinfoException("Destination host %s doesn't exist" % namespace.dsthost[0])

        ok=True

        # Get all the key/values from the source host and see if they exist on the dest host
        srckeylist=KeyValue.objects.filter(hostid__hostname=namespace.srchost[0])
        for srckey in srckeylist:
            ok=self.transferKey(srckey, srchostobj, dsthostobj)
            if not ok:
                break

        if ok and not namespace.kidding:
            error=srchostobj.delete()
        return None,0
예제 #5
0
 def checkHost(self, host):
     h=getHost(host)
     if h:
         return True
     return False