Esempio n. 1
0
def transfer_plugins_settings(orig_env_id, seed_env_id, plugins):
    orig_env = environment.Environment(orig_env_id)
    seed_env = environment.Environment(seed_env_id)
    astute = env_util.get_astute_yaml(orig_env)
    attrs = seed_env.get_settings_data()
    editable_attrs = attrs['editable']

    plugin_fns = {}
    plugin_attrs = {}
    for plugin in plugins:
        try:
            plugin_fns[plugin] = PLUGINS[plugin]
        except KeyError:
            raise UnknownPlugin(plugin)
        try:
            plugin_attrs[plugin] = editable_attrs[plugin]
        except KeyError:
            raise PluginNotConfigured(plugin, seed_env_id)

    for plugin in plugins:
        LOG.info("Fetching settings for plugin '%s'", plugin)
        plugin_fn = plugin_fns[plugin]
        plugin_attr = plugin_attrs[plugin]
        plugin_fn(astute, plugin_attr)

    seed_env.set_settings_data(attrs)
def transfer_plugins_settings(orig_env_id, seed_env_id, plugins):
    orig_env = environment.Environment(orig_env_id)
    seed_env = environment.Environment(seed_env_id)
    astute = env_util.get_astute_yaml(orig_env)
    attrs = seed_env.get_settings_data()
    editable_attrs = attrs['editable']

    plugin_fns = {}
    plugin_attrs = {}
    for plugin in plugins:
        try:
            plugin_fns[plugin] = PLUGINS[plugin]
        except KeyError:
            raise UnknownPlugin(plugin)
        try:
            plugin_attrs[plugin] = editable_attrs[plugin]
        except KeyError:
            raise PluginNotConfigured(plugin, seed_env_id)

    for plugin in plugins:
        LOG.info("Fetching settings for plugin '%s'", plugin)
        plugin_fn = plugin_fns[plugin]
        plugin_attr = plugin_attrs[plugin]
        plugin_fn(astute, plugin_attr)

    seed_env.set_settings_data(attrs)
Esempio n. 3
0
def upgrade_env(env_id):
    target_release = find_deployable_release("Ubuntu")
    seed_id = env_util.clone_env(env_id, target_release)

    master_ip = env_util.get_astute_yaml(environment_obj.Environment(env_id))[
        'master_ip']
    env_util.change_env_settings(seed_id, master_ip)
    return seed_id
Esempio n. 4
0
def upgrade_env(env_id):
    env = environment_obj.Environment(env_id)
    target_release = find_deployable_release("Ubuntu")
    seed_id = env_util.clone_env(env_id, target_release)
    env_util.cache_service_tenant_id(env)
    master_ip = env_util.get_astute_yaml(env)['master_ip']
    env_util.change_env_settings(seed_id, master_ip)
    return seed_id
Esempio n. 5
0
def transfer_plugins_settings(orig_env_id, seed_env_id, plugins):
    orig_env = environment.Environment(orig_env_id)
    seed_env = environment.Environment(seed_env_id)
    astute = env_util.get_astute_yaml(orig_env)
    attrs = seed_env.get_settings_data()

    for plugin in plugins:
        LOG.info("Fetching settings for plugin '%s'", plugin)
        PLUGINS[plugin](astute, attrs['editable'][plugin])

    seed_env.set_settings_data(attrs)
Esempio n. 6
0
def transfer_plugins_settings(orig_env_id, seed_env_id, plugins):
    orig_env = environment.Environment(orig_env_id)
    seed_env = environment.Environment(seed_env_id)
    astute = env_util.get_astute_yaml(orig_env)
    attrs = seed_env.get_settings_data()

    for plugin in plugins:
        LOG.info("Fetching settings for plugin '%s'", plugin)
        PLUGINS[plugin](astute, attrs['editable'][plugin])

    seed_env.set_settings_data(attrs)
