Exemple #1
0
class DeleteContainer(Delete):
    """
    Delete containers.
    """
    def __init__(self, name, config, runtime_config):
        """
        Delete a container.

        :param name: container name.
        :type name: str
        :param config: configuration of the container
        :type config: dict
        :param runtime_config: runtime configuration
        :type runtime_config: dict
        """
        super().__init__(name, config, runtime_config)
        self.path = os.path.join(BASE_CONTAINER_DIR,
                                 self.config["image"]["name"], self.name,
                                 self.config["container"]["version"])
        self.unit_name = "sponson-container-{}.service".format(self.name)
        self.systemd = SystemdContainer(runtime_config)

    def _sanity_check(self):
        """
        Container deletion sanity check.
        """
        if self.name and self.systemd.is_running(self.name):
            raise DeleteError("Container is currently running, "
                              "stop the container service before deleting")

    def _clean_sponson_conf(self):
        """
        Remove sponson container configuration files.
        """
        os.remove(os.path.join(ETC_CONTAINER_CONF_DIR,
                               "{}.yaml".format(self.name)))