Пример #1
0
 def link_distros(self):
     """
     Link a distro from its location into the web directory to make it available for usage.
     """
     for distro in self.api.distros():
         self.logger.debug("Linking Distro %s" % distro.name)
         utils.link_distro(self.settings, distro)
Пример #2
0
def test_link_distro():
    # Arrange
    test_api = CobblerAPI()
    test_distro = Distro(test_api)

    # Act
    utils.link_distro(Settings(), test_distro)

    # Assert
    assert False
Пример #3
0
def test_link_distro():
    # Arrange
    test_api = CobblerAPI()
    test_manager = CollectionManager(test_api)
    test_distro = Distro(test_manager)

    # Act
    utils.link_distro(test_manager.settings(), test_distro)

    # Assert
    assert False
Пример #4
0
    def rename(self,
               ref: item_base.Item,
               newname,
               with_sync: bool = True,
               with_triggers: bool = True):
        """
        Allows an object "ref" to be given a new name without affecting the rest of the object tree.

        :param ref: The reference to the object which should be renamed.
        :param newname: The new name for the object.
        :param with_sync: If a sync should be triggered when the object is renamed.
        :param with_triggers: If triggers should be run when the object is renamed.
        """
        # Nothing to do when it is the same name
        if newname == ref.name:
            return

        # make a copy of the object, but give it a new name.
        oldname = ref.name
        newref = ref.make_clone()
        newref.name = newname

        self.add(newref, with_triggers=with_triggers, save=True)

        # for mgmt classes, update all objects that use it
        if ref.COLLECTION_TYPE == "mgmtclass":
            for what in ["distro", "profile", "system"]:
                items = self.api.find_items(what, {"mgmt_classes": oldname})
                for item in items:
                    for i in range(0, len(item.mgmt_classes)):
                        if item.mgmt_classes[i] == oldname:
                            item.mgmt_classes[i] = newname
                    self.api.add_item(what, item, save=True)

        # for menus, update all objects that use it
        if ref.COLLECTION_TYPE == "menu":
            for what in ["profile", "image"]:
                items = self.api.find_items(what, {"menu": oldname})
                for item in items:
                    item.menu = newname
                    self.api.add_item(what, item, save=True)

        # for a repo, rename the mirror directory
        if ref.COLLECTION_TYPE == "repo":
            path = "/var/www/cobbler/repo_mirror/%s" % ref.name
            if os.path.exists(path):
                newpath = "/var/www/cobbler/repo_mirror/%s" % newref.name
                os.renames(path, newpath)

        # for a distro, rename the mirror and references to it
        if ref.COLLECTION_TYPE == 'distro':
            path = utils.find_distro_path(self.api.settings(), ref)

            # create a symlink for the new distro name
            utils.link_distro(self.api.settings(), newref)

            # Test to see if the distro path is based directly on the name of the distro. If it is, things need to
            # updated accordingly.
            if os.path.exists(
                    path
            ) and path == "/var/www/cobbler/distro_mirror/%s" % ref.name:
                newpath = "/var/www/cobbler/distro_mirror/%s" % newref.name
                os.renames(path, newpath)

                # update any reference to this path ...
                distros = self.api.distros()
                for d in distros:
                    if d.kernel.find(path) == 0:
                        d.kernel = d.kernel.replace(path, newpath)
                        d.initrd = d.initrd.replace(path, newpath)
                        self.collection_mgr.serialize_item(self, d)

        # Now descend to any direct ancestors and point them at the new object allowing the original object to be
        # removed without orphanage. Direct ancestors will either be profiles or systems. Note that we do have to
        # care as setting the parent is only really meaningful for subprofiles. We ideally want a more generic parent
        # setter.
        kids = ref.get_children()
        for k in kids:
            if self.api.find_profile(name=k) is not None:
                k = self.api.find_profile(name=k)
                if k.parent != "":
                    k.parent = newname
                else:
                    k.distro = newname
                self.api.profiles().add(k,
                                        save=True,
                                        with_sync=with_sync,
                                        with_triggers=with_triggers)
            elif self.api.find_menu(name=k) is not None:
                k = self.api.find_menu(name=k)
                k.parent = newname
                self.api.menus().add(k,
                                     save=True,
                                     with_sync=with_sync,
                                     with_triggers=with_triggers)
            elif self.api.find_system(name=k) is not None:
                k = self.api.find_system(name=k)
                k.profile = newname
                self.api.systems().add(k,
                                       save=True,
                                       with_sync=with_sync,
                                       with_triggers=with_triggers)
            else:
                raise CX(
                    "Internal error, unknown child type for child \"%s\"!" % k)

        # now delete the old version
        self.remove(oldname, with_delete=True, with_triggers=with_triggers)
        return
Пример #5
0
    def link_distros(self):

        for distro in self.api.distros():
            self.logger.debug("Linking Distro %s" % distro.name)
            utils.link_distro(self.settings, distro)
Пример #6
0
    def rename(self,
               ref,
               newname,
               with_sync=True,
               with_triggers=True,
               logger=None):
        """
        Allows an object "ref" to be given a newname without affecting the rest
        of the object tree.
        """
        # Nothing to do when it is the same name
        if newname == ref.name:
            return

        # make a copy of the object, but give it a new name.
        oldname = ref.name
        newref = ref.make_clone()
        newref.set_name(newname)

        self.add(newref, with_triggers=with_triggers, save=True)

        # for mgmt classes, update all objects that use it
        if ref.COLLECTION_TYPE == "mgmtclass":
            for what in ["distro", "profile", "system"]:
                items = self.api.find_items(what, {"mgmt_classes": oldname})
                for item in items:
                    for i in range(0, len(item.mgmt_classes)):
                        if item.mgmt_classes[i] == oldname:
                            item.mgmt_classes[i] = newname
                    self.api.add_item(what, item, save=True)

        # for a repo, rename the mirror directory
        if ref.COLLECTION_TYPE == "repo":
            path = "/var/www/cobbler/repo_mirror/%s" % ref.name
            if os.path.exists(path):
                newpath = "/var/www/cobbler/repo_mirror/%s" % newref.name
                os.renames(path, newpath)

        # for a distro, rename the mirror and references to it
        if ref.COLLECTION_TYPE == 'distro':
            path = utils.find_distro_path(self.api.settings(), ref)

            # create a symlink for the new distro name
            utils.link_distro(self.api.settings(), newref)

            # test to see if the distro path is based directly
            # on the name of the distro. If it is, things need
            # to updated accordingly
            if os.path.exists(
                    path
            ) and path == "/var/www/cobbler/distro_mirror/%s" % ref.name:
                newpath = "/var/www/cobbler/distro_mirror/%s" % newref.name
                os.renames(path, newpath)

                # update any reference to this path ...
                distros = self.api.distros()
                for d in distros:
                    if d.kernel.find(path) == 0:
                        d.set_kernel(d.kernel.replace(path, newpath))
                        d.set_initrd(d.initrd.replace(path, newpath))
                        self.collection_mgr.serialize_item(self, d)

        # now descend to any direct ancestors and point them at the new object allowing
        # the original object to be removed without orphanage.  Direct ancestors
        # will either be profiles or systems.  Note that we do have to care as
        # set_parent is only really meaningful for subprofiles. We ideally want a more
        # generic set_parent.
        kids = ref.get_children()
        for k in kids:
            if k.COLLECTION_TYPE == "distro":
                raise CX(
                    _("internal error, not expected to have distro child objects"
                      ))
            elif k.COLLECTION_TYPE == "profile":
                if k.parent != "":
                    k.set_parent(newname)
                else:
                    k.set_distro(newname)
                self.api.profiles().add(k,
                                        save=True,
                                        with_sync=with_sync,
                                        with_triggers=with_triggers)
            elif k.COLLECTION_TYPE == "system":
                k.set_profile(newname)
                self.api.systems().add(k,
                                       save=True,
                                       with_sync=with_sync,
                                       with_triggers=with_triggers)
            elif k.COLLECTION_TYPE == "repo":
                raise CX(
                    _("internal error, not expected to have repo child objects"
                      ))
            else:
                raise CX(
                    _("internal error, unknown child type (%s), cannot finish rename"
                      % k.COLLECTION_TYPE))

        # now delete the old version
        self.remove(oldname, with_delete=True, with_triggers=with_triggers)
        return