コード例 #1
0
ファイル: pump.py プロジェクト: pombredanne/pumphouse
def cleanup(plugins, events, cloud, target, dump=None):
    env = reset_tasks.Environment(cloud, plugins)
    runner = tasks_base.TaskflowRunner(env)
    cleanup_workload = runner.get_resource(reset_tasks.CleanupWorkload,
                                           {"id": cloud.name})
    runner.add(cleanup_workload.delete)
    if dump:
        with open(dump, "w") as f:
            utils.dump_flow(runner.create_flow(), f, True)
    else:
        runner.run()
コード例 #2
0
ファイル: pump.py プロジェクト: pombredanne/pumphouse
def setup(plugins, events, cloud, target,
          num_tenants, num_servers, num_volumes, workloads,
          dump=None):
    env = reset_tasks.Environment(cloud, plugins)
    runner = tasks_base.TaskflowRunner(env)
    setup_workload = runner.get_resource(reset_tasks.SetupWorkload, {
        "id": cloud.name,
        "populate": {
            "num_tenants": num_tenants,
            "num_servers": num_servers,
            "num_volumes": num_volumes,
        },
        "workloads": workloads,
    })
    runner.add(setup_workload.create)
    if dump:
        with open(dump, "w") as f:
            utils.dump_flow(runner.create_flow(), f, True)
    else:
        runner.run()
コード例 #3
0
ファイル: pump.py プロジェクト: UshF/pumphouse
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)