- Get pod IP with `get_pod_ip()`
"""
+from dataclasses import dataclass
import logging
import secrets
import socket
# Increment this PATCH version before using `charmcraft publish-lib` or reset
# to 0 if you are raising the major API version
-LIBPATCH = 1
+LIBPATCH = 3
logger = logging.getLogger(__name__)
"""
+@dataclass
+class SubModule:
+ """Represent RO Submodules."""
+ sub_module_path: str
+ container_path: str
+
+
class HostPath:
"""Represents a hostpath."""
-
- def __init__(self, config: str, container_path: str) -> None:
+ def __init__(self, config: str, container_path: str, submodules: dict = None) -> None:
mount_path_items = config.split("-")
mount_path_items.reverse()
self.mount_path = "/" + "/".join(mount_path_items)
self.config = config
- self.container_path = container_path
- self.module_name = container_path.split("/")[-1]
-
+ self.sub_module_dict = {}
+ if submodules:
+ for submodule in submodules.keys():
+ self.sub_module_dict[submodule] = SubModule(
+ sub_module_path=self.mount_path + "/" + submodule,
+ container_path=submodules[submodule],
+ )
+ else:
+ self.container_path = container_path
+ self.module_name = container_path.split("/")[-1]
class DebugMode(Object):
"""Class to handle the debug-mode."""
# Add symlinks to mounted hostpaths
for hostpath in mounted_hostpaths:
logger.debug(f"adding symlink for {hostpath.config}")
- self.container.exec(["rm", "-rf", hostpath.container_path]).wait_output()
- self.container.exec(
- [
- "ln",
- "-s",
- f"{hostpath.mount_path}/{hostpath.module_name}",
- hostpath.container_path,
- ]
- )
+ if len(hostpath.sub_module_dict) > 0:
+ for sub_module in hostpath.sub_module_dict.keys():
+ self.container.exec(["rm", "-rf", hostpath.sub_module_dict[sub_module].container_path]).wait_output()
+ self.container.exec(
+ [
+ "ln",
+ "-s",
+ hostpath.sub_module_dict[sub_module].sub_module_path,
+ hostpath.sub_module_dict[sub_module].container_path,
+ ]
+ )
+
+ else:
+ self.container.exec(["rm", "-rf", hostpath.container_path]).wait_output()
+ self.container.exec(
+ [
+ "ln",
+ "-s",
+ f"{hostpath.mount_path}/{hostpath.module_name}",
+ hostpath.container_path,
+ ]
+ )
def _configure_hostpaths(self, hostpaths: List[HostPath]):
client = Client()
pod_ip: str,
user: str = "root",
workspace_path: str = "/debug.code-workspace",
- ) -> None:
+ ) -> str:
return f"code --remote ssh-remote+{user}@{pod_ip} {workspace_path}"
def _restart(self):