Пример #1
0
    def setup(self):
        # Setup specific configurations
        oslo_parser = cfg.MultiConfigParser()
        parsed_buf = oslo_parser.read(cfg.CONF.config_file)

        if not len(parsed_buf) == len(cfg.CONF.config_file):
            raise utils.DMConfigError("Parsing problem")

        config = oslo_parser.parsed[0]

        # get each switch from config file
        switches = [i for i in config if str(i) != 'ml2_datacom']

        # create the actual dictionary
        for switch in switches:
            sw_dic = config[switch]
            # each field is a list, when it should be a value
            for i in sw_dic:
                if i.startswith('dm'):
                    sw_dic[i] = sw_dic[i][0]

            # get each global configuration, when not mentioned in the specific
            for field in cfg.CONF.ml2_datacom:
                if field not in sw_dic:
                    sw_dic[field] = cfg.CONF.ml2_datacom[field]

            sw_dic['rpc'] = rpc.RPC(str(sw_dic['dm_username']),
                                    str(sw_dic['dm_password']), str(switch),
                                    str(sw_dic['dm_method']))

            sw_dic['xml'] = ManagedXml()
            self.switches_dic[switch] = sw_dic
def create_agent_config_map(conf):
    agent_config = {}
    agent_config['epg_mapping_dir'] = conf.OPFLEX.epg_mapping_dir
    agent_config['opflex_networks'] = conf.OPFLEX.opflex_networks
    agent_config['endpoint_request_timeout'] = (
        conf.OPFLEX.endpoint_request_timeout)
    agent_config['config_apply_interval'] = conf.OPFLEX.config_apply_interval
    agent_config['internal_floating_ip_pool'] = (
        conf.OPFLEX.internal_floating_ip_pool)
    agent_config['internal_floating_ip6_pool'] = (
        conf.OPFLEX.internal_floating_ip6_pool)
    # DVR not supported
    agent_config['enable_distributed_routing'] = False
    # ARP responder not supported
    agent_config['arp_responder'] = False

    # read external-segment next-hop info
    es_info = {}
    multi_parser = cfg.MultiConfigParser()
    multi_parser.read(conf.config_file)
    for parsed_file in multi_parser.parsed:
        for parsed_item in parsed_file.keys():
            if parsed_item.startswith('opflex_external_segment:'):
                es_name = parsed_item.split(':', 1)[1]
                if es_name:
                    es_info[es_name] = parsed_file[parsed_item].items()
    agent_config['external_segment'] = es_info
    agent_config['dhcp_domain'] = conf.dhcp_domain
    return agent_config
