Example #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))
Example #2
0
    def unpatch_container_config(container_name):
        """
        Reverses the effect of patch_container_config call by removing the last line with static ip
        :param container_name: container in question
        :return: None
        """

        config_file_path = Config.container_config_path(container_name, False)
        try:
            with LxcConfig(config_file_path) as config_file:
                if not config_file[ConsoleHelper.LXC_IP_KEY]:
                    log_print_error('Config file has not been patched')
                    return
                config_file.remove_last_value(ConsoleHelper.LXC_IP_KEY)
                logging.info('Config file for container {0} patched'.format(container_name))
        except FileNotFoundError:
            log_print_error('No config for container {0} at {1}'.format(container_name, config_file_path))
Example #3
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))