1173d8a9aa21dfcc6405bcbd857e13f8c5f857d0
[openstack-build/neutron-build.git] / neutron / plugins / ml2 / drivers / mech_sriov / agent / common / config.py
1 # Copyright 2014 Mellanox Technologies, Ltd
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #    http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12 # implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16
17 from oslo_config import cfg
18
19 from neutron._i18n import _
20 from neutron.agent.common import config
21
22
23 def parse_exclude_devices(exclude_list):
24     """Parse Exclude devices list
25
26     parses excluded device list in the form:
27     dev_name:pci_dev_1;pci_dev_2
28     @param exclude list: list of string pairs in "key:value" format
29                         the key part represents the network device name
30                         the value part is a list of PCI slots separated by ";"
31     """
32     exclude_mapping = {}
33     for dev_mapping in exclude_list:
34         try:
35             dev_name, exclude_devices = dev_mapping.split(":", 1)
36         except ValueError:
37             raise ValueError(_("Invalid mapping: '%s'") % dev_mapping)
38         dev_name = dev_name.strip()
39         if not dev_name:
40             raise ValueError(_("Missing key in mapping: '%s'") % dev_mapping)
41         if dev_name in exclude_mapping:
42             raise ValueError(_("Device %(dev_name)s in mapping: %(mapping)s "
43                                "not unique") % {'dev_name': dev_name,
44                                                 'mapping': dev_mapping})
45         exclude_devices_list = exclude_devices.split(";")
46         exclude_devices_set = set()
47         for dev in exclude_devices_list:
48             dev = dev.strip()
49             if dev:
50                 exclude_devices_set.add(dev)
51         exclude_mapping[dev_name] = exclude_devices_set
52     return exclude_mapping
53
54 DEFAULT_DEVICE_MAPPINGS = []
55 DEFAULT_EXCLUDE_DEVICES = []
56
57 agent_opts = [
58     cfg.IntOpt('polling_interval', default=2,
59                help=_("The number of seconds the agent will wait between "
60                       "polling for local device changes.")),
61 ]
62
63 sriov_nic_opts = [
64     cfg.ListOpt('physical_device_mappings',
65                 default=DEFAULT_DEVICE_MAPPINGS,
66                 help=_("Comma-separated list of "
67                        "<physical_network>:<network_device> tuples mapping "
68                        "physical network names to the agent's node-specific "
69                        "physical network device interfaces of SR-IOV physical "
70                        "function to be used for VLAN networks. All physical "
71                        "networks listed in network_vlan_ranges on the server "
72                        "should have mappings to appropriate interfaces on "
73                        "each agent.")),
74     cfg.ListOpt('exclude_devices',
75                 default=DEFAULT_EXCLUDE_DEVICES,
76                 help=_("Comma-separated list of "
77                        "<network_device>:<vfs_to_exclude> tuples, mapping "
78                        "network_device to the agent's node-specific list of "
79                        "virtual functions that should not be used for virtual "
80                        "networking. vfs_to_exclude is a semicolon-separated "
81                        "list of virtual functions to exclude from "
82                        "network_device. The network_device in the mapping "
83                        "should appear in the physical_device_mappings "
84                        "list.")),
85 ]
86
87
88 cfg.CONF.register_opts(agent_opts, 'AGENT')
89 cfg.CONF.register_opts(sriov_nic_opts, 'SRIOV_NIC')
90 config.register_agent_state_opts_helper(cfg.CONF)