def save(self, *args, **kwargs):
        self.summary = []
        previous_settings = None
        try:
            previous_settings = self.app.appsettings_set.latest()
        except AppSettings.DoesNotExist:
            pass

        try:
            self.update_maintenance(previous_settings)
            self.update_routable(previous_settings)
            self.update_whitelist(previous_settings)
            self.update_autoscale(previous_settings)
        except (UnprocessableEntity, NotFound):
            raise
        except Exception as e:
            self.delete()
            raise DeisException(str(e)) from e

        if not self.summary and previous_settings:
            self.delete()
            raise AlreadyExists("{} changed nothing".format(self.owner))

        summary = ' '.join(self.summary)
        self.app.log('summary of app setting changes: {}'.format(summary), logging.DEBUG)
        return super(AppSettings, self).save(**kwargs)
Exemple #2
0
 def attach(self, *args, **kwargs):
     # add the certificate to the domain
     domain = get_object_or_404(Domain, domain=kwargs['domain'])
     if domain.certificate is not None:
         raise AlreadyExists(
             "Domain already has a certificate attached to it")
     # create in kubernetes
     self.attach_in_kubernetes(domain)
     domain.certificate = self
     domain.save()
Exemple #3
0
    def _check_previous_tls_settings(self):
        try:
            previous_tls_settings = self.app.tls_set.latest()

            if (previous_tls_settings.https_enforced is not None
                    and self.https_enforced
                    == previous_tls_settings.https_enforced):
                self.delete()
                raise AlreadyExists("{} changed nothing".format(self.owner))
        except TLS.DoesNotExist:
            pass
Exemple #4
0
 def _check_previous_tls_settings(self):
     """
     Only one value can be set at a time
     If the other value is None, using the previous setting.
     """
     try:
         previous_tls_settings = self.app.tls_set.latest()
         if self.https_enforced is not None:
             if previous_tls_settings.https_enforced == self.https_enforced:
                 raise AlreadyExists(
                     "{} changed nothing".format(self.owner))
             self.certs_auto_enabled = previous_tls_settings.certs_auto_enabled
         elif self.certs_auto_enabled is not None:
             if previous_tls_settings.certs_auto_enabled == self.certs_auto_enabled:
                 raise AlreadyExists(
                     "{} changed nothing".format(self.owner))
             self.https_enforced = previous_tls_settings.https_enforced
         previous_tls_settings.delete()
     except TLS.DoesNotExist:
         pass
Exemple #5
0
 def attach(self):
     try:
         self._scheduler.pvc.get(self.app.id, self.name)
         err = "Volume {} already exists in this namespace".format(
             self.name)  # noqa
         self.log(err, logging.INFO)
         raise AlreadyExists(err)
     except KubeException as e:
         logger.info(e)
         try:
             kwargs = {
                 "size": self._get_size(self.size),
                 "storage_class": settings.DRYCC_APP_STORAGE_CLASS,
             }
             self._scheduler.pvc.create(self.app.id, self.name, **kwargs)
         except KubeException as e:
             msg = 'There was a problem creating the volume ' \
                   '{} for {}'.format(self.name, self.app_id)
             raise ServiceUnavailable(msg) from e
Exemple #6
0
 def bind(self, *args, **kwargs):
     if self.status != "Ready":
         raise DryccException("the resource is not ready")
     if self.binding == "Ready":
         raise DryccException("the resource is binding")
     self.binding = "Binding"
     self.save()
     try:
         self._scheduler.svcat.get_binding(self.app.id, self.name)
         err = "Resource {} is binding".format(self.name)
         self.log(err, logging.INFO)
         raise AlreadyExists(err)
     except KubeException as e:
         logger.info(e)
         try:
             self._scheduler.svcat.create_binding(self.app.id, self.name,
                                                  **kwargs)
         except KubeException as e:
             msg = 'There was a problem binding the resource ' \
                   '{} for {}'.format(self.name, self.app_id)
             raise ServiceUnavailable(msg) from e
