def migrate_servers(ctx, flow, ids): for server in ctx.src_cloud.nova.servers.list( search_opts={'all_tenants': 1}): if server.id in ids: resources, server_flow = server_tasks.migrate_server(ctx, server.id) flow.add(*resources) flow.add(server_flow) return flow
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")