def get_default_attributes(cls, instance): """Get default attributes for interface. :param instance: NodeNICInterface instance :type instance: NodeNICInterface model :returns: dict -- Dict object of NIC attributes """ attributes = cls._get_default_attributes(instance) attributes = utils.dict_merge( attributes, PluginManager.get_nic_attributes(instance)) attributes = utils.dict_merge( attributes, PluginManager.get_nic_default_attributes(instance.node.cluster)) return attributes
def get_common_attrs(self, cluster): """Cluster attributes.""" attrs = objects.Attributes.merged_attrs_values(cluster.attributes) release = self.current_release(cluster) attrs['deployment_mode'] = cluster.mode attrs['deployment_id'] = cluster.id attrs['openstack_version_prev'] = getattr( self.previous_release(cluster), 'version', None) attrs['openstack_version'] = release.version attrs['fuel_version'] = cluster.fuel_version attrs.update( objects.Release.get_orchestrator_data_dict(release) ) attrs['nodes'] = self.node_list(get_nodes_not_for_deletion(cluster)) for node in attrs['nodes']: if node['role'] in 'cinder': attrs['use_cinder'] = True self.set_storage_parameters(cluster, attrs) self.set_primary_mongo(attrs['nodes']) attrs = dict_merge( attrs, self.get_net_provider_serializer(cluster).get_common_attrs(cluster, attrs)) return attrs
def create_attributes(cls, instance, editable_attributes=None): """Create attributes for Cluster instance, generate their values (see :func:`Attributes.generate_fields`) :param instance: Cluster instance :param editable_attributes: key-value dictionary represents editable attributes that will be merged with default editable attributes :returns: None """ merged_editable_attributes = \ cls.get_default_editable_attributes(instance) if editable_attributes: merged_editable_attributes = dict_merge( merged_editable_attributes, editable_attributes) attributes = Attributes.create( { "editable": merged_editable_attributes, "generated": instance.release.attributes_metadata.get( "generated" ), "cluster_id": instance.id } ) Attributes.generate_fields(attributes) db().flush() return attributes
def get_all_enabled_attributes_by_bond(cls, bond): """Returns plugin enabled attributes for specific Bond. :param interface: Bond instance :type interface: models.node.NodeBondInterface :returns: dict -- Dict object with plugin Bond attributes """ bond_attributes = {} bond_plugin_attributes_query = db().query( cls.model.id, models.Plugin.name, models.Plugin.title, cls.model.attributes).join( models.ClusterPlugin, models.Plugin).filter(cls.model.bond_id == bond.id).filter( models.ClusterPlugin.enabled.is_(True)) for bond_plugin_id, name, title, attributes \ in bond_plugin_attributes_query: bond_attributes[name] = { 'metadata': { 'label': title, 'bond_plugin_id': bond_plugin_id, 'class': 'plugin' } } # TODO(apopovych): resolve conflicts of same attribute names # for different plugins bond_attributes[name] = nailgun_utils.dict_merge( bond_attributes[name], attributes) return bond_attributes
def get_common_attrs(self, cluster): """Cluster attributes.""" attrs = objects.Attributes.merged_attrs_values(cluster.attributes) release = self.current_release(cluster) attrs['deployment_mode'] = cluster.mode attrs['deployment_id'] = cluster.id attrs['openstack_version_prev'] = getattr( self.previous_release(cluster), 'version', None) attrs['openstack_version'] = release.version attrs['fuel_version'] = cluster.fuel_version attrs['nodes'] = self.node_list( objects.Cluster.get_nodes_not_for_deletion(cluster)) # Adding params to workloads_collector if 'workloads_collector' not in attrs: attrs['workloads_collector'] = {} attrs['workloads_collector']['create_user'] = \ objects.MasterNodeSettings.must_send_stats() username = attrs['workloads_collector'].pop('user', None) attrs['workloads_collector']['username'] = username for node in attrs['nodes']: if node['role'] in 'cinder': attrs['use_cinder'] = True self.set_storage_parameters(cluster, attrs) net_serializer = self.get_net_provider_serializer(cluster) net_common_attrs = net_serializer.get_common_attrs(cluster, attrs) attrs = utils.dict_merge(attrs, net_common_attrs) return attrs
def serialize_generated(self, cluster, nodes): nodes = self.serialize_nodes(nodes) common_attrs = self.get_common_attrs(cluster) self.set_deployment_priorities(nodes) self.set_critical_nodes(nodes) return [utils.dict_merge(node, common_attrs) for node in nodes]
def get_common_attrs(self, cluster): """Cluster attributes.""" # tests call this method directly. # and we need this workaround to avoid refactoring a lot of tests. self._ensure_initialized_for(cluster) attrs = objects.Cluster.get_attributes(cluster) attrs = objects.Attributes.merged_attrs_values(attrs) attrs['deployment_mode'] = cluster.mode attrs['deployment_id'] = cluster.id attrs['openstack_version'] = cluster.release.version attrs['fuel_version'] = cluster.fuel_version attrs['nodes'] = self.node_list(self.all_nodes) # Adding params to workloads_collector if 'workloads_collector' not in attrs: attrs['workloads_collector'] = {} attrs['workloads_collector']['create_user'] = \ objects.MasterNodeSettings.must_send_stats() username = attrs['workloads_collector'].pop('user', None) attrs['workloads_collector']['username'] = username if self.role_resolver.resolve(['cinder']): attrs['use_cinder'] = True net_serializer = self.get_net_provider_serializer(cluster) net_common_attrs = net_serializer.get_common_attrs(cluster, attrs) attrs = utils.dict_merge(attrs, net_common_attrs) self.inject_list_of_plugins(attrs, cluster) return attrs
def get_common_attrs(cls, cluster): """Cluster attributes.""" attrs = objects.Attributes.merged_attrs_values( cluster.attributes ) release = objects.Release.get_by_uid(cluster.pending_release_id) \ if cluster.status == consts.CLUSTER_STATUSES.update \ else cluster.release attrs['deployment_mode'] = cluster.mode attrs['deployment_id'] = cluster.id attrs['openstack_version'] = release.version attrs['fuel_version'] = cluster.fuel_version attrs.update( objects.Release.get_orchestrator_data_dict(release) ) attrs['nodes'] = cls.node_list(get_nodes_not_for_deletion(cluster)) for node in attrs['nodes']: if node['role'] in 'cinder': attrs['use_cinder'] = True cls.set_storage_parameters(cluster, attrs) cls.set_primary_mongo(attrs['nodes']) attrs = dict_merge( attrs, cls.get_net_provider_serializer(cluster).get_common_attrs(cluster, attrs)) return attrs
def get_common_attrs(self, cluster): """Cluster attributes.""" attrs = objects.Attributes.merged_attrs_values(cluster.attributes) release = self.current_release(cluster) attrs["deployment_mode"] = cluster.mode attrs["deployment_id"] = cluster.id attrs["openstack_version_prev"] = getattr(self.previous_release(cluster), "version", None) attrs["openstack_version"] = release.version attrs["fuel_version"] = cluster.fuel_version attrs["nodes"] = self.node_list(objects.Cluster.get_nodes_not_for_deletion(cluster)) # Adding params to workloads_collector if "workloads_collector" not in attrs: attrs["workloads_collector"] = {} attrs["workloads_collector"]["create_user"] = objects.MasterNodeSettings.must_send_stats() username = attrs["workloads_collector"].pop("user", None) attrs["workloads_collector"]["username"] = username for node in attrs["nodes"]: if node["role"] in "cinder": attrs["use_cinder"] = True self.set_storage_parameters(cluster, attrs) net_serializer = self.get_net_provider_serializer(cluster) net_common_attrs = net_serializer.get_common_attrs(cluster, attrs) attrs = utils.dict_merge(attrs, net_common_attrs) return attrs
def get_common_attrs(self, cluster): """Cluster attributes.""" attrs = objects.Attributes.merged_attrs_values(cluster.attributes) release = self.current_release(cluster) attrs['deployment_mode'] = cluster.mode attrs['deployment_id'] = cluster.id attrs['openstack_version_prev'] = getattr( self.previous_release(cluster), 'version', None) attrs['openstack_version'] = release.version attrs['fuel_version'] = cluster.fuel_version attrs['nodes'] = self.node_list( objects.Cluster.get_nodes_not_for_deletion(cluster)) # Adding params to workloads_collector if 'workloads_collector' not in attrs: attrs['workloads_collector'] = {} attrs['workloads_collector']['create_user'] = \ objects.MasterNodeSettings.must_send_stats() username = attrs['workloads_collector'].pop('user', None) attrs['workloads_collector']['username'] = username for node in attrs['nodes']: if node['role'] in 'cinder': attrs['use_cinder'] = True self.set_storage_parameters(cluster, attrs) net_serializer = self.get_net_provider_serializer(cluster) net_common_attrs = net_serializer.get_common_attrs(cluster, attrs) attrs = utils.dict_merge(attrs, net_common_attrs) self.inject_list_of_plugins(attrs, cluster) return attrs
def patch_attributes(cls, instance, data): PluginManager.process_cluster_attributes(instance, data['editable']) instance.attributes.editable = dict_merge( instance.attributes.editable, data['editable']) cls.add_pending_changes(instance, "attributes") cls.get_network_manager(instance).update_restricted_networks(instance) db().flush()
def get_all_enabled_attributes_by_interface(cls, interface): """Returns plugin enabled attributes for specific NIC. :param interface: Interface instance :type interface: models.node.NodeNICInterface :returns: dict -- Dict object with plugin NIC attributes """ nic_attributes = {} nic_plugin_attributes_query = db().query( cls.model.id, models.Plugin.name, models.Plugin.title, cls.model.attributes).join( models.ClusterPlugin, models.Plugin).filter( cls.model.interface_id == interface.id).filter( models.ClusterPlugin.enabled.is_(True)).all() for nic_plugin_id, name, title, attributes \ in nic_plugin_attributes_query: nic_attributes[name] = { 'metadata': { 'label': title, 'nic_plugin_id': nic_plugin_id, 'class': 'plugin' } } # TODO(apopovych): resolve conflicts of same attribute names # for different plugins nic_attributes[name] = nailgun_utils.dict_merge( nic_attributes[name], attributes) return nic_attributes
def create(cls, data): """Create Cluster instance with specified parameters in DB. This includes: * creating Cluster attributes and generating default values \ (see :func:`create_attributes`) * creating NetworkGroups for Cluster * adding default pending changes (see :func:`add_pending_changes`) * if "nodes" are specified in data then they are added to Cluster \ (see :func:`update_nodes`) :param data: dictionary of key-value pairs as object fields :returns: Cluster instance """ # TODO(enchantner): fix this temporary hack in clients if "release_id" not in data: release_id = data.pop("release", None) data["release_id"] = release_id # remove read-only attribute data.pop("is_locked", None) assign_nodes = data.pop("nodes", []) enabled_editable_attributes = None if 'components' in data: enabled_core_attributes = cls.get_cluster_attributes_by_components( data['components'], data["release_id"]) data = dict_merge(data, enabled_core_attributes['cluster']) enabled_editable_attributes = enabled_core_attributes['editable'] data["fuel_version"] = settings.VERSION["release"] cluster = super(Cluster, cls).create(data) cls.create_default_group(cluster) cls.create_attributes(cluster, enabled_editable_attributes) cls.create_vmware_attributes(cluster) cls.create_default_extensions(cluster) try: cls.get_network_manager(cluster).\ create_network_groups_and_config(cluster, data) cls.add_pending_changes(cluster, consts.CLUSTER_CHANGES.attributes) cls.add_pending_changes(cluster, consts.CLUSTER_CHANGES.networks) cls.add_pending_changes(cluster, consts.CLUSTER_CHANGES.vmware_attributes) if assign_nodes: cls.update_nodes(cluster, assign_nodes) except (errors.OutOfVLANs, errors.OutOfIPs, errors.NoSuitableCIDR) as exc: raise errors.CannotCreate(exc.message) db().flush() ClusterPlugins.add_compatible_plugins(cluster) PluginManager.enable_plugins_by_components(cluster) return cluster
def _get_network_role_metadata(self, **kwargs): network_role = { "id": "test_network_role", "default_mapping": consts.NETWORKS.public, "properties": {"subnet": True, "gateway": False, "vip": [{"name": "test_vip_a"}]}, } return dict_merge(network_role, kwargs)
def get_default_attributes(cls, instance): """Get default attributes for interface. :param instance: NodeNICInterface instance :type instance: NodeNICInterface model :returns: dict -- Dict object of NIC attributes """ attributes = cls._get_default_attributes(instance) attributes = utils.dict_merge( attributes, PluginManager.get_nic_attributes(instance)) attributes = utils.dict_merge( attributes, PluginManager.get_nic_default_attributes( instance.node.cluster)) return attributes
def get_updated_editable_attributes(cls, instance, data): """Same as get_editable_attributes but also merges given data. :param instance: Cluster object :param data: dict :return: dict """ return {"editable": dict_merge(cls.get_editable_attributes(instance)["editable"], data.get("editable", {}))}
def test_bond_slaves_not_available_dpdk(self): self._create_bond_data() nic_3 = self.node.nic_interfaces[2] meta = {'dpdk': {'available': False}, 'pci_id': ''} objects.NIC.update(nic_3, {'meta': utils.dict_merge(nic_3.meta, meta)}) self.assertRaisesRegexp(errors.InvalidData, "DPDK is not available .*", self.validator, self.data)
def merged_attrs(cls, instance): """Generates merged dict which includes generated Cluster attributes recursively updated by new values from editable attributes. :param instance: Attributes instance :returns: dict of merged attributes """ return dict_merge(instance.generated, instance.editable)
def POST(self, cluster_id): """Create a clone of the cluster. Creates a new cluster with specified name and release_id. The new cluster are created with parameters that are copied from the cluster with cluster_id. The values of the generated and editable attributes are just copied from one to the other. :param cluster_id: ID of the cluster to copy parameters from it :returns: JSON representation of the created cluster :http: * 200 (OK) * 404 (cluster or release did not found in db) """ data = self.checked_data() orig_cluster = self.get_object_or_404(self.single, cluster_id) release = self.get_object_or_404(objects.Release, data["release_id"]) # TODO(ikharin): Here should be more elegant code that verifies # release versions of the original cluster and # the future cluster. The upgrade process itself # is meaningful only to upgrade the cluster # between the major releases. # TODO(ikharin): This method should properly handle the upgrade # from one major release to another but now it's # hardcoded to perform the upgrade from 5.1.1 to # 6.1 release. data = { "name": data["name"], "mode": orig_cluster.mode, "status": consts.CLUSTER_STATUSES.new, "net_provider": orig_cluster.net_provider, "grouping": consts.CLUSTER_GROUPING.roles, "release_id": release.id, } if orig_cluster.net_provider == consts.CLUSTER_NET_PROVIDERS.neutron: data["net_segment_type"] = \ orig_cluster.network_config.segmentation_type data["net_l23_provider"] = \ orig_cluster.network_config.net_l23_provider new_cluster = self.single.create(data) new_cluster.attributes.generated = utils.dict_merge( new_cluster.attributes.generated, orig_cluster.attributes.generated) new_cluster.attributes.editable = self.merge_attributes( orig_cluster.attributes.editable, new_cluster.attributes.editable) nets_serializer = self.network_serializers[orig_cluster.net_provider] nets = self.merge_nets( nets_serializer.serialize_for_cluster(orig_cluster), nets_serializer.serialize_for_cluster(new_cluster)) net_manager = self.single.get_network_manager(instance=new_cluster) net_manager.update(new_cluster, nets) self.copy_vips(orig_cluster, new_cluster) net_manager.assign_vips_for_net_groups(new_cluster) logger.debug("The cluster %s was created as a clone of the cluster %s", new_cluster.id, orig_cluster.id) return self.single.to_json(new_cluster)
def serialize(cls, cluster, nodes): """Method generates facts which through an orchestrator passes to puppet """ nodes = cls.serialize_nodes(nodes) common_attrs = cls.get_common_attrs(cluster) cls.set_deployment_priorities(nodes) return [dict_merge(node, common_attrs) for node in nodes]
def get_updated_editable_attributes(cls, instance, data): """Same as get_editable_attributes but also merges given data. :param instance: Cluster object :param data: dict :returns: dict """ return {'editable': dict_merge( cls.get_editable_attributes(instance), data.get('editable', {}) )}
def test_bond_slaves_not_available_dpdk(self): self._create_bond_data() nic_3 = self.node.nic_interfaces[2] dpdk_settings = {'dpdk': {'available': False}, 'pci_id': ''} objects.NIC.update(nic_3, {'interface_properties': utils.dict_merge( nic_3.interface_properties, dpdk_settings)}) self.assertRaisesRegexp( errors.InvalidData, "DPDK is not available .*", self.validator, self.data)
def validate(cls, data, node, cluster): data = cls.validate_json(data) full_data = utils.dict_merge(objects.Node.get_attributes(node), data) models = objects.Cluster.get_restrictions_models(cluster) attrs = cls.validate_attributes(full_data, models=models) cls._validate_cpu_pinning(node, attrs) cls._validate_hugepages(node, attrs) return data
def get_attributes(cls, instance): """Get native and plugin attributes for bond. :param instance: NodeBondInterface instance :type instance: NodeBondInterface model :returns: dict -- Object of bond attributes """ attributes = copy.deepcopy(instance.attributes) attributes = utils.dict_merge( attributes, PluginManager.get_bond_attributes(instance)) return attributes
def get_attributes(cls, instance): """Get all attributes for interface. :param instance: NodeNICInterface instance :type instance: NodeNICInterface model :returns: dict -- Object of interface attributes """ attributes = copy.deepcopy(instance.attributes) attributes = utils.dict_merge( attributes, PluginManager.get_nic_attributes(instance)) return attributes
def copy_attributes(cls, orig_cluster, new_cluster): # TODO(akscram): Attributes should be copied including # borderline cases when some parameters are # renamed or moved into plugins. Also, we should # to keep special steps in copying of parameters # that know how to translate parameters from one # version to another. A set of this kind of steps # should define an upgrade path of a particular # cluster. new_cluster.generated_attrs = utils.dict_merge( new_cluster.generated_attrs, orig_cluster.generated_attrs) new_cluster.editable_attrs = merge_attributes( orig_cluster.editable_attrs, new_cluster.editable_attrs)
def serialize_generated(self, common_attrs, nodes): serialized_nodes = self.serialize_nodes(common_attrs, nodes) nodes_map = {n.uid: n for n in nodes} self.set_deployment_priorities(serialized_nodes) for node_data in serialized_nodes: # the serialized nodes may contain fake nodes like master node # which does not have related db object. it shall be excluded. if node_data['uid'] in nodes_map: extensions.fire_callback_on_node_serialization_for_deployment( nodes_map[node_data['uid']], node_data ) yield utils.dict_merge(common_attrs, node_data)
def get_default_attributes(cls, cluster): """Get native and plugin default attributes for bond. :param cluster: A cluster instance :type cluster: Cluster model :returns: dict -- Object of bond default attributes """ default_attributes = cluster.release.bond_attributes default_attributes = utils.dict_merge( default_attributes, PluginManager.get_bond_default_attributes(cluster)) return default_attributes
def _deployment_info_in_compatible_format(depoyment_info, separate): # FIXME(bgaifullin) need to update fuelclient # uid 'common' because fuelclient expects list of dicts, where # each dict contains field 'uid', which will be used as name of file data = depoyment_info.get('nodes', []) common = depoyment_info.get('common') if common: if separate: data.append(dict(common, uid='common')) else: for i, node_info in enumerate(data): data[i] = utils.dict_merge(common, node_info) return data
def PATCH(self): """Update object :http: * 200 (OK) * 400 (Invalid data) * 404 (Object not present in DB) """ data = self.checked_data(self.validator.validate_update) instance = self.get_one_or_404() instance.update(utils.dict_merge(self.single.serializer.serialize(instance), data)) return self.single.to_json(instance)
def serialize_customized(self, cluster, nodes): for node in nodes: data = {} roles = [] for role_data in node.replaced_deployment_info: if 'role' in role_data: # if replaced_deployment_info consists # of old serialized info, the old info # have serialized data per role roles.append(role_data.pop('role')) data = utils.dict_merge(data, role_data) if roles: data['roles'] = roles yield data
def get_common_attrs(self, cluster): """Cluster attributes.""" attrs={} release = self.current_release(cluster) attrs.update( objects.Release.get_orchestrator_data_dict(release) ) attrs['nodes'] = self.node_list(get_nodes_not_for_deletion(cluster)) role_list=attrs['nodes'] clusterSetting=db().query(ClusterSetting).filter_by(cluster_id=cluster.id).first() if cluster.cluster_type==2: #cloudmaster环境只能安装centos dataSetting=json.loads(clusterSetting.cluster_setting) attrs["cobbler"]={"profile":"centos-x86_64"} attrs['deployment_id'] = cluster.id for node in role_list: if node.get("role")=="clsmaster": attrs['clsmaster']=self.create_cloudmaster_clsmaster(dataSetting["clsmaster"]) if node.get("role")=="clsslave": attrs['clsslave']=self.create_cloudmaster_clsslave(dataSetting["clsslave"]) if node.get("role")=="mysqlcls": attrs['mysqlcls']=self.create_cloudmaster_mysql(dataSetting["mysqlcls"]) if node.get("role")=="nagios": attrs['nagios']=self.create_cloudmaster_nagios(dataSetting["nagios"]) if node.get("role")=="ganglia": attrs['ganglia']=self.create_cloudmaster_ganglia(dataSetting["ganglia"]) if node.get("role")=="dhcpserver": attrs['dhcpserver']=self.create_cloudmaster_dhcpserver(dataSetting["dhcpserver"]) else: attrs.update(objects.Attributes.merged_attrs_values(cluster.attributes)) attrs['deployment_mode'] = cluster.mode attrs['openstack_version_prev'] = getattr( self.previous_release(cluster), 'version', None) attrs['openstack_version'] = release.version attrs['fuel_version'] = cluster.fuel_version for node in attrs['nodes']: if node['role'] in 'cinder': attrs['use_cinder'] = True self.set_storage_parameters(cluster, attrs) self.set_primary_mongo(attrs['nodes']) attrs = dict_merge( attrs, self.get_net_provider_serializer(cluster).get_common_attrs(cluster, attrs)) return attrs
def PATCH(self): """Update object :http: * 200 (OK) * 400 (Invalid data) * 404 (Object not present in DB) """ data = self.checked_data(self.validator.validate_update) instance = self.get_one_or_404() instance.update( utils.dict_merge(self.single.serializer.serialize(instance), data)) return self.single.to_dict(instance)
def update(cls, instance, data): """Update data of native and plugin attributes for interface. :param instance: NodeNICInterface instance :type instance: NodeNICInterface model :param data: Data to update :type data: dict :returns: instance of an object (model) """ attributes = data.pop('attributes', None) if attributes: PluginManager.update_nic_attributes(attributes) instance.attributes = utils.dict_merge( instance.attributes, attributes) return super(NIC, cls).update(instance, data)
def validate(cls, data, node, cluster): data = cls.validate_json(data) full_data = utils.dict_merge(objects.Node.get_attributes(node), data) models = { 'settings': objects.Cluster.get_editable_attributes(cluster), 'cluster': cluster, 'version': settings.VERSION, 'networking_parameters': cluster.network_config, } attrs = cls.validate_attributes(full_data, models=models) cls._validate_cpu_pinning(node, attrs) cls._validate_hugepages(node, attrs) return data
def PATCH(self): """Update settings for master node :http: * 200 (OK) * 400 (Invalid data) * 404 (Settings are not present in db) """ data = self.checked_data(self.validator.validate_update) instance = self.get_one_or_404() instance.settings = utils.dict_merge( instance.settings, data["settings"] ) return self.single.to_json(instance)
def update(cls, instance, data): """Update data of native and plugin attributes for interface. :param instance: NodeNICInterface instance :type instance: NodeNICInterface model :param data: Data to update :type data: dict :returns: instance of an object (model) """ attributes = data.pop('attributes', None) if attributes: PluginManager.update_nic_attributes(attributes) instance.attributes = utils.dict_merge(instance.attributes, attributes) return super(NIC, cls).update(instance, data)
def update(cls, instance, data): """Update existing Bond with specified parameters. :param instance: object (model) instance :param data: dictionary of key-value pairs as object fields :returns: instance of an object (model) """ attributes = data.pop('attributes', None) if attributes: PluginManager.update_bond_attributes(attributes) instance.attributes = utils.dict_merge(instance.attributes, attributes) instance = super(Bond, cls).update(instance, data) instance.offloading_modes = data.get('offloading_modes', {}) return instance
def update(cls, instance, data): """Update existing Bond with specified parameters. :param instance: object (model) instance :param data: dictionary of key-value pairs as object fields :returns: instance of an object (model) """ attributes = data.pop('attributes', None) if attributes: PluginManager.update_bond_attributes(attributes) instance.attributes = utils.dict_merge( instance.attributes, attributes) instance = super(Bond, cls).update(instance, data) instance.offloading_modes = data.get('offloading_modes', {}) return instance
def get_common_attrs(cls, cluster): """Cluster attributes.""" attrs = cluster.attributes.merged_attrs_values() attrs['deployment_mode'] = cluster.mode attrs['deployment_id'] = cluster.id attrs['nodes'] = cls.node_list(get_nodes_not_for_deletion(cluster)) for node in attrs['nodes']: if node['role'] in 'cinder': attrs['use_cinder'] = True attrs = dict_merge( attrs, cls.get_net_provider_serializer(cluster).get_common_attrs(cluster, attrs)) return attrs
def get_common_attrs(cls, cluster): """Cluster attributes.""" attrs = cluster.attributes.merged_attrs_values() attrs['deployment_mode'] = cluster.mode attrs['deployment_id'] = cluster.id attrs['nodes'] = cls.node_list(get_nodes_not_for_deletion(cluster)) for node in attrs['nodes']: if node['role'] in 'cinder': attrs['use_cinder'] = True attrs = dict_merge( attrs, cls.get_net_provider_serializer(cluster).get_common_attrs( cluster, attrs)) return attrs
def test_dict_merge(self): custom = {"coord": [10, 10], "pass": "******", "dict": {"body": "solid", "color": "black", "dict": {"stuff": "hz"}}} common = {"parent": None, "dict": {"transparency": 100, "dict": {"another_stuff": "hz"}}} result = dict_merge(custom, common) self.assertEqual(result, {"coord": [10, 10], "parent": None, "pass": "******", "dict": {"body": "solid", "color": "black", "transparency": 100, "dict": {"stuff": "hz", "another_stuff": "hz"}}})
def get_nic_default_attributes(cls, cluster): """Get default plugin nic attributes for cluster. :param cluster: A cluster instance :type cluster: Cluster model :returns: dict -- Object with nic attributes """ plugins_nic_metadata = {} enabled_plugins = ClusterPlugin.get_enabled(cluster.id) for plugin_adapter in six.moves.map(wrap_plugin, enabled_plugins): metadata = plugin_adapter.nic_attributes_metadata if metadata: metadata = dict_merge( { 'metadata': { 'label': plugin_adapter.title, 'class': 'plugin' } }, metadata) plugins_nic_metadata[plugin_adapter.name] = metadata return plugins_nic_metadata