示例#1
0
    def print_config_file(container_name, unprivileged):
        """
        Prints the config file of the container with *container_name*
        :param container_name: the name of the container, which config is printed
        :param unprivileged: whether to print the config of the unprivileged container
        :return:
        """

        config_file_path = Config.container_config_path(container_name, unprivileged)
        try:
            with LxcConfig(config_file_path) as config_file:
                config_file.print()
        except FileNotFoundError:
            log_print_error(no_config_found_message(container_name, config_file_path))
示例#2
0
    def patch_container_config(container_name, static_ip):
        """
        Adds a line to *container_name* container config with its new *static_ip*
        :param container_name: name of the container config in question
        :param static_ip: the desired static ip
        :return: None
        """

        config_file_path = Config.container_config_path(container_name, False)
        try:
            with LxcConfig(config_file_path) as config_file:
                if config_file[ConsoleHelper.LXC_IP_KEY]:
                    log_print_error('Config file has already been patched')
                    return
                config_file.set_value(ConsoleHelper.LXC_IP_KEY, static_ip)
                logging.info('Patched container {0} config'.format(container_name))
        except FileNotFoundError:
            log_print_error(no_config_found_message(container_name, config_file_path))