コード例 #1
0
ファイル: repos.py プロジェクト: tdukaric/cobbler
    def remove(self, name, with_delete=True, with_sync=True, with_triggers=True, recursive=False, logger=None):
        """
        Remove element named 'name' from the collection
        """
        # NOTE: with_delete isn't currently meaningful for repos
        # but is left in for consistancy in the API.  Unused.
        name = name.lower()
        obj = self.find(name=name)
        if obj is not None:
            if with_delete:
                if with_triggers:
                    utils.run_triggers(self.collection_mgr.api, obj, "/var/lib/cobbler/triggers/delete/repo/pre/*", [], logger)

            self.lock.acquire()
            try:
                del self.listing[name]
            finally:
                self.lock.release()
            self.collection_mgr.serialize_delete(self, obj)

            if with_delete:
                if with_triggers:
                    utils.run_triggers(self.collection_mgr.api, obj, "/var/lib/cobbler/triggers/delete/repo/post/*", [], logger)
                    utils.run_triggers(self.collection_mgr.api, obj, "/var/lib/cobbler/triggers/change/*", [], logger)

                # FIXME: better use config.settings() webdir?
                path = "/var/www/cobbler/repo_mirror/%s" % obj.name
                if os.path.exists("/srv/www/"):
                    path = "/srv/www/cobbler/repo_mirror/%s" % obj.name
                if os.path.exists(path):
                    utils.rmtree(path)

            return

        raise CX(_("cannot delete an object that does not exist: %s") % name)
コード例 #2
0
    def clean_trees(self):
        """
        Delete any previously built pxelinux.cfg tree and virt tree info and then create directories.

        Note: for SELinux reasons, some information goes in ``/tftpboot``, some in ``/var/www/cobbler`` and some must be
        duplicated in both. This is because PXE needs tftp, and automatic installation and Virt operations need http.
        Only the kernel and initrd images are duplicated, which is unfortunate, though SELinux won't let me give them
        two contexts, so symlinks are not a solution. *Otherwise* duplication is minimal.
        """

        # clean out parts of webdir and all of /tftpboot/images and /tftpboot/pxelinux.cfg
        for x in os.listdir(self.settings.webdir):
            path = os.path.join(self.settings.webdir, x)
            if os.path.isfile(path):
                if not x.endswith(".py"):
                    utils.rmfile(path, logger=self.logger)
            if os.path.isdir(path):
                if x not in self.settings.webdir_whitelist:
                    # delete directories that shouldn't exist
                    utils.rmtree(path, logger=self.logger)
                if x in [
                        "autoinstall_templates", "autoinstall_templates_sys",
                        "images", "systems", "distros", "profiles",
                        "repo_profile", "repo_system", "rendered"
                ]:
                    # clean out directory contents
                    utils.rmtree_contents(path, logger=self.logger)
        #
        self.make_tftpboot()
        utils.rmtree_contents(self.pxelinux_dir, logger=self.logger)
        utils.rmtree_contents(self.grub_dir, logger=self.logger)
        utils.rmtree_contents(self.images_dir, logger=self.logger)
        utils.rmtree_contents(self.yaboot_bin_dir, logger=self.logger)
        utils.rmtree_contents(self.yaboot_cfg_dir, logger=self.logger)
        utils.rmtree_contents(self.rendered_dir, logger=self.logger)
コード例 #3
0
    def remove(self, name, with_delete: bool = True, with_sync: bool = True, with_triggers: bool = True,
               recursive: bool = False):
        """
        Remove element named 'name' from the collection

        :raises CX: In case the object does not exist.
        """
        # NOTE: with_delete isn't currently meaningful for repos
        # but is left in for consistancy in the API.  Unused.
        name = name.lower()
        obj = self.find(name=name)
        if obj is None:
            raise CX("cannot delete an object that does not exist: %s" % name)

        if with_delete:
            if with_triggers:
                utils.run_triggers(self.api, obj, "/var/lib/cobbler/triggers/delete/repo/pre/*", [])

        self.lock.acquire()
        try:
            del self.listing[name]
        finally:
            self.lock.release()
        self.collection_mgr.serialize_delete(self, obj)

        if with_delete:
            if with_triggers:
                utils.run_triggers(self.api, obj, "/var/lib/cobbler/triggers/delete/repo/post/*", [])
                utils.run_triggers(self.api, obj, "/var/lib/cobbler/triggers/change/*", [])

            path = os.path.join(self.api.settings().webdir, "repo_mirror", obj.name)
            if os.path.exists(path):
                utils.rmtree(path)
コード例 #4
0
ファイル: collection_repos.py プロジェクト: ASyriy/cobbler
    def remove(self, name, with_delete=True, with_sync=True, with_triggers=True, recursive=False, logger=None):
        """
        Remove element named 'name' from the collection
        """
        # NOTE: with_delete isn't currently meaningful for repos
        # but is left in for consistancy in the API.  Unused.
        name = name.lower()
        obj = self.find(name=name)
        if obj is not None:
            if with_delete:
                if with_triggers:
                    utils.run_triggers(self.collection_mgr.api, obj, "/var/lib/cobbler/triggers/delete/repo/pre/*", [], logger)

            self.lock.acquire()
            try:
                del self.listing[name]
            finally:
                self.lock.release()
            self.collection_mgr.serialize_delete(self, obj)

            if with_delete:
                if with_triggers:
                    utils.run_triggers(self.collection_mgr.api, obj, "/var/lib/cobbler/triggers/delete/repo/post/*", [], logger)
                    utils.run_triggers(self.collection_mgr.api, obj, "/var/lib/cobbler/triggers/change/*", [], logger)

                # FIXME: better use config.settings() webdir?
                path = "/var/www/cobbler/repo_mirror/%s" % obj.name
                if os.path.exists("/srv/www/"):
                    path = "/srv/www/cobbler/repo_mirror/%s" % obj.name
                if os.path.exists(path):
                    utils.rmtree(path)

            return

        raise CX(_("cannot delete an object that does not exist: %s") % name)
コード例 #5
0
 def remove_single_profile(self, name, rebuild_menu=True):
     # delete profiles/$name file in webdir
     utils.rmfile(os.path.join(self.settings.webdir, "profiles", name))
     # delete contents on autoinstalls/$name directory in webdir
     utils.rmtree(os.path.join(self.settings.webdir, "autoinstalls", name))
     if rebuild_menu:
         self.sync.tftpgen.make_pxe_menu()
コード例 #6
0
 def remove_single_distro(self, name):
     bootloc = self.settings.tftpboot_location
     # delete contents of images/$name directory in webdir
     utils.rmtree(os.path.join(self.settings.webdir, "images", name))
     # delete contents of images/$name in tftpboot
     utils.rmtree(os.path.join(bootloc, "images", name))
     # delete potential symlink to tree in webdir/links
     utils.rmfile(os.path.join(self.settings.webdir, "links", name))
コード例 #7
0
ファイル: utils_test.py プロジェクト: openSUSE/cobbler
def test_rmtree():
    # Arrange
    testtree = "/dev/shm/testtree"
    os.mkdir(testtree)

    # Pre assert to check the creation succeeded.
    assert os.path.exists(testtree)

    # Act
    utils.rmtree(testtree)

    # Assert
    assert not os.path.exists(testtree)
コード例 #8
0
    def remove_single_profile(self, name: str, rebuild_menu: bool = True):
        """
        Sync removing a single profile.

        :param name: The name of the profile.
        :param rebuild_menu: Whether to rebuild the grub/... menu or not.
        """
        # delete profiles/$name file in webdir
        utils.rmfile(os.path.join(self.settings.webdir, "profiles", name))
        # delete contents on autoinstalls/$name directory in webdir
        utils.rmtree(os.path.join(self.settings.webdir, "autoinstalls", name))
        if rebuild_menu:
            self.tftpgen.make_pxe_menu()
コード例 #9
0
    def remove_single_distro(self, name):
        """
        Sync removing a single distro.

        :param name: The name of the distribution.
        """
        bootloc = self.settings.tftpboot_location
        # delete contents of images/$name directory in webdir
        utils.rmtree(os.path.join(self.settings.webdir, "images", name))
        # delete contents of images/$name in tftpboot
        utils.rmtree(os.path.join(bootloc, "images", name))
        # delete potential symlink to tree in webdir/links
        utils.rmfile(os.path.join(self.settings.webdir, "links", name))
        # delete potential distro config files
        utils.rmglob_files(
            os.path.join(self.settings.webdir, "distro_mirror", "config"),
            name + "*.repo")
