本文整理汇总了Python中nailgun.db.db.query函数的典型用法代码示例。如果您正苦于以下问题:Python query函数的具体用法?Python query怎么用?Python query使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了query函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: POST
def POST(self, cluster_id):
cluster = self.get_object_or_404(objects.Cluster, cluster_id)
data = self.checked_data()
node_id = data["node_id"]
node = self.get_object_or_404(objects.Node, node_id)
netgroups_mapping = self.get_netgroups_map(node.cluster, cluster)
orig_roles = node.roles
objects.Node.update_roles(node, []) # flush
objects.Node.update_pending_roles(node, []) # flush
node.replaced_deployment_info = []
node.deployment_info = []
node.kernel_params = None
node.cluster_id = cluster.id
node.group_id = None
objects.Node.assign_group(node) # flush
objects.Node.update_pending_roles(node, orig_roles) # flush
for ip in node.ip_addrs:
ip.network = netgroups_mapping[ip.network]
nic_assignments = db.query(models.NetworkNICAssignment).\
join(models.NodeNICInterface).\
filter(models.NodeNICInterface.node_id == node.id).\
all()
for nic_assignment in nic_assignments:
nic_assignment.network_id = \
netgroups_mapping[nic_assignment.network_id]
bond_assignments = db.query(models.NetworkBondAssignment).\
join(models.NodeBondInterface).\
filter(models.NodeBondInterface.node_id == node.id).\
all()
for bond_assignment in bond_assignments:
bond_assignment.network_id = \
netgroups_mapping[bond_assignment.network_id]
objects.Node.add_pending_change(node,
consts.CLUSTER_CHANGES.interfaces)
node.pending_addition = True
node.pending_deletion = False
task = models.Task(name=consts.TASK_NAMES.node_deletion,
cluster=cluster)
db.commit()
self.delete_node_by_astute(task, node)
示例2: test_fails_if_there_is_task
def test_fails_if_there_is_task(self):
for task_name in DeploymentCheckMixin.deployment_tasks:
task = models.Task(name=task_name, cluster_id=self.cluster.id)
db.add(task)
db.flush()
self.assertRaisesWithMessage(
errors.DeploymentAlreadyStarted,
'Cannot perform the actions because there are '
'running tasks {0}'.format([task]),
DeploymentCheckMixin.check_no_running_deployment,
self.cluster)
db.query(models.Task).delete()
示例3: validate_collection_update
def validate_collection_update(cls, data, cluster_id=None):
data = cls.validate_json(data)
cls.validate_schema(data, assignment_format_schema)
dict_data = dict((d["id"], d["roles"]) for d in data)
received_node_ids = dict_data.keys()
nodes = db.query(Node).filter(Node.id.in_(received_node_ids))
cls.check_all_nodes(nodes, received_node_ids)
cls.check_if_already_done(nodes)
release = db.query(Cluster).get(cluster_id).release
for node_id in received_node_ids:
cls.validate_roles(
release,
dict_data[node_id]
)
return dict_data
示例4: check_no_running_deployment
def check_no_running_deployment(cls, cluster):
tasks_q = objects.TaskCollection.get_by_name_and_cluster(
cluster, cls.deployment_tasks).filter_by(
status=consts.TASK_STATUSES.running)
tasks_exists = db.query(tasks_q.exists()).scalar()
if tasks_exists:
raise errors.DeploymentAlreadyStarted(
'Cannot perform the actions because there are '
'running tasks {0}'.format(tasks_q.all()))
示例5: _validate_nodes
def _validate_nodes(cls, new_node_ids, instance):
set_new_node_ids = set(new_node_ids)
set_old_node_ids = set(objects.Cluster.get_nodes_ids(instance))
nodes_to_add = set_new_node_ids - set_old_node_ids
nodes_to_remove = set_old_node_ids - set_new_node_ids
hostnames_to_add = [x[0] for x in db.query(Node.hostname)
.filter(Node.id.in_(nodes_to_add)).all()]
duplicated = [x[0] for x in db.query(Node.hostname).filter(
sa.and_(
Node.hostname.in_(hostnames_to_add),
Node.cluster_id == instance.id,
Node.id.notin_(nodes_to_remove)
)
).all()]
if duplicated:
raise errors.AlreadyExists(
"Nodes with hostnames [{0}] already exist in cluster {1}."
.format(",".join(duplicated), instance.id)
)
示例6: test_does_not_fail_if_there_is_deleted_task
def test_does_not_fail_if_there_is_deleted_task(self):
for task_name in DeploymentCheckMixin.deployment_tasks:
task = models.Task(name=task_name,
deleted_at=datetime.datetime.now(),
cluster_id=self.cluster.id)
db.add(task)
db.flush()
self.addCleanup(db.query(models.Task).delete)
self.assertNotRaises(
errors.DeploymentAlreadyStarted,
DeploymentCheckMixin.check_no_running_deployment,
self.cluster)
示例7: get_assigned_vips_for_controller_group
def get_assigned_vips_for_controller_group(cls, cluster):
"""Get VIPs assigned in specified cluster's controller node group
:param cluster: Cluster object
:type cluster: Cluster model
:returns: VIPs for given cluster
"""
node_group_id = Cluster.get_controllers_group_id(cluster)
cluster_vips = db.query(models.IPAddr).join(
models.IPAddr.network_data).filter(
models.IPAddr.vip_name.isnot(None) &
(models.NetworkGroup.group_id == node_group_id))
return cluster_vips
示例8: validate_collection_update
def validate_collection_update(cls, data, cluster_id=None):
list_data = cls.validate_json(data)
cls.validate_schema(list_data, unassignment_format_schema)
node_ids_set = set(n['id'] for n in list_data)
nodes = db.query(Node).filter(Node.id.in_(node_ids_set))
node_id_cluster_map = dict(
(n.id, n.cluster_id) for n in
db.query(Node.id, Node.cluster_id).filter(
Node.id.in_(node_ids_set)))
other_cluster_ids_set = set(node_id_cluster_map.values()) - \
set((int(cluster_id),))
if other_cluster_ids_set:
raise errors.InvalidData(
u"Nodes [{0}] are not members of environment {1}."
.format(
u", ".join(
str(n_id) for n_id, c_id in
node_id_cluster_map.iteritems()
if c_id in other_cluster_ids_set
), cluster_id), log_message=True
)
cls.check_all_nodes(nodes, node_ids_set)
return nodes
示例9: _get_admin_node_network
def _get_admin_node_network(cls, node_id):
net = cls.get_admin_network_group()
net_cidr = IPNetwork(net.cidr)
node = db.query(Node).get(node_id)
ip_addr = cls.get_admin_ip_for_node(node)
return {
'name': net.name,
'vlan': net.vlan_start,
'ip': "{0}/{1}".format(ip_addr, net_cidr.prefixlen),
'netmask': str(net_cidr.netmask),
'brd': str(net_cidr.broadcast),
'gateway': net.gateway,
'dev': node.admin_interface.name
}
示例10: check_unique_hostnames
def check_unique_hostnames(cls, nodes, cluster_id):
hostnames = [node.hostname for node in nodes]
conflicting_hostnames = [x[0] for x in db.query(
Node.hostname).filter(
sa.and_(
Node.hostname.in_(hostnames),
Node.cluster_id == cluster_id,
)
).all()]
if conflicting_hostnames:
raise errors.AlreadyExists(
"Nodes with hostnames [{0}] already exist in cluster {1}."
.format(",".join(conflicting_hostnames), cluster_id)
)
示例11: get_objects_list_or_404
def get_objects_list_or_404(self, model, ids):
"""Get list of objects
:param model: model object
:param ids: list of ids
:raises: web.notfound
:returns: query object
"""
node_query = db.query(model).filter(model.id.in_(ids))
objects_count = node_query.count()
if len(set(ids)) != objects_count:
raise web.notfound('{0} not found'.format(model.__name__))
return node_query
示例12: validate_collection_update
def validate_collection_update(cls, data, cluster_id=None):
data = cls.validate_json(data)
cls.validate_schema(data, assignment_format_schema)
dict_data = dict((d["id"], d["roles"]) for d in data)
received_node_ids = dict_data.keys()
nodes = db.query(Node).filter(Node.id.in_(received_node_ids))
cls.check_all_nodes(nodes, received_node_ids)
cls.check_if_already_done(nodes)
cluster = objects.Cluster.get_by_uid(
cluster_id, fail_if_not_found=True
)
for node_id in received_node_ids:
cls.validate_roles(
cluster,
dict_data[node_id]
)
return dict_data
示例13: get_for_model
def get_for_model(cls, instance):
"""Get deployment graphs related to given model.
:param instance: model that could have relation to graph
:type instance: models.Plugin|models.Cluster|models.Release|
:return: graph instance
:rtype: model.DeploymentGraph
"""
association_model = cls.single.get_association_for_model(instance)
graphs = db.query(
models.DeploymentGraph
).join(
association_model
).join(
instance.__class__
).filter(
instance.__class__.id == instance.id
)
return graphs.all()
示例14: prepare_data
def prepare_data(cls, data):
"""Prepares input data.
Filter input data based on the fact that
updating parameters of the fuel admin network
is forbidden for default node group.
Admin network cannot be updated because of:
- sharing itself between environments;
- having no mechanism to change its parameters on deployed Master node.
"""
if data.get("networks"):
default_admin = db.query(
NetworkGroup).filter_by(group_id=None).first()
data["networks"] = [
n for n in data["networks"]
if n.get("id") != default_admin.id
]
return data
示例15: _validate_unique_name
def _validate_unique_name(cls, data, *filters):
"""Validate node group name to be unique.
Validate whether node group name is unique for specific
environment. Prevent to have duplicated node group names for
the same environment.
:param data: data which contains node group name and cluster_id.
:param filters: additional filters for the query which is
used in the method for validation.
:type data: dict
:type filters: list
:returns: None
"""
nodegroup_query = objects.NodeGroupCollection.filter_by(None, name=data["name"], cluster_id=data["cluster_id"])
if filters:
nodegroup_query = nodegroup_query.filter(*filters)
nodegroup_exists = db.query(nodegroup_query.exists()).scalar()
if nodegroup_exists:
raise errors.NotAllowed(
"Node group '{0}' already exists " "in environment {1}.".format(data["name"], data["cluster_id"])
)