Revision dec501fa snf-cyclades-app/synnefo/logic/backend.py

b/snf-cyclades-app/synnefo/logic/backend.py
1030 1030
    return None
1031 1031

  
1032 1032

  
1033
def attach_volume(vm, volume, depends=[]):
1034
    log.debug("Attaching volume %s to vm %s", vm, volume)
1035

  
1036
    disk = {"size": volume.size,
1037
            "name": volume.backend_volume_uuid,
1038
            "volume_name": volume.backend_volume_uuid}
1039
    if volume.source_volume_id is not None:
1040
        disk["origin"] = volume.source_volume.backend_volume_uuid
1041
    elif volume.source_snapshot is not None:
1042
        disk["origin"] = volume.source_snapshot["checksum"]
1043
    elif volume.source_image is not None:
1044
        disk["origin"] = volume.source_image["checksum"]
1045

  
1046
    kwargs = {
1047
        "instance": vm.backend_vm_id,
1048
        "disks": [("add", "-1", disk)],
1049
        "depends": depends,
1050
    }
1051
    if vm.backend.use_hotplug():
1052
        kwargs["hotplug"] = True
1053
    if settings.TEST:
1054
        kwargs["dry_run"] = True
1055

  
1056
    with pooled_rapi_client(vm) as client:
1057
        return client.ModifyInstance(**kwargs)
1058

  
1059

  
1060
def detach_volume(vm, volume):
1061
    log.debug("Removing volume %s from vm %s", volume, vm)
1062
    kwargs = {
1063
        "instance": vm.backend_vm_id,
1064
        "disks": [("remove", volume.backend_volume_uuid, {})],
1065
    }
1066
    if vm.backend.use_hotplug():
1067
        kwargs["hotplug"] = True
1068
    if settings.TEST:
1069
        kwargs["dry_run"] = True
1070

  
1071
    with pooled_rapi_client(vm) as client:
1072
        return client.ModifyInstance(**kwargs)
1073

  
1074

  
1033 1075
def get_instances(backend, bulk=True):
1034 1076
    with pooled_rapi_client(backend) as c:
1035 1077
        return c.GetInstances(bulk=bulk)

Also available in: Unified diff