本文整理汇总了Python中nailgun.objects.NodeCollection类的典型用法代码示例。如果您正苦于以下问题:Python NodeCollection类的具体用法?Python NodeCollection怎么用?Python NodeCollection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了NodeCollection类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_pagination_of_node_collection
def test_pagination_of_node_collection(self):
def assert_pagination_and_cont_rng(q, cr, sz, first, last, ttl, valid):
self.assertEqual(q.count(), sz)
self.assertEqual(cr.first, first)
self.assertEqual(cr.last, last)
self.assertEqual(cr.total, ttl)
self.assertEqual(cr.valid, valid)
self.env.create_nodes(5)
# test pagination limited to 2 first items
pagination = Pagination(limit=2)
q, cr = NodeCollection.scope(pagination)
assert_pagination_and_cont_rng(q, cr, 2, 1, 2, 5, True)
# test invalid pagination
pagination = Pagination(offset=5)
q, cr = NodeCollection.scope(pagination)
assert_pagination_and_cont_rng(q, cr, 0, 0, 0, 5, False)
# test limit=0, offset ignored
pagination = Pagination(limit=0, offset=999)
q, cr = NodeCollection.scope(pagination)
assert_pagination_and_cont_rng(q, cr, 0, 0, 0, 5, True)
# test limit+offset+order_by
pagination = Pagination(limit=3, offset=1, order_by='-id')
q, cr = NodeCollection.scope(pagination)
assert_pagination_and_cont_rng(q, cr, 3, 2, 4, 5, True)
ids = sorted([i.id for i in self.env.nodes])
n = q.all()
self.assertEqual(n[0].id, ids[3])
self.assertEqual(n[1].id, ids[2])
self.assertEqual(n[2].id, ids[1])
示例2: update_nodes
def update_nodes(cls, instance, nodes_ids):
"""Update Cluster nodes by specified node IDs
Nodes with specified IDs will replace existing ones in Cluster
:param instance: Cluster instance
:param nodes_ids: list of nodes ids
:returns: None
"""
# TODO(NAME): sepatate nodes
# for deletion and addition by set().
new_nodes = []
if nodes_ids:
new_nodes = db().query(models.Node).filter(
models.Node.id.in_(nodes_ids)
)
nodes_to_remove = [n for n in instance.nodes
if n not in new_nodes]
nodes_to_add = [n for n in new_nodes
if n not in instance.nodes]
for node in nodes_to_add:
if not node.online:
raise errors.NodeOffline(
u"Cannot add offline node "
u"'{0}' to environment".format(node.id)
)
# we should reset hostname to default value to guarantee
# hostnames uniqueness for nodes outside clusters
from nailgun.objects import Node
for node in nodes_to_remove:
node.hostname = Node.default_slave_name(node)
map(instance.nodes.remove, nodes_to_remove)
map(instance.nodes.append, nodes_to_add)
net_manager = cls.get_network_manager(instance)
map(
net_manager.clear_assigned_networks,
nodes_to_remove
)
map(
net_manager.clear_bond_configuration,
nodes_to_remove
)
cls.replace_provisioning_info_on_nodes(instance, [], nodes_to_remove)
cls.replace_deployment_info_on_nodes(instance, [], nodes_to_remove)
from nailgun.objects import NodeCollection
NodeCollection.reset_network_template(nodes_to_remove)
map(
net_manager.assign_networks_by_default,
nodes_to_add
)
cls.update_nodes_network_template(instance, nodes_to_add)
db().flush()
示例3: get_clusters_info
def get_clusters_info(self):
clusters = ClusterCollection.all()
clusters_info = []
for cluster in clusters:
release = cluster.release
nodes_num = NodeCollection.filter_by(
None, cluster_id=cluster.id).count()
cluster_info = {
'id': cluster.id,
'nodes_num': nodes_num,
'release': {
'os': release.operating_system,
'name': release.name,
'version': release.version
},
'mode': cluster.mode,
'nodes': self.get_nodes_info(cluster.nodes),
'node_groups': self.get_node_groups_info(cluster.node_groups),
'status': cluster.status,
'attributes': self.get_attributes(cluster.attributes.editable,
self.attributes_white_list),
'vmware_attributes': self.get_attributes(
cluster.vmware_attributes.editable,
self.vmware_attributes_white_list
),
'net_provider': cluster.net_provider,
'fuel_version': cluster.fuel_version,
'is_customized': cluster.is_customized,
'network_configuration': self.get_network_configuration_info(
cluster),
'installed_plugins': self.get_cluster_plugins_info(cluster)
}
clusters_info.append(cluster_info)
return clusters_info
示例4: get_installation_info
def get_installation_info(self):
clusters_info = self.get_clusters_info()
allocated_nodes_num = sum([c['nodes_num'] for c in clusters_info])
unallocated_nodes_num = NodeCollection.filter_by(
None, cluster_id=None).count()
info = {
'master_node_uid': self.get_master_node_uid(),
'fuel_release': self.fuel_release_info(),
'clusters': clusters_info,
'clusters_num': len(clusters_info),
'allocated_nodes_num': allocated_nodes_num,
'unallocated_nodes_num': unallocated_nodes_num
}
return info
示例5: get_clusters_info
def get_clusters_info(self):
clusters = ClusterCollection.all()
clusters_info = []
for cluster in clusters:
release = cluster.release
nodes_num = NodeCollection.filter_by(
None, cluster_id=cluster.id).count()
cluster_info = {
'id': cluster.id,
'nodes_num': nodes_num,
'release': {
'os': release.operating_system,
'name': release.name,
'version': release.version
},
'mode': cluster.mode,
'nodes': self.get_nodes_info(cluster.nodes),
'status': cluster.status
}
clusters_info.append(cluster_info)
return clusters_info
示例6: get_clusters_info
def get_clusters_info(self):
clusters = ClusterCollection.all()
clusters_info = []
for cluster in clusters:
release = cluster.release
nodes_num = NodeCollection.filter_by(
None, cluster_id=cluster.id).count()
cluster_info = {
'id': cluster.id,
'nodes_num': nodes_num,
'release': {
'os': release.operating_system,
'name': release.name,
'version': release.version
},
'mode': cluster.mode,
'nodes': self.get_nodes_info(cluster.nodes),
'node_groups': self.get_node_groups_info(cluster.node_groups),
'status': cluster.status,
'extensions': cluster.extensions,
'attributes': self.get_attributes(
Cluster.get_editable_attributes(cluster),
self.attributes_white_list
),
'plugin_links': self.get_plugin_links(
cluster.plugin_links),
'net_provider': cluster.net_provider,
'fuel_version': cluster.fuel_version,
'is_customized': cluster.is_customized,
'network_configuration': self.get_network_configuration_info(
cluster),
'installed_plugins': self.get_cluster_plugins_info(cluster),
'components': cluster.components,
'cluster_plugins': cluster.cluster_plugins,
'roles_metadata': cluster.roles_metadata,
'tags_metadata': cluster.tags_metadata,
'volumes_metadata': cluster.volumes_metadata,
}
clusters_info.append(cluster_info)
return clusters_info