Пример #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")
Пример #2
0
    def evacuate():
        config = flask.current_app.config.get("PLUGINS") or {}
        src = hooks.source.connect()
        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_servers(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 is occured during evacuating host {}"
                   .format(host_id))
            LOG.exception(msg)
            events.emit("error", {
                "message": msg,
            }, namespace="/events")

        events.emit("update", {
            "id": host_id,
            "type": "host",
            "cloud": src.name,
            "progress": None,
            "action": None,
        }, namespace="/events")
Пример #3
0
    def migrate():
        config = flask.current_app.config.get("PLUGINS") or {}
        src = hooks.source.connect()
        dst = hooks.destination.connect()
        ctx = context.Context(config, src, dst)
        events.emit("update", {
            "id": tenant_id,
            "cloud": src.name,
            "type": "tenant",
            "progress": None,
            "action": "migration",
        }, namespace="/events")

        try:
            flow = resource_tasks.migrate_resources(ctx, tenant_id)
            LOG.debug("Migration flow: %s", flow)
            result = flows.run_flow(flow, ctx.store)
            LOG.debug("Result of migration: %s", result)
        except Exception:
            msg = ("Error is occured during migration resources of tenant: {}"
                   .format(tenant_id))
            LOG.exception(msg)
            events.emit("error", {
                "message": msg,
            }, namespace="/events")

        events.emit("update", {
            "id": tenant_id,
            "cloud": src.name,
            "type": "tenant",
            "progress": None,
            "action": None,
        }, namespace="/events")
Пример #4
0
    def migrate():
        config = flask.current_app.config.get("PLUGINS") or {}
        config.update(flask.current_app.config.get("PARAMETERS", {}))
        src = hooks.source.connect()
        dst = hooks.destination.connect()
        ctx = context.Context(config, src, dst)
        events.emit("update", {
            "id": tenant_id,
            "cloud": src.name,
            "type": "tenant",
            "progress": None,
            "action": "migration",
        }, namespace="/events")

        try:
            flow = resource_tasks.migrate_resources(ctx, tenant_id)
            LOG.debug("Migration flow: %s", flow)
            result = flows.run_flow(flow, ctx.store)
            LOG.debug("Result of migration: %s", result)
        except taskflow_excs.Empty:
            msg = ("There aren't any resources for migration in the {} tenant"
                   .format(tenant_id))
            LOG.warning(msg)
            events.emit("log", {
                "level": "warning",
                "message": msg,
            }, namespace="/events")
        except Exception:
            msg = ("Error occured during migration resources of tenant: {}"
                   .format(tenant_id))
            LOG.exception(msg)
            events.emit("log", {
                "level": "error",
                "message": msg,
            }, namespace="/events")

        events.emit("update", {
            "id": tenant_id,
            "cloud": src.name,
            "type": "tenant",
            "progress": None,
            "action": None,
        }, namespace="/events")
Пример #5
0
    def migrate():
        config = flask.current_app.config.get("PLUGINS") or {}
        config.update(flask.current_app.config.get("PARAMETERS", {}))
        src = hooks.source.connect()
        dst = hooks.destination.connect()
        ctx = context.Context(config, src, dst)
        events.emit("update", {
            "id": server_id,
            "cloud": src.name,
            "type": "server",
            "progress": None,
            "action": "migration",
        }, namespace="/events")

        try:
            flow = graph_flow.Flow("migrate-server-{}".format(server_id))
            LOG.debug("Migration flow: %s", flow)
            res, server_flow = server_tasks.migrate_server(ctx, server_id)
            flow.add(*res)
            flow.add(server_flow)
            result = flows.run_flow(flow, ctx.store)
            LOG.debug("Result of migration: %s", result)
        except Exception:
            msg = ("Error occured during migration of server: {}"
                   .format(server_id))
            LOG.exception(msg)
            events.emit("log", {
                "level": "error",
                "message": msg,
            }, namespace="/events")

        events.emit("update", {
            "id": server_id,
            "cloud": src.name,
            "type": "server",
            "progress": None,
            "action": None,
        }, namespace="/events")
Пример #6
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)