Exemple #7
0
 def attach(self, *args, **kwargs):
     try:
         self._scheduler.svcat.get_instance(self.app.id, self.name)
         err = "Resource {} already exists in this namespace".format(
             self.name)  # noqa
         self.log(err, logging.INFO)
         raise AlreadyExists(err)
     except KubeException as e:
         logger.info(e)
         try:
             instance = self.plan.split(":")
             kwargs = {
                 "instance_class": instance[0],
                 "instance_plan": ":".join(instance[1:]),
                 "parameters": self.options,
             }
             self._scheduler.svcat.create_instance(self.app.id, self.name,
                                                   **kwargs)
         except KubeException as e:
             msg = 'There was a problem creating the resource ' \
                   '{} for {}'.format(self.name, self.app_id)
             raise ServiceUnavailable(msg) from e
Exemple #8
0
    def save(self, *args, **kwargs):  # noqa
        if not self.summary:
            self.summary = ''
            prev_release = self.previous()
            # compare this build to the previous build
            old_build = prev_release.build if prev_release else None
            old_config = prev_release.config if prev_release else None
            # if the build changed, log it and who pushed it
            if self.version == 1:
                self.summary += "{} created initial release".format(self.app.owner)
            elif self.build != old_build:
                if self.build.sha:
                    self.summary += "{} deployed {}".format(self.build.owner, self.build.sha[:7])
                else:
                    self.summary += "{} deployed {}".format(self.build.owner, self.build.image)

            # if the config data changed, log the dict diff
            if self.config != old_config:
                # if env vars change, log the dict diff
                dict1 = self.config.values
                dict2 = old_config.values if old_config else {}
                diff = dict_diff(dict1, dict2)
                # try to be as succinct as possible
                added = ', '.join(k for k in diff.get('added', {}))
                added = 'added ' + added if added else ''
                changed = ', '.join(k for k in diff.get('changed', {}))
                changed = 'changed ' + changed if changed else ''
                deleted = ', '.join(k for k in diff.get('deleted', {}))
                deleted = 'deleted ' + deleted if deleted else ''
                changes = ', '.join(i for i in (added, changed, deleted) if i)
                if changes:
                    if self.summary:
                        self.summary += ' and '
                    self.summary += "{} {}".format(self.config.owner, changes)

                # if the limits changed (memory or cpu), log the dict diff
                changes = []
                old_mem = old_config.memory if old_config else {}
                diff = dict_diff(self.config.memory, old_mem)
                if diff.get('added') or diff.get('changed') or diff.get('deleted'):
                    changes.append('memory')
                old_cpu = old_config.cpu if old_config else {}
                diff = dict_diff(self.config.cpu, old_cpu)
                if diff.get('added') or diff.get('changed') or diff.get('deleted'):
                    changes.append('cpu')
                if changes:
                    changes = 'changed limits for '+', '.join(changes)
                    self.summary += "{} {}".format(self.config.owner, changes)

                # if the lifecycle_post_start hooks changed, log the dict diff
                changes = []
                old_lifecycle_post_start = old_config.lifecycle_post_start if old_config else {}
                diff = dict_diff(self.config.lifecycle_post_start, old_lifecycle_post_start)
                # try to be as succinct as possible
                added = ', '.join(k for k in diff.get('added', {}))
                added = 'added lifecycle_post_start  ' + added if added else ''
                changed = ', '.join(k for k in diff.get('changed', {}))
                changed = 'changed lifecycle_post_start ' + changed if changed else ''
                deleted = ', '.join(k for k in diff.get('deleted', {}))
                deleted = 'deleted lifecycle_post_start ' + deleted if deleted else ''
                changes = ', '.join(i for i in (added, changed, deleted) if i)
                if changes:
                    if self.summary:
                        self.summary += ' and '
                    self.summary += "{} {}".format(self.config.owner, changes)

                # if the lifecycle_pre_stop hooks changed, log the dict diff
                changes = []
                old_lifecycle_pre_stop = old_config.lifecycle_pre_stop if old_config else {}
                diff = dict_diff(self.config.lifecycle_pre_stop, old_lifecycle_pre_stop)
                # try to be as succinct as possible
                added = ', '.join(k for k in diff.get('added', {}))
                added = 'added lifecycle_pre_stop  ' + added if added else ''
                changed = ', '.join(k for k in diff.get('changed', {}))
                changed = 'changed lifecycle_pre_stop ' + changed if changed else ''
                deleted = ', '.join(k for k in diff.get('deleted', {}))
                deleted = 'deleted lifecycle_pre_stop ' + deleted if deleted else ''
                changes = ', '.join(i for i in (added, changed, deleted) if i)
                if changes:
                    if self.summary:
                        self.summary += ' and '

                # if the timeouts changed, log the dict diff
                changes = []
                old_timeout = old_config.termination_grace_period if old_config else {}
                diff = dict_diff(self.config.termination_grace_period, old_timeout)
                if diff.get('added') or diff.get('changed') or diff.get('deleted'):
                    changes.append('termination_grace_period')
                if changes:
                    changes = 'changed timeouts for '+', '.join(changes)
                    self.summary += "{} {}".format(self.config.owner, changes)

                # if the tags changed, log the dict diff
                changes = []
                old_tags = old_config.tags if old_config else {}
                diff = dict_diff(self.config.tags, old_tags)
                # try to be as succinct as possible
                added = ', '.join(k for k in diff.get('added', {}))
                added = 'added tag ' + added if added else ''
                changed = ', '.join(k for k in diff.get('changed', {}))
                changed = 'changed tag ' + changed if changed else ''
                deleted = ', '.join(k for k in diff.get('deleted', {}))
                deleted = 'deleted tag ' + deleted if deleted else ''
                changes = ', '.join(i for i in (added, changed, deleted) if i)
                if changes:
                    if self.summary:
                        self.summary += ' and '
                    self.summary += "{} {}".format(self.config.owner, changes)

                # if the registry information changed, log the dict diff
                changes = []
                old_registry = old_config.registry if old_config else {}
                diff = dict_diff(self.config.registry, old_registry)
                # try to be as succinct as possible
                added = ', '.join(k for k in diff.get('added', {}))
                added = 'added registry info ' + added if added else ''
                changed = ', '.join(k for k in diff.get('changed', {}))
                changed = 'changed registry info ' + changed if changed else ''
                deleted = ', '.join(k for k in diff.get('deleted', {}))
                deleted = 'deleted registry info ' + deleted if deleted else ''
                changes = ', '.join(i for i in (added, changed, deleted) if i)
                if changes:
                    if self.summary:
                        self.summary += ' and '
                    self.summary += "{} {}".format(self.config.owner, changes)

                # if the healthcheck information changed, log the dict diff
                changes = []
                old_healthcheck = old_config.healthcheck if old_config else {}
                diff = dict_diff(self.config.healthcheck, old_healthcheck)
                # try to be as succinct as possible
                added = ', '.join(list(map(lambda x: 'default' if x == '' else x, [k for k in diff.get('added', {})])))  # noqa
                added = 'added healthcheck info for proc type ' + added if added else ''
                changed = ', '.join(list(map(lambda x: 'default' if x == '' else x, [k for k in diff.get('changed', {})])))  # noqa
                changed = 'changed healthcheck info for proc type ' + changed if changed else ''
                deleted = ', '.join(list(map(lambda x: 'default' if x == '' else x, [k for k in diff.get('deleted', {})])))  # noqa
                deleted = 'deleted healthcheck info for proc type ' + deleted if deleted else ''
                changes = ', '.join(i for i in (added, changed, deleted) if i)
                if changes:
                    if self.summary:
                        self.summary += ' and '
                    self.summary += "{} {}".format(self.config.owner, changes)

            if not self.summary:
                if self.version == 1:
                    self.summary = "{} created the initial release".format(self.owner)
                else:
                    # There were no changes to this release
                    raise AlreadyExists("{} changed nothing - release stopped".format(self.owner))

        super(Release, self).save(*args, **kwargs)
