Ejemplo n.º 1
0
    def addNode(self, contextUid='', id='', type=''):
        """
        Add an organizer or new blank MIB.

        @type  contextUid: string
        @param contextUid: Context to attach new node
        @type  id: string
        @param id: Id of the new orgainzer or blank MIB
        @type  type: string
        @param type: Type of new node. Can be 'organizer' or 'MIB'
        @rtype:   DirectResponse
        @return:  B{Properties}:
           - tree: ([dictionary]) Object representing the new tree
        """
        # GAH!  JS passes back a keyword of 'type'
        nodeType = type
        try:
            if nodeType == 'organizer':
                uid = contextUid + '/' + id
                maoUid = uid.replace('/zport/dmd', '')
                self.context.dmd.Mibs.manage_addOrganizer(maoUid)
                self.context.dmd.restrictedTraverse(uid)
                audit('UI.Organizer.Add', uid)
            elif nodeType == 'MIB':
                container = self.context.dmd.restrictedTraverse(contextUid)
                container.manage_addMibModule(id)
                audit('UI.Mib.Add', contextUid + '/' + id)
            else:
                return DirectResponse.fail('Invalid node type "%s"' % nodeType)
            return DirectResponse.succeed(tree=self.getTree())
        except Exception as ex:
            log.exception(ex)
            return DirectResponse.exception(
                ex, message="Failed to create '{}'".format(id))
Ejemplo n.º 2
0
    def addNode(self, contextUid='', id='', type=''):
        """
        Add an organizer or new blank MIB.

        @type  contextUid: string
        @param contextUid: Context to attach new node
        @type  id: string
        @param id: Id of the new orgainzer or blank MIB
        @type  type: string
        @param type: Type of new node. Can be 'organizer' or 'MIB'
        @rtype:   DirectResponse
        @return:  B{Properties}:
           - tree: ([dictionary]) Object representing the new tree
        """
        # GAH!  JS passes back a keyword of 'type'
        nodeType = type
        if nodeType not in ['organizer', 'MIB']:
            return DirectResponse.fail('Not creating "%s"' % nodeType)

        try:
            if nodeType == 'organizer':
                uid = contextUid + '/' + id
                maoUid = uid.replace('/zport/dmd', '')
                self.context.dmd.Mibs.manage_addOrganizer(maoUid)
                self.context.dmd.restrictedTraverse(uid)
                audit('UI.Organizer.Add', uid)
            else:
                container = self.context.dmd.restrictedTraverse(contextUid)
                container.manage_addMibModule(id)
                audit('UI.Mib.Add', contextUid + '/' + id)

            return DirectResponse.succeed(tree=self.getTree())
        except Exception, e:
            return DirectResponse.exception(e)
Ejemplo n.º 3
0
    def addNode(self, newSubnet, contextUid):
        """
        Add a new subnet.

        @type  newSubnet: string
        @param newSubnet: New subnet to add
        @type  contextUid: string
        @param contextUid: Unique identifier of the network parent of the new subnet
        @rtype:   DirectResponse
        @return:  B{Properties}:
           - newNode: (dictionary) An object representing the new subnet node
        """
        # If the user doesn't include a mask, reject the request.
        if '/' not in newSubnet:
            response = DirectResponse.fail('You must include a subnet mask.')
        else:
            try:
                contextUid = getUtility(IVirtualRoot).strip_virtual_root(
                    contextUid)
                netip, netmask = newSubnet.split('/')
                netmask = int(netmask)
                foundSubnet = self.api.findSubnet(netip, netmask, contextUid)

                if foundSubnet is not None:
                    response = DirectResponse.fail(
                        'Did not add duplicate subnet: %s (%s/%s)' %
                        (newSubnet, foundSubnet.id, foundSubnet.netmask))
                else:
                    newNet = self.api.addSubnet(newSubnet, contextUid)
                    node = ITreeNode(newNet)
                    audit('UI.Network.AddSubnet', contextUid, subnet=newSubnet)
                    response = DirectResponse.succeed(
                        newNode=Zuul.marshal(node))

            except IpAddressError as error:
                response = DirectResponse.exception(error,
                                                    'Error adding subnet.')

            except Exception as error:
                log.exception("Error adding subnet.")
                response = DirectResponse.exception(error,
                                                    'Error adding subnet.')

        return response
Ejemplo n.º 4
0
 def gzip_b64(self, string):
     """
     gzip an arbitrary string, base64 encode it, and return it
     """
     try:
         compressed = base64.urlsafe_b64encode(zlib.compress(string))
     except Exception as e:
         log.exception(e)
         return DirectResponse.exception(e, 'Unable to compress data')
     return DirectResponse.succeed(data=Zuul.marshal({'data': compressed}))
Ejemplo n.º 5
0
    def addNode(self, newSubnet, contextUid):
        """
        Add a new subnet.

        @type  newSubnet: string
        @param newSubnet: New subnet to add
        @type  contextUid: string
        @param contextUid: Unique identifier of the network parent of the new subnet
        @rtype:   DirectResponse
        @return:  B{Properties}:
           - newNode: (dictionary) An object representing the new subnet node
        """
        # If the user doesn't include a mask, reject the request.
        if '/' not in newSubnet:
            response = DirectResponse.fail('You must include a subnet mask.')
        else:
            try:
                contextUid = getUtility(IVirtualRoot).strip_virtual_root(contextUid)
                netip, netmask = newSubnet.split('/')
                netmask = int(netmask)
                foundSubnet = self.api.findSubnet(netip, netmask, contextUid)

                if foundSubnet is not None:
                    response = DirectResponse.fail('Did not add duplicate subnet: %s (%s/%s)' %
                                                   (newSubnet, foundSubnet.id, foundSubnet.netmask))
                else:
                    newNet = self.api.addSubnet(newSubnet, contextUid)
                    node = ITreeNode(newNet)
                    audit('UI.Network.AddSubnet', contextUid, subnet=newSubnet)
                    response = DirectResponse.succeed(newNode=Zuul.marshal(node))

            except IpAddressError as error:
                response = DirectResponse.exception(error, 'Error adding subnet.')

            except Exception as error:
                log.exception("Error adding subnet.")
                response = DirectResponse.exception(error, 'Error adding subnet.')

        return response
Ejemplo n.º 6
0
 def getGraphLink(self, data):
     """
     Make hash from graph config, and save this config in Redis using
     the hash for the key
     """
     try:
         dataHash = hashlib.sha224(data).hexdigest()
         if not self.redis_tool.push_to_redis(dataHash, data):
             dataHash = None
     except Exception as e:
         log.exception(e)
         return DirectResponse.exception(e, 'Unable to process graph data')
     return DirectResponse.succeed(data=Zuul.marshal({'data': dataHash}))
Ejemplo n.º 7
0
 def getGraphLink(self, data):
     """
     Make hash from graph config, and save this config in Redis using
     the hash for the key
     """
     try:
         dataHash = hashlib.sha224(data).hexdigest()
         if not self.redis_tool.push_to_redis(dataHash, data):
             dataHash = None
     except Exception as e:
         log.exception(e)
         return DirectResponse.exception(e, 'Unable to process graph data')
     return DirectResponse.succeed(data=Zuul.marshal({'data': dataHash}))
Ejemplo n.º 8
0
 def gunzip_b64(self, string):
     """
     Base 64 decode a string, then gunzip it and return the result as JSON.
     The input to this method should be gzipped, base 64 encoded JSON. Base
     64 encoded strings are allowed to have up to 2 '='s of padding. The
     zenoss Ext router eats these, so there is some logic to try padding
     them back into the string should initial decoding fail.
     """
     data = ''
     for pad in ('', '=', '=='):
         try:
             data = zlib.decompress(base64.urlsafe_b64decode(string + pad))
             break
         except Exception as e:
             if pad == '==':
                 log.exception(e)
                 return DirectResponse.exception(e, 'Unable to decompress data')
     return DirectResponse.succeed(data=Zuul.marshal({'data': data}))
Ejemplo n.º 9
0
 def gunzip_b64(self, string):
     """
     Base 64 decode a string, then gunzip it and return the result as JSON.
     The input to this method should be gzipped, base 64 encoded JSON. Base
     64 encoded strings are allowed to have up to 2 '='s of padding. The
     zenoss Ext router eats these, so there is some logic to try padding
     them back into the string should initial decoding fail.
     """
     data = ''
     for pad in ('', '=', '=='):
         try:
             data = zlib.decompress(base64.urlsafe_b64decode(string + pad))
             break
         except Exception as e:
             if pad == '==':
                 log.exception(e)
                 return DirectResponse.exception(
                     e, 'Unable to decompress data')
     return DirectResponse.succeed(data=Zuul.marshal({'data': data}))