def query_unit(unit): """The unit is online: query it, return uptime""" # this first query gets firmware version and also tests the password try: version = unit.get_version() except: raise emit_tab(version) # also query for uptime try: uptime = unit.get_uptime() emit_tab(crawler_util.rough_timespan(uptime)) except: raise return uptime
def backup(self, backup_root): src_dir = '/tmp' src_file = 'system.cfg' dst_dir = HostControl.backup(self, backup_root) dst_file = '%s_%s.cfg' % (self.hostname, self.get_version()) self._safe_scp(src_dir, src_file, dst_dir, dst_file) return src_file def reboot(self, tick): return HostControl.reboot(self, 'reboot', 10, tick) if __name__ == '__main__': if len(sys.argv) < 3: sys.exit('usage: %s ipaddress password [reboot]' % sys.argv[0]) ip = ipaddr.IPv4Address(sys.argv[1]) pwd = sys.argv[2] reboot = (len(sys.argv) > 3 and sys.argv[3] == 'reboot') radio = UbiquitiRadio('MyRadio', ip, pwd) if not radio.is_pingable(): sys.exit('CANNOT PING') print 'Version =', radio.get_version() print 'Hardware =', radio.get_hardware() print 'Uptime about', crawler_util.rough_timespan(radio.get_uptime()) if reboot: print radio.backup('.') print radio.reboot(True)
def backup(self, backup_root): dst_dir = HostControl.backup(self, backup_root) fileb = self._backup_binary(dst_dir) filec = self._backup_config(dst_dir) return '%s+%s' % (fileb, filec) def reboot(self, tick): return HostControl.reboot(self, 'system reboot ; beep', 10, tick) if __name__ == '__main__': if len(sys.argv) < 3: sys.exit('usage: %s ipaddress password [reboot]' % sys.argv[0]) ip = ipaddr.IPv4Address(sys.argv[1]) pwd = sys.argv[2] reboot = (len(sys.argv) > 3 and sys.argv[3] == 'reboot') router = MikrotikRouter('MyRouter', ip, pwd) if not router.is_pingable(): sys.exit('CANNOT PING') print 'Version =', router.get_version() print 'Hardware =', router.get_hardware() print 'Uptime about', crawler_util.rough_timespan(router.get_uptime()) # print 'Adjacency:' # print router.get_adjacency() if reboot: print router.backup('.') print router.reboot(True)
child.sendline('quit') child.expect([pexpect.EOF]) return result def command(self, command): """login and then transfer to lambda, which passes extra parameter""" return self.ssh_command(None, lambda child: self.commandCB(child, command)) if __name__ == '__main__': if len(sys.argv) < 3: sys.exit('usage: %s ipaddress password [reboot]' % sys.argv[0]) ip = ipaddr.IPv4Address(sys.argv[1]) pwd = sys.argv[2] reboot = (len(sys.argv) > 3 and sys.argv[3] == 'reboot') switch = H3CSwitch('MySwitch', ip, pwd) if not switch.is_pingable(): sys.exit('CANNOT PING') print 'Version =', switch.get_version() print 'Hardware =', switch.get_hardware() print 'Uptime about', crawler_util.rough_timespan(switch.get_uptime()) print 'Device:', switch.command('display device') if reboot: print 'Backup config =', switch.backup('.') sys.stdout.write('Reboot: ') switch.reboot(True)