daemon: added capability to config services to shadow directory structures, from a given path, or from a local source, files may be templates or a straight copy and can be sourced from node named unique paths for node specific files, also refactored and renamed file creation related functions for nodes
This commit is contained in:
parent
b96dc621cd
commit
bd896d1336
10 changed files with 212 additions and 130 deletions
|
@ -140,7 +140,7 @@ class LxcNode(CoreNode):
|
|||
"""
|
||||
return f"lxc exec {self.name} -- {sh}"
|
||||
|
||||
def privatedir(self, dir_path: Path) -> None:
|
||||
def create_dir(self, dir_path: Path) -> None:
|
||||
"""
|
||||
Create a private directory.
|
||||
|
||||
|
@ -163,7 +163,7 @@ class LxcNode(CoreNode):
|
|||
logger.debug("mounting source(%s) target(%s)", src_path, target_path)
|
||||
raise Exception("not supported")
|
||||
|
||||
def nodefile(self, file_path: Path, contents: str, mode: int = 0o644) -> None:
|
||||
def create_file(self, file_path: Path, contents: str, mode: int = 0o644) -> None:
|
||||
"""
|
||||
Create a node file with a given mode.
|
||||
|
||||
|
@ -172,7 +172,7 @@ class LxcNode(CoreNode):
|
|||
:param mode: mode for file
|
||||
:return: nothing
|
||||
"""
|
||||
logger.debug("nodefile filename(%s) mode(%s)", file_path, mode)
|
||||
logger.debug("node(%s) create file(%s) mode(%o)", self.name, file_path, mode)
|
||||
temp = NamedTemporaryFile(delete=False)
|
||||
temp.write(contents.encode("utf-8"))
|
||||
temp.close()
|
||||
|
@ -189,27 +189,28 @@ class LxcNode(CoreNode):
|
|||
temp_path.unlink()
|
||||
logger.debug("node(%s) added file: %s; mode: 0%o", self.name, file_path, mode)
|
||||
|
||||
def nodefilecopy(self, file_path: Path, src_path: Path, mode: int = None) -> None:
|
||||
def copy_file(self, src_path: Path, dst_path: Path, mode: int = None) -> None:
|
||||
"""
|
||||
Copy a file to a node, following symlinks and preserving metadata.
|
||||
Change file mode if specified.
|
||||
|
||||
:param file_path: file name to copy file to
|
||||
:param dst_path: file name to copy file to
|
||||
:param src_path: file to copy
|
||||
:param mode: mode to copy to
|
||||
:return: nothing
|
||||
"""
|
||||
logger.info(
|
||||
"node file copy file(%s) source(%s) mode(%s)", file_path, src_path, mode
|
||||
"node file copy file(%s) source(%s) mode(%o)", dst_path, src_path, mode or 0
|
||||
)
|
||||
self.cmd(f"mkdir -p {file_path.parent}")
|
||||
self.cmd(f"mkdir -p {dst_path.parent}")
|
||||
if self.server:
|
||||
temp = NamedTemporaryFile(delete=False)
|
||||
temp_path = Path(temp.name)
|
||||
src_path = temp_path
|
||||
self.server.remote_put(src_path, temp_path)
|
||||
self.client.copy_file(src_path, file_path)
|
||||
self.cmd(f"chmod {mode:o} {file_path}")
|
||||
self.client.copy_file(src_path, dst_path)
|
||||
if mode is not None:
|
||||
self.cmd(f"chmod {mode:o} {dst_path}")
|
||||
|
||||
def add_iface(self, iface: CoreInterface, iface_id: int) -> None:
|
||||
super().add_iface(iface, iface_id)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue