def _write_craft_image_config(self, *, executor: Executor) -> None: conf = {"compatibility_tag": self.compatibility_tag} executor.create_file( destination=pathlib.Path("/etc/craft-image.conf"), content=yaml.dump(conf).encode(), file_mode="0644", )
def _setup_networkd(self, *, executor: Executor) -> None: """Configure networkd and start it. Installs eth0 network configuration using ipv4. :param executor: Executor for target container. """ executor.create_file( destination=pathlib.Path("/etc/systemd/network/10-eth0.network"), content=dedent(""" [Match] Name=eth0 [Network] DHCP=ipv4 LinkLocalAddressing=ipv6 [DHCP] RouteMetric=100 UseMTU=true """).encode(), file_mode="0644", ) executor.execute_run( command=["systemctl", "enable", "systemd-networkd"], check=True) executor.execute_run( command=["systemctl", "restart", "systemd-networkd"], check=True)
def _setup_hostname(self, *, executor: Executor) -> None: """Configure hostname, installing /etc/hostname. :param executor: Executor for target container. """ executor.create_file( destination=pathlib.Path("/etc/hostname"), content=self.hostname.encode(), file_mode="0644", )
def save( *, executor: Executor, config: Dict[str, Any], config_path: pathlib.Path ) -> None: """Save craft image config. :param executor: Executor for instance. :param config: Configuration data to write. :param config_path: Path to configuration file. """ executor.create_file( destination=config_path, content=yaml.dump(config).encode(), file_mode="0644", )