mwallraf / ZenPacks.TwoNMS.Rancid

Zenoss ZenPack to integrate Rancid
http://mwallraf.github.io/ZenPacks.TwoNMS.Rancid/
2 stars 1 forks source link

Zenoss 3.2.1 compatibility #6

Open htolic opened 9 years ago

htolic commented 9 years ago

This one should come as pull request but my rig for where I have Zenoss 3.2.1 installed is pretty messed up. Nevertheless here goes the code I had to add to make this fine piece of ZenPack work with Zenoss 3.2.1.

I used code from master branch as of July 10th, 2015.

First of all I had troubles installing the ZenPack. Before you do "zenpack --link --install" modify the __init__.py in Rancid folder. Somewhere within class ZenPack(ZenPackBase) add these two functions: (The functions are taken from Zenoss Core 4.2.5 code.)

    def installFile(self, relativePath, relativeDestPath=None,
                    overwriteIfExists=True, symLink=False):
        """
        Install a file from this zenpack to ZENHOME upon installation.
        By default, relativePath is for the zenpack and its ZENHOME destination.
        Returns True if installed, False/Exception otherwise.

        Example: self.installFile('etc/myzenpack.data')
        """
        srcPath = self.path(relativePath)
        destPath = zenPath(relativePath) if relativeDestPath is None \
                                         else zenPath(relativeDestPath)

        if not overwriteIfExists and os.path.lexists(destPath):
            return False
        if not os.path.exists(srcPath):
            raise ZenPackException('Missing source file %s' % srcPath)
        if os.path.lexists(destPath):
            os.remove(destPath)
            # If the file is open for edit in Unix then it'll still exist
            # until it's closed, which means we can't overwrite it.
            if os.path.lexists(destPath):
                raise ZenPackException('Failed to remove file %s' % destPath)
        if symLink:
            os.symlink(srcPath, destPath)
        else:
            shutil.copy2(srcPath, destPath)
        if not os.path.lexists(destPath):
            raise ZenPackException('Failed to write file %s' % destPath)
        return True

    def removeFile(self, relativePath, mustSucceed=False):
        """
        Remove a file installed in ZENHOME by this zenpack, if it exists.

        Example: self.removeFile('etc/myzenpack.data')
        """
        destPath = zenPath(relativePath)
        if os.path.lexists(destPath):
            os.remove(destPath)
            if mustSucceed and os.path.lexists(destPath):
                raise ZenPackException('Failed to remove file %s' % destPath)

Furthermore the Components view did not work. So I had to edit the browser/resources/js/RancidRevision.js and add a hidden column to a columns config:

            {
                id: 'name',
                dataIndex: 'Name',
                header: _t('Name'),
                sortable: true,
                hidden: true,
            }

That had me back to the road. If you have had any issues using this ZenPack on Zenoss 3.2.1 and want to contribute, write here please. Or event better do a pull request. If so, be kind and include my changes too :)

mwallraf commented 9 years ago

Hi, Thank you very much for this. As soon as I've been able to try it out I will add it to the code and create a distribution for 3.2.1.