示例#1
0
    def config_erase_property(container_name, key, unprivileged):
        """
        Erases the property from a config
        :param container_name: name of the container in question
        :param key: property to be erased
        :param unprivileged: if the container is unprivileged
        :return: None
        """

        config_file_path = Config.container_config_path(container_name, unprivileged)
        with LxcConfig(config_file_path) as config_file:
            config_file.erase_property(key)
示例#2
0
    def config_add_property(container_name, key, value, unprivileged):
        """
        Adds a property to a config file with *value*
        :param container_name: name of the container in question
        :param key: property to be added
        :param value: value to be added property
        :param unprivileged: if the container is unprivileged
        :return: None
        """

        config_file_path = Config.container_config_path(container_name, unprivileged)
        with LxcConfig(config_file_path) as config_file:
            config_file.append_value(key, value)
示例#3
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))
示例#4
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))
示例#5
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))