Ejemplo n.º 1
0
class PythonManagementSynchronizeRequest(VirtualEnvMixin,
                                         PythonManagementRequest):
    libraries_to_install = core_fields.JSONField(
        default=list, help_text=_('List of libraries to install'), blank=True)
    libraries_to_remove = core_fields.JSONField(
        default=list, help_text=_('List of libraries to remove'), blank=True)
    initialization_request = models.ForeignKey(
        PythonManagementInitializeRequest,
        related_name="sychronization_requests",
        null=True)
Ejemplo n.º 2
0
class IdentityProvider(models.Model):
    name = models.TextField(db_index=True)
    url = models.URLField()
    metadata = core_fields.JSONField(default=dict)

    class Meta:
        ordering = ('name', )
Ejemplo n.º 3
0
class Offering(core_models.UuidMixin,
               core_models.NameMixin,
               common_mixins.ProductCodeMixin,
               common_mixins.UnitPriceMixin,
               structure_models.StructureLoggableMixin,
               TimeStampedModel):

    class Meta:
        ordering = ['-created']
        verbose_name = _('Request')
        verbose_name_plural = _('Requests')

    class Permissions(object):
        customer_path = 'project__customer'
        project_path = 'project'

    class States(object):
        REQUESTED = 'requested'
        OK = 'ok'
        TERMINATED = 'terminated'

        CHOICES = ((REQUESTED, _('Requested')), (OK, _('OK')), (TERMINATED, _('Terminated')))

    type = models.CharField(max_length=255)
    issue = models.ForeignKey(Issue, null=True, on_delete=models.SET_NULL)
    project = models.ForeignKey(structure_models.Project, null=True, on_delete=models.PROTECT)
    state = models.CharField(default=States.REQUESTED, max_length=30, choices=States.CHOICES)
    report = core_fields.JSONField(blank=True)
    terminated_at = models.DateTimeField(editable=False, blank=True, null=True)

    tracker = FieldTracker()

    def get_backend(self):
        backend.get_active_backend()

    def get_log_fields(self):
        return super(Offering, self).get_log_fields() + ('state', )

    @property
    def type_label(self):
        offerings = settings.WALDUR_SUPPORT.get('OFFERINGS', {})
        type_settings = offerings.get(self.type, {})
        return type_settings.get('label', None)

    @classmethod
    def get_url_name(cls):
        return 'support-offering'

    def __str__(self):
        return '{}: {}'.format(self.type_label or self.name, self.state)

    @classmethod
    def get_scope_type(cls):
        return 'Support.Offering'

    def _get_log_context(self, entity_name):
        context = super(Offering, self)._get_log_context(entity_name)
        context['resource_type'] = self.get_scope_type()
        context['resource_uuid'] = self.uuid.hex
        return context
Ejemplo n.º 4
0
class Job(
        core_models.UuidMixin,
        core_models.StateMixin,
        core_models.NameMixin,
        core_models.DescribableMixin,
        TimeStampedModel,
        common_models.ApplicationModel,
):
    class Meta:
        pass

    class Permissions:
        project_path = 'service_project_link__project'
        customer_path = 'service_project_link__project__customer'

    user = models.ForeignKey(on_delete=models.CASCADE,
                             to=User,
                             related_name='+')
    ssh_public_key = models.ForeignKey(on_delete=models.CASCADE,
                                       to=core_models.SshPublicKey,
                                       related_name='+')
    service_project_link = models.ForeignKey(
        on_delete=models.CASCADE,
        to=openstack_models.OpenStackTenantServiceProjectLink,
        related_name='+',
    )
    subnet = models.ForeignKey(on_delete=models.CASCADE,
                               to=openstack_models.SubNet,
                               related_name='+')
    playbook = models.ForeignKey(on_delete=models.CASCADE,
                                 to=Playbook,
                                 related_name='jobs')
    arguments = core_fields.JSONField(default=dict, blank=True, null=True)
    output = models.TextField(blank=True)

    @staticmethod
    def get_url_name():
        return 'ansible_job'

    def get_backend(self):
        return self.playbook.get_backend()

    def __str__(self):
        return self.name

    def get_tag(self):
        return 'job:%s' % self.uuid.hex

    def get_related_resources(self):
        return openstack_models.Instance.objects.filter(
            tags__name=self.get_tag())
