本文整理汇总了Python中nailgun.utils.dict_merge函数的典型用法代码示例。如果您正苦于以下问题:Python dict_merge函数的具体用法?Python dict_merge怎么用?Python dict_merge使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了dict_merge函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_common_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
示例2: create_attributes
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
示例3: serialize_generated
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]
示例4: get_common_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
示例5: patch_attributes
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()
示例6: get_common_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.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
示例7: get_common_attrs
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
示例8: get_common_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
示例9: get_default_attributes
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
示例10: get_updated_editable_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", {}))}
示例11: _get_network_role_metadata
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)
示例12: merged_attrs
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)
示例13: POST
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)
示例14: serialize
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]
示例15: test_bond_slaves_not_available_dpdk
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)