Esempio n. 1
0
def main():
    action = None
    from_release = None
    to_release = None
    arg = 1

    while arg < len(sys.argv):
        if arg == 1:
            from_release = sys.argv[arg]
        elif arg == 2:
            to_release = sys.argv[arg]  # noqa
        elif arg == 3:
            action = sys.argv[arg]
        else:
            print("Invalid option %s." % sys.argv[arg])
            return 1
        arg += 1

    log.configure()

    LOG.debug("%s invoked with from_release = %s to_release = %s action = %s" %
              (sys.argv[0], from_release, to_release, action))

    # This host table data migration will likely be required for each release
    if action == "migrate":
        try:
            reset_config_target()
        except Exception as ex:
            LOG.exception(ex)
            return 1
def main():
    action = None
    from_release = None
    to_release = None  # noqa
    arg = 1

    while arg < len(sys.argv):
        if arg == 1:
            from_release = sys.argv[arg]
        elif arg == 2:
            to_release = sys.argv[arg]  # noqa
        elif arg == 3:
            action = sys.argv[arg]
        else:
            print("Invalid option %s." % sys.argv[arg])
            return 1
        arg += 1

    log.configure()

    LOG.debug("%s invoked with from_release = %s to_release = %s action = %s" %
              (sys.argv[0], from_release, to_release, action))
    if from_release == "20.06" and action == "migrate":
        try:
            adjust_user_partitions()
        except Exception as ex:
            LOG.exception(ex)
            return 1
def main():
    action = None
    from_release = None
    to_release = None  # noqa
    arg = 1

    while arg < len(sys.argv):
        if arg == 1:
            from_release = sys.argv[arg]
        elif arg == 2:
            to_release = sys.argv[arg]  # noqa
        elif arg == 3:
            action = sys.argv[arg]
        else:
            print("Invalid option %s." % sys.argv[arg])
            return 1
        arg += 1

    log.configure()

    if from_release == "18.03" and action == "migrate":
        try:
            cleanup_ceph_cache_tiering_service_parameters(from_release)
            cleanup_ceph_personality_subtype(from_release)
        except Exception as ex:
            LOG.exception(ex)
            return 1
def main():
    action = None
    from_release = None
    to_release = None  # noqa
    arg = 1
    while arg < len(sys.argv):
        if arg == 1:
            from_release = sys.argv[arg]
        elif arg == 2:
            to_release = sys.argv[arg]  # noqa
        elif arg == 3:
            action = sys.argv[arg]
        else:
            print("Invalid option %s." % sys.argv[arg])
            return 1
        arg += 1

    log.configure()

    if from_release == "18.03" and action == "migrate":
        try:
            move_routers_off_controller_1()
            move_networks_off_controller_1()
            move_port_bindings_off_controller_1()
            move_dhcp_port_device_id_off_controller_1()
            move_distributed_port_bindings_off_controller_1()
        except Exception as ex:
            LOG.exception(ex)
            print(ex)
            return 1
Esempio n. 5
0
def main():
    action = None
    from_release = None
    to_release = None
    arg = 1
    while arg < len(sys.argv):
        if arg == 1:
            from_release = sys.argv[arg]
        elif arg == 2:
            to_release = sys.argv[arg]
        elif arg == 3:
            action = sys.argv[arg]
        else:
            print("Invalid option %s." % sys.argv[arg])
            return 1
        arg += 1

    log.configure()

    LOG.debug("%s invoked with from_release = %s to_release = %s action = %s" %
              (sys.argv[0], from_release, to_release, action))

    if from_release == "20.06" and action == "migrate":
        try:
            if is_system_controller():
                LOG.info("Performing dcorch snmp data removal...")
                remove_snmp_record()
        except Exception as ex:
            LOG.exception(ex)
            print(ex)
            return 1
Esempio n. 6
0
def main():
    action = None
    from_release = None
    to_release = None
    arg = 1
    while arg < len(sys.argv):
        if arg == 1:
            from_release = sys.argv[arg]
        elif arg == 2:
            to_release = sys.argv[arg]
        elif arg == 3:
            action = sys.argv[arg]
        else:
            print("Invalid option %s." % sys.argv[arg])
            return 1
        arg += 1

    log.configure()

    LOG.debug("%s invoked with from_release = %s to_release = %s action = %s" %
              (sys.argv[0], from_release, to_release, action))
    if from_release == "20.06" and action == "migrate":
        try:
            if is_subcloud():
                LOG.info("Removing identity shared service...")
                remove_identity_shared_service()
        except Exception:
            LOG.exception("Failed to remove identity entry during upgrade.")
            return 1
