diff --git a/netbox_paas/forms.py b/netbox_paas/forms.py index abebe8d..cf08114 100644 --- a/netbox_paas/forms.py +++ b/netbox_paas/forms.py @@ -85,7 +85,7 @@ def __init__(self, *args, **kwargs): self.fields["env_name_storage"].initial = self.instance.env_name_storage env_infos = ( - self.instance.iaas(self.instance.env_name, auto_init=False) + self.instance.paas(self.instance.env_name, auto_init=False) .client.environment.Control.GetEnvs() .get("infos", []) ) @@ -206,7 +206,7 @@ def __init__(self, *args, **kwargs): # Fetch the region list and build the choices nc = NetBoxConfiguration.objects.first() - regions = nc.iaas(nc.env_name, auto_init=False).client.environment.Control.GetRegions().get("array", []) + regions = nc.paas(nc.env_name, auto_init=False).client.environment.Control.GetRegions().get("array", []) self.fields["region"].choices = [ (hard_node_group["uniqueName"], region["displayName"]) for region in regions diff --git a/netbox_paas/models.py b/netbox_paas/models.py index b1f8070..d22b69f 100644 --- a/netbox_paas/models.py +++ b/netbox_paas/models.py @@ -23,7 +23,7 @@ NODE_GROUP_SQLDB, NODE_GROUP_CP, ) -from .iaas import * +from .paas import * __all__ = ("NetBoxConfiguration", "NetBoxDBBackup") @@ -71,7 +71,7 @@ def clean(self): raise ValidationError("There can only be one NetBoxConfiguration instance.") # Clear any cached values from lru_cache - self.iaas.cache_clear() + self.paas.cache_clear() # Environment name must not contain dots if "." in self.env_name: @@ -80,14 +80,14 @@ def clean(self): if self.pk: try: # Ensure the provided env_name exists - self.iaas(self.env_name) + self.paas(self.env_name) except JelasticApiError as e: raise ValidationError(e) if self.env_name_storage: try: # Ensure the provided env_name exists - self.iaas(self.env_name_storage) + self.paas(self.env_name_storage) except JelasticApiError as e: raise ValidationError(e) @@ -96,31 +96,31 @@ def clean(self): raise ValidationError({"license": "Invalid license key"}) @lru_cache(maxsize=2) - def iaas(self, env_name, auto_init=True): - return IaaSNetBox( + def paas(self, env_name, auto_init=True): + return PaaSNetBox( token=self.key, env_name=env_name, auto_init=auto_init, ) def get_env(self): - return self.iaas(self.env_name) + return self.paas(self.env_name) def get_docker_tag(self): return self.get_env().get_master_node(NODE_GROUP_CP).get("customitem", {}).get("dockerTag", "") def get_env_storage(self): - return self.iaas(self.env_name_storage) + return self.paas(self.env_name_storage) def netbox_admin(self): """ Returns NetBox administration configuration. """ - iaas = self.get_env() + paas = self.get_env() - result = {"url": iaas.get_url()} + result = {"url": paas.get_url()} for setting in NETBOX_SUPERUSER_SETTINGS: - result[setting] = iaas.get_env_var(setting) + result[setting] = paas.get_env_var(setting) return result @@ -214,7 +214,7 @@ def apply_settings(self, data: dict): self.schedule_restart() def enqueue(self, func, request, *args, **kwargs): - return self.iaas(self.env_name).enqueue( + return self.paas(self.env_name).enqueue( func, self, request, diff --git a/netbox_paas/iaas.py b/netbox_paas/paas.py similarity index 99% rename from netbox_paas/iaas.py rename to netbox_paas/paas.py index 3d9165d..2fe96d5 100644 --- a/netbox_paas/iaas.py +++ b/netbox_paas/paas.py @@ -21,8 +21,8 @@ logger = logging.getLogger("netbox_paas") __all__ = ( - "IaaS", - "IaaSNetBox", + "PaaS", + "PaaSNetBox", ) @@ -92,7 +92,7 @@ def dumps(self) -> str: return "\n".join([str(r.line) for r in self.requirements]) -class IaaSJob: +class PaaSJob: @classmethod def enqueue(cls, func, model, request=None, *args, **kwargs): """ @@ -136,9 +136,9 @@ def _run_job(job, *args, **kwargs): job.save() -class IaaS(IaaSJob): +class PaaS(PaaSJob): """ - This class is used to manage the IaaS layer of the Jelastic platform. + This class is used to manage the PaaS layer of the Jelastic platform. """ def __init__(self, token: str, env_name: str, auto_init: bool = True): @@ -148,7 +148,7 @@ def __init__(self, token: str, env_name: str, auto_init: bool = True): if auto_init: self._get_env_info() - logger.debug(f"IaaS layer initialized for environment {self.env_name}") + logger.debug(f"PaaS layer initialized for environment {self.env_name}") @lru_cache(maxsize=1) def _get_env_info(self): @@ -451,9 +451,9 @@ def get_actions(self): return [action for action in actions if action.get("text", {}).get("env") == self.env_name] -class IaaSNetBox(IaaS): +class PaaSNetBox(PaaS): """ - This class is used to manage the IaaS layer of the Jelastic platform for NetBox. + This class is used to manage the PaaS layer of the Jelastic platform for NetBox. """ NETBOX_DIR = '/etc/netbox' diff --git a/netbox_paas/views.py b/netbox_paas/views.py index 4131074..fd8fe50 100644 --- a/netbox_paas/views.py +++ b/netbox_paas/views.py @@ -49,10 +49,10 @@ def post(self, request, pk): env_name = request.POST.get("env_name") node_id = request.POST.get("node_id") - iaas = instance.iaas(env_name) + paas = instance.paas(env_name) - node = iaas.get_node(node_id) - logs = iaas.get_node_log(node_id) + node = paas.get_node(node_id) + logs = paas.get_node_log(node_id) return render( request, "netbox_paas/nodelogs.html", @@ -126,7 +126,7 @@ def post(self, request, pk): env_name = request.POST.get("env_name") node_group = request.POST.get("node_group") job = instance.enqueue( - instance.iaas(env_name, auto_init=False).restart_nodes, + instance.paas(env_name, auto_init=False).restart_nodes, request, node_groups=[node_group], ) @@ -168,7 +168,7 @@ def post(self, request, *args, **kwargs): # Deploy a new environment for backup-storage job = obj.enqueue( - obj.iaas(env_name, auto_init=False).client.marketplace.App.Install, + obj.paas(env_name, auto_init=False).client.marketplace.App.Install, request, id="wp-restore", env_name=env_name,