def resize_vm(uid, flavor_id, context):
    """
    Resizes a VM up or down

    Update: libvirt now supports resize see:
    http://wiki.openstack.org/HypervisorSupportMatrix

    uid -- id of the instance
    flavor_id -- image reference.
    context -- the os context
    """
    instance = get_vm(uid, context)
    kwargs = {}
    try:
        flavor = flavors.get_flavor_by_flavor_id(flavor_id)
        COMPUTE_API.resize(context, instance, flavor_id=flavor['flavorid'],
                           **kwargs)
        ready = False
        i = 0
        # XXX are 15 secs enough to resize?
        while not ready and i < 15:
            i += 1
            state = get_vm(uid, context)['vm_state']
            if state == 'resized':
                ready = True
            import time
            time.sleep(1)
        instance = get_vm(uid, context)
        COMPUTE_API.confirm_resize(context, instance)
    except Exception as e:
        raise AttributeError(str(e))
dataset/ETHPy150Open tmetsch/occi-os/occi_os_api/nova_glue/vm.py/resize_vm/original