Ejemplo n.º 1
0
def register_deprecated(conf):
    conf.register_opts([host_route_depr])
    multi_parser = cfg.MultiConfigParser()
    read_ok = multi_parser.read(conf.config_file)
    if len(read_ok) != len(conf.config_file):
        raise cfg.Error("Some config files were not parsed properly")

    for parsed_file in multi_parser.parsed:
        for section in parsed_file.keys():
            if section not in conf and section.startswith("CLUSTER:"):
                conf.register_opts(cluster_opts + [controller_depr], section)
Ejemplo n.º 2
0
def _get_specific_config(prefix):
    """retrieve config in the format [<prefix>:<value>]."""
    conf_dict = {}
    multi_parser = cfg.MultiConfigParser()
    multi_parser.read(cfg.CONF.config_file)
    for parsed_file in multi_parser.parsed:
        for parsed_item in parsed_file.keys():
            if parsed_item.startswith(prefix):
                switch, switch_id = parsed_item.split(':')
                if switch.lower() == prefix:
                    conf_dict[switch_id] = parsed_file[parsed_item].items()
    return conf_dict
Ejemplo n.º 3
0
    def __init__(self):
        multi_parser = cfg.MultiConfigParser()
        read_ok = multi_parser.read(cfg.CONF.config_file)

        if len(read_ok) != len(cfg.CONF.config_file):
            raise cfg.Error(
                _("Failed to read config files %(file)s") %
                {'file': cfg.CONF.config_file})

        for parsed_file in multi_parser.parsed:
            for parsed_item in parsed_file.keys():
                for key, value in parsed_file[parsed_item].items():
                    if parsed_item == 'mech_driver_agent':
                        self.dfa_cfg[key] = value
Ejemplo n.º 4
0
    def _create_hp_config(self):
        multi_parser = cfg.MultiConfigParser()
        read_ok = multi_parser.read(cfg.CONF.config_file)

        if len(read_ok) != len(cfg.CONF.config_file):
            raise cfg.Error(_("Some config files were not parsed properly."))

        for parsed_file in multi_parser.parsed:
            for parsed_item in parsed_file.keys():
                config_id, sep, ip = parsed_item.partition(':')
                config_key = config_id.lower()
                key_items = parsed_file[parsed_item].items()
                if config_key == 'ml2_hp_leaf':
                    self._create_leaf_config(ip, key_items)
                elif config_key == 'ml2_hp_spine':
                    self._create_spine_config(ip, key_items)
Ejemplo n.º 5
0
def _parse_files():
    conf_files = _get_config_files()
    try:
        multi_parser = cfg.MultiConfigParser()
        multi_parser.read(conf_files)
        return multi_parser.parsed
    except AttributeError:
        # Oslo 6.0.0+
        sections = {}
        for filename in conf_files:
            parser = cfg.ConfigParser(filename, sections)
            try:
                parser.parse()
            except IOError:
                continue
        return [sections]
Ejemplo n.º 6
0
    def _create_ml2_mech_device_cisco_dictionary(self):
        """Create the ML2 device cisco dictionary.

        Read data from the ml2_conf_cisco.ini device supported sections.
        """
        multi_parser = cfg.MultiConfigParser()
        read_ok = multi_parser.read(cfg.CONF.config_file)

        if len(read_ok) != len(cfg.CONF.config_file):
            raise cfg.Error(_("Some config files were not parsed properly"))

        for parsed_file in multi_parser.parsed:
            for parsed_item in parsed_file.keys():
                dev_id, sep, dev_ip = parsed_item.partition(':')
                if dev_id.lower() == 'ml2_mech_cisco_nexus':
                    for dev_key, value in parsed_file[parsed_item].items():
                        self.nexus_dict[dev_ip, dev_key] = value[0]
Ejemplo n.º 7
0
    def _create_device_dictionary(self):
        """
        Create the device dictionary from the cisco_plugins.ini
        device supported sections. Ex. NEXUS_SWITCH, N1KV.
        """

        multi_parser = cfg.MultiConfigParser()
        read_ok = multi_parser.read(CONF.config_file)

        if len(read_ok) != len(CONF.config_file):
            raise cfg.Error(_("Some config files were not parsed properly"))

        for parsed_file in multi_parser.parsed:
            for parsed_item in parsed_file.keys():
                dev_id, sep, dev_ip = parsed_item.partition(':')
                if dev_id.lower() in ['nexus_switch', 'n1kv']:
                    for dev_key, value in parsed_file[parsed_item].items():
                        device_dictionary[dev_id, dev_ip, dev_key] = value[0]
