Commit d4aef292 by Dudás Ádám

one: started refactoring model

parent 41694da4
...@@ -53,9 +53,9 @@ class UserCloudDetails(models.Model): ...@@ -53,9 +53,9 @@ class UserCloudDetails(models.Model):
'accessing store from Linux.')) 'accessing store from Linux.'))
ssh_private_key = models.TextField(verbose_name=_('SSH key (private)'), ssh_private_key = models.TextField(verbose_name=_('SSH key (private)'),
blank=True, blank=True,
help_text=_('Generated SSH private key ' help_text=_('Generated SSH private '
'for accessing store from ' 'key for accessing '
'Linux.')) 'store from Linux.'))
share_quota = models.IntegerField(verbose_name=_('share quota'), share_quota = models.IntegerField(verbose_name=_('share quota'),
default=0) default=0)
instance_quota = models.IntegerField(verbose_name=_('instance quota'), instance_quota = models.IntegerField(verbose_name=_('instance quota'),
...@@ -82,11 +82,10 @@ class UserCloudDetails(models.Model): ...@@ -82,11 +82,10 @@ class UserCloudDetails(models.Model):
self.smb_password = pwgen() self.smb_password = pwgen()
def get_weighted_instance_count(self): def get_weighted_instance_count(self):
c = 0 credits = [i.template.instance_type.credit
for i in self.user.instance_set.all(): for i in self.user.instance_set.all()
if i.state in ('ACTIVE', 'PENDING', ): if i.state in ('ACTIVE', 'PENDING', )]
c = c + i.template.instance_type.credit return sum(credits)
return c
def get_instance_pc(self): def get_instance_pc(self):
return 100 * self.get_weighted_instance_count() / self.instance_quota return 100 * self.get_weighted_instance_count() / self.instance_quota
...@@ -106,9 +105,7 @@ def set_quota(sender, instance, created, **kwargs): ...@@ -106,9 +105,7 @@ def set_quota(sender, instance, created, **kwargs):
try: try:
password = instance.smb_password password = instance.smb_password
quota = instance.disk_quota * 1024 quota = instance.disk_quota * 1024
key_list = [] key_list = [key.key for key in instance.user.sshkey_set.all()]
for key in instance.user.sshkey_set.all():
key_list.append(key.key)
except: except:
pass pass
# Create user # Create user
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment