本文整理汇总了Python中aquilon.worker.processes.DSDBRunner.update_city方法的典型用法代码示例。如果您正苦于以下问题:Python DSDBRunner.update_city方法的具体用法?Python DSDBRunner.update_city怎么用?Python DSDBRunner.update_city使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类aquilon.worker.processes.DSDBRunner
的用法示例。
在下文中一共展示了DSDBRunner.update_city方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: render
# 需要导入模块: from aquilon.worker.processes import DSDBRunner [as 别名]
# 或者: from aquilon.worker.processes.DSDBRunner import update_city [as 别名]
def render(self, session, logger, city, timezone, campus,
default_dns_domain, comments, **arguments):
dbcity = get_location(session, city=city)
# Updating machine templates is expensive, so only do that if needed
update_machines = False
if timezone is not None:
dbcity.timezone = timezone
if comments is not None:
dbcity.comments = comments
if default_dns_domain is not None:
if default_dns_domain:
dbdns_domain = DnsDomain.get_unique(session, default_dns_domain,
compel=True)
dbcity.default_dns_domain = dbdns_domain
else:
dbcity.default_dns_domain = None
prev_campus = None
dsdb_runner = None
dsdb_runner = DSDBRunner(logger=logger)
if campus is not None:
dbcampus = get_location(session, campus=campus)
# This one would change the template's locations hence forbidden
if dbcampus.hub != dbcity.hub:
# Doing this both to reduce user error and to limit
# testing required.
raise ArgumentError("Cannot change campus. {0} is in {1:l}, "
"while {2:l} is in {3:l}.".format(
dbcampus, dbcampus.hub,
dbcity, dbcity.hub))
if dbcity.campus:
prev_campus = dbcity.campus
dbcity.update_parent(parent=dbcampus)
update_machines = True
session.flush()
if campus is not None:
if prev_campus:
prev_name = prev_campus.name
else:
prev_name = None
dsdb_runner.update_city(city, dbcampus.name, prev_name)
plenaries = PlenaryCollection(logger=logger)
plenaries.append(Plenary.get_plenary(dbcity))
if update_machines:
q = session.query(Machine)
q = q.filter(Machine.location_id.in_(dbcity.offspring_ids()))
logger.client_info("Updating %d machines..." % q.count())
for dbmachine in q:
plenaries.append(Plenary.get_plenary(dbmachine))
count = plenaries.write()
dsdb_runner.commit_or_rollback()
logger.client_info("Flushed %d templates." % count)