cobbler_sync_master

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I've attached a small script that we use to sync multiple subcobbler instances to a single master. We currently use an out of band copy mechanism to get /var/www/cobbler/ks_mirror onto all our cobbler server, but we had no way of getting cobbler to know about the distro and the attached profiles. This script will add both, without syncing any data and create the necessary symlinks in /var/www/cobbler/links.

Why should you use it?
We currently use it for network segmentation purposes. We have several subcobblers that serve a single part of our network and we don't want to have to import distros in each place. Instead we use snap mirroring to get /var/www/cobbler/ks_mirror out and then run cobbler_sync_master to get cobbler to create the distros and profiles in its configuration files. This can also be used to distribute the load of a single network across multiple cobblers mounting ks_mirror off the same nfs share.

How do you use it?
Easy! You use cobbler import to get the distro into the master server. Then when the ks_mirror files arrive on the subcobblers, you run 'cobbler_sync_master --server master.example.com'. The script will add any distros that it sees on the master that are not on the subcobbler and that the kernel has arrived for.

If someone else finds this script useful I'll probably clean it up a bit and we can throw it in scripts/. If more than a few people find this useful I'd be willing to port it into cobbler core.

- --
Scott Henson
Red Hat Production Operations Release Engineer
WVU Alum BSAE/BSME
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org

iD8DBQFID5b/cQOfHbe3DKARAhGoAKC3J9S3csZHEaPhcX7it/ObUwK1lACg7NGG
LOEV4jWYsW6KF3vSJ2Gh8ic=
=Bb3Q
-----END PGP SIGNATURE-----

#!/usr/bin/python
"""
Sync Cobbler with Master

Copyright 2008, Red Hat, Inc
Scott Henson <shenson@xxxxxxxxxx>

This software may be freely redistributed under the terms of the GNU
general public license.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
"""

from cobbler import api
from optparse import OptionParser
import xmlrpclib, os

def link_distro(settings, distro):
    # find the tree location
    dirname = os.path.dirname(distro.kernel)
    tokens = dirname.split("/")
    tokens = tokens[:-2]
    base = "/".join(tokens)
    dest_link = os.path.join(settings.webdir, "links", distro.name)

    # create the links directory only if we are mirroring because with
    # SELinux Apache can't symlink to NFS (without some doing)

    if not os.path.exists(dest_link):
        try:
            os.symlink(base, dest_link)
        except:
            # this shouldn't happen but I've seen it ... debug ...
            print _("- symlink creation failed: %(base)s, %(dest)s") % { "base" : base, "dest" : dest_link }
                
       
def add_distro(cobbler, distro):
    #Register the distro
    if os.path.exists(distro['kernel']):
        new_distro = cobbler.new_distro()
        new_distro.from_datastruct(distro)
        #create the symlinks
        link_distro(cobbler.settings(), new_distro)
        #Add the distro permanently
        cobbler.distros().add(new_distro, save=True)
        print 'Added distro %s. Creating Links.' % distro['name']
        return True
    else:
        print 'Distro %s not here yet.' % distro['name']
        return False

def add_profile(cobbler, profile):
    #Register the new profile
    new_profile = cobbler.new_profile()
    new_profile.from_datastruct(profile)
    cobbler.profiles().add(new_profile, save=True)
    print 'Added profile %s.' % profile['name']

def check_profile(cobbler, profile):
    profiles = cobbler.profiles().to_datastruct()
    if profile not in profiles:
        for distro in cobbler.distros().to_datastruct():
            if distro['name'] == profile['name']:
                return True
    return False
        
    
def main(uri):
    remote =  xmlrpclib.Server(uri)

    cobbler = api.BootAPI()
    settings = cobbler.settings()

    local_profiles = cobbler.profiles()
    local_distros = cobbler.distros()

    remote_profiles = remote.get_profiles()
    remote_distros = remote.get_distros()
    needsync = False
    for distro in remote_distros:
        if distro not in local_distros.to_datastruct():
            print 'Found distro %s.' % distro['name']
            if add_distro(cobbler, distro) or needsync:
                needsync = True
    if needsync:
        cobbler.sync()
        needsync = False
            
    for profile in remote_profiles:
        if check_profile(cobbler, profile):
            print 'Found profile %s.' % distro['name']
            add_profile(cobbler, profile)
            needsync = True
    if needsync:
        cobbler.sync()
        
if __name__=='__main__':
    parser = OptionParser()
    parser.add_option('-s', '--server', dest='server',
                      help='Server you wish to user',
                      default=None, type='string')
    (opts, args) = parser.parse_args()
                     
    if opts.server is None:
        parser.error('You must provide a server')
    uri = 'http://%s/cobbler_api' % opts.server
    main(uri)

    
_______________________________________________
et-mgmt-tools mailing list
et-mgmt-tools@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/et-mgmt-tools

[Index of Archives]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux