Commit f009956d by Dudás Ádám

one: refactor in models

parent ca125a86
...@@ -64,6 +64,10 @@ class UserCloudDetails(models.Model): ...@@ -64,6 +64,10 @@ class UserCloudDetails(models.Model):
help_text=_('Disk quota in mebibytes.')) help_text=_('Disk quota in mebibytes.'))
def reset_keys(self): def reset_keys(self):
"""Deprecated. Use reset_ssh_keys instead."""
self.reset_ssh_keys()
def reset_ssh_keys(self):
"""Delete old SSH key pair and generate new one.""" """Delete old SSH key pair and generate new one."""
pri, pub = keygen() pri, pub = keygen()
self.ssh_private_key = pri self.ssh_private_key = pri
...@@ -112,16 +116,12 @@ class UserCloudDetails(models.Model): ...@@ -112,16 +116,12 @@ class UserCloudDetails(models.Model):
def set_quota(sender, instance, created, **kwargs): def set_quota(sender, instance, created, **kwargs):
try: try:
if not StoreApi.userexist(instance.user.username): if not StoreApi.userexist(instance.user.username):
try:
password = instance.smb_password password = instance.smb_password
quota = instance.disk_quota * 1024 quota = instance.disk_quota * 1024
key_list = [key.key for key in instance.user.sshkey_set.all()] key_list = [k.key for k in instance.user.sshkey_set.all()]
except:
pass
# Create user # Create user
if not StoreApi.createuser(instance.user.username, password, StoreApi.createuser(instance.user.username, password, key_list,
key_list, quota): quota)
pass
else: else:
StoreApi.set_quota(instance.user.username, StoreApi.set_quota(instance.user.username,
instance.disk_quota * 1024) instance.disk_quota * 1024)
...@@ -133,7 +133,7 @@ post_save.connect(set_quota, sender=UserCloudDetails) ...@@ -133,7 +133,7 @@ post_save.connect(set_quota, sender=UserCloudDetails)
def reset_keys(sender, instance, created, **kwargs): def reset_keys(sender, instance, created, **kwargs):
if created: if created:
instance.reset_smb() instance.reset_smb()
instance.reset_keys() instance.reset_ssh_keys()
post_save.connect(reset_keys, sender=UserCloudDetails) post_save.connect(reset_keys, sender=UserCloudDetails)
...@@ -148,7 +148,7 @@ class OpenSshKeyValidator(object): ...@@ -148,7 +148,7 @@ class OpenSshKeyValidator(object):
def __call__(self, value): def __call__(self, value):
try: try:
value = "%s comment" % value value = value + ' comment'
type, key_string, comment = value.split(None, 2) type, key_string, comment = value.split(None, 2)
if type not in self.valid_types: if type not in self.valid_types:
raise ValidationError(_('OpenSSH key type %s is not ' raise ValidationError(_('OpenSSH key type %s is not '
......
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