Exemple #9
0
    def save(self, *args, **kwargs):  # noqa
        if not self.summary:
            self.summary = ''
            prev_release = self.previous()
            # compare this build to the previous build
            old_build = prev_release.build if prev_release else None
            old_config = prev_release.config if prev_release else None
            # if the build changed, log it and who pushed it
            if self.version == 1:
                self.summary += "{} created initial release".format(
                    self.app.owner)
            elif self.build != old_build:
                if self.build.sha:
                    self.summary += "{} deployed {}".format(
                        self.build.owner, self.build.sha[:7])
                else:
                    self.summary += "{} deployed {}".format(
                        self.build.owner, self.build.image)

            # if the config data changed, log the dict diff
            if self.config != old_config:
                # if env vars change, log the dict diff
                dict1 = self.config.values
                dict2 = old_config.values if old_config else {}
                diff = dict_diff(dict1, dict2)
                # try to be as succinct as possible
                added = ', '.join(k for k in diff.get('added', {}))
                added = 'added ' + added if added else ''
                changed = ', '.join(k for k in diff.get('changed', {}))
                changed = 'changed ' + changed if changed else ''
                deleted = ', '.join(k for k in diff.get('deleted', {}))
                deleted = 'deleted ' + deleted if deleted else ''
                changes = ', '.join(i for i in (added, changed, deleted) if i)
                if changes:
                    if self.summary:
                        self.summary += ' and '
                    self.summary += "{} {}".format(self.config.owner, changes)

                # if the limits changed (memory or cpu), log the dict diff
                changes = []
                old_mem = old_config.memory if old_config else {}
                diff = dict_diff(self.config.memory, old_mem)
                if diff.get('added') or diff.get('changed') or diff.get(
                        'deleted'):
                    changes.append('memory')
                old_cpu = old_config.cpu if old_config else {}
                diff = dict_diff(self.config.cpu, old_cpu)
                if diff.get('added') or diff.get('changed') or diff.get(
                        'deleted'):
                    changes.append('cpu')
                if changes:
                    changes = 'changed limits for ' + ', '.join(changes)
                    self.summary += "{} {}".format(self.config.owner, changes)

                # if the tags changed, log the dict diff
                changes = []
                old_tags = old_config.tags if old_config else {}
                diff = dict_diff(self.config.tags, old_tags)
                # try to be as succinct as possible
                added = ', '.join(k for k in diff.get('added', {}))
                added = 'added tag ' + added if added else ''
                changed = ', '.join(k for k in diff.get('changed', {}))
                changed = 'changed tag ' + changed if changed else ''
                deleted = ', '.join(k for k in diff.get('deleted', {}))
                deleted = 'deleted tag ' + deleted if deleted else ''
                changes = ', '.join(i for i in (added, changed, deleted) if i)
                if changes:
                    if self.summary:
                        self.summary += ' and '
                    self.summary += "{} {}".format(self.config.owner, changes)

                # if the registry information changed, log the dict diff
                changes = []
                old_registry = old_config.registry if old_config else {}
                diff = dict_diff(self.config.registry, old_registry)
                # try to be as succinct as possible
                added = ', '.join(k for k in diff.get('added', {}))
                added = 'added registry info ' + added if added else ''
                changed = ', '.join(k for k in diff.get('changed', {}))
                changed = 'changed registry info ' + changed if changed else ''
                deleted = ', '.join(k for k in diff.get('deleted', {}))
                deleted = 'deleted registry info ' + deleted if deleted else ''
                changes = ', '.join(i for i in (added, changed, deleted) if i)
                if changes:
                    if self.summary:
                        self.summary += ' and '
                    self.summary += "{} {}".format(self.config.owner, changes)

            if not self.summary:
                if self.version == 1:
                    self.summary = "{} created the initial release".format(
                        self.owner)
                else:
                    # There were no changes to this release
                    raise AlreadyExists(
                        "{} changed nothing - release stopped".format(
                            self.owner))

        super(Release, self).save(*args, **kwargs)