def main(): logging.basicConfig() if len(sys.argv) == 2 and sys.argv[1] == '-v': logging.getLogger().setLevel(logging.INFO) if len(sys.argv) == 2 and sys.argv[1] == '-d': logging.getLogger().setLevel(logging.DEBUG) i = Ixia('ixia01') i.connect() i.discover() i.session.login('mw') pg = i.new_port_group() pg.create() pg.add_port(i.chassis.cards[0].ports[2]) pg.add_port(i.chassis.cards[0].ports[3]) pg.take_ownership() pg.destroy() i.disconnect()
def main(): usage = 'usage: %(prog)s <host> [options]' parser = argparse.ArgumentParser(usage=usage) parser.add_argument('host', help='be more verbose') parser.add_argument('-v', action='store_true', dest='verbose', help='be more verbose') parser.add_argument('-d', action='store_true', dest='debug', help='enable debug mode') parser.add_argument('-o', '--ownership', dest='ownership', default='pyixia', help='use ownership', metavar='OWNER') parser.add_argument('-p', '--ports', dest='ports_list', type=int, help='connect to card port', metavar='card port', action='append', nargs=2) parser.add_argument('-c', '--commands', dest='commands_string', help='execute commands', metavar='command', choices=ALLOWED_COMMANDS, action='append') parser.add_argument('-s', '--statistics', dest='statistics_list', help='show statistics', metavar='statistic_counter', choices=ALLOWED_STATISTICS, action='append') parser.add_argument('-g', '--Settings', dest='settings_list', help='set port settings', metavar='port_setting_argument', choices=ALLOWED_SETTINGS, action='append') parser.add_argument('-f', '--file', dest='file', help='set file for settings', metavar='settings_file') args = parser.parse_args() logging.basicConfig() if args.verbose: logging.getLogger('').setLevel(logging.INFO) if args.debug: logging.getLogger('').setLevel(logging.DEBUG) try: i = Ixia(args.host) i.connect() i.discover() i.session.login(args.ownership) pg = i.new_port_group() pg.create() ports_list = add_ports(i, pg, args.ports_list) if args.file: perform_file_settings(i, ports_list, args.file) if args.settings_list: set_settings(i, ports_list, args.settings_list) if args.commands_string: exec_commands(pg, args.commands_string) if args.statistics_list: get_statistics(i, ports_list, args.statistics_list) pg.destroy() i.disconnect() except socket.error as e: print e.strerror