Exemple #1
0
    def evacuate():
        config = flask.current_app.config.get("PLUGINS") or {}
        src = hooks.source.connect()
        if "destination" not in flask.current_app.config["CLOUDS"]:
            dst = None
        else:
            dst = hooks.destination.connect()
        ctx = context.Context(config, src, dst)
        events.emit("update", {
            "id": host_id,
            "type": "host",
            "cloud": src.name,
            "progress": None,
            "action": "evacuation",
        }, namespace="/events")

        try:
            flow = evacuation.evacuate_host(ctx, host_id)
            LOG.debug("Evacuation flow: %s", flow)
            result = flows.run_flow(flow, ctx.store)
            LOG.debug("Result of evacuation: %s", result)
        except Exception:
            msg = ("Error occured during evacuating host {}"
                   .format(host_id))
            LOG.exception(msg)
            events.emit("log", {
                "level": "error",
                "message": msg,
            }, namespace="/events")

        events.emit("update", {
            "id": host_id,
            "type": "host",
            "cloud": src.name,
            "progress": None,
            "action": None,
        }, namespace="/events")
Exemple #2
0
def main():
    args = get_parser().parse_args()

    utils.configure_logging(args.config)

    events = Events()
    Cloud, Identity = load_cloud_driver(is_fake=args.fake)
    clouds_config = args.config["CLOUDS"]
    plugins_config = args.config["PLUGINS"]
    if args.config.get("PARAMETERS"):
        plugins_config.update(args.config.get("PARAMETERS"))
    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", {})
            setup(plugins_config, 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)
        cleanup(plugins_config, events, cloud, args.target, dump=args.dump)
    elif args.action == "setup":
        src_config = clouds_config["source"]
        src = init_client(src_config,
                          "source",
                          Cloud,
                          Identity)
        workloads = clouds_config["source"].get("workloads", {})
        setup(plugins_config, events, src, "source",
              args.num_tenants, args.num_servers, args.num_volumes,
              workloads, dump=args.dump)
    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_host(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 = dict(plugins_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)
    elif args.action == "get_resources":
        client = init_client(
            clouds_config[args.target],
            args.target,
            Cloud,
            Identity,
        )
        print(json.dumps(get_resources(args.config, client)))