neutron/neutron/plugins/ml2/drivers/cisco/apic/config.py

85 lines
3.4 KiB
Python

# Copyright (c) 2014 OpenStack Foundation
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
# @author: Arvind Somya (asomya@cisco.com), Cisco Systems Inc.
from oslo.config import cfg
apic_opts = [
cfg.ListOpt('apic_hosts',
default=[],
help=_("An ordered list of host names or IP addresses of "
"the APIC controller(s).")),
cfg.StrOpt('apic_username',
help=_("Username for the APIC controller")),
cfg.StrOpt('apic_password',
help=_("Password for the APIC controller"), secret=True),
cfg.BoolOpt('apic_use_ssl', default=True,
help=_("Use SSL to connect to the APIC controller")),
cfg.StrOpt('apic_vmm_provider', default='VMware',
help=_("Name for the VMM domain provider")),
cfg.StrOpt('apic_vmm_domain', default='openstack',
help=_("Name for the VMM domain to be created for Openstack")),
cfg.StrOpt('apic_vlan_ns_name', default='openstack_ns',
help=_("Name for the vlan namespace to be used for openstack")),
cfg.StrOpt('apic_vlan_range', default='2:4093',
help=_("Range of VLAN's to be used for Openstack")),
cfg.StrOpt('apic_node_profile', default='openstack_profile',
help=_("Name of the node profile to be created")),
cfg.StrOpt('apic_entity_profile', default='openstack_entity',
help=_("Name of the entity profile to be created")),
cfg.StrOpt('apic_function_profile', default='openstack_function',
help=_("Name of the function profile to be created")),
cfg.BoolOpt('apic_clear_node_profiles', default=False,
help=_("Clear the node profiles on the APIC at startup "
"(mainly used for testing)")),
]
cfg.CONF.register_opts(apic_opts, "ml2_cisco_apic")
def get_switch_and_port_for_host(host_id):
for switch, connected in _switch_dict.items():
for port, hosts in connected.items():
if host_id in hosts:
return switch, port
_switch_dict = {}
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