Пример #1
0
 def handle(self, namespace):
     desc=""
     if namespace.keytype:
         keytype=namespace.keytype
         desc=" ".join(namespace.key[1:])
     else:
         if len(namespace.key)==1:
             keytype='single'
         else:
             keytype=namespace.key[1]
         desc=" ".join(namespace.key[2:])
     key=namespace.key[0].lower()
     keytype=self.validateKeytype(keytype)
     try:
         AllowedKey.objects.get(key=key)
     except:
         newak=AllowedKey(key=key, validtype=keytype, desc=desc, restrictedFlag=namespace.restricted, readonlyFlag=namespace.readonly, auditFlag=namespace.audit)
         newak.save()
     else:
         raise HostinfoException("Key already exists with that name: %s" % key)
     return None,0
Пример #2
0
    def handleKey(self,key):
        """
          <key>
            <name>appsla</name>
            <type>single</type>
            <readonlyFlag>1</readonlyFlag>
            <auditFlag>1</auditFlag>
            <restricted>
                <value>Foo</value>
            </restricted>
            <docpage>None</docpage>
            <desc>Application SLA</desc>
          </key>
        """

        name=''
        keytype=''
        restrictedKid=None
        restrictedFlag=False
        readonlyFlag=False
        auditFlag=True
        docpage=''
        desc=''
        for kid in key.getchildren():
            if kid.tag=='name':
                name=kid.text
            if kid.tag=='type':
                keytype=self.validateKeytype(kid.text)
            if kid.tag=='restricted':
                restrictedKid=kid
                restrictedFlag=True
            if kid.tag=='readonlyFlag':
                readonlyFlag=(kid.text=='1')
            if kid.tag=='auditFlag':
                auditFlag=(kid.text=='0')
            if kid.tag=='docpage':
                if kid.text:
                    docpage=kid.text.strip()
                if docpage=='None':
                    docpage=None
            if kid.tag=='desc':
                if kid.text:
                    desc=kid.text.strip()
        if not name:
            raise HostinfoException("No name specified for key")

        try:
            ak=AllowedKey.objects.get(key=name)
        except ObjectDoesNotExist:
            ak=AllowedKey(key=name, validtype=keytype, restricted=restricted, readonlyFlag=readonlyFlag, auditFlag=auditFlag, docpage=docpage, desc=desc)
            verbose("New key %s" % `ak`)
            if not kiddingFlag:
                ak.save()
        else:
            change=False
            if ak.validtype!=keytype:
                verbose("Changing %s: keytype from %s to %s" % (name, ak.get_validtype_display(ak.validtype), ak.get_validtype_display(keytype)))
                ak.validtype=keytype
                change=True
            if ak.restrictedFlag!=restrictedFlag:
                verbose("Changing %s: restrictedFlag from %s to %s" % (name, ak.restrictedFlag, restrictedFlag))
                ak.restrictedFlag=restrictedFlag
                change=True
            if ak.readonlyFlag!=readonlyFlag:
                verbose("Changing %s: readonlyFlag from %s to %s" % (name, ak.readonlyFlag, readonlyFlag))
                ak.readonlyFlag=readonlyFlag
                change=True
            if ak.auditFlag!=auditFlag:
                verbose("Changing %s: auditFlag from %s to %s" % (name, ak.auditFlag, auditFlag))
                ak.auditFlag=auditFlag
                change=True
            if ak.docpage!=docpage:
                verbose("Changing %s: docpage from '%s' to '%s'" % (name, ak.docpage, docpage))
                ak.docpage=docpage
                change=True
            if ak.desc!=desc:
                verbose("Changing %s: desc from '%s' to '%s'" % (name, ak.desc, desc))
                ak.desc=desc
                change=True
            if change and not kiddingFlag:
                ak.save()

        if restrictedKid:
            self.handleRestrictedKey(restrictedKid, ak)