Skip to content

Commit

Permalink
refractor nodeGroup to mission
Browse files Browse the repository at this point in the history
  • Loading branch information
owngr committed May 27, 2024
1 parent f57dc36 commit fbbd059
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 27 deletions.
2 changes: 1 addition & 1 deletion jelapi/classes/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def attach_node_group(self, node_group: JelasticNodeGroup) -> None:
"""
Make sure a node_group is attached correctly to that Environment
"""
self.nodeGroups[node_group.nodeGroupType.value] = node_group
self.nodeGroups[node_group.mission.value] = node_group
node_group._parent = self

def update_from_env_dict(self, jelastic_env_dict: Dict[str, Any]) -> None:
Expand Down
4 changes: 2 additions & 2 deletions jelapi/classes/mountpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def add_to_api(self) -> None:
self.api._(
"Environment.File.AddMountPointByGroup",
envName=self._envName,
nodeGroup=self._nodeGroup.nodeGroupType.value,
nodeGroup=self._nodeGroup.mission.value,
path=self.path,
sourceNodeId=self.sourceNode.id,
sourcePath=self.sourcePath,
Expand All @@ -122,7 +122,7 @@ def del_from_api(self) -> None:
self.api._(
"Environment.File.RemoveMountPointByGroup",
envName=self._envName,
nodeGroup=self._nodeGroup.nodeGroupType.value,
nodeGroup=self._nodeGroup.mission.value,
path=self.path,
)
self.copy_self_as_from_api()
Expand Down
38 changes: 19 additions & 19 deletions jelapi/classes/nodegroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class NodeGroupType(Enum):
NOSQL_DATABASE = "nosqldb"
STORAGE_CONTAINER = "storage"

nodeGroupType = _JelAttr(read_only=True)
mission = _JelAttr(read_only=True)
envName = _JelAttrStr(read_only=True)

isSLBAccessEnabled = _JelAttrBool()
Expand Down Expand Up @@ -91,7 +91,7 @@ def envVars(self):
response = self.api._(
"Environment.Control.GetContainerEnvVarsByGroup",
envName=self.envName,
nodeGroup=self.nodeGroupType.value,
nodeGroup=self.mission.value,
)
self._envVars = response["object"]
self._envVars_need_fetching = False
Expand All @@ -118,7 +118,7 @@ def _set_env_vars(self):
self.api._(
"Environment.Control.SetContainerEnvVarsByGroup",
envName=self.envName,
nodeGroup=self.nodeGroupType.value,
nodeGroup=self.mission.value,
data=json.dumps(self._envVars),
)
self.copy_self_as_from_api("_envVars")
Expand Down Expand Up @@ -147,7 +147,7 @@ def mountPoints(self) -> List["JelasticMountPoint"]:
response = self.api._(
"Environment.File.GetMountPoints",
envName=self.envName,
nodeGroup=self.nodeGroupType.value,
nodeGroup=self.mission.value,
)

for mpdict in response["array"]:
Expand All @@ -171,7 +171,7 @@ def links(self) -> Dict[str, NodeGroupType]:
for link in self.nodes[0].links:
for node_group in self._parent.nodeGroups.values():
if link["sourceNodeId"] in [n.id for n in node_group.nodes]:
self._links[link["alias"]] = node_group.nodeGroupType
self._links[link["alias"]] = node_group.mission
break
self.copy_self_as_from_api("_links")

Expand Down Expand Up @@ -219,7 +219,7 @@ def containerVolumes(self) -> List[str]:
response = self.api._(
"Environment.Control.GetContainerVolumesByGroup",
envName=self.envName,
nodeGroup=self.nodeGroupType.value,
nodeGroup=self.mission.value,
)
# We need to exclude the mountPoints
self._containerVolumes = [
Expand Down Expand Up @@ -253,7 +253,7 @@ def _save_container_volumes(self):
self.api._(
"Environment.Control.RemoveContainerVolumes",
envName=self.envName,
nodeGroup=self.nodeGroupType.value,
nodeGroup=self.mission.value,
volumes=json.dumps(toremove),
)

Expand All @@ -267,7 +267,7 @@ def _save_container_volumes(self):
self.api._(
"Environment.Control.AddContainerVolumes",
envName=self.envName,
nodeGroup=self.nodeGroupType.value,
nodeGroup=self.mission.value,
volumes=json.dumps(toadd),
)
self.copy_self_as_from_api("_containerVolumes")
Expand All @@ -284,7 +284,7 @@ def get_topology(self) -> Dict[str, Any]:
"restartDelay": 0,
"displayName": self.displayName,
"isSLBAccessEnabled": self.isSLBAccessEnabled,
"nodeGroup": self.nodeGroupType.value,
"nodeGroup": self.mission.value,
"nodeType": node0.nodeType.value,
"diskLimit": self.diskLimit,
"mission": node0.nodemission,
Expand All @@ -310,9 +310,9 @@ def get_topology(self) -> Dict[str, Any]:
# Find the correct node_group value ("storage" or "sqldb") in the parent's
node_group = next(
(
ng.nodeGroupType.value
ng.mission.value
for ng in self._parent.nodeGroups.values()
if ng.nodeGroupType == ngtype
if ng.mission == ngtype
),
)
links.append(f"{node_group}:{key}")
Expand Down Expand Up @@ -380,7 +380,7 @@ def update_from_env_dict(self, node_group_from_env: Dict[str, Any]) -> None:
# Allow exploration of the returned object, but don't act on it.
self._node_group = node_group_from_env

self._nodeGroupType = next(
self._mission = next(
(ng for ng in self.NodeGroupType if ng.value == self._node_group["name"]),
)

Expand Down Expand Up @@ -434,7 +434,7 @@ def __init__(

if nodeGroupType:
# Construct a node Group out of the blue
self._nodeGroupType = nodeGroupType
self._mission = nodeGroupType

if parent:
deprecation(
Expand Down Expand Up @@ -475,7 +475,7 @@ def _apply_data(self):
self.api._(
"Environment.NodeGroup.ApplyData",
envName=self.envName,
nodeGroup=self.nodeGroupType.value,
nodeGroup=self.mission.value,
data=json.dumps(data),
)
for k in data.keys():
Expand All @@ -495,7 +495,7 @@ def _slb_access(self):
self.api._(
"Environment.NodeGroup.SetSLBAccessEnabled",
envName=self.envName,
nodeGroup=self.nodeGroupType.value,
nodeGroup=self.mission.value,
enabled=self.isSLBAccessEnabled,
)
self._from_api["isSLBAccessEnabled"] = self.isSLBAccessEnabled
Expand All @@ -517,7 +517,7 @@ def __str__(self) -> str:
"""
String representation
"""
return f"JelasticNodeGroup {self.nodeGroupType.value}"
return f"JelasticNodeGroup {self.mission.value}"

# Jelastic-related utilites
def read_file(self, path: str) -> str:
Expand All @@ -538,7 +538,7 @@ def read_file(self, path: str) -> str:
response = self.api._(
"Environment.File.Read",
envName=self.envName,
nodeGroup=self.nodeGroupType.value,
nodeGroup=self.mission.value,
path=path,
)
return response["body"]
Expand All @@ -552,7 +552,7 @@ def redeploy(self, docker_tag: str = "latest"):
self.api._(
"Environment.Control.RedeployContainersByGroup",
envName=self.envName,
nodeGroup=self.nodeGroupType.value,
nodeGroup=self.mission.value,
tag=docker_tag,
)

Expand All @@ -565,5 +565,5 @@ def restart(self):
self.api._(
"Environment.Control.RestartNodes",
envName=self.envName,
nodeGroup=self.nodeGroupType.value,
nodeGroup=self.mission.value,
)
8 changes: 4 additions & 4 deletions jelapi/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,16 @@ def _after_postgeneration(obj, instance, create, results=None):
It can be set according to needs afterwards.
"""
instance.update_from_env_dict(
get_standard_node_group(node_group_type=instance.nodeGroupType)
get_standard_node_group(node_group_type=instance.mission)
)
node = JelasticNodeFactory()

# Set different Ids
if instance.nodeGroupType.value == "cp":
if instance.mission.value == "cp":
node._id = 110
if instance.nodeGroupType.value == "sqldb":
if instance.mission.value == "sqldb":
node._id = 120
if instance.nodeGroupType.value == "storage":
if instance.mission.value == "storage":
node._id = 130

node.attach_to_node_group(instance)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from setuptools import find_packages, setup

__version__ = "0.1.1"
__version__ = "0.2.0-rc1"

install_requires = ["httpx[http2]>=0.18"]
test_requires = [
Expand Down

0 comments on commit fbbd059

Please sign in to comment.