def main(): with open("show_version.txt", "r") as version_file: show_ver = version_file.read() #print "Model: "+(show_version.obtain_model(show_ver)) # print "%15s: %-50s" % ("model", model) print "%15s: %-70s" % ("Model", (show_version.obtain_model(show_ver))) print "%15s: %-50s" % ("Version", (show_version.obtain_os_version(show_ver))) print "%15s: %-50s" % ("Uptime", (show_version.obtain_uptime(show_ver)))
def main(): with open("show_version.txt", "r") as show_ver_file: show_ver = show_ver_file.read() uptime = show_version.obtain_uptime(show_ver) model = show_version.obtain_model(show_ver) os_version = show_version.obtain_os_version(show_ver) print print "%15s %-50s" % ("model:", model) print "%15s %-50s" % ("os_version:", os_version) print "%15s %-50s" % ("uptime:", uptime) print
def main(): ''' Write a script that processes the show_version output using the 'show_version' package It should return something similar to the following: model: 881 os_version: Version 15.0(1)M4 uptime: uptime is 12 weeks, 5 days, 1 hour, 4 minutes ''' with open("show_version.txt", "r") as version_file: show_ver = version_file.read() model = show_version.obtain_model(show_ver) os_version = show_version.obtain_os_version(show_ver) uptime = show_version.obtain_uptime(show_ver) print print "%15s: %-50s" % ("model", model) print "%15s: %-50s" % ("os_version", os_version) print "%15s: %-50s" % ("uptime", uptime) print
>>> show_version.obtain_uptime(show_ver) '12 weeks, 5 days, 1 hour, 4 minutes' C. Write a script that processes the show_version output using this package. It should return something similar to the following: model: 881 os_version: Version 15.0(1)M4 uptime: uptime is 12 weeks, 5 days, 1 hour, 4 minutes ''' import show_version if __name__ == "__main__": f = open("show_version.txt") show_ver = f.read() model = show_version.obtain_model(show_ver) os_version = show_version.obtain_os_version(show_ver) uptime = show_version.obtain_uptime(show_ver) print print "%15s: %-50s" % ("model", model) print "%15s: %-50s" % ("os_version", os_version) print "%15s: %-50s" % ("uptime", uptime) print
"""Create three functions in three separate modules and put them in a show_version directory (in practice you wouldn't do this--you would just have them all in one file, but this will let you experiment with packages). 1. Function1 = obtain_os_version -- process the show version output and return the OS version (Version 15.0(1)M4) else return None. 2. Function2 = obtain_uptime -- process the show version output and return the network device's uptime string (uptime is 12 weeks, 5 days, 1 hour, 4 minutes) else return None. 3. Function3 = obtain_model -- process the show version output and return the model (881) else return None. B. Make a package out of this 'show_version' directory using a blank __init__.py file. """ import show_version with open("show_version.txt") as f: lines = f.read() print "Version: %s" % show_version.obtain_os_version(lines) print "Model: %s" % show_version.obtain_model(lines) print "Uptime: %s" % show_version.obtain_uptime(lines)
>>> show_version.obtain_uptime(show_ver) '12 weeks, 5 days, 1 hour, 4 minutes' C. Write a script that processes the show_version output using this package. It should return something similar to the following: model: 881 os_version: Version 15.0(1)M4 uptime: uptime is 12 weeks, 5 days, 1 hour, 4 minutes """ import show_version if __name__ == "__main__": f = open("show_version.txt") show_ver = f.read() model = show_version.obtain_model(show_ver) os_version = show_version.obtain_os_version(show_ver) uptime = show_version.obtain_uptime(show_ver) print print "%15s: %-50s" % ("model", model) print "%15s: %-50s" % ("os_version", os_version) print "%15s: %-50s" % ("uptime", uptime) print
>>> import show_version.model >>> import show_version.uptime 2. Now edit the __init__.py file such that it automatically loads each of the modules. In other words, you should be able to type: >>> import show_version and have all of your functions available as follows: >>> show_version.obtain_model(show_ver_data) >>> show_version.obtain_os_version(show_ver_data) >>> show_version.obtain_uptime(show_ver_data) C. Write a script that processes the show_version output using this package. It should return something similar to the following: model: 881 os_version: Version 15.0(1)M4 uptime: uptime is 12 weeks, 5 days, 1 hour, 4 minutes ''' import show_version with open("show_version.txt", "rU") as a_file: data = a_file.read() model = show_version.obtain_model(data) version = show_version.obtain_version(data) uptime = show_version.obtain_uptime(data) print "%10s %-20s" %("model:", model) print "%10s %-20s" %("version:", version) print "%10s %-20s" %("uptime:", uptime)