Esempio n. 7
0
def main():
    action = None
    from_release = None
    to_release = None
    arg = 1

    while arg < len(sys.argv):
        if arg == 1:
            action = sys.argv[arg]
        elif arg == 2:
            from_release = sys.argv[arg]
        elif arg == 3:
            to_release = sys.argv[arg]
        else:
            print("Invalid option %s." % sys.argv[arg])
            return 1
        arg += 1

    log.configure()

    LOG.info("upgrade_swact_migration called with action: %s from_release: %s "
             "to_release: %s" % (action, from_release, to_release))

    if action == "migrate_etcd":
        try:
            migrate_etcd_on_swact()
        except Exception as ex:
            LOG.exception(ex)
            return 1
    elif action == "prepare_swact":
        upgrade_prepare_swact(from_release, to_release)

    LOG.info("upgrade_swact_migration complete")
    return 0
Esempio n. 8
0
def main():
    action = None
    from_release = None
    to_release = None  # noqa
    arg = 1
    while arg < len(sys.argv):
        if arg == 1:
            from_release = sys.argv[arg]
        elif arg == 2:
            to_release = sys.argv[arg]  # noqa
        elif arg == 3:
            action = sys.argv[arg]
        else:
            print("Invalid option %s." % sys.argv[arg])
            return 1
        arg += 1

    log.configure()

    if from_release == "17.06" and action == "migrate":
        try:
            LOG.info("performing sample migration from release %s to %s with "
                     "action: %s" % (from_release, to_release, action))
            do_migration_work()
        except Exception as ex:
            LOG.exception(ex)
            print(ex)
            return 1
def main():
    action = None
    from_release = None
    to_release = None
    arg = 1
    while arg < len(sys.argv):
        if arg == 1:
            from_release = sys.argv[arg]
        elif arg == 2:
            to_release = sys.argv[arg]
        elif arg == 3:
            action = sys.argv[arg]
        else:
            print ("Invalid option %s." % sys.argv[arg])
            return 1
        arg += 1

    log.configure()

    if from_release == '20.06' and action == 'activate':
        LOG.info("%s invoked with from_release = %s to_release = %s "
                 "action = %s"
                 % (sys.argv[0], from_release, to_release, action))
        migrate_helm_releases()
        LOG.info("Complete helm releases migration for release %s "
                 "to %s with action %s."
                 % (from_release, to_release, action))
Esempio n. 10
0
def config_main(config_type=REGION_CONFIG):
    allow_ssh = False
    if config_type == REGION_CONFIG:
        config_file = "/home/wrsroot/region_config"
    elif config_type == SUBCLOUD_CONFIG:
        config_file = "/home/wrsroot/subcloud_config"
    else:
        raise ConfigFail("Invalid config_type: %s" % config_type)

    arg = 1
    while arg < len(sys.argv):
        if sys.argv[arg] in ['--help', '-h', '-?']:
            if config_type == REGION_CONFIG:
                show_help_region()
            else:
                show_help_subcloud()
            exit(1)
        elif sys.argv[arg] == "--allow-ssh":
            allow_ssh = True
        elif arg == len(sys.argv) - 1:
            config_file = sys.argv[arg]
        else:
            print("Invalid option. Use --help for more information.")
            exit(1)
        arg += 1

    log.configure()

    # Check if that the command is being run from the console
    if utils.is_ssh_parent():
        if allow_ssh:
            print(textwrap.fill(constants.SSH_WARNING_MESSAGE, 80))
            print('')
        else:
            print(textwrap.fill(constants.SSH_ERROR_MESSAGE, 80))
            exit(1)

    if not os.path.isfile(config_file):
        print("Config file %s does not exist." % config_file)
        exit(1)

    try:
        configure_region(config_file, config_type=config_type)
    except KeyboardInterrupt:
        print("\nAborting configuration")
    except ConfigFail as e:
        LOG.exception(e)
        print("\nConfiguration failed: {}".format(e))
    except Exception as e:
        LOG.exception(e)
        print("\nConfiguration failed: {}".format(e))
    else:
        print("\nConfiguration finished successfully.")
    finally:
        if os.path.isfile(TEMP_CGCS_CONFIG_FILE):
            os.remove(TEMP_CGCS_CONFIG_FILE)
