Example #1
0
    def put(self, vm, nic_id, nics, nic, data):
        """Update VM nic definition"""
        ser = VmDefineNicSerializer(self.request, vm, nic.copy(), nic_id=nic_id, data=data, partial=True)

        if ser.is_valid():
            nics[nic_id].update(ser.jsondata)
            vm.resolvers = ser.resolvers
            vm.save_nics(nics, monitoring_ip=ser.get_monitoring_ip())
            res = SuccessTaskResponse(self.request, ser.data, vm=vm,
                                      detail='nic_id=' + str(nic_id + 1), detail_dict=ser.detail_dict(),
                                      msg=LOG_NIC_UPDATE)
            ser.update_ip(res.data.get('task_id'))  # Always update ip.vm

            return res

        return FailureTaskResponse(self.request, ser.errors, vm=vm)
Example #2
0
    def post(self, vm, nic_id, nics, nic, data):
        """Create VM nic definition"""
        ser = VmDefineNicSerializer(self.request, vm, nic_id=nic_id, data=data)

        if ser.is_valid():
            nics[nic_id] = ser.jsondata
            vm.resolvers = ser.resolvers
            vm.save_nics(nics, monitoring_ip=ser.get_monitoring_ip())
            res = SuccessTaskResponse(self.request, ser.data,
                                      status=scode.HTTP_201_CREATED, vm=vm,
                                      detail='nic_id=' + str(nic_id + 1), detail_dict=ser.detail_dict(),
                                      msg=LOG_NIC_CREATE)
            ser.save_ip(res.data.get('task_id'))  # Always save ip.vm

            return res

        return FailureTaskResponse(self.request, ser.errors, vm=vm)