Skip to content

Commit

Permalink
Merge pull request #48 from Onemind-Services-LLC/NB-44-rename-file
Browse files Browse the repository at this point in the history
NB-44 iaas.py File Renamed to paas.py
  • Loading branch information
abhi1693 authored Jun 17, 2024
2 parents 5d45235 + 8eab925 commit f9a6d2d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 27 deletions.
4 changes: 2 additions & 2 deletions netbox_paas/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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", [])
)
Expand Down Expand Up @@ -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
Expand Down
24 changes: 12 additions & 12 deletions netbox_paas/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
NODE_GROUP_SQLDB,
NODE_GROUP_CP,
)
from .iaas import *
from .paas import *

__all__ = ("NetBoxConfiguration", "NetBoxDBBackup")

Expand Down Expand Up @@ -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:
Expand All @@ -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)

Expand All @@ -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

Expand Down Expand Up @@ -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,
Expand Down
16 changes: 8 additions & 8 deletions netbox_paas/iaas.py → netbox_paas/paas.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
logger = logging.getLogger("netbox_paas")

__all__ = (
"IaaS",
"IaaSNetBox",
"PaaS",
"PaaSNetBox",
)


Expand Down Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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):
Expand All @@ -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):
Expand Down Expand Up @@ -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'
Expand Down
10 changes: 5 additions & 5 deletions netbox_paas/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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],
)
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit f9a6d2d

Please sign in to comment.