Esempio n. 11
0
def main():
    if (len(sys.argv) < 2 or sys.argv[1] in ['--help', '-h', '-?']):
        show_help()
        exit(1)

    log.configure()

    result_file = sys.argv[1]

    try:
        open(result_file, 'w')
    except IOError:
        raise TidyStorageFail("Failed to open file: %s" % result_file)
        exit(1)

    tidy_storage(result_file)
Esempio n. 12
0
def main():

    from_release = None
    to_release = None
    arg = 1
    while arg < len(sys.argv):
        if sys.argv[arg] in ['--help', '-h', '-?']:
            show_help()
            exit(1)
        elif arg == 1:
            from_release = sys.argv[arg]
        elif arg == 2:
            to_release = sys.argv[arg]
        else:
            print("Invalid option %s. Use --help for more information." %
                  sys.argv[arg])
            exit(1)
        arg += 1

    log.configure()

    if not from_release or not to_release:
        print("Both the FROM_RELEASE and TO_RELEASE must be specified")
        exit(1)

    try:
        upgrade_controller(from_release, to_release)
    except Exception as e:
        LOG.exception(e)
        print("Upgrade failed: {}".format(e))

        # Set upgrade fail flag on mate controller
        LOG.info("Set upgrade fail flag on mate controller")
        os.mkdir("/tmp/etc_platform")
        nfs_mount_filesystem("/etc/platform", "/tmp/etc_platform")
        upgrade_fail_flag_file = os.path.join(
            "/tmp/etc_platform",
            os.path.basename(CONTROLLER_UPGRADE_FAIL_FLAG))
        open(upgrade_fail_flag_file, "w").close()
        unmount_filesystem("/tmp/etc_platform")
        os.rmdir("/tmp/etc_platform")

        exit(1)
Esempio n. 13
0
def main():
    action = None
    from_release = None
    to_release = None
    arg = 1
    while arg < len(sys.argv):
        if arg == 1:
            from_release = sys.argv[arg]
        elif arg == 2:
            to_release = sys.argv[arg]
        elif arg == 3:
            action = sys.argv[arg]
        else:
            print("Invalid option %s." % sys.argv[arg])
            return 1
        arg += 1

    log.configure()
    LOG.debug("%s invoked with from_release = %s to_release = %s action = %s" %
              (sys.argv[0], from_release, to_release, action))

    if from_release == '20.06' and action == 'activate':
        create_deployment_ns()
Esempio n. 14
0
def main():
    action = None
    from_release = None
    to_release = None
    arg = 1
    while arg < len(sys.argv):
        if arg == 1:
            from_release = sys.argv[arg]
        elif arg == 2:
            to_release = sys.argv[arg]
        elif arg == 3:
            action = sys.argv[arg]
        else:
            print ("Invalid option %s." % sys.argv[arg])
            return 1
        arg += 1

    log.configure()

    if action == 'activate' and not is_containerized_armada_installed():
        LOG.info("%s invoked with from_release = %s to_release = %s "
                 "action = %s"
                 % (sys.argv[0], from_release, to_release, action))
        update_armada_helmv3()
Esempio n. 15
0
def simplex_main():
    backup_file = None
    arg = 1
    while arg < len(sys.argv):
        if sys.argv[arg] in ['--help', '-h', '-?']:
            show_help()
            exit(1)
        elif arg == 1:
            backup_file = sys.argv[arg]
        else:
            print("Invalid option %s. Use --help for more information." %
                  sys.argv[arg])
            exit(1)
        arg += 1

    log.configure()

    # Enforce that the command is being run from the console
    if cutils.is_ssh_parent():
        print (
            "Error attempting upgrade. Ensure this command is run from the"
            " console.")
        exit(1)

    if not backup_file:
        print("The BACKUP_FILE must be specified")
        exit(1)

    try:
        upgrade_controller_simplex(backup_file)
    except Exception as e:
        LOG.exception(e)
        print("Upgrade failed: {}".format(e))
        # TODO SET Upgrade fail flag
        # Set upgrade fail flag on mate controller
        exit(1)
Esempio n. 16
0
def main():
    action = None
    from_release = None
    to_release = None
    arg = 1
    while arg < len(sys.argv):
        if arg == 1:
            from_release = sys.argv[arg]
        elif arg == 2:
            to_release = sys.argv[arg]
        elif arg == 3:
            action = sys.argv[arg]
        else:
            print ("Invalid option %s." % sys.argv[arg])
            return 1
        arg += 1

    log.configure()
    LOG.debug("%s invoked with from_release = %s to_release = %s action = %s"
              % (sys.argv[0], from_release, to_release, action))

    if to_release == '20.06' and action == 'activate':
        if is_system_controller():
            update_dc_root_ca()
