def render(self, session, logger, building, city, fullname, comments, address, **arguments): dbcity = City.get_unique(session, city, compel=True) add_location(session, Building, building, dbcity, fullname=fullname, address=address, comments=comments) session.flush() dsdb_runner = DSDBRunner(logger=logger) dsdb_runner.add_building(building, city, address) if dbcity.campus: dsdb_runner.add_campus_building(dbcity.campus, building) dsdb_runner.commit_or_rollback() return
def render(self, session, logger, building, city, address, fullname, default_dns_domain, comments, **arguments): dbbuilding = get_location(session, building=building) old_city = dbbuilding.city dsdb_runner = DSDBRunner(logger=logger) if address is not None: old_address = dbbuilding.address dbbuilding.address = address dsdb_runner.update_building(dbbuilding.name, dbbuilding.address, old_address) if fullname is not None: dbbuilding.fullname = fullname if comments is not None: dbbuilding.comments = comments if default_dns_domain is not None: if default_dns_domain: dbdns_domain = DnsDomain.get_unique(session, default_dns_domain, compel=True) dbbuilding.default_dns_domain = dbdns_domain else: dbbuilding.default_dns_domain = None plenaries = PlenaryCollection(logger=logger) if city: dbcity = get_location(session, city=city) # This one would change the template's locations hence forbidden if dbcity.hub != dbbuilding.hub: # Doing this both to reduce user error and to limit # testing required. raise ArgumentError("Cannot change hubs. {0} is in {1} " "while {2} is in {3}.".format( dbcity, dbcity.hub, dbbuilding, dbbuilding.hub)) # issue svcmap warnings maps = 0 for map_type in [ServiceMap, PersonalityServiceMap]: maps = maps + session.query(map_type).\ filter_by(location=old_city).count() if maps > 0: logger.client_info("There are {0} service(s) mapped to the " "old location of the ({1:l}), please " "review and manually update mappings for " "the new location as needed.".format( maps, dbbuilding.city)) dbbuilding.update_parent(parent=dbcity) if old_city.campus and (old_city.campus != dbcity.campus): dsdb_runner.del_campus_building(old_city.campus, building) if dbcity.campus and (old_city.campus != dbcity.campus): dsdb_runner.add_campus_building(dbcity.campus, building) query = session.query(Machine) query = query.filter( Machine.location_id.in_(dbcity.offspring_ids())) for dbmachine in query: plenaries.append(PlenaryMachineInfo(dbmachine, logger=logger)) session.flush() if plenaries.plenaries: with plenaries.get_write_key() as key: plenaries.stash() try: plenaries.write(locked=True) dsdb_runner.commit_or_rollback() except: plenaries.restore_stash() else: dsdb_runner.commit_or_rollback() return
def render(self, session, logger, building, city, address, fullname, default_dns_domain, comments, **arguments): dbbuilding = get_location(session, building=building) old_city = dbbuilding.city dsdb_runner = DSDBRunner(logger=logger) if address is not None: old_address = dbbuilding.address dbbuilding.address = address dsdb_runner.update_building(dbbuilding.name, dbbuilding.address, old_address) if fullname is not None: dbbuilding.fullname = fullname if comments is not None: dbbuilding.comments = comments if default_dns_domain is not None: if default_dns_domain: dbdns_domain = DnsDomain.get_unique(session, default_dns_domain, compel=True) dbbuilding.default_dns_domain = dbdns_domain else: dbbuilding.default_dns_domain = None plenaries = PlenaryCollection(logger=logger) if city: dbcity = get_location(session, city=city) # This one would change the template's locations hence forbidden if dbcity.hub != dbbuilding.hub: # Doing this both to reduce user error and to limit # testing required. raise ArgumentError("Cannot change hubs. {0} is in {1} " "while {2} is in {3}.".format( dbcity, dbcity.hub, dbbuilding, dbbuilding.hub)) # issue svcmap warnings maps = 0 for map_type in [ServiceMap, PersonalityServiceMap]: maps = maps + session.query(map_type).\ filter_by(location=old_city).count() if maps > 0: logger.client_info("There are {0} service(s) mapped to the " "old location of the ({1:l}), please " "review and manually update mappings for " "the new location as needed.".format( maps, dbbuilding.city)) dbbuilding.update_parent(parent=dbcity) if old_city.campus and (old_city.campus != dbcity.campus): dsdb_runner.del_campus_building(old_city.campus, building) if dbcity.campus and (old_city.campus != dbcity.campus): dsdb_runner.add_campus_building(dbcity.campus, building) query = session.query(Machine) query = query.filter(Machine.location_id.in_(dbcity.offspring_ids())) for dbmachine in query: plenaries.append(Plenary.get_plenary(dbmachine)) session.flush() if plenaries.plenaries: with plenaries.get_key(): plenaries.stash() try: plenaries.write(locked=True) dsdb_runner.commit_or_rollback() except: plenaries.restore_stash() raise else: dsdb_runner.commit_or_rollback() return