Commit ac1ee026 by Guba Sándor

new model for connection template

parent c06380e5
......@@ -46,6 +46,7 @@ from acl.models import AclBase
from common.models import HumanReadableObject, create_readable, Encoder
from vm.tasks.agent_tasks import add_keys, del_keys
from vm.models.instance import ACCESS_METHODS
from .store_api import Store, NoStoreException, NotOkException
......@@ -100,6 +101,19 @@ class Notification(TimeStampedModel):
self.message_data = None if value is None else value.to_dict()
class ConnectCommand(Model):
user = ForeignKey(User, related_name='command_set')
access_method = CharField(max_length=10, choices=ACCESS_METHODS,
verbose_name=_('access method'),
help_text=_('Primary remote access method.'))
application = CharField(max_length="128", verbose_name=_('application'),
help_text=_(
'Application name to use for this type '
'of connection protocol.'))
template = CharField(blank=True, null=True, max_length=256,
help_text=_('Template for connection command.'))
class Profile(Model):
user = OneToOneField(User)
preferred_language = CharField(verbose_name=_('preferred language'),
......@@ -129,6 +143,23 @@ class Profile(Model):
default=2048 * 1024 * 1024,
help_text=_('Disk quota in mebibytes.'))
def get_connect_command(self, instance, use_ipv6=False):
""" Generate connection command based on template."""
try:
command = self.user.command_set.get(
access_method=instance.access_method)
except ConnectCommand.DoesNotExist:
# No template for this protocol return default
return instance.get_connect_command(use_ipv6)
else:
return command.template % {
'port': instance.get_connect_port(use_ipv6=use_ipv6),
'host': instance.get_connect_host(use_ipv6=use_ipv6),
'password': instance.pw,
'app': command.application,
'username': 'cloud'
}
def notify(self, subject, template, context=None, valid_until=None,
**kwargs):
if context is not None:
......
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