Esempio n. 17
0
def main():
    action = None
    from_release = None
    to_release = None
    arg = 1
    while arg < len(sys.argv):
        if arg == 1:
            from_release = sys.argv[arg]
        elif arg == 2:
            to_release = sys.argv[arg]
        elif arg == 3:
            action = sys.argv[arg]
        else:
            print("Invalid option %s." % sys.argv[arg])
            return 1
        arg += 1

    log.configure()
    LOG.debug("%s invoked with from_release = %s to_release = %s action = %s" %
              (sys.argv[0], from_release, to_release, action))

    if from_release == '20.06' and action == 'activate':
        if is_subcloud():
            update_sc_admin_endpoint_cert(to_release)
Esempio n. 18
0
def cleanup():
    """ Cleanup after installation """
    LOG.info("Cleaning up...")
    subprocess.call(['systemctl', 'disable', 'install-clone'], stderr=DEVNULL)
    OLD_FILE = os.path.join(tsconfig.PLATFORM_CONF_PATH, clone.CLONE_ISO_INI)
    if os.path.exists(OLD_FILE):
        os.remove(OLD_FILE)
    if os.path.exists(INI_FILE):
        os.chmod(INI_FILE, 0o400)
        shutil.move(INI_FILE, tsconfig.PLATFORM_CONF_PATH)
    shutil.rmtree(os.path.join("/", clone.CLONE_ARCHIVE_DIR),
                  ignore_errors=True)


