4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
16 from cmframework.apis import cmuserconfig
17 from cmframework.apis import cmerror
18 from cmdatahandlers.api import configerror
19 from cmdatahandlers.network_profiles.config import config as net_prof_config
22 This plugin is used to handle REC specific network profiles configs. Currently
23 its sole purpuse is to set default type for any provider networks.
27 class recnetworkprofileshandler(cmuserconfig.CMUserConfigPlugin):
28 defaul_sriov_net_type = 'caas'
29 defaul_provider_interface_type = 'caas'
32 super(recnetworkprofileshandler, self).__init__()
34 def handle(self, confman):
36 self._set_default_type_for_provider_networks(confman)
37 except configerror.ConfigError as exp:
38 raise cmerror.CMError(str(exp))
40 def _set_default_type_for_provider_networks(self, confman):
41 netprofconf = confman.get_network_profiles_config_handler()
42 network_profiles = netprofconf.get_network_profiles()
43 for profile in network_profiles:
45 self._set_default_provider_network_type(netprofconf, profile)
46 self._set_default_sriov_provider_network_type(netprofconf, profile)
47 except (net_prof_config.MissingProviderNetworkInterfaces, net_prof_config.MissingSriovProviderNetworks):
50 def _set_default_provider_network_type(self, netprofconf, profile):
51 for interface in netprofconf.get_profile_provider_network_interfaces(profile):
53 netprofconf.get_profile_provider_network_interface_type(
55 except net_prof_config.MissingProviderNetworkInterfaceType:
56 netprofconf.set_profile_provider_network_interface_type(
57 profile, interface, self.defaul_provider_interface_type)
59 def _set_default_sriov_provider_network_type(self, netprofconf, profile):
60 for sriov_net in netprofconf.get_profile_sriov_provider_networks(profile):
61 if not netprofconf.get_profile_sriov_provider_network_type(
63 netprofconf.set_profile_sriov_provider_network_type(
64 profile, sriov_net, self.defaul_sriov_net_type)