2014-05-08 16:59:35 +00:00
|
|
|
from django.db import models
|
|
|
|
from django.utils.translation import ugettext_lazy as _
|
|
|
|
from django.contrib.auth.hashers import make_password
|
|
|
|
|
|
|
|
from orchestra.core import services
|
|
|
|
from orchestra.core.validators import validate_hostname
|
|
|
|
|
|
|
|
from . import settings
|
|
|
|
|
|
|
|
|
|
|
|
class VPS(models.Model):
|
|
|
|
hostname = models.CharField(_("hostname"), max_length=256, unique=True,
|
2015-04-05 10:46:24 +00:00
|
|
|
validators=[validate_hostname])
|
2014-05-08 16:59:35 +00:00
|
|
|
type = models.CharField(_("type"), max_length=64, choices=settings.VPS_TYPES,
|
2015-04-05 10:46:24 +00:00
|
|
|
default=settings.VPS_DEFAULT_TYPE)
|
2014-05-08 16:59:35 +00:00
|
|
|
template = models.CharField(_("template"), max_length=64,
|
2015-04-05 10:46:24 +00:00
|
|
|
choices=settings.VPS_TEMPLATES, default=settings.VPS_DEFAULT_TEMPLATE)
|
2014-05-08 16:59:35 +00:00
|
|
|
password = models.CharField(_('password'), max_length=128,
|
2015-04-05 10:46:24 +00:00
|
|
|
help_text=_("<TT>root</TT> password of this virtual machine"))
|
2014-05-08 16:59:35 +00:00
|
|
|
account = models.ForeignKey('accounts.Account', verbose_name=_("Account"),
|
2015-04-05 10:46:24 +00:00
|
|
|
related_name='vpss')
|
2014-05-08 16:59:35 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
verbose_name = "VPS"
|
|
|
|
verbose_name_plural = "VPSs"
|
|
|
|
|
2015-04-02 16:14:55 +00:00
|
|
|
def __str__(self):
|
2014-05-08 16:59:35 +00:00
|
|
|
return self.hostname
|
|
|
|
|
|
|
|
def set_password(self, raw_password):
|
|
|
|
self.password = make_password(raw_password)
|
|
|
|
|
|
|
|
def get_username(self):
|
|
|
|
return self.hostname
|
|
|
|
|
|
|
|
|
|
|
|
services.register(VPS)
|