Beispiel #1
0
def main():
    cobbler = CobblerAPI(
        url,
        user,
        password,
    )
    ret = cobbler.add_system(hostname='test',
                             ip_add='#',
                             mac_add='#',
                             profile='CentOS6.3-x86_64')
    print ret
Beispiel #2
0
def main():
    cobbler = CobblerAPI(url=,user,password,)
    ret = cobbler.add_system(hostname='test',ip_add='#',mac_add='#',profile='CentOS6.3-x86_64')
    print ret
Beispiel #3
0
def main():
    cobbler = CobblerAPI(url="http://192.168.9.250/cobbler_web/",user="******",password="******")
    ret = cobbler.add_system(hostname='test',ip_add='192.168.9.34',mac_add='',profile='CentOS_5.5_Final-x86_64')
    print ret
Beispiel #4
0
def create():

    if OPTIONS.cell_name is None:
        PARSER.print_usage()
        print("[  0] Please specify a cell name")
        sys.exit(127)

    if OPTIONS.leg is None:
        print("[  0] No leg reference passed!")
        sys.exit(129)

    leg = str(OPTIONS.leg).upper()

    OPTIONS.cell_name = fix_cell_name(OPTIONS.cell_name)
    if OPTIONS.cell_name is None:
        print("[  0] Cellname too short")
        sys.exit(115)
    print("[  1] Converted cell name to %s according to rules" %
          OPTIONS.cell_name)

    logger = logging.getLogger("cellar")
    logger.setLevel(logging.DEBUG)
    sh = logging.StreamHandler()
    sh.setLevel(logging.DEBUG)
    sysh = logging.handlers.SysLogHandler(address=('syslog', 514),
                                          facility='local5')
    # create formatter
    sh_formatter = logging.Formatter("%(asctime)s - " + OPTIONS.cell_name +
                                     " - %(message)s")
    sysh_formatter = logging.Formatter(OPTIONS.cell_name + " - %(message)s")
    # add formatter to sh
    sh.setFormatter(sh_formatter)
    sysh.setFormatter(sysh_formatter)
    # add sh to logger
    logger.addHandler(sh)
    logger.addHandler(sysh)

    if OPTIONS.ticket is None:
        logger.exception("[  0] No ticket reference passed!")
        sys.exit(126)

    if OPTIONS.variables:
        cProps = {}
        for var in OPTIONS.variables:
            cProps[var.split("=")[0]] = var.split("=")[1]

        if 'MCC' not in cProps:
            if OPTIONS.cell_name[10:12] == 'SP' or OPTIONS.cell_name[
                    10:12] == 'DC':
                logger.exception("[  0] SP or DC cell chosen, but DC group "
                                 "not specified. Use -v MCC= to specify.")
                sys.exit(128)
        if 'SAM' in cProps:
            test = cProps['SAM'].lower()
            if test not in ['live', 'stub']:
                logger.exception("[  0] SAM variable should be used with "
                                 "either 'live' or 'stub' value")
                sys.exit(129)
        if 'MPP' in cProps:
            test = cProps['MPP'].lower()
            if test not in ['live', 'stub']:
                logger.exception("[  0] MPP variable should be used with "
                                 "either 'live' or 'stub' value")
                sys.exit(129)
        if 'LIVETV' in cProps:
            test = cProps['LIVETV'].lower()
            if test not in ['live', 'stub']:
                logger.exception("[  0] LIVETV variable should be used with "
                                 "either 'live' or 'stub' value")
                sys.exit(129)
        if 'PLAYER' not in cProps:
            logger.exception("[  0] Player revision not specified. "
                             "Use -v PLAYER= to specify")
            sys.exit(123)
        if cProps['PLAYER'] not in list_revisions():
            logger.exception("[  0] Player revision %s not found!" %
                             cProps['PLAYER'])
            logger.exception(
                "[  0] %s: %s" %
                ("Available revisions are", ", ".join(list_revisions())))
            sys.exit(124)

    logger.info("[  1] cellar build starting")
    found_revision = os.path.realpath(__file__).split('/')[-3]
    start_time = int(time.time())
    # Check that revision exists
    revision = OPTIONS.revision
    if OPTIONS.revision:
        if found_revision == "trunk":
            if not os.path.isdir(
                    "/export/infrastructure/%d" % OPTIONS.revision):
                logger.exception("[  4] Revision not found! %d" %
                                 OPTIONS.revision)
                sys.exit(124)
            else:
                logger.info("[  5] Building revision %s" % OPTIONS.revision)
        else:
            logger.exception("[  3] Can not specify a revision when running "
                             "from a deployed version!")
            sys.exit(139)
    else:
        if found_revision == "trunk":
            revision = None
        else:
            revision = found_revision
        logger.info("[  8] Building revision %s" % revision)

    # Check that physical machine exists in Cobbler

    tin_fqdn = OPTIONS.cell_name[0:10] + '.' + domain()
    tin_name = OPTIONS.cell_name[0:10]

    mgt = "U1" if "CM" in OPTIONS.cell_name else "M1"

    m1_func_cert = "/var/lib/certmaster/certmaster/certs/" + OPTIONS.cell_name + mgt + domain(
    )
    if os.path.exists(m1_func_cert):
        logger.info("[  9] Deleting func certificate %s" % m1_func_cert)
        os.unlink(m1_func_cert)
    else:
        logger.info("[  9] Cell not previously registered with func")

    vmtmpl = {}
    vmlist = templates.cell_template(str(OPTIONS.cell_name[10:12]))["vms"]
    for vm in vmlist:
        vmtmpl[vm] = templates.vm_template(vm)
        if "lbport" in vmtmpl[vm] and not OPTIONS.nolb:
            ltm.offline_member("pool-" + vmtmpl[vm]['profile'] + '-' + leg,
                               OPTIONS.cell_name + vm, vmtmpl[vm]['lbport'])

    # Check for systems and create if it doesn't exist
    do_cobbler_sync = False
    for i, vm in enumerate(vmlist):
        while os.path.isfile("/var/lock/cellar.lock"):
            time.sleep(5)
            print("Lockfile found - sleeping for 5 seconds")
        open("/var/lock/cellar.lock", "a")
        if not OPTIONS.new and not cobbler.system_exists(OPTIONS.cell_name +
                                                         vm):
            logger.exception("[ %d] System %s%s does not already exist, "
                             "not permitted to create it." %
                             (10 + 3 * i, OPTIONS.cell_name, vm))
            sys.exit(125)
        cobbler.delete_system(OPTIONS.cell_name + vm)
        cobbler.add_system(OPTIONS.cell_name + vm, revision, OPTIONS.ticket,
                           leg, 10 + 3 * i, OPTIONS.variables)
        do_cobbler_sync = True
        os.remove("/var/lock/cellar.lock")
    if do_cobbler_sync:
        logger.info("[ 25] Synchronizing Cobbler data")
        cobbler.sync()

    for i, vm in enumerate(vmlist):
        logger.info("[ %d] Deleting VM %s if it already exists" %
                    (26 + i, OPTIONS.cell_name + vm))
        virt.delete_vm(vm, OPTIONS.cell_name, 26 + i)

    mgt = "U1" if "CM" in OPTIONS.cell_name else "M1"

    nagios.remove_config_files(OPTIONS.cell_name + mgt + domain())

    # Group VM templated by their stage number,
    # and iterate through each stage until all nodes in that stage are
    # fully installed and back up again.
    for stage, vms in itertools.groupby(sorted(vmtmpl.iteritems(),
                                               key=lambda (k, v): v["stage"]),
                                        key=lambda (k, v): v["stage"]):