daemon: fix PhysicalNode instantiation issues, remove old functions that are no longer use and update session to use the new variation
This commit is contained in:
parent
2dd3839396
commit
e557b402b6
3 changed files with 15 additions and 52 deletions
|
@ -694,7 +694,11 @@ class Session:
|
||||||
self.run_hook(hook)
|
self.run_hook(hook)
|
||||||
|
|
||||||
def add_node_file(
|
def add_node_file(
|
||||||
self, node_id: int, src_path: Path, file_path: Path, data: str
|
self,
|
||||||
|
node_id: int,
|
||||||
|
src_path: Optional[Path],
|
||||||
|
file_path: Path,
|
||||||
|
data: Optional[str],
|
||||||
) -> None:
|
) -> None:
|
||||||
"""
|
"""
|
||||||
Add a file to a node.
|
Add a file to a node.
|
||||||
|
@ -707,7 +711,7 @@ class Session:
|
||||||
"""
|
"""
|
||||||
node = self.get_node(node_id, CoreNode)
|
node = self.get_node(node_id, CoreNode)
|
||||||
if src_path is not None:
|
if src_path is not None:
|
||||||
node.addfile(src_path, file_path)
|
node.copy_file(src_path, file_path)
|
||||||
elif data is not None:
|
elif data is not None:
|
||||||
node.create_file(file_path, data)
|
node.create_file(file_path, data)
|
||||||
|
|
||||||
|
|
|
@ -271,18 +271,6 @@ class CoreNodeBase(NodeBase):
|
||||||
"""
|
"""
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
@abc.abstractmethod
|
|
||||||
def addfile(self, src_path: Path, file_path: Path) -> None:
|
|
||||||
"""
|
|
||||||
Add a file.
|
|
||||||
|
|
||||||
:param src_path: source file path
|
|
||||||
:param file_path: file name to add
|
|
||||||
:return: nothing
|
|
||||||
:raises CoreCommandError: when a non-zero exit status occurs
|
|
||||||
"""
|
|
||||||
raise NotImplementedError
|
|
||||||
|
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
def cmd(self, args: str, wait: bool = True, shell: bool = False) -> str:
|
def cmd(self, args: str, wait: bool = True, shell: bool = False) -> str:
|
||||||
"""
|
"""
|
||||||
|
@ -847,28 +835,9 @@ class CoreNode(CoreNodeBase):
|
||||||
self.ifup(iface_id)
|
self.ifup(iface_id)
|
||||||
return self.get_iface(iface_id)
|
return self.get_iface(iface_id)
|
||||||
|
|
||||||
def addfile(self, src_path: Path, file_path: Path) -> None:
|
|
||||||
"""
|
|
||||||
Add a file.
|
|
||||||
|
|
||||||
:param src_path: source file path
|
|
||||||
:param file_path: file name to add
|
|
||||||
:return: nothing
|
|
||||||
:raises CoreCommandError: when a non-zero exit status occurs
|
|
||||||
"""
|
|
||||||
logger.info("adding file from %s to %s", src_path, file_path)
|
|
||||||
directory = file_path.parent
|
|
||||||
if self.server is None:
|
|
||||||
self.client.check_cmd(f"mkdir -p {directory}")
|
|
||||||
self.client.check_cmd(f"mv {src_path} {file_path}")
|
|
||||||
self.client.check_cmd("sync")
|
|
||||||
else:
|
|
||||||
self.host_cmd(f"mkdir -p {directory}")
|
|
||||||
self.server.remote_put(src_path, file_path)
|
|
||||||
|
|
||||||
def _find_parent_path(self, path: Path) -> Optional[Path]:
|
def _find_parent_path(self, path: Path) -> Optional[Path]:
|
||||||
"""
|
"""
|
||||||
Check if there is an existing mounted parent directory created for this node.
|
Check if there is a mounted parent directory created for this node.
|
||||||
|
|
||||||
:param path: existing parent path to use
|
:param path: existing parent path to use
|
||||||
:return: exist parent path if exists, None otherwise
|
:return: exist parent path if exists, None otherwise
|
||||||
|
|
|
@ -187,21 +187,17 @@ class PhysicalNode(CoreNodeBase):
|
||||||
except CoreCommandError:
|
except CoreCommandError:
|
||||||
logger.exception("unmounting failed for %s", target_path)
|
logger.exception("unmounting failed for %s", target_path)
|
||||||
|
|
||||||
def nodefile(self, file_path: Path, contents: str, mode: int = 0o644) -> None:
|
|
||||||
host_path = self.host_path(file_path)
|
|
||||||
directory = host_path.parent
|
|
||||||
if not directory.is_dir():
|
|
||||||
directory.mkdir(parents=True, mode=0o755)
|
|
||||||
with host_path.open("w") as f:
|
|
||||||
f.write(contents)
|
|
||||||
host_path.chmod(mode)
|
|
||||||
logger.info("created nodefile: '%s'; mode: 0%o", host_path, mode)
|
|
||||||
|
|
||||||
def cmd(self, args: str, wait: bool = True, shell: bool = False) -> str:
|
def cmd(self, args: str, wait: bool = True, shell: bool = False) -> str:
|
||||||
return self.host_cmd(args, wait=wait)
|
return self.host_cmd(args, wait=wait)
|
||||||
|
|
||||||
def addfile(self, src_path: str, file_path: str) -> None:
|
def create_dir(self, dir_path: Path) -> None:
|
||||||
raise CoreError("physical node does not support addfile")
|
raise CoreError("physical node does not support creating directories")
|
||||||
|
|
||||||
|
def create_file(self, file_path: Path, contents: str, mode: int = 0o644) -> None:
|
||||||
|
raise CoreError("physical node does not support creating files")
|
||||||
|
|
||||||
|
def copy_file(self, src_path: Path, dst_path: Path, mode: int = None) -> None:
|
||||||
|
raise CoreError("physical node does not support copying files")
|
||||||
|
|
||||||
|
|
||||||
class Rj45Node(CoreNodeBase):
|
class Rj45Node(CoreNodeBase):
|
||||||
|
@ -430,12 +426,6 @@ class Rj45Node(CoreNodeBase):
|
||||||
def termcmdstring(self, sh: str) -> str:
|
def termcmdstring(self, sh: str) -> str:
|
||||||
raise CoreError("rj45 does not support terminal commands")
|
raise CoreError("rj45 does not support terminal commands")
|
||||||
|
|
||||||
def addfile(self, src_path: str, file_path: str) -> None:
|
|
||||||
raise CoreError("rj45 does not support addfile")
|
|
||||||
|
|
||||||
def nodefile(self, file_path: str, contents: str, mode: int = 0o644) -> None:
|
|
||||||
raise CoreError("rj45 does not support nodefile")
|
|
||||||
|
|
||||||
def cmd(self, args: str, wait: bool = True, shell: bool = False) -> str:
|
def cmd(self, args: str, wait: bool = True, shell: bool = False) -> str:
|
||||||
raise CoreError("rj45 does not support cmds")
|
raise CoreError("rj45 does not support cmds")
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue