def migrate_project_keypairs(context, flow, tenant_id):
    tenant = context.src_cloud.keystone.tenants.get(tenant_id)
    users = context.src_cloud.keystone.users.list(tenant_id)
    for user in users:
        if user.id == context.src_cloud.keystone.auth_ref.user_id:
            continue
        # XXX(akscram): Works only for users' passowrd which are equal
        #               to "default".
        cloud = context.src_cloud.restrict(username=user.name,
                                           password="******",
                                           tenant_name=tenant.name)
        keypairs = cloud.nova.keypairs.list()
        for keypair in keypairs:
            keypair_tasks.migrate_keypair(context, flow, tenant_id, user.id,
                                          keypair.name)
示例#2
0
def reprovision_server(context, server, server_nics):
    flavor_ensure = "flavor-{}-ensure".format(server.flavor["id"])
    user_ensure = "user-{}-ensure".format(server.user_id)
    tenant_ensure = "tenant-{}-ensure".format(server.tenant_id)

    server_id = server.id
    server_start_event = "server-{}-start-event".format(server_id)
    server_finish_event = "server-{}-finish-event".format(server_id)
    server_binding = "server-{}".format(server_id)
    server_retrieve = "server-{}-retrieve".format(server_id)
    server_suspend = "server-{}-suspend".format(server_id)
    server_terminate = "server-{}-terminate".format(server_id)
    server_boot = "server-{}-boot".format(server_id)
    server_sync = "server-{}-sync".format(server_id)
    server_dm = "{}-device-mapping".format(server_binding)
    server_volumes = "{}-volumes".format(server_binding)
    volumes_delete = "{}-volumes-delete".format(server_binding)

    pre_suspend_tasks, pre_suspend_sync, pre_boot_tasks, image_ensure = \
        provision_server(context, server)

    if server.key_name:
        keypair_ensure = "keypair-{}-ensure".format(server.key_name)
        keypair_flow = keypair_tasks.migrate_keypair(context, None,
                                                     server.tenant_id,
                                                     server.user_id,
                                                     server.key_name)
        if keypair_flow is not None:
            pre_suspend_tasks += [keypair_flow]
    else:
        keypair_ensure = "keypair-server-{}-ensure".format(server_id)
        context.store[keypair_ensure] = None

    migrate_server_volumes = volume_tasks.migrate_server_volumes(
        context,
        server_id,
        getattr(server,
                "os-extended-volumes:volumes_attached"),
        server.user_id,
        server.tenant_id)
    pre_boot_tasks = pre_boot_tasks + [migrate_server_volumes]

    flow = linear_flow.Flow("migrate-server-{}".format(server_id))
    # NOTE(akscram): The synchronization point avoids excessive downtime
    #                of the server.
    flow.add(
        task_utils.SyncPoint(name=server_sync,
                             requires=[flavor_ensure] + pre_suspend_sync),
        ServerStartMigrationEvent(context.src_cloud,
                                  name=server_start_event,
                                  rebind=[server_retrieve]),
        RetrieveServer(context.src_cloud,
                       name=server_binding,
                       provides=server_binding,
                       rebind=[server_retrieve]),
        SuspendServer(context.src_cloud,
                      name=server_suspend,
                      provides=server_suspend,
                      rebind=[server_binding]),
    )
    if pre_boot_tasks:
        flow.add(*pre_boot_tasks)
    flow.add(
        BootServerFromImage(context.dst_cloud,
                            name=server_boot,
                            provides=server_boot,
                            rebind=[server_suspend, image_ensure,
                                    flavor_ensure, keypair_ensure,
                                    user_ensure, tenant_ensure,
                                    server_nics, server_dm]),
    )
    restore_floating_ips = network_manager(context, server.to_dict())
    if restore_floating_ips:
        flow.add(restore_floating_ips)
    flow.add(
        TerminateServer(context.src_cloud,
                        name=server_terminate,
                        rebind=[server_suspend]))
    if context.config.get("delete_source_volumes"):
        flow.add(volume_tasks.DeleteServerVolumes(context.src_cloud,
                                                  name=volumes_delete,
                                                  rebind=[server_volumes],
                                                  requires=[server_boot]))
    context.store[server_retrieve] = server_id
    return pre_suspend_tasks, flow