Ejemplo n.º 1
0
    def reassign():
        # NOTE(akscram): Initialization of fuelclient.
        fuel_config = flask.current_app.config["CLOUDS"]["fuel"]["endpoint"]
        os.environ["SERVER_ADDRESS"] = fuel_config["host"]
        os.environ["LISTEN_PORT"] = str(fuel_config["port"])
        os.environ["KEYSTONE_USER"] = fuel_config["username"]
        os.environ["KEYSTONE_PASS"] = fuel_config["password"]

        src_config = hooks.source.config()
        dst_config = hooks.destination.config()
        config = {
            "source": src_config["environment"],
            "destination": dst_config["environment"],
        }

        try:
            src = hooks.source.connect()
            dst = hooks.destination.connect()
            ctx = context.Context(config, src, dst)

            flow = node_tasks.reassign_node(ctx, host_id)
            LOG.debug("Reassigning flow: %s", flow)
            result = flows.run_flow(flow, ctx.store)
            LOG.debug("Result of migration: %s", result)
        except Exception:
            msg = ("Error is occured during reassigning host {}"
                   .format(host_id))
            LOG.exception(msg)
            events.emit("error", {
                "message": msg,
            }, namespace="/events")
Ejemplo n.º 2
0
def main():
    args = get_parser().parse_args()

    logging.basicConfig(level=logging.INFO)

    events = Events()
    Cloud, Identity = load_cloud_driver(is_fake=args.fake)
    clouds_config = args.config["CLOUDS"]
    plugins_config = args.config["PLUGINS"]
    if args.action == "migrate":
        flow = graph_flow.Flow("migrate-resources")
        store = {}
        src_config = clouds_config["source"]
        src = init_client(src_config,
                          "source",
                          Cloud,
                          Identity)
        if args.setup:
            workloads = clouds_config["source"].get("workloads", {})
            management.setup(events, src, "source", args.num_tenants,
                             args.num_servers, args.num_volumes, workloads)
        dst_config = clouds_config["destination"]
        dst = init_client(dst_config,
                          "destination",
                          Cloud,
                          Identity)
        migrate_function = RESOURCES_MIGRATIONS[args.resource]
        if args.ids:
            ids = args.ids
        elif args.tenant:
            ids = get_ids_by_tenant(src, args.resource, args.tenant)
        elif args.host:
            ids = get_ids_by_host(src, args.resource, args.host)
        else:
            raise exceptions.UsageError("Missing tenant ID")
        ctx = context.Context(plugins_config, src, dst)
        resources_flow = migrate_function(ctx, flow, ids)
        if (args.dump):
            with open(args.dump, "w") as f:
                utils.dump_flow(resources_flow, f, True)
            return 0

        flows.run_flow(resources_flow, ctx.store)
    elif args.action == "cleanup":
        cloud_config = clouds_config[args.target]
        cloud = init_client(cloud_config,
                            args.target,
                            Cloud,
                            Identity)
        management.cleanup(events, cloud, args.target)
    elif args.action == "setup":
        src_config = clouds_config["source"]
        src = init_client(src_config,
                          "source",
                          Cloud,
                          Identity)
        workloads = clouds_config["source"].get("workloads", {})
        management.setup(plugins_config, events, src, "source",
                         args.num_tenants,
                         args.num_servers,
                         args.num_volumes,
                         workloads)
    elif args.action == "evacuate":
        src = init_client(clouds_config["source"],
                          "source",
                          Cloud,
                          Identity)
        dst = init_client(clouds_config["destination"],
                          "destination",
                          Cloud,
                          Identity)
        ctx = context.Context(plugins_config, src, dst)
        flow = evacuation_tasks.evacuate_servers(ctx, args.hostname)
        if (args.dump):
            with open(args.dump, "w") as f:
                utils.dump_flow(flow, f, True)
            return
        flows.run_flow(flow, ctx.store)
    elif args.action == "reassign":
        fuel_config = clouds_config["fuel"]["endpoint"]
        os.environ["SERVER_ADDRESS"] = fuel_config["host"]
        os.environ["LISTEN_PORT"] = str(fuel_config["port"])
        os.environ["KEYSTONE_USER"] = fuel_config["username"]
        os.environ["KEYSTONE_PASS"] = fuel_config["password"]

        src_config = clouds_config["source"]
        dst_config = clouds_config["destination"]
        config = {
            "source": src_config["environment"],
            "destination": dst_config["environment"],
        }
        src = init_client(src_config,
                          "source",
                          Cloud,
                          Identity)
        dst = init_client(dst_config,
                          "destination",
                          Cloud,
                          Identity)
        ctx = context.Context(config, src, dst)
        flow = reassignment_tasks.reassign_node(ctx, args.hostname)
        if (args.dump):
            with open(args.dump, "w") as f:
                utils.dump_flow(flow, f, True)
            return
        flows.run_flow(flow, ctx.store)