Exemplo n.º 1
0
def upgrade(ctx):
    oo_cfg = ctx.obj['oo_cfg']

    if len(oo_cfg.hosts) == 0:
        click.echo("No hosts defined in: %s" % oo_cfg['configuration'])
        sys.exit(1)

    # Update config to reflect the version we're targetting, we'll write
    # to disk once ansible completes successfully, not before.
    old_variant = oo_cfg.settings['variant']
    old_version = oo_cfg.settings['variant_version']
    if oo_cfg.settings['variant'] == 'enterprise':
        oo_cfg.settings['variant'] = 'openshift-enterprise'
    version = find_variant(oo_cfg.settings['variant'])[1]
    oo_cfg.settings['variant_version'] = version.name
    click.echo("Openshift will be upgraded from %s %s to %s %s on the following hosts:\n" % (
        old_variant, old_version, oo_cfg.settings['variant'],
        oo_cfg.settings['variant_version']))
    for host in oo_cfg.hosts:
        click.echo("  * %s" % host.connect_to)

    if not ctx.obj['unattended']:
        # Prompt interactively to confirm:
        proceed = click.confirm("\nDo you wish to proceed?")
        if not proceed:
            click.echo("Upgrade cancelled.")
            sys.exit(0)

    retcode = openshift_ansible.run_upgrade_playbook()
    if retcode > 0:
        click.echo("Errors encountered during upgrade, please check %s." %
            oo_cfg.settings['ansible_log_path'])
    else:
        click.echo("Upgrade completed! Rebooting all hosts is recommended.")
Exemplo n.º 2
0
def generate_inventory(hosts):
    global CFG
    masters = [host for host in hosts if host.master]
    nodes = [host for host in hosts if host.node]
    proxy = determine_proxy_configuration(hosts)
    multiple_masters = len(masters) > 1

    base_inventory_path = CFG.settings['ansible_inventory_path']
    base_inventory = open(base_inventory_path, 'w')

    write_inventory_children(base_inventory, multiple_masters, proxy)

    write_inventory_vars(base_inventory, multiple_masters, proxy)

    # Find the correct deployment type for ansible:
    ver = find_variant(CFG.settings['variant'],
                       version=CFG.settings.get('variant_version', None))[1]
    base_inventory.write('deployment_type={}\n'.format(ver.ansible_key))

    if 'OO_INSTALL_ADDITIONAL_REGISTRIES' in os.environ:
        base_inventory.write('cli_docker_additional_registries={}\n'.format(
            os.environ['OO_INSTALL_ADDITIONAL_REGISTRIES']))
    if 'OO_INSTALL_INSECURE_REGISTRIES' in os.environ:
        base_inventory.write('cli_docker_insecure_registries={}\n'.format(
            os.environ['OO_INSTALL_INSECURE_REGISTRIES']))
    if 'OO_INSTALL_PUDDLE_REPO' in os.environ:
        # We have to double the '{' here for literals
        base_inventory.write(
            "openshift_additional_repos=[{{'id': 'ose-devel', "
            "'name': 'ose-devel', "
            "'baseurl': '{}', "
            "'enabled': 1, 'gpgcheck': 0}}]\n".format(
                os.environ['OO_INSTALL_PUDDLE_REPO']))

    base_inventory.write('\n[masters]\n')
    for master in masters:
        write_host(master, base_inventory)

    if len(masters) > 1:
        base_inventory.write('\n[etcd]\n')
        for master in masters:
            write_host(master, base_inventory)

    base_inventory.write('\n[nodes]\n')

    for node in nodes:
        # Let the fact defaults decide if we're not a master:
        schedulable = None

        # If the node is also a master, we must explicitly set schedulablity:
        if node.master:
            schedulable = node.is_schedulable_node(hosts)
        write_host(node, base_inventory, schedulable)

    if not getattr(proxy, 'preconfigured', True):
        base_inventory.write('\n[lb]\n')
        write_host(proxy, base_inventory)

    base_inventory.close()
    return base_inventory_path
