'Allows an object "ref" to be given a newname without affecting the rest
of the object tree.'

def rename(self, ref, newname, with_sync=True, with_triggers=True, logger=None):

    if (newname == ref.name):
        return
    oldname = ref.name
    newref = ref.make_clone()
    newref.set_name(newname)
    self.add(newref, with_triggers=with_triggers, save=True)
    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)
    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)
    if (ref.COLLECTION_TYPE == 'distro'):
        path = utils.find_distro_path(self.api.settings(), ref)
        utils.link_distro(self.api.settings(), newref)
        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)
            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)
    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)))
    self.remove(oldname, with_delete=True, with_triggers=with_triggers)
    return
