def start_app(config=None, **kwargs): """Starts the created application with given configuration. :param config: a dict with configuration values """ def get_bind_host(): bind_host = app.config.get("BIND_HOST", app.config["SERVER_NAME"]) if bind_host is not None: host, _, port = bind_host.partition(":") if isinstance(port, basestring) and port.isdigit(): port = int(port) else: port = None return (host, port) return (None, None) utils.configure_logging(config) app = create_app() app.config.setdefault("CLOUDS_RESET", False) app.config.setdefault("BIND_HOST", None) app.config.setdefault("PLUGINS", None) if config is not None: app.config.update(config) events.init_app(app) hooks.source.init_app(app) hooks.destination.init_app(app) host, port = get_bind_host() events.run(app, policy_server=False, host=host, port=port)
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)))