Exemplo n.º 3
0
def write_inventory_vars(base_inventory, lb):
    global CFG
    base_inventory.write('\n[OSEv3:vars]\n')

    for variable, value in CFG.settings.items():
        inventory_var = VARIABLES_MAP.get(variable, None)
        if inventory_var and value:
            base_inventory.write('{}={}\n'.format(inventory_var, value))

    for variable, value in CFG.deployment.variables.items():
        inventory_var = VARIABLES_MAP.get(variable, variable)
        if value:
            base_inventory.write('{}={}\n'.format(inventory_var, value))

    if CFG.deployment.variables['ansible_ssh_user'] != 'root':
        base_inventory.write('ansible_become=yes\n')

    base_inventory.write('openshift_override_hostname_check=true\n')

    if lb is not None:
        base_inventory.write('openshift_master_cluster_method=native\n')
        base_inventory.write("openshift_master_cluster_hostname={}\n".format(lb.hostname))
        base_inventory.write(
            "openshift_master_cluster_public_hostname={}\n".format(lb.public_hostname))

    if CFG.settings.get('variant_version', None) == '3.1':
        # base_inventory.write('openshift_image_tag=v{}\n'.format(CFG.settings.get('variant_version')))
        base_inventory.write('openshift_image_tag=v{}\n'.format('3.1.1.6'))

    write_proxy_settings(base_inventory)

    # Find the correct deployment type for ansible:
    ver = find_variant(CFG.settings['variant'],
                       version=CFG.settings.get('variant_version', None))[1]
    base_inventory.write('deployment_type={}\n'.format(ver.ansible_key))
    if getattr(ver, 'variant_subtype', False):
        base_inventory.write('deployment_subtype={}\n'.format(ver.deployment_subtype))

    if 'OO_INSTALL_ADDITIONAL_REGISTRIES' in os.environ:
        base_inventory.write('openshift_docker_additional_registries={}\n'.format(
            os.environ['OO_INSTALL_ADDITIONAL_REGISTRIES']))
    if 'OO_INSTALL_INSECURE_REGISTRIES' in os.environ:
        base_inventory.write('openshift_docker_insecure_registries={}\n'.format(
            os.environ['OO_INSTALL_INSECURE_REGISTRIES']))
    if 'OO_INSTALL_PUDDLE_REPO' in os.environ:
        # We have to double the '{' here for literals
        base_inventory.write("openshift_additional_repos=[{{'id': 'ose-devel', "
                             "'name': 'ose-devel', "
                             "'baseurl': '{}', "
                             "'enabled': 1, 'gpgcheck': 0}}]\n".format(os.environ['OO_INSTALL_PUDDLE_REPO']))

    for name, role_obj in CFG.deployment.roles.items():
        if role_obj.variables:
            group_name = ROLES_TO_GROUPS_MAP.get(name, name)
            base_inventory.write("\n[{}:vars]\n".format(group_name))
            for variable, value in role_obj.variables.items():
                inventory_var = VARIABLES_MAP.get(variable, variable)
                if value:
                    base_inventory.write('{}={}\n'.format(inventory_var, value))
            base_inventory.write("\n")
def generate_inventory(hosts):
    global CFG
    masters = [host for host in hosts if host.master]
    nodes = [host for host in hosts if host.node]
    proxy = determine_proxy_configuration(hosts)
    multiple_masters = len(masters) > 1

    base_inventory_path = CFG.settings['ansible_inventory_path']
    base_inventory = open(base_inventory_path, 'w')

    write_inventory_children(base_inventory, multiple_masters, proxy)

    write_inventory_vars(base_inventory, multiple_masters, proxy)

    # Find the correct deployment type for ansible:
    ver = find_variant(CFG.settings['variant'],
        version=CFG.settings.get('variant_version', None))[1]
    base_inventory.write('deployment_type={}\n'.format(ver.ansible_key))

    if 'OO_INSTALL_ADDITIONAL_REGISTRIES' in os.environ:
        base_inventory.write('cli_docker_additional_registries={}\n'
          .format(os.environ['OO_INSTALL_ADDITIONAL_REGISTRIES']))
    if 'OO_INSTALL_INSECURE_REGISTRIES' in os.environ:
        base_inventory.write('cli_docker_insecure_registries={}\n'
          .format(os.environ['OO_INSTALL_INSECURE_REGISTRIES']))
    if 'OO_INSTALL_PUDDLE_REPO' in os.environ:
        # We have to double the '{' here for literals
        base_inventory.write("openshift_additional_repos=[{{'id': 'ose-devel', "
            "'name': 'ose-devel', "
            "'baseurl': '{}', "
            "'enabled': 1, 'gpgcheck': 0}}]\n".format(os.environ['OO_INSTALL_PUDDLE_REPO']))

    base_inventory.write('\n[masters]\n')
    for master in masters:
        write_host(master, base_inventory)

    if len(masters) > 1:
        base_inventory.write('\n[etcd]\n')
        for master in masters:
            write_host(master, base_inventory)

    base_inventory.write('\n[nodes]\n')

    for node in nodes:
        # Let the fact defaults decide if we're not a master:
        schedulable = None

        # If the node is also a master, we must explicitly set schedulablity:
        if node.master:
            schedulable = node.is_schedulable_node(hosts)
        write_host(node, base_inventory, schedulable)

    if not getattr(proxy, 'preconfigured', True):
        base_inventory.write('\n[lb]\n')
        write_host(proxy, base_inventory)

    base_inventory.close()
    return base_inventory_path
def upgrade(ctx):
    oo_cfg = ctx.obj['oo_cfg']
    verbose = ctx.obj['verbose']

    if len(oo_cfg.hosts) == 0:
        click.echo("No hosts defined in: %s" % oo_cfg.config_path)
        sys.exit(1)

    old_variant = oo_cfg.settings['variant']
    old_version = oo_cfg.settings['variant_version']

    message = """
        This tool will help you upgrade your existing OpenShift installation.
"""
    click.echo(message)
    click.echo("Version {} found. Do you want to update to the latest version of {} " \
               "or migrate to the next major release?".format(old_version, old_version))
    resp = click.prompt(
        "(1) Update to latest {} (2) Migrate to next relese".format(
            old_version))

    if resp == "2":
        # TODO: Make this a lot more flexible
        new_version = "3.1"
        # Update config to reflect the version we're targetting, we'll write
        # to disk once ansible completes successfully, not before.
        if oo_cfg.settings['variant'] == 'enterprise':
            oo_cfg.settings['variant'] = 'openshift-enterprise'
        version = find_variant(oo_cfg.settings['variant'])[1]
        oo_cfg.settings['variant_version'] = version.name
    else:
        new_version = old_version

    click.echo(
        "Openshift will be upgraded from %s %s to %s %s on the following hosts:\n"
        % (old_variant, old_version, oo_cfg.settings['variant'],
           oo_cfg.settings['variant_version']))
    for host in oo_cfg.hosts:
        click.echo("  * %s" % host.connect_to)

    if not ctx.obj['unattended']:
        # Prompt interactively to confirm:
        proceed = click.confirm("\nDo you wish to proceed?")
        if not proceed:
            click.echo("Upgrade cancelled.")
            sys.exit(0)

    retcode = openshift_ansible.run_upgrade_playbook(old_version, new_version,
                                                     verbose)
    if retcode > 0:
        click.echo("Errors encountered during upgrade, please check %s." %
                   oo_cfg.settings['ansible_log_path'])
    else:
        oo_cfg.save_to_disk()
        click.echo("Upgrade completed! Rebooting all hosts is recommended.")
