Exemplo n.º 1
0
def finalize_install():
    """ Complete the installation """
    subprocess.call(["rm", "-f", tsconfig.CONFIG_PATH + '/dnsmasq.leases'])
    console_log("Updating system parameters...")
    i = 1
    system_update = False
    # Retries if sysinv is not yet ready
    while i < 10:
        time.sleep(20)
        LOG.info("Attempt %d to update system parameters..." % i)
        try:
            if sysinv.update_clone_system('Cloned_from_' + clone_name,
                                          utils.get_controller_hostname()):
                system_update = True
                break
        except Exception:
            # Sysinv might not be ready yet
            pass
        i += 1
    if not system_update:
        LOG.error("System update failed")
        raise CloneFail("System update failed")

    try:
        output = subprocess.check_output(["finish_install_clone.sh"],
                                         stderr=subprocess.STDOUT)
        LOG.info("finish_install_clone out: {}".format(output))
    except Exception:
        console_log("Failed to cleanup stale OpenStack resources. "
                    "Manually delete the Volumes and Instances.")
Exemplo n.º 2
0
def create_ini_file(clone_archive_dir, iso_name):
    """Create clone ini file."""
    interfaces = ""
    my_hostname = utils.get_controller_hostname()
    macs = sysinv_api.get_mac_addresses(my_hostname)
    for intf in macs.keys():
        interfaces += intf + " "

    disk_paths = ""
    for _, _, files in os.walk('/dev/disk/by-path'):
        for f in files:
            if f.startswith("pci-") and "part" not in f and "usb" not in f:
                disk_size = get_disk_size('/dev/disk/by-path/' + f)
                disk_paths += f + "#" + disk_size + " "
        break  # no need to go into sub-dirs.

    LOG.info("create ini: {} {}".format(macs, files))
    with open(os.path.join(clone_archive_dir, CLONE_ISO_INI), 'w') as f:
        f.write('[clone_iso]\n')
        f.write('name=' + iso_name + '\n')
        f.write('host=' + my_hostname + '\n')
        f.write('created_at=' + time.strftime("%Y-%m-%d %H:%M:%S %Z") + '\n')
        f.write('interfaces=' + interfaces + '\n')
        f.write('disks=' + disk_paths + '\n')
        f.write('cpus=' + get_online_cpus() + '\n')
        f.write('mem=' + get_total_mem() + '\n')
    LOG.info("create ini: ({}) ({})".format(interfaces, disk_paths))
Exemplo n.º 3
0
def config_worker():
    """
    Enable worker functionality for AIO system.
    :return: True if worker-config-complete is executed
    """
    if utils.get_system_type() == si_const.TIS_AIO_BUILD:
        console_log("Applying worker manifests for {}. "
                    "Node will reboot on completion.".format(
                        utils.get_controller_hostname()))
        sysinv.do_worker_config_complete(utils.get_controller_hostname())
        time.sleep(30)
        # worker-config-complete has no logs to console. So, wait
        # for some time before showing the login prompt.
        for i in range(1, 10):
            console_log("worker-config in progress..")
            time.sleep(30)
        console_log("Timed out on do_worker_config_complete")
        raise CloneFail("Timed out on do_worker_config_complete")
        return True
    else:
        # worker_config_complete is not needed.
        return False
Exemplo n.º 4
0
def update_mac_in_archive(tmpdir):
    """ Update MAC addresses in system archive file. """
    hostname = utils.get_controller_hostname()
    macs = sysinv_api.get_mac_addresses(hostname)
    for intf, mac in macs.items():
        find_and_replace([os.path.join(tmpdir, 'postgres/sysinv.sql.data')],
                         mac, "CLONEISOMAC_{}{}".format(hostname, intf))

    if (tsconfig.system_mode == si_const.SYSTEM_MODE_DUPLEX
            or tsconfig.system_mode == si_const.SYSTEM_MODE_DUPLEX_DIRECT):
        hostname = utils.get_mate_controller_hostname()
        macs = sysinv_api.get_mac_addresses(hostname)
        for intf, mac in macs.items():
            find_and_replace(
                [os.path.join(tmpdir, 'postgres/sysinv.sql.data')], mac,
                "CLONEISOMAC_{}{}".format(hostname, intf))
Exemplo n.º 5
0
def update_disk_serial_id_in_archive(tmpdir):
    """ Update disk serial id in system archive file. """
    hostname = utils.get_controller_hostname()
    disk_sids = sysinv_api.get_disk_serial_ids(hostname)
    for d_dnode, d_sid in disk_sids.items():
        find_and_replace([os.path.join(tmpdir, 'postgres/sysinv.sql.data')],
                         d_sid,
                         "CLONEISODISKSID_{}{}".format(hostname, d_dnode))

    if (tsconfig.system_mode == si_const.SYSTEM_MODE_DUPLEX
            or tsconfig.system_mode == si_const.SYSTEM_MODE_DUPLEX_DIRECT):
        hostname = utils.get_mate_controller_hostname()
        disk_sids = sysinv_api.get_disk_serial_ids(hostname)
        for d_dnode, d_sid in disk_sids.items():
            find_and_replace(
                [os.path.join(tmpdir, 'postgres/sysinv.sql.data')], d_sid,
                "CLONEISODISKSID_{}{}".format(hostname, d_dnode))
Exemplo n.º 6
0
def validate_controller_state():
    """ Cloning allowed now? """
    # Check if this Controller is enabled and provisioned
    try:
        if not sysinv_api.controller_enabled_provisioned(
                utils.get_controller_hostname()):
            raise CloneFail("Controller is not enabled/provisioned")
        if (tsconfig.system_mode == si_const.SYSTEM_MODE_DUPLEX
                or tsconfig.system_mode == si_const.SYSTEM_MODE_DUPLEX_DIRECT):
            if not sysinv_api.controller_enabled_provisioned(
                    utils.get_mate_controller_hostname()):
                raise CloneFail("Mate controller is not enabled/provisioned")
    except CloneFail:
        raise
    except Exception:
        raise CloneFail("Controller is not enabled/provisioned")

    if utils.get_system_type() != si_const.TIS_AIO_BUILD:
        raise CloneFail("Cloning supported only on All-in-one systems")

    if len(sysinv_api.get_alarms()) > 0:
        raise CloneFail("There are active alarms on this system!")