Esempio n. 7
0
def transfer_plugins_settings(orig_env_id, seed_env_id, plugins):
    orig_env = environment.Environment(orig_env_id)
    seed_env = environment.Environment(seed_env_id)
    astute = env_util.get_astute_yaml(orig_env)
    attrs = {}

    for plugin in plugins:
        LOG.info("Fetching settings for plugin '%s'", plugin)
        attrs[plugin] = PLUGINS[plugin](astute)

    seed_env.update_attributes({'editable': attrs})
Esempio n. 8
0
def sync_glance_images(source_env_id, seed_env_id, seed_swift_ep):
    """Sync glance images from original ENV to seed ENV

    Args:
        source_env_id (int): ID of original ENV.
        seed_env_id (int): ID of seed ENV.
        seed_swift_ep (str): endpoint's name where swift-proxy service is
                             listening on.

    Examples:
        sync_glance_images(2, 3, 'br-mgmt')
    """
    # set glance username
    glance_user = "******"
    # set swift container value
    container = "glance"
    # choose tenant
    tenant = "services"
    # get clusters by id
    source_env = environment_obj.Environment(source_env_id)
    seed_env = environment_obj.Environment(seed_env_id)
    # gather cics admin IPs
    source_node = next(env_util.get_controllers(source_env))
    seed_node = next(env_util.get_controllers(seed_env))
    # get cics yaml files
    source_yaml = env_util.get_astute_yaml(source_env, source_node)
    seed_yaml = env_util.get_astute_yaml(seed_env, seed_node)
    # get glance passwords
    source_glance_pass = get_glance_password(source_yaml)
    seed_glance_pass = get_glance_password(seed_yaml)
    # get seed node swift ip
    seed_swift_ip = get_endpoint_ip(seed_swift_ep, seed_yaml)
    # get service tenant id & lists of objects for source env
    source_token = get_auth_token(source_node, tenant, glance_user,
                                  source_glance_pass)
    source_swift_list = set(
        get_swift_objects(source_node, tenant, glance_user, source_glance_pass,
                          source_token, container))
    # get service tenant id & lists of objects for seed env
    seed_token = get_auth_token(seed_node, tenant, glance_user,
                                seed_glance_pass)
    seed_swift_list = set(
        get_swift_objects(seed_node, tenant, glance_user, seed_glance_pass,
                          seed_token, container))
    # get service tenant for seed env
    seed_tenant = env_util.get_service_tenant_id(seed_env)
    # check consistency of matched images
    source_token = get_auth_token(source_node, tenant, glance_user,
                                  source_glance_pass)
    seed_token = get_auth_token(seed_node, tenant, glance_user,
                                seed_glance_pass)
    for image in source_swift_list & seed_swift_list:
        source_obj_etag = get_object_property(source_node, tenant, glance_user,
                                              source_glance_pass, source_token,
                                              container, image, 'ETag')
        seed_obj_etag = get_object_property(seed_node, tenant, glance_user,
                                            seed_glance_pass, seed_token,
                                            container, image, 'ETag')
        if source_obj_etag != seed_obj_etag:
            # image should be resynced
            delete_image(seed_node, tenant, glance_user, seed_glance_pass,
                         seed_token, container, image)
            LOG.info("Swift %s image should be resynced" % image)
            seed_swift_list.remove(image)
    # migrate new images
    for image in source_swift_list - seed_swift_list:
        # download image on source's node local drive
        source_token = get_auth_token(source_node, tenant, glance_user,
                                      source_glance_pass)
        download_image(source_node, tenant, glance_user, source_glance_pass,
                       source_token, container, image)
        # transfer image
        source_token = get_auth_token(source_node, tenant, glance_user,
                                      source_glance_pass)
        seed_token = get_auth_token(seed_node, tenant, glance_user,
                                    seed_glance_pass)
        transfer_image(source_node, tenant, glance_user, seed_glance_pass,
                       seed_token, container, image, seed_swift_ip,
                       seed_tenant)
        # remove transferred image
        ssh.sftp(source_node).remove(image)
    # delete outdated images
    for image in seed_swift_list - source_swift_list:
        token = get_auth_token(seed_node, tenant, glance_user,
                               seed_glance_pass)
        delete_image(seed_node, tenant, glance_user, seed_glance_pass, token,
                     container, image)