def generate_inventory(hosts):
    global CFG

    installer_host = socket.gethostname()
    base_inventory_path = CFG.settings['ansible_inventory_path']
    base_inventory = open(base_inventory_path, 'w')
    base_inventory.write('\n[OSEv3:children]\nmasters\nnodes\n')
    base_inventory.write('\n[OSEv3:vars]\n')
    base_inventory.write('ansible_ssh_user={}\n'.format(CFG.settings['ansible_ssh_user']))
    if CFG.settings['ansible_ssh_user'] != 'root':
        base_inventory.write('ansible_become=true\n')

    # Find the correct deployment type for ansible:
    ver = find_variant(CFG.settings['variant'],
        version=CFG.settings.get('variant_version', None))[1]
    base_inventory.write('deployment_type={}\n'.format(ver.ansible_key))

    if 'OO_INSTALL_DEVEL_REGISTRY' in os.environ:
        base_inventory.write('oreg_url=rcm-img-docker01.build.eng.bos.redhat.com:'
            '5001/openshift3/ose-${component}:${version}\n')
    if 'OO_INSTALL_PUDDLE_REPO_ENABLE' in os.environ:
        base_inventory.write("openshift_additional_repos=[{'id': 'ose-devel', "
            "'name': 'ose-devel', "
            "'baseurl': 'http://buildvm-devops.usersys.redhat.com"
            "/puddle/build/AtomicOpenShift/3.1/latest/RH7-RHAOS-3.1/$basearch/os', "
            "'enabled': 1, 'gpgcheck': 0}]\n")
    if 'OO_INSTALL_STAGE_REGISTRY' in os.environ:
        base_inventory.write('oreg_url=registry.access.stage.redhat.com/openshift3/ose-${component}:${version}\n')

    if any(host.hostname == installer_host or host.public_hostname == installer_host
            for host in hosts):
        no_pwd_sudo = subprocess.call(['sudo', '-v', '--non-interactive'])
        if no_pwd_sudo == 1:
            print 'The atomic-openshift-installer requires sudo access without a password.'
            sys.exit(1)
        base_inventory.write("ansible_connection=local\n")

    base_inventory.write('\n[masters]\n')
    masters = (host for host in hosts if host.master)
    for master in masters:
        write_host(master, base_inventory)
    base_inventory.write('\n[nodes]\n')
    nodes = (host for host in hosts if host.node)
    for node in nodes:
        # TODO: Until the Master can run the SDN itself we have to configure the Masters
        # as Nodes too.
        scheduleable = True
        # If there's only one Node and it's also a Master we want it to be scheduleable:
        if node in masters and len(masters) != 1:
            scheduleable = False
        write_host(node, base_inventory, scheduleable)
    base_inventory.close()
    return base_inventory_path
Exemplo n.º 7
0
def upgrade(ctx):
    oo_cfg = ctx.obj['oo_cfg']
    verbose = ctx.obj['verbose']

    if len(oo_cfg.hosts) == 0:
        click.echo("No hosts defined in: %s" % oo_cfg.config_path)
        sys.exit(1)

    old_variant = oo_cfg.settings['variant']
    old_version = oo_cfg.settings['variant_version']


    message = """
        This tool will help you upgrade your existing OpenShift installation.
"""
    click.echo(message)
    click.echo("Version {} found. Do you want to update to the latest version of {} " \
               "or migrate to the next major release?".format(old_version, old_version))
    resp = click.prompt("(1) Update to latest {} (2) Migrate to next relese".format(old_version))

    if resp == "2":
        # TODO: Make this a lot more flexible
        new_version = "3.1"
        # Update config to reflect the version we're targetting, we'll write
        # to disk once ansible completes successfully, not before.
        if oo_cfg.settings['variant'] == 'enterprise':
            oo_cfg.settings['variant'] = 'openshift-enterprise'
        version = find_variant(oo_cfg.settings['variant'])[1]
        oo_cfg.settings['variant_version'] = version.name
    else:
        new_version = old_version

    click.echo("Openshift will be upgraded from %s %s to %s %s on the following hosts:\n" % (
        old_variant, old_version, oo_cfg.settings['variant'],
        oo_cfg.settings['variant_version']))
    for host in oo_cfg.hosts:
        click.echo("  * %s" % host.connect_to)

    if not ctx.obj['unattended']:
        # Prompt interactively to confirm:
        proceed = click.confirm("\nDo you wish to proceed?")
        if not proceed:
            click.echo("Upgrade cancelled.")
            sys.exit(0)

    retcode = openshift_ansible.run_upgrade_playbook(old_version, new_version, verbose)
    if retcode > 0:
        click.echo("Errors encountered during upgrade, please check %s." %
            oo_cfg.settings['ansible_log_path'])
    else:
        oo_cfg.save_to_disk()
        click.echo("Upgrade completed! Rebooting all hosts is recommended.")
