From 04ffd0a9c00d4b58fb5e82825a4c7cdec5b42467 Mon Sep 17 00:00:00 2001 From: Krisztian Lengyel Date: Fri, 17 May 2019 16:59:59 -0400 Subject: [PATCH] Add CaaS related network type queries Change-Id: Iee3f4bf2d7bf45c92b0beb1c2ed63c4385dfe209 Signed-off-by: Krisztian Lengyel --- .../src/cmdatahandlers/network_profiles/config.py | 216 +++++++++++++++++++-- .../src/cmframework/utils/cmansibleinventory.py | 2 +- userconfigtemplate/user_config.yaml | 16 +- 3 files changed, 212 insertions(+), 22 deletions(-) diff --git a/cmdatahandlers/src/cmdatahandlers/network_profiles/config.py b/cmdatahandlers/src/cmdatahandlers/network_profiles/config.py index a773c57..e6d193a 100644 --- a/cmdatahandlers/src/cmdatahandlers/network_profiles/config.py +++ b/cmdatahandlers/src/cmdatahandlers/network_profiles/config.py @@ -16,6 +16,7 @@ from cmdatahandlers.api import configerror from cmdatahandlers.api import config from cmdatahandlers.api import utils + class Config(config.Config): def __init__(self, confman): super(Config, self).__init__(confman) @@ -46,10 +47,12 @@ class Config(config.Config): utils.validate_list_items_unique(bondinginterfaces) for bond in bondinginterfaces: - bondedinterfaces = self.get_profile_bonded_interfaces(profile, bond) + bondedinterfaces = self.get_profile_bonded_interfaces( + profile, bond) utils.validate_list_items_unique(bondedinterfaces) if len(bondedinterfaces) < 2: - raise configerror.ConfigError('Number of bonded interfaces should be at least 2 in %s' % bond) + raise configerror.ConfigError( + 'Number of bonded interfaces should be at least 2 in %s' % bond) mappedinterfaces = self.get_profile_network_mapped_interfaces(profile) @@ -58,11 +61,13 @@ class Config(config.Config): netconf = self.confman.get_networking_config_handler() validnetworks = netconf.get_networks() for interface in mappedinterfaces: - networks = self.get_profile_interface_mapped_networks(profile, interface) + networks = self.get_profile_interface_mapped_networks( + profile, interface) utils.validate_list_items_unique(networks) for network in networks: if network not in validnetworks: - raise configerror.ConfigError('Network %s is not valid' % network) + raise configerror.ConfigError( + 'Network %s is not valid' % network) def is_valid_profile(self, profile): """ @@ -111,7 +116,9 @@ class Config(config.Config): self.is_valid_profile(profile) if 'linux_bonding_options' not in self.config[self.ROOT][profile]: - raise configerror.ConfigError('profile %s has no linux bonding options' % profile) + raise configerror.ConfigError( + 'profile %s has no linux bonding options' % + profile) return self.config[self.ROOT][profile]['linux_bonding_options'] @@ -131,7 +138,9 @@ class Config(config.Config): self.is_valid_profile(profile) if 'bonding_interfaces' not in self.config[self.ROOT][profile]: - raise configerror.ConfigError('Profile %s has no bonding interfaces' % profile) + raise configerror.ConfigError( + 'Profile %s has no bonding interfaces' % + profile) return self.config[self.ROOT][profile]['bonding_interfaces'].keys() @@ -152,7 +161,9 @@ class Config(config.Config): self.validate_root() bondinterfaces = self.get_profile_bonding_interfaces(profile) if bond not in bondinterfaces: - raise configerror.ConfigError('Invalid bond interface name %s in profile %s' % (bond, profile)) + raise configerror.ConfigError( + 'Invalid bond interface name %s in profile %s' % + (bond, profile)) return self.config[self.ROOT][profile]['bonding_interfaces'][bond] @@ -172,7 +183,9 @@ class Config(config.Config): self.is_valid_profile(profile) if 'interface_net_mapping' not in self.config[self.ROOT][profile]: - raise configerror.ConfigError('Profile %s has now interface to network mapping' % profile) + raise configerror.ConfigError( + 'Profile %s has now interface to network mapping' % + profile) return self.config[self.ROOT][profile]['interface_net_mapping'].keys() @@ -193,7 +206,9 @@ class Config(config.Config): self.is_valid_profile(profile) mappedinterfaces = self.get_profile_network_mapped_interfaces(profile) if interface not in mappedinterfaces: - raise configerror.ConfigError('Interface %s is not valid for profile %s' % (interface, profile)) + raise configerror.ConfigError( + 'Interface %s is not valid for profile %s' % + (interface, profile)) return self.config[self.ROOT][profile]['interface_net_mapping'][interface] @@ -212,15 +227,20 @@ class Config(config.Config): """ self.is_valid_profile(profile) if 'provider_network_interfaces' not in self.config[self.ROOT][profile]: - raise configerror.ConfigError('Profile %s has no provider network interfaces' % profile) + raise configerror.ConfigError( + 'Profile %s has no provider network interfaces' % + profile) - return sorted(self.config[self.ROOT][profile]['provider_network_interfaces'].keys()) + return sorted(self.config[self.ROOT][profile] + ['provider_network_interfaces'].keys()) def _get_profile_provider_network_interface_dict(self, profile, interface): self.is_valid_profile(profile) interfaces = self.get_profile_provider_network_interfaces(profile) if interface not in interfaces: - raise configerror.ConfigError('Profile %s has no provider interface with name %s' % (profile, interface)) + raise configerror.ConfigError( + 'Profile %s has no provider interface with name %s' % + (profile, interface)) return self.config[self.ROOT][profile]['provider_network_interfaces'][interface] @@ -238,12 +258,52 @@ class Config(config.Config): Raises: ConfigError in-case of an error """ - iface_dict = self._get_profile_provider_network_interface_dict(profile, interface) + iface_dict = self._get_profile_provider_network_interface_dict( + profile, interface) if 'type' not in iface_dict: - raise configerror.ConfigError('Provider network interface %s in profile %s does not have a type!' % (interface, profile)) + raise configerror.ConfigError( + 'Provider network interface %s in profile %s does not have a type!' % + (interface, profile)) return iface_dict['type'] + def set_profile_provider_network_interface_type(self, profile, interface, type): + """ + Set provider network type + + Arguments: + The profile name + The interface name + The type of provider network + + Raises: + ConfigError in-case of an error + """ + iface_dict = self._get_profile_provider_network_interface_dict( + profile, interface) + if not isinstance(type, basestring): + raise configerror.ConfigError( + 'Profile %s has invalid provider network type for interface %s: %s' % + (profile, interface, type)) + + iface_dict['type'] = type + + def is_provider_network_type_caas(self, profile, interface): + """ + Is provider network type caas + + Arguments: + The profile name + The interface name + + Returns: + True if provider network is for CaaS + + Raises: + ConfigError in-case of an error + """ + return self.get_profile_provider_network_interface_type(profile, interface) == 'caas' + def get_profile_provider_interface_networks(self, profile, interface): """ Get provider networks for the interface @@ -258,9 +318,12 @@ class Config(config.Config): Raises: ConfigError in-case of an error """ - iface_dict = self._get_profile_provider_network_interface_dict(profile, interface) + iface_dict = self._get_profile_provider_network_interface_dict( + profile, interface) if 'provider_networks' not in iface_dict: - raise configerror.ConfigError('Profile %s has no provider networks for interface %s' % (profile, interface)) + raise configerror.ConfigError( + 'Profile %s has no provider networks for interface %s' % + (profile, interface)) return iface_dict['provider_networks'] @@ -279,7 +342,9 @@ class Config(config.Config): """ self.is_valid_profile(profile) if 'sriov_provider_networks' not in self.config[self.ROOT][profile]: - raise configerror.ConfigError('Profile %s has no SR-IOV provider networks' % profile) + raise configerror.ConfigError( + 'Profile %s has no SR-IOV provider networks' % + profile) return self.config[self.ROOT][profile]['sriov_provider_networks'].keys() @@ -297,10 +362,121 @@ class Config(config.Config): Raises: ConfigError in-case of an error """ - if network not in self.get_profile_sriov_provider_networks(profile): - raise configerror.ConfigError('Profile %s has no SR-IOV provider network %s' % (profile, network)) + self._validate_network_is_sriov_provider_network(profile, network) if 'interfaces' not in self.config[self.ROOT][profile]['sriov_provider_networks'][network]: - raise configerror.ConfigError('Profile %s has no SR-IOV provider network interfaces for the network %s' % (profile, network)) + raise configerror.ConfigError( + 'Profile %s has no SR-IOV provider network interfaces for the network %s' % + (profile, network)) return self.config[self.ROOT][profile]['sriov_provider_networks'][network]['interfaces'] + + def set_profile_sriov_provider_network_type(self, profile, network, type): + """ + Set SR-IOV provider network type + + Arguments: + The profile name + The SR-IOV network name + The type of SR-IOV network + + Raises: + ConfigError in-case of an error + """ + self._validate_network_is_sriov_provider_network(profile, network) + + if not isinstance(type, basestring): + raise configerror.ConfigError( + 'Profile %s has invalid SR-IOV provider network type for the network %s: %s' % + (profile, network, type)) + + self.config[self.ROOT][profile]['sriov_provider_networks'][network]['type'] = type + + def is_sriov_network_trusted(self, profile, network): + """ + Is SR-IOV provider network trusted (VF parameter) + + Arguments: + The profile name + The SR-IOV network name + + Returns: + True if VFs should be configured as trusted in this network + + Raises: + ConfigError in-case of an error + """ + self._validate_network_is_sriov_provider_network(profile, network) + + return self.config[self.ROOT][profile]['sriov_provider_networks'][network].get('trusted') is True + + def is_sriov_network_type_caas(self, profile, network): + """ + Is SR-IOV network type caas + + Arguments: + The profile name + The SR-IOV network name + + Returns: + True if SR-IOV network is for CaaS + + Raises: + ConfigError in-case of an error + """ + self._validate_network_is_sriov_provider_network(profile, network) + + return self.config[self.ROOT][profile]['sriov_provider_networks'][network].get('type') == 'caas' + + def _validate_network_is_sriov_provider_network(self, profile, network): + if network not in self.get_profile_sriov_provider_networks(profile): + raise configerror.ConfigError( + 'Profile %s has no SR-IOV provider network %s' % + (profile, network)) + + def get_profile(self, name): + """ + Get the network profile data + + Arguments: + The profile name + + Returns: + A dict of network profile data + + """ + self.is_valid_profile(name) + return self.config[self.ROOT][name] + + def dump(self): + """ Dump all network profiles data. """ + + self.validate_root() + return self.config[self.ROOT] + + def add_profile(self, name, profile): + """ Add network profile. + + Parameters + ---------- + name : str, profile name. + profile : dict, profile data + + """ + if name in self.config[self.ROOT]: + raise configerror.ConfigError('Profile %s already exists' % name) + + data = {} + data[name] = profile + self.config[self.ROOT].update(data) + + def delete_profile(self, name): + """ Delete network profile. + + Parameters + ---------- + name : str, profile name. + + """ + self.is_valid_profile(name) + self.config[self.ROOT].pop(name) diff --git a/cmframework/src/cmframework/utils/cmansibleinventory.py b/cmframework/src/cmframework/utils/cmansibleinventory.py index 13db5f2..4bd9824 100644 --- a/cmframework/src/cmframework/utils/cmansibleinventory.py +++ b/cmframework/src/cmframework/utils/cmansibleinventory.py @@ -232,7 +232,7 @@ class AnsibleInventory(object): plugins = self.pluginloader.get_plugin_instances(self.confman, inventory, ownhost) if self._is_setup(): inventory.clear() - for name, plugin in plugins.iteritems(): + for name, plugin in sorted(plugins.iteritems()): if self._is_bootstrapping(): plugin.handle_bootstrapping() elif self._is_provisioning(): diff --git a/userconfigtemplate/user_config.yaml b/userconfigtemplate/user_config.yaml index e75ea7c..6f8ce3a 100644 --- a/userconfigtemplate/user_config.yaml +++ b/userconfigtemplate/user_config.yaml @@ -29,7 +29,7 @@ ### - Minor changes in template (e.g. new optional attributes or ### changes in possible values, value ranges or default values) ### - Backwards compatible -version: 2.0.1 +version: 2.0.2 ### Cloud name can consist of lower case letters, digits and dash (-). ### Name must start and end with a letter or a digit. @@ -316,6 +316,15 @@ network_profiles: ### Provider network physical interface. ### Either Ethernet or bonding interface. #: + ### Optional provider network type. + ### + ### Supported types: + ### caas: + ### Containers as a Service (CaaS) provider network + ### Notes: + ### CaaS bond interfaces are configured as a Linux bond interfaces. + #type: + ### Provider networks on this interface. ### Provider networks must be defined also in the networking: ### provider_networks: configuration. @@ -355,6 +364,11 @@ network_profiles: ### details. ### Default: false #trusted: [true|false] + + ### Optional provider network type + ### - caas: configure as CaaS SR-IOV cluster network + ### Default: caas + #type: ### Use above structure for all the SR-IOV provider networks in ### this profile # -- 2.16.6