29 from common.states
import vm_states
30 from cm.utils.decorators
import user_log
31 from cm.utils.exception
import CMException
32 from cm.models.user
import User
33 from cm.models.vm
import VM
34 from cm.utils.threads.vm
import VMThread
35 from cm.utils
import message
60 def create(caller_id, name, description, image_id, template_id, public_ip_id, iso_list, disk_list, vnc, groups, count=1, user_data=None,
61 ssh_key=
None, ssh_username=
None):
62 user = User.get(caller_id)
66 message.warn(caller_id,
'point_limit', {
'used_points': user.used_points,
'point_limit': user.points})
67 vms = VM.create(user, name=name, description=description, image_id=image_id,
68 template_id=template_id, public_ip_id=public_ip_id, iso_list=iso_list, disk_list=disk_list,
69 vnc=vnc, groups=groups, count=count, user_data=user_data, ssh_key=ssh_key, ssh_username=ssh_username)
72 thread = VMThread(vm,
'create')
75 return [vm.dict
for vm
in vms]
109 vms.append(VM.get(caller_id, vm_id))
110 return VM.destroy(vms)
125 user = User.get(caller_id)
126 vm = VM.get(caller_id, vm_id)
128 if user.used_storage + vm.system_image.size > user.storage:
129 raise CMException(
'user_storage_limit')
131 VM.save_and_shutdown(caller_id, vm, name, description)
144 vms = VM.objects.exclude(state__in=[vm_states[
'closed'], vm_states[
'erased']]).filter(user__id__exact=caller_id)\
145 .filter(farm=
None).order_by(
'-id')
146 vms_mod = [vm.dict
for vm
in vms]
161 vm = VM.get(caller_id, vm_id)
162 vm_mod = vm.long_dict
183 vms.append(VM.get(caller_id, vm_id))
200 def edit(caller_id, vm_id, name=None, description=None):
201 vm = VM.get(caller_id, vm_id)
203 vm.name = name
or vm.name
204 vm.description = description
or vm.description
206 vm.save(update_fields=[
'name',
'description'])
218 vm = VM.get(caller_id, vm_id)
224 raise CMException(
'vnc_attach')
236 vm = VM.get(caller_id, vm_id)
242 raise CMException(
'vnc_detach')