コード例 #10
0
ファイル: distros.py プロジェクト: maduhu/cobbler
    def remove(self,
               name,
               with_delete: bool = True,
               with_sync: bool = True,
               with_triggers: bool = True,
               recursive: bool = False):
        """
        Remove element named 'name' from the collection
        """
        name = name.lower()

        # first see if any Groups use this distro
        if not recursive:
            for v in self.collection_mgr.profiles():
                if v.distro and v.distro.lower() == name:
                    raise CX("removal would orphan profile: %s" % v.name)

        obj = self.find(name=name)

        if obj is not None:
            kernel = obj.kernel
            if recursive:
                kids = obj.get_children()
                for k in kids:
                    self.collection_mgr.api.remove_profile(
                        k.name,
                        recursive=recursive,
                        delete=with_delete,
                        with_triggers=with_triggers)

            if with_delete:
                if with_triggers:
                    utils.run_triggers(
                        self.collection_mgr.api, obj,
                        "/var/lib/cobbler/triggers/delete/distro/pre/*", [])
                if with_sync:
                    lite_sync = litesync.CobblerLiteSync(self.collection_mgr)
                    lite_sync.remove_single_distro(name)
            self.lock.acquire()
            try:
                del self.listing[name]
            finally:
                self.lock.release()

            self.collection_mgr.serialize_delete(self, obj)

            if with_delete:
                if with_triggers:
                    utils.run_triggers(
                        self.collection_mgr.api, obj,
                        "/var/lib/cobbler/triggers/delete/distro/post/*", [])
                    utils.run_triggers(self.collection_mgr.api, obj,
                                       "/var/lib/cobbler/triggers/change/*",
                                       [])

            # look through all mirrored directories and find if any directory is holding
            # this particular distribution's kernel and initrd
            settings = self.collection_mgr.settings()
            possible_storage = glob.glob(settings.webdir + "/distro_mirror/*")
            path = None
            for storage in possible_storage:
                if os.path.dirname(obj.kernel).find(storage) != -1:
                    path = storage
                    continue

            # if we found a mirrored path above, we can delete the mirrored storage /if/
            # no other object is using the same mirrored storage.
            if with_delete and path is not None and os.path.exists(
                    path) and kernel.find(settings.webdir) != -1:
                # this distro was originally imported so we know we can clean up the associated
                # storage as long as nothing else is also using this storage.
                found = False
                distros = self.api.distros()
                for d in distros:
                    if d.kernel.find(path) != -1:
                        found = True
                if not found:
                    utils.rmtree(path)
コード例 #11
0
    def remove(self, name, with_delete=True, with_sync=True, with_triggers=True, recursive=False, logger=None):
        """
        Remove element named 'name' from the collection
        """
        name = name.lower()

        # first see if any Groups use this distro
        if not recursive:
            for v in self.config.profiles():
                if v.distro and v.distro.lower() == name:
                    raise CX(_("removal would orphan profile: %s") % v.name)

        obj = self.find(name=name)

        if obj is not None:
            kernel = obj.kernel
            if recursive:
                kids = obj.get_children()
                for k in kids:
                    self.config.api.remove_profile(k.name, recursive=recursive, delete=with_delete, with_triggers=with_triggers, logger=logger)

            if with_delete:
                if with_triggers:
                    utils.run_triggers(self.config.api, obj, "/var/lib/cobbler/triggers/delete/distro/pre/*", [], logger)
                if with_sync:
                    lite_sync = action_litesync.BootLiteSync(self.config, logger=logger)
                    lite_sync.remove_single_distro(name)
            self.lock.acquire()
            try:
                del self.listing[name]
            finally:
                self.lock.release()

            self.config.serialize_delete(self, obj)

            if with_delete:
                if with_triggers:
                    utils.run_triggers(self.config.api, obj, "/var/lib/cobbler/triggers/delete/distro/post/*", [], logger)
                    utils.run_triggers(self.config.api, obj, "/var/lib/cobbler/triggers/change/*", [], logger)


            # look through all mirrored directories and find if any directory is holding
            # this particular distribution's kernel and initrd
            settings = self.config.settings()
            possible_storage = glob.glob(settings.webdir + "/ks_mirror/*")
            path = None
            for storage in possible_storage:
                if os.path.dirname(obj.kernel).find(storage) != -1:
                    path = storage
                    continue

            # if we found a mirrored path above, we can delete the mirrored storage /if/
            # no other object is using the same mirrored storage.
            if with_delete and path is not None and os.path.exists(path) and kernel.find(settings.webdir) != -1:
                # this distro was originally imported so we know we can clean up the associated
                # storage as long as nothing else is also using this storage.
                found = False
                distros = self.api.distros()
                for d in distros:
                    if d.kernel.find(path) != -1:
                        found = True
                if not found:
                    utils.rmtree(path)

        return True