Example #1
0
    def delete(self, vm, disk_id, disks, disk, data):
        """Delete VM disk definition"""
        if not vm.is_kvm() and (disk_id == 0 or vm.is_deployed()):
            raise OperationNotSupported

        ser = VmDefineDiskSerializer(self.request, vm, disk, disk_id=disk_id)
        del disks[disk_id]
        ns = ser.get_node_storage(ser.object.get('zpool'), vm.node)

        if ns:
            update_storage_resources = [ns]
        else:
            update_storage_resources = []

        vm.save_disks(disks,
                      update_node_resources=True,
                      update_storage_resources=update_storage_resources)
        res = SuccessTaskResponse(self.request,
                                  None,
                                  vm=vm,
                                  detail='disk_id=' + str(disk_id + 1),
                                  msg=LOG_DISK_DELETE)
        self._delete_vm_tags(vm,
                             ser.img_old,
                             data,
                             task_id=res.data.get('task_id'))

        return res
Example #2
0
    def put(self, vm, disk_id, disks, disk, data):
        """Update VM disk definition"""
        ser = VmDefineDiskSerializer(self.request,
                                     vm,
                                     disk.copy(),
                                     disk_id=disk_id,
                                     data=data,
                                     partial=True)

        if not ser.is_valid():
            return FailureTaskResponse(self.request, ser.errors, vm=vm)

        disks[disk_id] = ser.jsondata
        vm.save_disks(disks,
                      update_node_resources=ser.update_node_resources,
                      update_storage_resources=ser.update_storage_resources)
        res = SuccessTaskResponse(self.request,
                                  ser.data,
                                  vm=vm,
                                  msg=LOG_DISK_UPDATE,
                                  detail='disk_id=' + str(disk_id + 1),
                                  detail_dict=ser.detail_dict())
        self._update_vm_tags(vm,
                             ser.img,
                             ser.img_old,
                             data,
                             task_id=res.data.get('task_id'))

        return res
Example #3
0
    def post(self, vm, disk_id, disks, disk, data):
        """Create VM nic definition"""
        if not vm.is_kvm() and vm.is_deployed():
            raise OperationNotSupported

        ser = VmDefineDiskSerializer(self.request,
                                     vm,
                                     disk_id=disk_id,
                                     data=data)

        if not ser.is_valid():
            return FailureTaskResponse(self.request, ser.errors, vm=vm)

        disks[disk_id] = ser.jsondata
        vm.save_disks(disks,
                      update_node_resources=ser.update_node_resources,
                      update_storage_resources=ser.update_storage_resources)
        res = SuccessTaskResponse(self.request,
                                  ser.data,
                                  status=scode.HTTP_201_CREATED,
                                  vm=vm,
                                  msg=LOG_DISK_CREATE,
                                  detail='disk_id=' + str(disk_id + 1),
                                  detail_dict=ser.detail_dict())
        self._update_vm_tags(vm,
                             ser.img,
                             ser.img_old,
                             data,
                             task_id=res.data.get('task_id'))

        return res
Example #4
0
def get_vm_define_disk(request, vm, disk_id=None):
    """
    Like GET api.vm.define.vm_define_disk_list.
    """
    request.method = 'GET'

    if disk_id is not None:
        return VmDefineDiskSerializer(request, vm, vm.json_get_disks()[disk_id], disk_id=disk_id).data

    return VmDefineDiskSerializer(request, vm, vm.json_get_disks(), many=True).data
Example #5
0
    def get_diff(self, vm):
        """Show disk differences between active and in db json. Implies full and denies active vm_define_disk."""
        def_current = VmDefineDiskSerializer(self.request,
                                             vm,
                                             vm.json_get_disks(),
                                             disk_id=None,
                                             many=True).data
        def_active = VmDefineDiskSerializer(self.request,
                                            vm,
                                            vm.json_active_get_disks(),
                                            disk_id=None,
                                            many=True).data

        return self._diff_lists(def_active, def_current)
Example #6
0
    def get(self, vm, disk_id, disks, disk, data, many=False):
        """Get VM disk definition"""
        ser = VmDefineDiskSerializer(self.request,
                                     vm,
                                     disk,
                                     disk_id=disk_id,
                                     many=many)

        return SuccessTaskResponse(self.request, ser.data, vm=vm)
Example #7
0
    def _get_vm_define(self, vm):
        """Get one VM definition"""
        if self.active:
            vm.revert_active()

        res = VmDefineSerializer(self.request, vm).data

        if self.full:
            res['disks'] = VmDefineDiskSerializer(self.request, vm, vm.json_get_disks(), many=True).data
            res['nics'] = VmDefineNicSerializer(self.request, vm, vm.json_get_nics(), many=True).data

        return res