Пример #3
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.
        All reserved keywords are saved in the nexus_dict and all other
        keys (host systems) are saved in the host mapping db.
        """
        defined_attributes = [
            const.USERNAME, const.PASSWORD, const.SSHPORT, const.PHYSNET,
            const.NVE_SRC_INTF
        ]
        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"))

        nxos_db.remove_all_static_host_mappings()
        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():
                        if dev_key in defined_attributes:
                            self.nexus_dict[dev_ip, dev_key] = value[0]
                        else:
                            for if_id in value[0].split(','):
                                nxos_db.add_host_mapping(
                                    dev_key, dev_ip, if_id, 0, True)
Пример #4
0
    def __init__(self, service_name=None):
        self.dfa_cfg = {}
        self._load_default_opts()
        args = sys.argv[1:]
        try:
            opts = [(args[i], args[i + 1]) for i in range(0, len(args), 2)]
        except IndexError:
            opts = []

        cfgfile = cfg.find_config_files(service_name)
        for k, v in opts:
            if k == '--config-file':
                cfgfile.append(v)
        multi_parser = cfg.MultiConfigParser()
        read_ok = multi_parser.read(cfgfile)

        if len(read_ok) != len(cfgfile):
            raise cfg.Error(_LE("Failed to parse config file."))

        for parsed_file in multi_parser.parsed:
            for parsed_item in parsed_file.keys():
                if parsed_item not in self.dfa_cfg:
                    self.dfa_cfg[parsed_item] = {}
                for key, value in parsed_file[parsed_item].items():
                    self.dfa_cfg[parsed_item][key] = value[0]

        # Convert it to object.
        self._cfg = utils.Dict2Obj(self.dfa_cfg)
Пример #5
0
    def _create_multi_ucsm_dicts(self):
        """Creates a dictionary of all UCS Manager data from config."""
        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(':')
                dev_ip = dev_ip.strip()
                if dev_id.lower() == 'ml2_cisco_ucsm_ip':
                    ucsm_info = []
                    eth_port_list = []
                    for dev_key, value in parsed_file[parsed_item].items():
                        config_item = dev_key.lower()
                        if config_item == 'ucsm_virtio_eth_ports':
                            for eth_port in value[0].split(','):
                                eth_port_list.append(const.ETH_PREFIX +
                                                     str(eth_port).strip())
                            self.ucsm_port_dict[dev_ip] = eth_port_list
                        elif config_item == 'sp_template_list':
                            self._parse_sp_template_list(dev_ip, value)
                            self.sp_template_mode = True
                        elif config_item == 'vnic_template_list':
                            self._parse_vnic_template_list(dev_ip, value)
                            self.vnic_template_mode = True
                        else:
                            ucsm_info.append(value[0])
                    self.ucsm_dict[dev_ip] = ucsm_info
                    self.multi_ucsm_mode = True
Пример #6
0
def get_config():
    LOG.warning("Usage of networking_generic_switch.config.get_config method "
                "is deprecated and this method will be removed after the Pike "
                "release or any time earlier if MultiConfigParser is removed "
                "from oslo_config. Use get_devices method directly.")
    multi_parser = cfg.MultiConfigParser()
    multi_parser.read(CONF.config_file)
    return multi_parser.parsed
Пример #7
0
    def _parse_file(self):
        cfg_parser = cfg.MultiConfigParser()
        try:
            cfg_parser.read([self.config_file])
        except Exception as e:
            LOG.warning('Failed to parse file %(file)s: %(exc)s', {
                'file': self.config_file,
                'exc': e
            })
            return

        def sanitize_scope(scope):
            if scope:
                scope = scope.strip().lower()
                if scope in [SCOPE_PUBLIC, SCOPE_PRIVATE, SCOPE_DENY]:
                    return scope
            return None

        def parse_cidr_list(cidrs):
            try:
                return netaddr.IPSet(
                    [c for c in cidrs.split(',') if c.strip()])
            except Exception as e:
                LOG.warning('Failed to parse CIDRs: %(cidr)s: %(exc)s', {
                    'cidr': cidrs,
                    'exc': e
                })
                return None

        def_scope = None
        constraints = {}
        LOG.debug('Parsing network constraints file %s', self.config_file)
        for cfg_file in cfg_parser.parsed:
            for section_name in cfg_file.keys():
                if section_name == 'DEFAULT':
                    def_scope = sanitize_scope(cfg_file[section_name].get(
                        'subnet_scope', [None])[0])
                    LOG.debug('Default subnet scope: %s', def_scope)
                else:
                    net = tuple(section_name.split('/', 1))
                    if len(net) < 2:  # tenant case
                        net += tuple([None])
                    constraints[net] = {}
                    for k, v in cfg_file[section_name].iteritems():
                        k = k.lower()
                        if k in ['public', 'private', 'deny']:
                            constraints[net][k] = parse_cidr_list(v[0])
                        elif k == 'default':
                            constraints[net][k] = sanitize_scope(v[0])
                    LOG.debug('Constraints for network %(n)s - %(c)s', {
                        'n': net,
                        'c': constraints[net]
                    })
        self.subnet_default_scope = def_scope
        self.subnet_constraints = constraints
Пример #8
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
Пример #9
0
def _get_specific_config(prefix):
    """retrieve config in the format [<label>:<key>]."""
    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):
                label, key = parsed_item.split(':')
                if label.lower() == prefix:
                    conf_dict[key] = parsed_file[parsed_item].items()
    return conf_dict
Пример #10
0
    def _create_multi_ucsm_dicts(self):
        """Creates a dictionary of all UCS Manager data from config."""
        username = None
        password = None
        local_sp_dict = {}
        local_host_dict = {}
        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(':')
                dev_ip = dev_ip.strip()
                if dev_id.lower() == 'ml2_cisco_ucsm_ip':
                    ucsm_info = []
                    eth_port_list = []
                    for dev_key, value in parsed_file[parsed_item].items():
                        config_item = dev_key.lower()
                        if config_item == 'ucsm_host_list':
                            local_sp_dict, local_host_dict = (
                                parse_ucsm_host_config(dev_ip,
                                                       value[0].split(',')))
                            self.ucsm_sp_dict.update(local_sp_dict)
                            self.ucsm_host_dict.update(local_host_dict)
                        elif config_item == 'ucsm_virtio_eth_ports':
                            for eth_port in value[0].split(','):
                                eth_port_list.append(const.ETH_PREFIX +
                                                     str(eth_port).strip())
                            self.ucsm_port_dict[dev_ip] = eth_port_list
                        elif config_item == 'sp_template_list':
                            self._parse_sp_template_list(dev_ip, value)
                            self.sp_template_mode = True
                        elif config_item == 'vnic_template_list':
                            self._parse_vnic_template_list(dev_ip, value)
                            self.vnic_template_mode = True
                        elif config_item == 'sriov_qos_policy':
                            LOG.debug('QoS Policy: %s', value[0].strip())
                            self.sriov_qos_policy[dev_ip] = value[0].strip()
                        elif dev_key.lower() == 'ucsm_username':
                            username = value[0].strip()
                        elif dev_key.lower() == 'ucsm_password':
                            password = value[0].strip()
                        ucsm_info = (username, password)
                        self.ucsm_dict[dev_ip] = ucsm_info
                        self.multi_ucsm_mode = True
                if dev_id.lower() == 'sriov_multivlan_trunk':
                    for dev_key, value in parsed_file[parsed_item].items():
                        self._parse_sriov_multivlan_trunk_config(
                            dev_key, value)
Пример #11
0
    def _create_multi_ucsm_dict(self):
        """Creates a dictionary of all UCS Manager data from config."""
        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_cisco_ucsm_ip':
                    ucsm_info = []
                    for dev_key, value in parsed_file[parsed_item].items():
                        ucsm_info.append(value[0])
                    self.ucsm_dict[dev_ip] = ucsm_info
Пример #12
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]
Пример #13
0
def _parse_files(conf_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:
                LOG.warning('IOError failure on %(file)s: %(exc)s',
                            {'file': filename,
                             'exc': '(file missing or permission issue?)'})
                continue
            except Exception as e:
                LOG.warning('Failed to parse file %(file)s: %(exc)s',
                            {'file': filename, 'exc': e})
        return [sections]
Пример #14
0
def get_specific_config(prefix):
    """Retrieve config based on the format [<prefix>:<value>].

    returns: a dict, {<UUID>: {<key1>:<value1>, <key2>:<value2>, ...}}
    """
    conf_dict = {}
    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():
            p_i = parsed_item.lower()
            if p_i.startswith(prefix):
                section_type, uuid = p_i.split(':')
                if section_type == prefix:
                    conf_dict[uuid] = {
                        k: v[0]
                        for (k, v) in parsed_file[parsed_item].items()
                    }
    return conf_dict
Пример #15
0
    def _create_device_dictionary(self):
        """
        Create the device dictionary from the cisco_plugins.ini
        device supported sections. Ex. NEXUS_SWITCH, N1KV.
        """

        global first_device_ip

        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"))

        first_device_ip = None
        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() == 'n1kv':
                    for dev_key, value in parsed_file[parsed_item].items():
                        if dev_ip and not first_device_ip:
                            first_device_ip = dev_ip
                        device_dictionary[dev_id, dev_ip, dev_key] = value[0]
Пример #16
0
def get_config():
    CONF = cfg.CONF
    multi_parser = cfg.MultiConfigParser()
    multi_parser.read(CONF.config_file)

    return multi_parser.parsed