def task_remove(self, arg, flags): ''' Remove something on the network until it's seen again: REMOVE [IP|MAC|ID] REMOVE 10.0.0.1 REMOVE 18:EF:02:2D:49:00 REMOVE 8579d412f787432c1a3864c1833e48efb6e61dd466e39038a674f64652129293 REMOVE IGNORED REMOVE INACTIVE ''' # defaults fields = self.parser.default_fields valid, fields, sort_by, max_width, unique, nonzero, output_format, ipv4_only, ipv6_only, ipv4_and_ipv6 = self.parser._check_flags( flags, fields) if not valid: self.poutput("Unknown flag, try 'help task'") else: endpoints = [] if arg.startswith('ignored'): endpoints = Commands().remove_ignored(arg) elif arg.startswith('inactive'): endpoints = Commands().remove_inactives(arg) else: endpoints = Commands().remove(arg) self.poutput('Removed the following devices:') self.poutput(self.parser.display_results(endpoints, fields, sort_by=sort_by, max_width=max_width, unique=unique, nonzero=nonzero, output_format=output_format, ipv4_only=ipv4_only, ipv6_only=ipv6_only, ipv4_and_ipv6=ipv4_and_ipv6))
def do_remove(self, arg): ''' Remove and forget about something on the network until it's seen again: REMOVE [IP|MAC|ID] REMOVE 10.0.0.1 REMOVE 18:EF:02:2D:49:00 REMOVE 8579d412f787432c1a3864c1833e48efb6e61dd466e39038a674f64652129293 REMOVE IGNORED DEVICES REMOVE INACTIVE DEVICES ''' # defaults fields = self.default_fields flags, arg = PoseidonShell.get_flags(arg) fields, sort_by, max_width, unique = self._check_flags(flags, fields) endpoints = [] if arg.startswith('ignored'): endpoints = Commands().remove_ignored(arg) elif arg.startswith('inactive'): endpoints = Commands().remove_inactives(arg) else: endpoints = Commands().remove(arg) print('Removed the following devices:') PoseidonShell.display_results(endpoints, fields, sort_by=sort_by, max_width=max_width, unique=unique)
def task_clear(self, arg, flags): ''' Stop ignoring something on the network: CLEAR [IP|MAC|ID] CLEAR 10.0.0.1 CLEAR 18:EF:02:2D:49:00 CLEAR 8579d412f787432c1a3864c1833e48efb6e61dd466e39038a674f64652129293 CLEAR IGNORED ''' # defaults fields = self.parser.default_fields valid, fields, sort_by, max_width, unique, nonzero, output_format, ipv4_only, ipv6_only, ipv4_and_ipv6 = self.parser._check_flags( flags, fields) if not valid: self.poutput("Unknown flag, try 'help task'") else: self.poutput( 'Cleared the following devices that were being ignored:') self.poutput( self.parser.display_results(Commands().clear_ignored(arg), fields, sort_by=sort_by, max_width=max_width, unique=unique, nonzero=nonzero, output_format=output_format, ipv4_only=ipv4_only, ipv6_only=ipv6_only, ipv4_and_ipv6=ipv4_and_ipv6))
def show_what(self, arg, flags): ''' Find out what something is: WHAT [IP|MAC|ID] WHAT 10.0.0.1 WHAT 18:EF:02:2D:49:00 WHAT 8579d412f787432c1a3864c1833e48efb6e61dd466e39038a674f64652129293 ''' # defaults fields = self.parser.all_fields valid, fields, sort_by, max_width, unique, nonzero, output_format, ipv4_only, ipv6_only, ipv4_and_ipv6 = self.parser._check_flags( flags, fields) if not valid: self.poutput("Unknown flag, try 'help show'") else: self.poutput( self.parser.display_results(Commands().what_is(arg), fields, sort_by=sort_by, max_width=max_width, unique=unique, nonzero=nonzero, output_format=output_format, ipv4_only=ipv4_only, ipv6_only=ipv6_only, ipv4_and_ipv6=ipv4_and_ipv6))
def show_acls(self, arg, flags): ''' Find out the history of ACLs of something on the network: ACLS [IP|MAC|ID] ACLS 10.0.0.1 ACLS 18:EF:02:2D:49:00 ACLS 8579d412f787432c1a3864c1833e48efb6e61dd466e39038a674f64652129293 ''' # defaults fields = ['ACL History'] valid, fields, sort_by, max_width, unique, nonzero, output_format, ipv4_only, ipv6_only, ipv4_and_ipv6 = self.parser._check_flags( flags, fields) if not valid: self.poutput("Unknown flag, try 'help show'") else: self.poutput( self.parser.display_results(Commands().acls_of(arg), fields, sort_by=sort_by, max_width=max_width, unique=unique, nonzero=nonzero, output_format=output_format, ipv4_only=ipv4_only, ipv6_only=ipv6_only, ipv4_and_ipv6=ipv4_and_ipv6))
def show_where(self, arg, flags): ''' Find out where something is: WHERE [IP|MAC|ID] WHERE 10.0.0.1 WHERE 18:EF:02:2D:49:00 WHERE 8579d412f787432c1a3864c1833e48efb6e61dd466e39038a674f64652129293 ''' # defaults fields = ['Switch', 'Port', 'VLAN', 'IPv4', 'IPv6', 'MAC Address'] valid, fields, sort_by, max_width, unique, nonzero, output_format, ipv4_only, ipv6_only, ipv4_and_ipv6 = self.parser._check_flags( flags, fields, ipv4_only=False) if not valid: self.poutput("Unknown flag, try 'help show'") else: self.poutput( self.parser.display_results(Commands().where_is(arg), fields, sort_by=sort_by, max_width=max_width, unique=unique, nonzero=nonzero, output_format=output_format, ipv4_only=ipv4_only, ipv6_only=ipv6_only, ipv4_and_ipv6=ipv4_and_ipv6))
def task_ignore(self, arg, flags): ''' Ignore something on the network: IGNORE [IP|MAC|ID] IGNORE 10.0.0.1 IGNORE 18:EF:02:2D:49:00 IGNORE 8579d412f787432c1a3864c1833e48efb6e61dd466e39038a674f64652129293 IGNORE INACTIVE ''' # defaults fields = self.parser.default_fields valid, fields, sort_by, max_width, unique, nonzero, output_format, ipv4_only, ipv6_only, ipv4_and_ipv6 = self.parser._check_flags( flags, fields) if not valid: self.poutput("Unknown flag, try 'help task'") else: self.poutput('Ignored the following devices:') self.poutput( self.parser.display_results(Commands().ignore(arg), fields, sort_by=sort_by, max_width=max_width, unique=unique, nonzero=nonzero, output_format=output_format, ipv4_only=ipv4_only, ipv6_only=ipv6_only, ipv4_and_ipv6=ipv4_and_ipv6))
def task_set(self, arg, flags): ''' Set the state of things on the network: SET [IP|MAC|ID] [STATE] SET 10.0.0.1 INACTIVE SET ABNORMAL UNKNOWN (TODO - NOT IMPLEMENTED YET) SET 18:EF:02:2D:49:00 KNOWN SET 8579d412f787432c1a3864c1833e48efb6e61dd466e39038a674f64652129293 SHUTDOWN ''' # defaults fields = self.parser.default_fields + ['State', 'Next State'] valid, fields, sort_by, max_width, unique, nonzero, output_format, ipv4_only, ipv6_only, ipv4_and_ipv6 = self.parser._check_flags( flags, fields) if not valid: self.poutput("Unknown flag, try 'help task'") else: self.poutput('Set the following device states:') self.poutput( self.parser.display_results(Commands().change_devices(arg), fields, sort_by=sort_by, max_width=max_width, unique=unique, nonzero=nonzero, output_format=output_format, ipv4_only=ipv4_only, ipv6_only=ipv6_only, ipv4_and_ipv6=ipv4_and_ipv6))
def show_os(self, arg, flags): '''Show all things on the network that match a behavior''' fields = self.parser.default_fields valid, fields, sort_by, max_width, unique, nonzero, output_format, ipv4_only, ipv6_only, ipv4_and_ipv6 = self.parser._check_flags( flags, fields) if not valid: self.poutput("Unknown flag, try 'help show'") else: self.poutput(self.parser.display_results(Commands().show_devices(arg), fields, sort_by=sort_by, max_width=max_width, unique=unique, nonzero=nonzero, output_format=output_format, ipv4_only=ipv4_only, ipv6_only=ipv6_only, ipv4_and_ipv6=ipv4_and_ipv6))
def show_state(self, arg, flags): '''Show all things on the network that match a state''' fields = ['Switch', 'Port', 'State', 'Ethernet Vendor', 'Mac', 'IPv4', 'IPv6'] valid, fields, sort_by, max_width, unique, nonzero, output_format, ipv4_only, ipv6_only, ipv4_and_ipv6 = self.parser._check_flags( flags, fields, ipv4_only=False) if not valid: self.poutput("Unknown flag, try 'help show'") else: self.poutput(self.parser.display_results(Commands().show_devices(arg), fields, sort_by=sort_by, max_width=max_width, unique=unique, nonzero=nonzero, output_format=output_format, ipv4_only=ipv4_only, ipv6_only=ipv6_only, ipv4_and_ipv6=ipv4_and_ipv6))
def show_behavior(self, arg, flags): '''Show all things on the network that match a behavior''' fields = self.parser.default_fields + ['Behavior'] fields, sort_by, max_width, unique, nonzero, output_format, ipv4_only, ipv6_only, ipv4_and_ipv6 = self.parser._check_flags( flags, fields) self.parser.display_results(Commands().show_devices(arg), fields, sort_by=sort_by, max_width=max_width, unique=unique, nonzero=nonzero, output_format=output_format, ipv4_only=ipv4_only, ipv6_only=ipv6_only, ipv4_and_ipv6=ipv4_and_ipv6)
def do_where(self, arg): ''' Find out where something is: WHERE IS [IP|MAC|ID] WHERE IS 10.0.0.1 WHERE IS 18:EF:02:2D:49:00 WHERE IS 8579d412f787432c1a3864c1833e48efb6e61dd466e39038a674f64652129293 ''' # defaults fields = ['ID', 'MAC Address', 'Switch', 'Port'] flags, arg = PoseidonShell.get_flags(arg) fields, sort_by, max_width, unique = self._check_flags(flags, fields) PoseidonShell.display_results(Commands().where_is(arg), fields, sort_by=sort_by, max_width=max_width, unique=unique)
def do_show(self, arg): ''' Show things on the network based on filters: SHOW ACTIVE DEVICES SHOW INACTIVE DEVICES SHOW WINDOWS DEVICES SHOW ABNORMAL DEVICES ''' # defaults fields = self.default_fields + ['State', 'Next State'] flags, arg = PoseidonShell.get_flags(arg) fields, sort_by, max_width, unique = self._check_flags(flags, fields) PoseidonShell.display_results(Commands().show_devices(arg), fields, sort_by=sort_by, max_width=max_width, unique=unique)
def do_history(self, arg): ''' Find out the history of something on the network: HISTORY OF [IP|MAC|ID] HISTORY OF 10.0.0.1 HISTORY OF 18:EF:02:2D:49:00 HISTORY OF 8579d412f787432c1a3864c1833e48efb6e61dd466e39038a674f64652129293 ''' # defaults fields = ['Previous States'] flags, arg = PoseidonShell.get_flags(arg) fields, sort_by, max_width, unique = self._check_flags(flags, fields) PoseidonShell.display_results(Commands().history_of(arg), fields, sort_by=sort_by, max_width=max_width, unique=unique)
def do_collect(self, arg): ''' TODO - NOT IMPLEMENTED YET Collect on something on the network: COLLECT ON [IP|MAC] COLLECT ON 10.0.0.1 FOR 300 SECONDS COLLECT ON 18:EF:02:2D:49:00 FOR 5 MINUTES ''' # defaults fields = self.default_fields flags, arg = PoseidonShell.get_flags(arg) fields, sort_by, max_width, unique = self._check_flags(flags, fields) print('Collecting on the following devices:') PoseidonShell.display_results(Commands().collect_on(arg), fields, sort_by=sort_by, max_width=max_width, unique=unique)
def do_ignore(self, arg): ''' Ignore something on the network: IGNORE [IP|MAC|ID] IGNORE 10.0.0.1 IGNORE 18:EF:02:2D:49:00 IGNORE 8579d412f787432c1a3864c1833e48efb6e61dd466e39038a674f64652129293 IGNORE INACTIVE DEVICES ''' # defaults fields = self.default_fields flags, arg = PoseidonShell.get_flags(arg) fields, sort_by, max_width, unique = self._check_flags(flags, fields) print('Ignored the following devices:') PoseidonShell.display_results(Commands().ignore(arg), fields, sort_by=sort_by, max_width=max_width, unique=unique)
def do_clear(self, arg): ''' Stop ignoring something on the network: CLEAR [IP|MAC|ID] CLEAR 10.0.0.1 CLEAR 18:EF:02:2D:49:00 CLEAR 8579d412f787432c1a3864c1833e48efb6e61dd466e39038a674f64652129293 CLEAR IGNORED DEVICES ''' # defaults fields = self.default_fields flags, arg = PoseidonShell.get_flags(arg) fields, sort_by, max_width, unique = self._check_flags(flags, fields) print('Cleared the following devices that were being ignored:') PoseidonShell.display_results(Commands().clear_ignored(arg), fields, sort_by=sort_by, max_width=max_width, unique=unique)
def do_what(self, arg): ''' Find out what something is: WHAT IS [IP|MAC|ID] WHAT IS 10.0.0.1 WHAT IS 18:EF:02:2D:49:00 WHAT IS 8579d412f787432c1a3864c1833e48efb6e61dd466e39038a674f64652129293 ''' # defaults fields = self.default_fields + \ ['State', 'Next State', 'First Seen', 'Last Seen'] flags, arg = PoseidonShell.get_flags(arg) fields, sort_by, max_width, unique = self._check_flags(flags, fields) # TODO print more info PoseidonShell.display_results(Commands().what_is(arg), fields, sort_by=sort_by, max_width=max_width, unique=unique)
def show_history(self, arg, flags): ''' Find out the history of something on the network: HISTORY [IP|MAC|ID] HISTORY 10.0.0.1 HISTORY 18:EF:02:2D:49:00 HISTORY 8579d412f787432c1a3864c1833e48efb6e61dd466e39038a674f64652129293 ''' # defaults fields = ['Previous States'] fields, sort_by, max_width, unique, nonzero, output_format, ipv4_only, ipv6_only, ipv4_and_ipv6 = self.parser._check_flags( flags, fields) self.parser.display_results(Commands().history_of(arg), fields, sort_by=sort_by, max_width=max_width, unique=unique, nonzero=nonzero, output_format=output_format, ipv4_only=ipv4_only, ipv6_only=ipv6_only, ipv4_and_ipv6=ipv4_and_ipv6)
def test_commands(): commands = Commands() commands.what_is('foo') commands.history_of('foo') commands.where_is('foo') commands.collect_on('foo') commands.remove_inactives('foo') commands.remove_ignored('foo') commands.ignore('foo') commands.clear_ignored('foo') commands.remove('foo') commands.show_devices('foo')
def test_commands(): commands = Commands() endpoint = endpoint_factory('foo') endpoint.endpoint_data = { 'tenant': 'foo', 'mac': '00:00:00:00:00:00', 'segment': 'foo', 'port': '1' } commands.sdnc.endpoints[endpoint.name] = endpoint commands.what_is('foo') commands.history_of('foo') commands.where_is('foo') commands.show_devices('foo bar') commands.show_devices('all') commands.change_devices('foo') commands.remove('foo') commands.clear_ignored('foo') commands.clear_ignored('ignored') commands.ignore('foo') commands.ignore('inactive') commands.remove_inactives('foo') commands.remove_ignored('foo')