26 from django.db
import models
27 from django.db.models
import Sum
28 from django.template
import loader, Context
30 from cm.utils.exception
import CMException
31 from common.states
import storage_states
43 name = models.CharField(max_length=256)
44 capacity = models.IntegerField()
45 state = models.IntegerField(default=0)
46 address = models.CharField(max_length=64, null=
True)
47 dir = models.CharField(max_length=256, null=
True)
48 transport = models.CharField(max_length=20, default=
"netfs")
73 d[
'storage_id'] = self.id
74 d[
'state'] = self.
state
79 d[
'mountpoint'] = self.
path
101 conn = libvirt.open(
'qemu:///system')
102 conn.storagePoolLookupByName(self.
name)
106 return '/var/lib/cc1/storages/%s/' % self.
name
116 return self.image_set.aggregate(Sum(
'size'))[
'size__sum']
or 0
136 storages = Storage.objects.filter(state__exact=storage_states[
'ok'])
139 if storages.count() == 0:
140 raise CMException(
"storage_no_storage")
144 sorted(storages, key=
lambda storage: storage.free_space)
156 self.
state = storage_states[
'locked']
163 self.
state = storage_states[
'ok']
166 template = loader.get_template(
"pools/%s.xml" % self.
transport)
167 c = Context({
'storage': self,
170 return template.render(c)