Exemplo n.º 8
0
def generate_inventory(hosts):
    print hosts
    global CFG
    base_inventory_path = CFG.settings['ansible_inventory_path']
    base_inventory = open(base_inventory_path, 'w')
    base_inventory.write('\n[OSEv3:children]\nmasters\nnodes\n')
    base_inventory.write('\n[OSEv3:vars]\n')
    base_inventory.write('ansible_ssh_user={}\n'.format(
        CFG.settings['ansible_ssh_user']))
    if CFG.settings['ansible_ssh_user'] != 'root':
        base_inventory.write('ansible_sudo=true\n')

    # Find the correct deployment type for ansible:
    ver = find_variant(CFG.settings['variant'],
                       version=CFG.settings.get('variant_version', None))[1]
    base_inventory.write('deployment_type={}\n'.format(ver.ansible_key))

    if 'OO_INSTALL_DEVEL_REGISTRY' in os.environ:
        base_inventory.write(
            'oreg_url=rcm-img-docker01.build.eng.bos.redhat.com:'
            '5001/openshift3/ose-${component}:${version}\n')
    if 'OO_INSTALL_PUDDLE_REPO_ENABLE' in os.environ:
        base_inventory.write(
            "openshift_additional_repos=[{'id': 'ose-devel', "
            "'name': 'ose-devel', "
            "'baseurl': 'http://buildvm-devops.usersys.redhat.com"
            "/puddle/build/AtomicOpenShift/3.1/latest/RH7-RHAOS-3.1/$basearch/os', "
            "'enabled': 1, 'gpgcheck': 0}]\n")
    if 'OO_INSTALL_STAGE_REGISTRY' in os.environ:
        base_inventory.write(
            'oreg_url=registry.access.stage.redhat.com/openshift3/ose-${component}:${version}\n'
        )

    base_inventory.write('\n[masters]\n')
    masters = (host for host in hosts if host.master)
    for master in masters:
        write_host(master, base_inventory)
    base_inventory.write('\n[nodes]\n')
    nodes = (host for host in hosts if host.node)
    for node in nodes:
        # TODO: Until the Master can run the SDN itself we have to configure the Masters
        # as Nodes too.
        scheduleable = True
        # If there's only one Node and it's also a Master we want it to be scheduleable:
        if node in masters and len(masters) != 1:
            scheduleable = False
        write_host(node, base_inventory, scheduleable)
    base_inventory.close()
    return base_inventory_path
def generate_inventory(hosts):
    global CFG

    base_inventory_path = CFG.settings["ansible_inventory_path"]
    base_inventory = open(base_inventory_path, "w")
    base_inventory.write("\n[OSEv3:children]\nmasters\nnodes\n")
    base_inventory.write("\n[OSEv3:vars]\n")
    base_inventory.write("ansible_ssh_user={}\n".format(CFG.settings["ansible_ssh_user"]))
    if CFG.settings["ansible_ssh_user"] != "root":
        base_inventory.write("ansible_become=true\n")

    # Find the correct deployment type for ansible:
    ver = find_variant(CFG.settings["variant"], version=CFG.settings.get("variant_version", None))[1]
    base_inventory.write("deployment_type={}\n".format(ver.ansible_key))

    if "OO_INSTALL_ADDITIONAL_REGISTRIES" in os.environ:
        base_inventory.write(
            "cli_docker_additional_registries={}\n".format(os.environ["OO_INSTALL_ADDITIONAL_REGISTRIES"])
        )
    if "OO_INSTALL_INSECURE_REGISTRIES" in os.environ:
        base_inventory.write("cli_docker_insecure_registries={}\n".format(os.environ["OO_INSTALL_INSECURE_REGISTRIES"]))
    if "OO_INSTALL_PUDDLE_REPO" in os.environ:
        # We have to double the '{' here for literals
        base_inventory.write(
            "openshift_additional_repos=[{{'id': 'ose-devel', "
            "'name': 'ose-devel', "
            "'baseurl': '{}', "
            "'enabled': 1, 'gpgcheck': 0}}]\n".format(os.environ["OO_INSTALL_PUDDLE_REPO"])
        )

    base_inventory.write("\n[masters]\n")
    masters = (host for host in hosts if host.master)
    for master in masters:
        write_host(master, base_inventory)
    base_inventory.write("\n[nodes]\n")
    nodes = (host for host in hosts if host.node)
    for node in nodes:
        # TODO: Until the Master can run the SDN itself we have to configure the Masters
        # as Nodes too.
        scheduleable = True
        # If there's only one Node and it's also a Master we want it to be scheduleable:
        if node in masters and len(masters) != 1:
            scheduleable = False
        write_host(node, base_inventory, scheduleable)
    base_inventory.close()
    return base_inventory_path
