Skip to content

Commit

Permalink
Add internet as a Network on creation of a new organization XTDB node (
Browse files Browse the repository at this point in the history
  • Loading branch information
Donnype authored Nov 20, 2023
1 parent 5b6c25f commit 189a7f8
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion rocky/tools/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import datetime
import logging
from functools import cached_property
from typing import Iterable, Set
Expand All @@ -8,7 +9,7 @@
from django.core.exceptions import ValidationError
from django.core.validators import MaxValueValidator, MinValueValidator
from django.db import models
from django.db.models.signals import pre_save
from django.db.models.signals import post_save, pre_save
from django.urls import reverse
from django.utils.translation import gettext_lazy as _
from katalogus.client import KATalogusClientV1, get_katalogus
Expand All @@ -19,7 +20,9 @@
)
from requests import RequestException

from octopoes.api.models import Declaration
from octopoes.connector.octopoes import OctopoesAPIConnector
from octopoes.models.ooi.web import Network
from rocky.exceptions import (
OctopoesDownException,
OctopoesException,
Expand Down Expand Up @@ -168,6 +171,16 @@ def pre_create(cls, sender, instance, *args, **kwargs):

raise OctopoesException("Failed creating organization in Octopoes") from e

@classmethod
def post_create(cls, sender, instance, *args, **kwargs):
octopoes_client = cls._get_healthy_octopoes(instance.code)

try:
valid_time = datetime.datetime.now(datetime.timezone.utc)
octopoes_client.save_declaration(Declaration(ooi=Network(name="internet"), valid_time=valid_time))
except Exception:
logger.exception("Could not seed internet for organization %s", sender)

@staticmethod
def _get_healthy_katalogus(organization_code: str) -> KATalogusClientV1:
katalogus_client = get_katalogus(organization_code)
Expand Down Expand Up @@ -197,6 +210,7 @@ def _get_healthy_octopoes(organization_code: str) -> OctopoesAPIConnector:


pre_save.connect(Organization.pre_create, sender=Organization)
post_save.connect(Organization.post_create, sender=Organization)


class OrganizationMember(models.Model):
Expand Down

0 comments on commit 189a7f8

Please sign in to comment.