Ejemplo n.º 5
0
class ExpertRequest(core_models.UuidMixin, core_models.NameMixin, PriceMixin,
                    common_mixins.ProductCodeMixin,
                    structure_models.StructureLoggableMixin,
                    structure_models.TimeStampedModel):
    class States(object):
        PENDING = 'pending'
        ACTIVE = 'active'
        CANCELLED = 'cancelled'
        COMPLETED = 'completed'

        CHOICES = ((PENDING, _('Pending')), (ACTIVE, _('Active')),
                   (CANCELLED, _('Cancelled')), (COMPLETED, _('Completed')))

    description = models.TextField(blank=True)
    user = models.ForeignKey(
        core_models.User,
        related_name='+',
        on_delete=models.CASCADE,
        help_text=_('The user which has created this request.'))
    project = models.ForeignKey(structure_models.Project,
                                related_name='+',
                                on_delete=models.SET_NULL,
                                null=True)
    # Project name, project UUID, customer should be stored separately
    # because they are not available after project removal
    project_name = models.CharField(max_length=150, blank=True)
    project_uuid = models.CharField(max_length=32, blank=True)
    customer = models.ForeignKey(structure_models.Customer,
                                 on_delete=models.CASCADE,
                                 null=True)

    state = models.CharField(default=States.PENDING,
                             max_length=30,
                             choices=States.CHOICES)
    type = models.CharField(max_length=255)
    extra = core_fields.JSONField(default=dict)
    issue = models.ForeignKey(support_models.Issue,
                              null=True,
                              on_delete=models.SET_NULL)
    recurring_billing = models.BooleanField(
        default=False,
        help_text=
        _('Defines whether expert request has to be billed every month or only once'
          ))
    objectives = models.TextField(blank=True)
    milestones = models.TextField(blank=True)
    contract_methodology = models.TextField(blank=True)
    out_of_scope = models.TextField(
        blank=True,
        help_text=_('Elements that are explicitly excluded from the contract'))
    common_tos = models.TextField(blank=True)

    tracker = FieldTracker()
    objects = managers.ExpertRequestManager()

    class Meta:
        ordering = ['-created']

    def get_log_fields(self):
        return super(ExpertRequest,
                     self).get_log_fields() + ('state', 'project', 'user')

    @classmethod
    def get_url_name(cls):
        return 'expert-request'

    @property
    def type_label(self):
        offerings = settings.WALDUR_SUPPORT.get('CONTRACT',
                                                {}).get('offerings', {})
        type_settings = offerings.get(self.type, {})
        return type_settings.get('label', None)

    @property
    def planned_budget(self):
        price = self.extra.get('price')
        if price:
            try:
                return float(price)
            except ValueError:
                return 0
        return 0

    def __str__(self):
        if self.project:
            return '%s (%s)' % (self.name, self.project)
        return self.name
Ejemplo n.º 6
0
class Offering(
        core_models.UuidMixin,
        core_models.NameMixin,
        common_mixins.ProductCodeMixin,
        common_mixins.UnitPriceMixin,
        structure_models.StructureLoggableMixin,
        TimeStampedModel,
):
    class Meta:
        ordering = ['-created']
        verbose_name = _('Request')
        verbose_name_plural = _('Requests')

    class Permissions:
        customer_path = 'project__customer'
        project_path = 'project'

    class States:
        REQUESTED = 'requested'
        OK = 'ok'
        TERMINATED = 'terminated'

        CHOICES = (
            (REQUESTED, _('Requested')),
            (OK, _('OK')),
            (TERMINATED, _('Terminated')),
        )

    template = models.ForeignKey('OfferingTemplate', on_delete=models.PROTECT)
    plan = models.ForeignKey('OfferingPlan',
                             blank=True,
                             null=True,
                             on_delete=models.PROTECT)
    issue = models.ForeignKey(Issue, null=True, on_delete=models.PROTECT)
    project = models.ForeignKey(structure_models.Project,
                                null=True,
                                on_delete=models.PROTECT)
    state = models.CharField(default=States.REQUESTED,
                             max_length=30,
                             choices=States.CHOICES)
    report = core_fields.JSONField(blank=True)
    terminated_at = models.DateTimeField(editable=False, blank=True, null=True)

    # For storing unique reference to the resource provided through request-based item.
    # E.g. ecs s3 namespace name.
    backend_id = models.CharField(max_length=255, blank=True)

    tracker = FieldTracker()

    def get_backend(self):
        backend.get_active_backend()

    def get_log_fields(self):
        return super(Offering, self).get_log_fields() + ('state', )

    def terminate(self):
        self.state = Offering.States.TERMINATED
        self.save()

    def set_ok(self):
        self.state = Offering.States.OK
        self.save()

    @property
    def type(self):
        return self.template.name

    @property
    def type_label(self):
        return self.template.config.get('label', None)

    @classmethod
    def get_url_name(cls):
        return 'support-offering'

    def __str__(self):
        return '{}: {}'.format(self.type_label or self.name, self.state)

    @classmethod
    def get_scope_type(cls):
        return 'Support.Offering'

    def _get_log_context(self, entity_name):
        context = super(Offering, self)._get_log_context(entity_name)
        context['resource_type'] = self.get_scope_type()
        context['resource_uuid'] = self.uuid.hex
        return context

    @property
    def config(self):
        return self.template.config if self.template else {}