Exemplo n.º 10
0
def error_if_missing_info(oo_cfg):
    missing_info = False
    if not oo_cfg.deployment.hosts:
        missing_info = True
        click.echo('For unattended installs, hosts must be specified on the '
                   'command line or in the config file: %s' % oo_cfg.config_path)
        sys.exit(1)

    if 'ansible_ssh_user' not in oo_cfg.settings:
        click.echo("Must specify ansible_ssh_user in configuration file.")
        sys.exit(1)

    # Lookup a variant based on the key we were given:
    if not oo_cfg.settings['variant']:
        click.echo("No variant specified in configuration file.")
        sys.exit(1)

    ver = None
    if 'variant_version' in oo_cfg.settings:
        ver = oo_cfg.settings['variant_version']
    variant, version = find_variant(oo_cfg.settings['variant'], version=ver)
    if variant is None or version is None:
        err_variant_name = oo_cfg.settings['variant']
        if ver:
            err_variant_name = "%s %s" % (err_variant_name, ver)
        click.echo("%s is not an installable variant." % err_variant_name)
        sys.exit(1)
    oo_cfg.settings['variant_version'] = version.name

    missing_facts = oo_cfg.calc_missing_facts()
    if len(missing_facts) > 0:
        missing_info = True
        click.echo('For unattended installs, facts must be provided for all masters/nodes:')
        for host in missing_facts:
            click.echo('Host "%s" missing facts: %s' % (host, ", ".join(missing_facts[host])))

    # check that all listed host roles are included
    listed_roles = get_host_roles_set(oo_cfg)
    configured_roles = set([role for role in oo_cfg.deployment.roles])
    if listed_roles != configured_roles:
        missing_info = True
        click.echo('Any roles assigned to hosts must be defined.')

    if missing_info:
        sys.exit(1)
Exemplo n.º 11
0
def error_if_missing_info(oo_cfg):
    missing_info = False
    if not oo_cfg.hosts:
        missing_info = True
        click.echo('For unattended installs, hosts must be specified on the '
                   'command line or in the config file: %s' %
                   oo_cfg.config_path)
        sys.exit(1)

    if 'ansible_ssh_user' not in oo_cfg.settings:
        click.echo("Must specify ansible_ssh_user in configuration file.")
        sys.exit(1)

    # Lookup a variant based on the key we were given:
    if not oo_cfg.settings['variant']:
        click.echo("No variant specified in configuration file.")
        sys.exit(1)

    ver = None
    if 'variant_version' in oo_cfg.settings:
        ver = oo_cfg.settings['variant_version']
    variant, version = find_variant(oo_cfg.settings['variant'], version=ver)
    if variant is None or version is None:
        err_variant_name = oo_cfg.settings['variant']
        if ver:
            err_variant_name = "%s %s" % (err_variant_name, ver)
        click.echo("%s is not an installable variant." % err_variant_name)
        sys.exit(1)
    oo_cfg.settings['variant_version'] = version.name

    missing_facts = oo_cfg.calc_missing_facts()
    if len(missing_facts) > 0:
        missing_info = True
        click.echo(
            'For unattended installs, facts must be provided for all masters/nodes:'
        )
        for host in missing_facts:
            click.echo('Host "%s" missing facts: %s' %
                       (host, ", ".join(missing_facts[host])))

    if missing_info:
        sys.exit(1)
Exemplo n.º 12
0
def error_if_missing_info(oo_cfg):
    missing_info = False
    if not oo_cfg.deployment.hosts:
        missing_info = True
        click.echo(
            "For unattended installs, hosts must be specified on the "
            "command line or in the config file: %s" % oo_cfg.config_path
        )
        sys.exit(1)

    if "ansible_ssh_user" not in oo_cfg.deployment.variables:
        click.echo("Must specify ansible_ssh_user in configuration file.")
        sys.exit(1)

    # Lookup a variant based on the key we were given:
    if not oo_cfg.settings["variant"]:
        click.echo("No variant specified in configuration file.")
        sys.exit(1)

    ver = None
    if "variant_version" in oo_cfg.settings:
        ver = oo_cfg.settings["variant_version"]
    variant, version = find_variant(oo_cfg.settings["variant"], version=ver)
    if variant is None or version is None:
        err_variant_name = oo_cfg.settings["variant"]
        if ver:
            err_variant_name = "%s %s" % (err_variant_name, ver)
        click.echo("%s is not an installable variant." % err_variant_name)
        sys.exit(1)
    oo_cfg.settings["variant_version"] = version.name

    # check that all listed host roles are included
    listed_roles = get_host_roles_set(oo_cfg)
    configured_roles = set([role for role in oo_cfg.deployment.roles])
    if listed_roles != configured_roles:
        missing_info = True
        click.echo("Any roles assigned to hosts must be defined.")

    if missing_info:
        sys.exit(1)