Esempio n. 9
0
def disconnect_networks(env):
    controllers = list(env_util.get_controllers(env))
    for node in controllers:
        deployment_info = env_util.get_astute_yaml(env, node)
        network.delete_patch_ports(node, deployment_info)
Esempio n. 10
0
def sync_glance_images(source_env_id, seed_env_id, seed_swift_ep):
    """Sync glance images from original ENV to seed ENV

    Args:
        source_env_id (int): ID of original ENV.
        seed_env_id (int): ID of seed ENV.
        seed_swift_ep (str): endpoint's name where swift-proxy service is
                             listening on.

    Examples:
        sync_glance_images(2, 3, 'br-mgmt')
    """
    # set glance username
    glance_user = "******"
    # set swift container value
    container = "glance"
    # choose tenant
    tenant = "services"
    # get clusters by id
    source_env = environment_obj.Environment(source_env_id)
    seed_env = environment_obj.Environment(seed_env_id)
    # gather cics admin IPs
    source_node = next(env_util.get_controllers(source_env))
    seed_node = next(env_util.get_controllers(seed_env))
    # get cics yaml files
    source_yaml = env_util.get_astute_yaml(source_env, source_node)
    seed_yaml = env_util.get_astute_yaml(seed_env, seed_node)
    # get glance passwords
    source_glance_pass = get_glance_password(source_yaml)
    seed_glance_pass = get_glance_password(seed_yaml)
    # get seed node swift ip
    seed_swift_ip = get_endpoint_ip(seed_swift_ep, seed_yaml)
    # get service tenant id & lists of objects for source env
    source_token = get_auth_token(source_node, tenant, glance_user, source_glance_pass)
    source_swift_list = set(
        get_swift_objects(source_node, tenant, glance_user, source_glance_pass, source_token, container)
    )
    # get service tenant id & lists of objects for seed env
    seed_token = get_auth_token(seed_node, tenant, glance_user, seed_glance_pass)
    seed_swift_list = set(get_swift_objects(seed_node, tenant, glance_user, seed_glance_pass, seed_token, container))
    # get service tenant for seed env
    seed_tenant = env_util.get_service_tenant_id(seed_env)
    # check consistency of matched images
    source_token = get_auth_token(source_node, tenant, glance_user, source_glance_pass)
    seed_token = get_auth_token(seed_node, tenant, glance_user, seed_glance_pass)
    for image in source_swift_list & seed_swift_list:
        source_obj_etag = get_object_property(
            source_node, tenant, glance_user, source_glance_pass, source_token, container, image, "ETag"
        )
        seed_obj_etag = get_object_property(
            seed_node, tenant, glance_user, seed_glance_pass, seed_token, container, image, "ETag"
        )
        if source_obj_etag != seed_obj_etag:
            # image should be resynced
            delete_image(seed_node, tenant, glance_user, seed_glance_pass, seed_token, container, image)
            LOG.info("Swift %s image should be resynced" % image)
            seed_swift_list.remove(image)
    # migrate new images
    for image in source_swift_list - seed_swift_list:
        # download image on source's node local drive
        source_token = get_auth_token(source_node, tenant, glance_user, source_glance_pass)
        download_image(source_node, tenant, glance_user, source_glance_pass, source_token, container, image)
        # transfer image
        source_token = get_auth_token(source_node, tenant, glance_user, source_glance_pass)
        seed_token = get_auth_token(seed_node, tenant, glance_user, seed_glance_pass)
        transfer_image(
            source_node, tenant, glance_user, seed_glance_pass, seed_token, container, image, seed_swift_ip, seed_tenant
        )
        # remove transferred image
        ssh.sftp(source_node).remove(image)
    # delete outdated images
    for image in seed_swift_list - source_swift_list:
        token = get_auth_token(seed_node, tenant, glance_user, seed_glance_pass)
        delete_image(seed_node, tenant, glance_user, seed_glance_pass, token, container, image)