def render(self, session, logger, network_device, type, clear, vlan, **arguments): NetworkDevice.check_type(type) dbnetdev = NetworkDevice.get_unique(session, network_device, compel=True) if type is not None and dbnetdev.switch_type != type: raise ArgumentError("{0} is not a {1} switch.".format(dbnetdev, type)) return self.poll(session, logger, [dbnetdev], clear, vlan)
def render(self, session, logger, rack, type, clear, vlan, **arguments): dblocation = get_location(session, rack=rack) NetworkDevice.check_type(type) q = session.query(NetworkDevice) q = q.filter_by(location=dblocation) if type: q = q.filter_by(switch_type=type) netdevs = q.all() if not netdevs: raise NotFoundException("No network device found.") return self.poll(session, logger, netdevs, clear, vlan)
def render(self, session, logger, network_device, model, type, ip, vendor, serial, rename_to, discovered_macs, clear, discover, comments, **arguments): dbnetdev = NetworkDevice.get_unique(session, network_device, compel=True) oldinfo = DSDBRunner.snapshot_hw(dbnetdev) plenary = Plenary.get_plenary(dbnetdev, logger=logger) if discover: discover_network_device(session, logger, self.config, dbnetdev, False) if vendor and not model: model = dbnetdev.model.name if model: dbmodel = Model.get_unique(session, name=model, vendor=vendor, model_type=NetworkDeviceType.Switch, compel=True) dbnetdev.model = dbmodel dblocation = get_location(session, **arguments) if dblocation: dbnetdev.location = dblocation if serial is not None: dbnetdev.serial_no = serial # FIXME: What do the error messages for an invalid enum (switch_type) # look like? if type: NetworkDevice.check_type(type) dbnetdev.switch_type = type if ip: update_primary_ip(session, logger, dbnetdev, ip) if comments is not None: dbnetdev.comments = comments if rename_to: # Handling alias renaming would not be difficult in AQDB, but the # DSDB synchronization would be painful, so don't do that for now. # In theory we should check all configured IP addresses for aliases, # but this is the most common case if dbnetdev.primary_name and dbnetdev.primary_name.fqdn.aliases: raise ArgumentError("The network device has aliases and it cannot be " "renamed. Please remove all aliases first.") rename_hardware(session, dbnetdev, rename_to) if clear: session.query(ObservedMac).filter_by(network_device=dbnetdev).delete() if discovered_macs: now = datetime.now() for (macaddr, port) in discovered_macs: update_or_create_observed_mac(session, dbnetdev, port, macaddr, now) session.flush() with plenary.get_key(): plenary.stash() try: plenary.write(locked=True) dsdb_runner = DSDBRunner(logger=logger) dsdb_runner.update_host(dbnetdev, oldinfo) dsdb_runner.commit_or_rollback("Could not update network device in DSDB") except: plenary.restore_stash() raise return