Exemplo n.º 13
0
def error_if_missing_info(oo_cfg):
    missing_info = False
    if not oo_cfg.hosts:
        missing_info = True
        click.echo(
            "For unattended installs, hosts must be specified on the "
            "command line or in the config file: %s" % oo_cfg.config_path
        )
        sys.exit(1)

    if "ansible_ssh_user" not in oo_cfg.settings:
        click.echo("Must specify ansible_ssh_user in configuration file.")
        sys.exit(1)

    # Lookup a variant based on the key we were given:
    if not oo_cfg.settings["variant"]:
        click.echo("No variant specified in configuration file.")
        sys.exit(1)

    ver = None
    if "variant_version" in oo_cfg.settings:
        ver = oo_cfg.settings["variant_version"]
    variant, version = find_variant(oo_cfg.settings["variant"], version=ver)
    if variant is None or version is None:
        err_variant_name = oo_cfg.settings["variant"]
        if ver:
            err_variant_name = "%s %s" % (err_variant_name, ver)
        click.echo("%s is not an installable variant." % err_variant_name)
        sys.exit(1)
    oo_cfg.settings["variant_version"] = version.name

    missing_facts = oo_cfg.calc_missing_facts()
    if len(missing_facts) > 0:
        missing_info = True
        click.echo("For unattended installs, facts must be provided for all masters/nodes:")
        for host in missing_facts:
            click.echo('Host "%s" missing facts: %s' % (host, ", ".join(missing_facts[host])))

    if missing_info:
        sys.exit(1)
Exemplo n.º 14
0
def error_if_missing_info(oo_cfg):
    missing_info = False
    if not oo_cfg.deployment.hosts:
        missing_info = True
        click.echo('For unattended installs, hosts must be specified on the '
                   'command line or in the config file: %s' %
                   oo_cfg.config_path)
        sys.exit(1)

    if 'ansible_ssh_user' not in oo_cfg.deployment.variables:
        click.echo("Must specify ansible_ssh_user in configuration file.")
        sys.exit(1)

    # Lookup a variant based on the key we were given:
    if not oo_cfg.settings['variant']:
        click.echo("No variant specified in configuration file.")
        sys.exit(1)

    ver = None
    if 'variant_version' in oo_cfg.settings:
        ver = oo_cfg.settings['variant_version']
    variant, version = find_variant(oo_cfg.settings['variant'], version=ver)
    if variant is None or version is None:
        err_variant_name = oo_cfg.settings['variant']
        if ver:
            err_variant_name = "%s %s" % (err_variant_name, ver)
        click.echo("%s is not an installable variant." % err_variant_name)
        sys.exit(1)
    oo_cfg.settings['variant_version'] = version.name

    # check that all listed host roles are included
    listed_roles = get_host_roles_set(oo_cfg)
    configured_roles = set([role for role in oo_cfg.deployment.roles])
    if listed_roles != configured_roles:
        missing_info = True
        click.echo('Any roles assigned to hosts must be defined.')

    if missing_info:
        sys.exit(1)
Exemplo n.º 15
0
def upgrade(ctx):
    oo_cfg = ctx.obj['oo_cfg']
    verbose = ctx.obj['verbose']

    if len(oo_cfg.hosts) == 0:
        click.echo("No hosts defined in: %s" % oo_cfg.config_path)
        sys.exit(1)

    # Update config to reflect the version we're targetting, we'll write
    # to disk once ansible completes successfully, not before.
    old_variant = oo_cfg.settings['variant']
    old_version = oo_cfg.settings['variant_version']
    if oo_cfg.settings['variant'] == 'enterprise':
        oo_cfg.settings['variant'] = 'openshift-enterprise'
    version = find_variant(oo_cfg.settings['variant'])[1]
    oo_cfg.settings['variant_version'] = version.name
    click.echo(
        "Openshift will be upgraded from %s %s to %s %s on the following hosts:\n"
        % (old_variant, old_version, oo_cfg.settings['variant'],
           oo_cfg.settings['variant_version']))
    for host in oo_cfg.hosts:
        click.echo("  * %s" % host.connect_to)

    if not ctx.obj['unattended']:
        # Prompt interactively to confirm:
        proceed = click.confirm("\nDo you wish to proceed?")
        if not proceed:
            click.echo("Upgrade cancelled.")
            sys.exit(0)

    retcode = openshift_ansible.run_upgrade_playbook(verbose)
    if retcode > 0:
        click.echo("Errors encountered during upgrade, please check %s." %
                   oo_cfg.settings['ansible_log_path'])
    else:
        oo_cfg.save_to_disk()
        click.echo("Upgrade completed! Rebooting all hosts is recommended.")
