本文整理汇总了Python中aquilon.aqdb.model.Personality.get_matching_query方法的典型用法代码示例。如果您正苦于以下问题:Python Personality.get_matching_query方法的具体用法?Python Personality.get_matching_query怎么用?Python Personality.get_matching_query使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类aquilon.aqdb.model.Personality
的用法示例。
在下文中一共展示了Personality.get_matching_query方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: render
# 需要导入模块: from aquilon.aqdb.model import Personality [as 别名]
# 或者: from aquilon.aqdb.model.Personality import get_matching_query [as 别名]
def render(self, session, logger, hostname, machine, archetype,
buildstatus, personality, host_environment, osname, osversion,
service, instance, model, machine_type, vendor, serial, cluster,
guest_on_cluster, guest_on_share, member_cluster_share,
domain, sandbox, branch, sandbox_owner,
dns_domain, shortname, mac, ip, networkip, network_environment,
exact_location, server_of_service, server_of_instance, grn,
eon_id, fullinfo, style, **arguments):
dbnet_env = NetworkEnvironment.get_unique_or_default(session,
network_environment)
q = session.query(Host)
if machine:
dbmachine = Machine.get_unique(session, machine, compel=True)
q = q.filter_by(hardware_entity=dbmachine)
# Add the machine definition and the primary name. Use aliases to make
# sure the end result will be ordered by primary name.
PriDns = aliased(DnsRecord)
PriFqdn = aliased(Fqdn)
PriDomain = aliased(DnsDomain)
q = q.join(HardwareEntity,
(PriDns, PriDns.id == Machine.primary_name_id),
(PriFqdn, PriDns.fqdn_id == PriFqdn.id),
(PriDomain, PriFqdn.dns_domain_id == PriDomain.id))
q = q.order_by(PriFqdn.name, PriDomain.name)
q = q.options(contains_eager('hardware_entity'),
contains_eager('hardware_entity.primary_name', alias=PriDns),
contains_eager('hardware_entity.primary_name.fqdn', alias=PriFqdn),
contains_eager('hardware_entity.primary_name.fqdn.dns_domain',
alias=PriDomain))
q = q.reset_joinpoint()
# Hardware-specific filters
dblocation = get_location(session, **arguments)
if dblocation:
if exact_location:
q = q.filter(HardwareEntity.location == dblocation)
else:
childids = dblocation.offspring_ids()
q = q.filter(HardwareEntity.location_id.in_(childids))
if model or vendor or machine_type:
subq = Model.get_matching_query(session, name=model, vendor=vendor,
model_type=machine_type,
compel=True)
q = q.filter(HardwareEntity.model_id.in_(subq))
if serial:
self.deprecated_option("serial",
"Please use search machine --serial instead.",
logger=logger, **arguments)
q = q.filter(HardwareEntity.serial_no == serial)
# DNS IP address related filters
if mac or ip or networkip or hostname or dns_domain or shortname:
# Inner joins are cheaper than outer joins, so make some effort to
# use inner joins when possible
if mac or ip or networkip:
q = q.join(Interface)
else:
q = q.outerjoin(Interface)
if ip or networkip:
q = q.join(AddressAssignment, Network, from_joinpoint=True)
else:
q = q.outerjoin(AddressAssignment, Network, from_joinpoint=True)
if mac:
self.deprecated_option("mac", "Please use search machine "
"--mac instead.", logger=logger,
**arguments)
q = q.filter(Interface.mac == mac)
if ip:
q = q.filter(AddressAssignment.ip == ip)
q = q.filter(Network.network_environment == dbnet_env)
if networkip:
dbnetwork = get_network_byip(session, networkip, dbnet_env)
q = q.filter(AddressAssignment.network == dbnetwork)
dbdns_domain = None
if hostname:
(shortname, dbdns_domain) = parse_fqdn(session, hostname)
if dns_domain:
dbdns_domain = DnsDomain.get_unique(session, dns_domain, compel=True)
if shortname or dbdns_domain:
ARecAlias = aliased(ARecord)
ARecFqdn = aliased(Fqdn)
q = q.outerjoin((ARecAlias,
and_(ARecAlias.ip == AddressAssignment.ip,
ARecAlias.network_id == AddressAssignment.network_id)),
(ARecFqdn, ARecAlias.fqdn_id == ARecFqdn.id))
if shortname:
q = q.filter(or_(ARecFqdn.name == shortname,
PriFqdn.name == shortname))
if dbdns_domain:
q = q.filter(or_(ARecFqdn.dns_domain == dbdns_domain,
PriFqdn.dns_domain == dbdns_domain))
#.........这里部分代码省略.........