Editando Arquivos de Configuração – Ocultar comentários

Code

Alguns dias atrás iniciei o deploy do OpenStack, para quem conhece sabe como os arquivos de configurações são complexos e extensos, para se ter uma idéia o arquivo sample neutron.conf possui mais de 1500 linhas, onde as configurações precisam ser inseridas exatamente dentro da seção de configuração correta.

Abaixo copiei um pequeno trecho deste arquivo da linha 1 à 150 apenas para fins didáticos, como você pode ver há muitas linhas de comentários, e em um arquivo grande é difícil se encontrar.

[DEFAULT]

#
# From neutron
#

# Where to store Neutron state files. This directory must be writable by the
# agent. (string value)
#state_path = /var/lib/neutron

# The host IP to bind to (string value)
#bind_host = 0.0.0.0

# The port to bind to (port value)
# Minimum value: 0
# Maximum value: 65535
#bind_port = 9696

# The path for API extensions. Note that this can be a colon-separated list of
# paths. For example: api_extensions_path =
# extensions:/path/to/more/exts:/even/more/exts. The __path__ of
# neutron.extensions is appended to this, so if your extensions are in there
# you don't need to specify them here. (string value)
#api_extensions_path =

# The type of authentication to use (string value)
#auth_strategy = keystone

# The core plugin Neutron will use (string value)
#core_plugin = <None>

# The service plugins Neutron will use (list value)
#service_plugins =

# The base MAC address Neutron will use for VIFs. The first 3 octets will
# remain unchanged. If the 4th octet is not 00, it will also be used. The
# others will be randomly generated. (string value)
base_mac = fa:16:3e:00:00:00

# How many times Neutron will retry MAC generation (integer value)
#mac_generation_retries = 16

# Allow the usage of the bulk API (boolean value)
#allow_bulk = true

# Allow the usage of the pagination (boolean value)
#allow_pagination = false

# Allow the usage of the sorting (boolean value)
#allow_sorting = false

# The maximum number of items returned in a single response, value was
# 'infinite' or negative integer means no limit (string value)
#pagination_max_limit = -1

# Default value of availability zone hints. The availability zone aware
# schedulers use this when the resources availability_zone_hints is empty.
# Multiple availability zones can be specified by a comma separated string.
# This value can be empty. In this case, even if availability_zone_hints for a
# resource is empty, availability zone is considered for high availability
# while scheduling the resource. (list value)
#default_availability_zones =

# Maximum number of DNS nameservers per subnet (integer value)
#max_dns_nameservers = 5

# Maximum number of host routes per subnet (integer value)
#max_subnet_host_routes = 20

# Maximum number of fixed ips per port. This option is deprecated and will be
# removed in the N release. (integer value)
# This option is deprecated for removal.
# Its value may be silently ignored in the future.
max_fixed_ips_per_port = 5

# Default IPv4 subnet pool to be used for automatic subnet CIDR allocation.
# Specifies by UUID the pool to be used in case where creation of a subnet is
# being called without a subnet pool ID. If not set then no pool will be used
# unless passed explicitly to the subnet create. If no pool is used, then a
# CIDR must be passed to create a subnet and that subnet will not be allocated
# from any pool; it will be considered part of the tenant's private address
# space. This option is deprecated for removal in the N release. (string value)
# This option is deprecated for removal.
# Its value may be silently ignored in the future.
#default_ipv4_subnet_pool = <None>

# Default IPv6 subnet pool to be used for automatic subnet CIDR allocation.
# Specifies by UUID the pool to be used in case where creation of a subnet is
# being called without a subnet pool ID. See the description for
# default_ipv4_subnet_pool for more information. This option is deprecated for
# removal in the N release. (string value)
# This option is deprecated for removal.
# Its value may be silently ignored in the future.
#default_ipv6_subnet_pool = <None>

# Enables IPv6 Prefix Delegation for automatic subnet CIDR allocation. Set to
# True to enable IPv6 Prefix Delegation for subnet allocation in a PD-capable
# environment. Users making subnet creation requests for IPv6 subnets without
# providing a CIDR or subnetpool ID will be given a CIDR via the Prefix
# Delegation mechanism. Note that enabling PD will override the behavior of the
# default IPv6 subnetpool. (boolean value)
#ipv6_pd_enabled = false

# DHCP lease duration (in seconds). Use -1 to tell dnsmasq to use infinite
# lease times. (integer value)
# Deprecated group/name - [DEFAULT]/dhcp_lease_time
#dhcp_lease_duration = 86400

# Domain to use for building the hostnames (string value)
#dns_domain = openstacklocal

# Driver for external DNS integration. (string value)
#external_dns_driver = <None>

# Allow sending resource operation notification to DHCP agent (boolean value)
dhcp_agent_notification = true

# Allow overlapping IP support in Neutron. Attention: the following parameter
# MUST be set to False if Neutron is being used in conjunction with Nova
# security groups. (boolean value)
#allow_overlapping_ips = false

# Hostname to be used by the Neutron server, agents and services running on
# this machine. All the agents and services running on this machine must use
# the same host value. (string value)
#host = example.domain

# Ensure that configured gateway is on subnet. For IPv6, validate only if
# gateway is not a link local address. Deprecated, to be removed during the
# Newton release, at which point the gateway will not be forced on to subnet.
# (boolean value)
# This option is deprecated for removal.
# Its value may be silently ignored in the future.
#force_gateway_on_subnet = true

# Send notification to nova when port status changes (boolean value)
#notify_nova_on_port_status_changes = true

# Send notification to nova when port data (fixed_ips/floatingip) changes so
# nova can update its cache. (boolean value)
notify_nova_on_port_data_changes = true

# Number of seconds between sending events to nova if there are any events to
# send. (integer value)
#send_events_interval = 2

# If True, advertise network MTU values if core plugin calculates them. MTU is
# advertised to running instances via DHCP and RA MTU options. (boolean value)
#advertise_mtu = true

Como facilitar a leitura deste arquivo apenas com as configurações que estão sendo realmente aplicadas?

Para isso, utilize o comando egrep e fitros Regex, no exemplo abaixo o comando egrep com a opção -v aplicará o filtro buscando por linhas iniciadas com # ou $ porém inverterá esta seleção devido a opção -v ou seja, exibirá todas as linhas com exceção das iniciadas com # ou $.

egrep -v '(^$|^#)'  /etc/neutron/neutron.conf

Aplicando o arquivo acima o resultado será este:

[DEFAULT]
base_mac = fa:16:3e:00:00:00
max_fixed_ips_per_port = 5
dhcp_agent_notification = true
notify_nova_on_port_data_changes = true

Para saber mais sobre expressões regulares veja este artigo no Wikipedia.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.