Exemplo n.º 16
0
def upgrade(ctx, latest_minor, next_major):
    oo_cfg = ctx.obj['oo_cfg']

    if len(oo_cfg.deployment.hosts) == 0:
        click.echo("No hosts defined in: %s" % oo_cfg.config_path)
        sys.exit(1)

    variant = oo_cfg.settings['variant']
    if find_variant(variant)[0] is None:
        click.echo("%s is not a supported variant for upgrade." % variant)
        sys.exit(0)

    old_version = oo_cfg.settings['variant_version']

    try:
        mapping = UPGRADE_MAPPINGS[old_version]
    except KeyError:
        click.echo('No upgrades available for %s %s' % (variant, old_version))
        sys.exit(0)

    message = """
        This tool will help you upgrade your existing OpenShift installation.
        Currently running: %s %s
"""
    click.echo(message % (variant, old_version))

    # Map the dynamic upgrade options to the playbook to run for each.
    # Index offset by 1.
    # List contains tuples of booleans for (latest_minor, next_major)
    selections = []
    if not (latest_minor or next_major):
        i = 0
        if 'minor_playbook' in mapping:
            click.echo("(%s) Update to latest %s" % (i + 1, old_version))
            selections.append((True, False))
            i += 1
        if 'major_playbook' in mapping:
            click.echo("(%s) Upgrade to next release: %s" % (i + 1, mapping['major_version']))
            selections.append((False, True))
            i += 1

        response = click.prompt("\nChoose an option from above",
                                type=click.Choice(list(map(str, range(1, len(selections) + 1)))))
        latest_minor, next_major = selections[int(response) - 1]

    if next_major:
        if 'major_playbook' not in mapping:
            click.echo("No major upgrade supported for %s %s with this version "
                       "of atomic-openshift-utils." % (variant, old_version))
            sys.exit(0)
        playbook = mapping['major_playbook']
        new_version = mapping['major_version']
        # Update config to reflect the version we're targeting, we'll write
        # to disk once Ansible completes successfully, not before.
        oo_cfg.settings['variant_version'] = new_version
        if oo_cfg.settings['variant'] == 'enterprise':
            oo_cfg.settings['variant'] = 'openshift-enterprise'

    if latest_minor:
        if 'minor_playbook' not in mapping:
            click.echo("No minor upgrade supported for %s %s with this version "
                       "of atomic-openshift-utils." % (variant, old_version))
            sys.exit(0)
        playbook = mapping['minor_playbook']
        new_version = old_version

    click.echo("OpenShift will be upgraded from %s %s to latest %s %s on the following hosts:\n" % (
        variant, old_version, oo_cfg.settings['variant'], new_version))
    for host in oo_cfg.deployment.hosts:
        click.echo("  * %s" % host.connect_to)

    if not ctx.obj['unattended']:
        # Prompt interactively to confirm:
        if not click.confirm("\nDo you want to proceed?"):
            click.echo("Upgrade cancelled.")
            sys.exit(0)

    retcode = openshift_ansible.run_upgrade_playbook(oo_cfg.deployment.hosts,
                                                     playbook,
                                                     ctx.obj['verbose'])
    if retcode > 0:
        click.echo("Errors encountered during upgrade, please check %s." %
                   oo_cfg.settings['ansible_log_path'])
    else:
        oo_cfg.save_to_disk()
        click.echo("Upgrade completed! Rebooting all hosts is recommended.")
Exemplo n.º 17
0
def upgrade(ctx, latest_minor, next_major):
    oo_cfg = ctx.obj['oo_cfg']

    if len(oo_cfg.deployment.hosts) == 0:
        click.echo("No hosts defined in: %s" % oo_cfg.config_path)
        sys.exit(1)

    variant = oo_cfg.settings['variant']
    if find_variant(variant)[0] is None:
        click.echo("%s is not a supported variant for upgrade." % variant)
        sys.exit(0)

    old_version = oo_cfg.settings['variant_version']
    mapping = UPGRADE_MAPPINGS.get(old_version)

    message = """
        This tool will help you upgrade your existing OpenShift installation.
        Currently running: %s %s
"""
    click.echo(message % (variant, old_version))

    # Map the dynamic upgrade options to the playbook to run for each.
    # Index offset by 1.
    # List contains tuples of booleans for (latest_minor, next_major)
    selections = []
    if not (latest_minor or next_major):
        i = 0
        if 'minor_playbook' in mapping:
            click.echo("(%s) Update to latest %s" % (i + 1, old_version))
            selections.append((True, False))
            i += 1
        if 'major_playbook' in mapping:
            click.echo("(%s) Upgrade to next release: %s" %
                       (i + 1, mapping['major_version']))
            selections.append((False, True))
            i += 1

        response = click.prompt(
            "\nChoose an option from above",
            type=click.Choice(list(map(str, range(1,
                                                  len(selections) + 1)))))
        latest_minor, next_major = selections[int(response) - 1]

    if next_major:
        if 'major_playbook' not in mapping:
            click.echo(
                "No major upgrade supported for %s %s with this version "
                "of atomic-openshift-utils." % (variant, old_version))
            sys.exit(0)
        playbook = mapping['major_playbook']
        new_version = mapping['major_version']
        # Update config to reflect the version we're targetting, we'll write
        # to disk once Ansible completes successfully, not before.
        oo_cfg.settings['variant_version'] = new_version
        if oo_cfg.settings['variant'] == 'enterprise':
            oo_cfg.settings['variant'] = 'openshift-enterprise'

    if latest_minor:
        if 'minor_playbook' not in mapping:
            click.echo(
                "No minor upgrade supported for %s %s with this version "
                "of atomic-openshift-utils." % (variant, old_version))
            sys.exit(0)
        playbook = mapping['minor_playbook']
        new_version = old_version

    click.echo(
        "OpenShift will be upgraded from %s %s to latest %s %s on the following hosts:\n"
        % (variant, old_version, oo_cfg.settings['variant'], new_version))
    for host in oo_cfg.deployment.hosts:
        click.echo("  * %s" % host.connect_to)

    if not ctx.obj['unattended']:
        # Prompt interactively to confirm:
        if not click.confirm("\nDo you want to proceed?"):
            click.echo("Upgrade cancelled.")
            sys.exit(0)

    retcode = openshift_ansible.run_upgrade_playbook(oo_cfg.deployment.hosts,
                                                     playbook,
                                                     ctx.obj['verbose'])
    if retcode > 0:
        click.echo("Errors encountered during upgrade, please check %s." %
                   oo_cfg.settings['ansible_log_path'])
    else:
        oo_cfg.save_to_disk()
        click.echo("Upgrade completed! Rebooting all hosts is recommended.")
