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)
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)