Ejemplo n.º 8
0
    def _create_nexus_dictionary(self):
        """Create the Nexus dictionary.

        Reads data from cisco_plugins.ini NEXUS_SWITCH section(s).
        """

        multi_parser = cfg.MultiConfigParser()
        read_ok = multi_parser.read(CONF.config_file)

        if len(read_ok) != len(CONF.config_file):
            raise cfg.Error("Some config files were not parsed properly")

        for parsed_file in multi_parser.parsed:
            for parsed_item in parsed_file.keys():
                nexus_name, sep, nexus_ip = parsed_item.partition(':')
                if nexus_name.lower() == "nexus_switch":
                    for nexus_key, value in parsed_file[parsed_item].items():
                        nexus_dictionary[nexus_ip, nexus_key] = value[0]
Ejemplo n.º 9
0
def create_switch_dictionary():
    multi_parser = cfg.MultiConfigParser()
    read_ok = multi_parser.read(cfg.CONF.config_file)

    if len(read_ok) != len(cfg.CONF.config_file):
        raise cfg.Error(_("Some config files were not parsed properly"))

    for parsed_file in multi_parser.parsed:
        for parsed_item in parsed_file.keys():
            if parsed_item.startswith('apic_switch'):
                switch, switch_id = parsed_item.split(':')
                if switch.lower() == 'apic_switch':
                    _switch_dict[switch_id] = {}
                    port_cfg = parsed_file[parsed_item].items()
                    for host_list, port in port_cfg:
                        hosts = host_list.split(',')
                        port = port[0]
                        _switch_dict[switch_id][port] = hosts

    return _switch_dict
Ejemplo n.º 10
0
def find_available_csrs_from_config(config_files):
    """Read INI for available Cisco CSRs that driver can use.

    Loads management port, tunnel IP, user, and password information for
    available CSRs from configuration file. Driver will use this info to
    configure VPN connections. The CSR is associated 1:1 with a Neutron
    router. To identify which CSR to use for a VPN service, the public
    (GW) IP of the Neutron router will be used as an index into the CSR
    config info.
    """
    multi_parser = cfg.MultiConfigParser()
    LOG.info(_("Scanning config files %s for Cisco CSR configurations"),
             config_files)
    try:
        read_ok = multi_parser.read(config_files)
    except cfg.ParseError as pe:
        LOG.error(_("Config file parse error: %s"), pe)
        return {}

    if len(read_ok) != len(config_files):
        raise cfg.Error(
            _("Unable to parse config files %s for Cisco CSR "
              "info") % config_files)
    csrs_found = {}
    for parsed_file in multi_parser.parsed:
        for parsed_item in parsed_file.keys():
            device_type, sep, for_router = parsed_item.partition(':')
            if device_type.lower() == 'cisco_csr_rest':
                try:
                    netaddr.IPNetwork(for_router)
                except netaddr.core.AddrFormatError:
                    LOG.error(
                        _("Ignoring Cisco CSR configuration entry - "
                          "router IP %s is not valid"), for_router)
                    continue
                entry = parsed_file[parsed_item]
                # Check for missing fields
                try:
                    rest_mgmt_ip = entry['rest_mgmt'][0]
                    tunnel_ip = entry['tunnel_ip'][0]
                    username = entry['username'][0]
                    password = entry['password'][0]
                except KeyError as ke:
                    LOG.error(
                        _("Ignoring Cisco CSR for router %(router)s "
                          "- missing %(field)s setting"), {
                              'router': for_router,
                              'field': str(ke)
                          })
                    continue
                # Validate fields
                try:
                    timeout = float(entry['timeout'][0])
                except ValueError:
                    LOG.error(
                        _("Ignoring Cisco CSR for router %s - "
                          "timeout is not a floating point number"),
                        for_router)
                    continue
                except KeyError:
                    timeout = csr_client.TIMEOUT
                try:
                    netaddr.IPAddress(rest_mgmt_ip)
                except netaddr.core.AddrFormatError:
                    LOG.error(
                        _("Ignoring Cisco CSR for subnet %s - "
                          "REST management is not an IP address"), for_router)
                    continue
                try:
                    netaddr.IPAddress(tunnel_ip)
                except netaddr.core.AddrFormatError:
                    LOG.error(
                        _("Ignoring Cisco CSR for router %s - "
                          "local tunnel is not an IP address"), for_router)
                    continue
                csrs_found[for_router] = {
                    'rest_mgmt': rest_mgmt_ip,
                    'tunnel_ip': tunnel_ip,
                    'username': username,
                    'password': password,
                    'timeout': timeout
                }

                LOG.debug(_("Found CSR for router %(router)s: %(info)s"), {
                    'router': for_router,
                    'info': csrs_found[for_router]
                })
    return csrs_found