Exemplo n.º 18
0
def generate_inventory(hosts):
    global CFG
    masters = [host for host in hosts if host.master]
    nodes = [host for host in hosts if host.node]
    proxy = determine_proxy_configuration(hosts)
    multiple_masters = len(masters) > 1

    base_inventory_path = CFG.settings['ansible_inventory_path']
    base_inventory = open(base_inventory_path, 'w')

    write_inventory_children(base_inventory, multiple_masters, proxy)

    write_inventory_vars(base_inventory, multiple_masters, proxy)

    # Find the correct deployment type for ansible:
    ver = find_variant(CFG.settings['variant'],
        version=CFG.settings.get('variant_version', None))[1]
    base_inventory.write('deployment_type={}\n'.format(ver.ansible_key))

    if 'OO_INSTALL_ADDITIONAL_REGISTRIES' in os.environ:
        base_inventory.write('cli_docker_additional_registries={}\n'
          .format(os.environ['OO_INSTALL_ADDITIONAL_REGISTRIES']))
    if 'OO_INSTALL_INSECURE_REGISTRIES' in os.environ:
        base_inventory.write('cli_docker_insecure_registries={}\n'
          .format(os.environ['OO_INSTALL_INSECURE_REGISTRIES']))
    if 'OO_INSTALL_PUDDLE_REPO' in os.environ:
        # We have to double the '{' here for literals
        base_inventory.write("openshift_additional_repos=[{{'id': 'ose-devel', "
            "'name': 'ose-devel', "
            "'baseurl': '{}', "
            "'enabled': 1, 'gpgcheck': 0}}]\n".format(os.environ['OO_INSTALL_PUDDLE_REPO']))

    base_inventory.write('\n[masters]\n')
    for master in masters:
        write_host(master, base_inventory)

    if len(masters) > 1:
        base_inventory.write('\n[etcd]\n')
        for master in masters:
            write_host(master, base_inventory)

    base_inventory.write('\n[nodes]\n')

    # TODO: It would be much better to calculate the scheduleability elsewhere
    # and store it on the Node object.
    if set(nodes) == set(masters):
        for node in nodes:
            write_host(node, base_inventory)
    else:
        for node in nodes:
            # TODO: Until the Master can run the SDN itself we have to configure the Masters
            # as Nodes too.
            schedulable = True
            if node in masters:
                schedulable = False
            write_host(node, base_inventory, schedulable)

    if not getattr(proxy, 'preconfigured', True):
        base_inventory.write('\n[lb]\n')
        write_host(proxy, base_inventory)

    base_inventory.close()
    return base_inventory_path
Exemplo n.º 19
0
def generate_inventory(hosts):
    global CFG
    masters = [host for host in hosts if host.master]
    nodes = [host for host in hosts if host.node]
    proxy = determine_proxy_configuration(hosts)
    multiple_masters = len(masters) > 1

    base_inventory_path = CFG.settings['ansible_inventory_path']
    base_inventory = open(base_inventory_path, 'w')

    write_inventory_children(base_inventory, multiple_masters, proxy)

    write_inventory_vars(base_inventory, multiple_masters, proxy)

    # Find the correct deployment type for ansible:
    ver = find_variant(CFG.settings['variant'],
                       version=CFG.settings.get('variant_version', None))[1]
    base_inventory.write('deployment_type={}\n'.format(ver.ansible_key))

    if 'OO_INSTALL_ADDITIONAL_REGISTRIES' in os.environ:
        base_inventory.write('cli_docker_additional_registries={}\n'.format(
            os.environ['OO_INSTALL_ADDITIONAL_REGISTRIES']))
    if 'OO_INSTALL_INSECURE_REGISTRIES' in os.environ:
        base_inventory.write('cli_docker_insecure_registries={}\n'.format(
            os.environ['OO_INSTALL_INSECURE_REGISTRIES']))
    if 'OO_INSTALL_PUDDLE_REPO' in os.environ:
        # We have to double the '{' here for literals
        base_inventory.write(
            "openshift_additional_repos=[{{'id': 'ose-devel', "
            "'name': 'ose-devel', "
            "'baseurl': '{}', "
            "'enabled': 1, 'gpgcheck': 0}}]\n".format(
                os.environ['OO_INSTALL_PUDDLE_REPO']))

    base_inventory.write('\n[masters]\n')
    for master in masters:
        write_host(master, base_inventory)

    if len(masters) > 1:
        base_inventory.write('\n[etcd]\n')
        for master in masters:
            write_host(master, base_inventory)

    base_inventory.write('\n[nodes]\n')

    # TODO: It would be much better to calculate the scheduleability elsewhere
    # and store it on the Node object.
    if set(nodes) == set(masters):
        for node in nodes:
            write_host(node, base_inventory)
    else:
        for node in nodes:
            # TODO: Until the Master can run the SDN itself we have to configure the Masters
            # as Nodes too.
            schedulable = True
            if node in masters:
                schedulable = False
            write_host(node, base_inventory, schedulable)

    if not getattr(proxy, 'preconfigured', True):
        base_inventory.write('\n[lb]\n')
        write_host(proxy, base_inventory)

    base_inventory.close()
    return base_inventory_path