log.configure()
if os.path.exists(INI_FILE):
    try:
        parser.read(INI_FILE)
        if parser.has_section(SECTION):
            clone_name = parser.get(SECTION, clone.NAME)
            LOG.info("System archive [%s] to be installed." % clone_name)

            first_boot = False
            last_result = clone.IN_PROGRESS
            if not parser.has_option(SECTION, clone.RESULT):
                # first boot after cloning
                first_boot = True
            else:
                last_result = parser.get(SECTION, clone.RESULT)
                LOG.info("Last attempt to install clone was [{}]".format(
Esempio n. 19
0
def main():
    options = {}
    answerfile = None
    backup_name = None
    archive_dir = constants.BACKUPS_PATH
    do_default_config = False
    do_backup = False
    do_system_restore = False
    include_storage_reinstall = False
    do_clone = False
    do_non_interactive = False
    do_provision = False
    system_config_file = "/home/sysadmin/system_config"
    allow_ssh = False

    # Disable completion as the default completer shows python commands
    readline.set_completer(no_complete)

    # remove any previous config fail flag file
    if os.path.exists(constants.CONFIG_FAIL_FILE) is True:
        os.remove(constants.CONFIG_FAIL_FILE)

    if os.environ.get('CGCS_LABMODE'):
        options['labmode'] = True

    arg = 1
    while arg < len(sys.argv):
        if sys.argv[arg] == "--answerfile":
            arg += 1
            if arg < len(sys.argv):
                answerfile = sys.argv[arg]
            else:
                print("--answerfile option requires a file to be specified")
                exit(1)
        elif sys.argv[arg] == "--backup":
            arg += 1
            if arg < len(sys.argv):
                backup_name = sys.argv[arg]
            else:
                print("--backup requires the name of the backup")
                exit(1)
            do_backup = True
        elif sys.argv[arg] == "--restore-system":
            arg += 1
            if arg < len(sys.argv):
                if sys.argv[arg] in [
                        "include-storage-reinstall",
                        "exclude-storage-reinstall"
                ]:
                    if sys.argv[arg] == "include-storage-reinstall":
                        include_storage_reinstall = True
                    arg += 1
                    if arg < len(sys.argv):
                        backup_name = sys.argv[arg]
                    else:
                        print(
                            textwrap.fill(
                                "--restore-system requires the filename "
                                " of the backup", 80))
                        exit(1)
                else:
                    backup_name = sys.argv[arg]
            else:
                print(
                    textwrap.fill(
                        "--restore-system requires the filename "
                        "of the backup", 80))
                exit(1)
            do_system_restore = True
        elif sys.argv[arg] == "--archive-dir":
            arg += 1
            if arg < len(sys.argv):
                archive_dir = sys.argv[arg]
            else:
                print("--archive-dir requires a directory")
                exit(1)
        elif sys.argv[arg] == "--clone-iso":
            arg += 1
            if arg < len(sys.argv):
                backup_name = sys.argv[arg]
            else:
                print("--clone-iso requires the name of the image")
                exit(1)
            do_clone = True
        elif sys.argv[arg] == "--clone-status":
            clone.clone_status()
            exit(0)
        elif sys.argv[arg] == "--default":
            do_default_config = True
        elif sys.argv[arg] == "--config-file":
            arg += 1
            if arg < len(sys.argv):
                system_config_file = sys.argv[arg]
            else:
                print("--config-file requires the filename of the config file")
                exit(1)
            do_non_interactive = True
        elif sys.argv[arg] in ["--help", "-h", "-?"]:
            show_help()
            exit(1)
        elif sys.argv[arg] == "--labhelp":
            show_help_lab_only()
            exit(1)
        elif sys.argv[arg] == "--provision":
            do_provision = True
        elif sys.argv[arg] == "--allow-ssh":
            allow_ssh = True
        elif sys.argv[arg] == "--kubernetes":
            # This is a temporary flag for use during development. Once things
            # are stable, we will remove it and make kubernetes the default.
            options['kubernetes'] = True
        else:
            print("Invalid option. Use --help for more information.")
            exit(1)
        arg += 1

    if [
            do_backup, do_system_restore, do_clone, do_default_config,
            do_non_interactive
    ].count(True) > 1:
        print("Invalid combination of options selected")
        exit(1)

    if answerfile and [
            do_backup, do_system_restore, do_clone, do_default_config,
            do_non_interactive
    ].count(True) > 0:
        print("The --answerfile option cannot be used with the selected "
              "option")
        exit(1)

    log.configure()

    if not do_backup and not do_clone:
        # Check if that the command is being run from the console
        if utils.is_ssh_parent():
            if allow_ssh:
                print(textwrap.fill(constants.SSH_WARNING_MESSAGE, 80))
                print('')
            else:
                print(textwrap.fill(constants.SSH_ERROR_MESSAGE, 80))
                exit(1)

    # Reduce the printk console log level to avoid noise during configuration
    printk_levels = ''
    with open('/proc/sys/kernel/printk', 'r') as f:
        printk_levels = f.readline()

    temp_printk_levels = '3' + printk_levels[1:]
    with open('/proc/sys/kernel/printk', 'w') as f:
        f.write(temp_printk_levels)

    try:
        if do_backup:
            backup_restore.backup(backup_name, archive_dir)
            print("\nBackup complete")
        elif do_system_restore:
            backup_restore.restore_system(backup_name,
                                          include_storage_reinstall)
            print("\nSystem restore complete")
        elif do_clone:
            clone.clone(backup_name, archive_dir)
            print("\nCloning complete")
        elif do_provision:
            assistant = ConfigAssistant(**options)
            assistant.provision(answerfile)
        else:
            print(
                textwrap.fill(
                    "Please use bootstrap playbook to configure the "
                    "first controller.", 80))
            exit(1)

            if do_non_interactive:
                if not os.path.isfile(system_config_file):
                    raise ConfigFail("Config file %s does not exist." %
                                     system_config_file)
                if (os.path.exists(constants.CGCS_CONFIG_FILE)
                        or os.path.exists(constants.CONFIG_PERMDIR)
                        or os.path.exists(
                            constants.INITIAL_CONFIG_COMPLETE_FILE)):
                    raise ConfigFail("Configuration has already been done "
                                     "and cannot be repeated.")
                configure_system(system_config_file)
                answerfile = TEMP_CGCS_CONFIG_FILE
            assistant = ConfigAssistant(**options)
            assistant.configure(answerfile, do_default_config)
            print("\nConfiguration was applied\n")
            print(
                textwrap.fill(
                    "Please complete any out of service commissioning steps "
                    "with system commands and unlock controller to proceed.",
                    80))
            assistant.check_required_interfaces_status()

    except KeyboardInterrupt:
        print("\nAborting configuration")
    except BackupFail as e:
        print("\nBackup failed: {}".format(e))
    except RestoreFail as e:
        print("\nRestore failed: {}".format(e))
    except ConfigFail as e:
        print("\nConfiguration failed: {}".format(e))
    except CloneFail as e:
        print("\nCloning failed: {}".format(e))
    except UserQuit:
        print("\nAborted configuration")
    finally:
        if os.path.isfile(TEMP_CGCS_CONFIG_FILE):
            os.remove(TEMP_CGCS_CONFIG_FILE)

    # Restore the printk console log level
    with open('/proc/sys/kernel/printk', 'w') as f:
        f.write(printk_levels)