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 ''' # 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) 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 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 ''' # 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_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_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_set(self, arg, flags): ''' Set the state of things on the network: SET [IP|MAC|ID] [STATE] SET 18:EF:02:2D:49:00 KNOWN ''' # 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_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_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_os(self, arg, flags): '''Show all things on the network that match an os''' 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 test_commands(): commands = Commands(config=get_test_config(), faucetconfgetsetter_cl=FaucetLocalConfGetSetter) endpoint = endpoint_factory('foo') endpoint.endpoint_data = { 'tenant': 'foo', 'mac': '00:00:00:00:00:00', 'segment': 'foo', 'port': '1' } commands.sdnc.endpoints = {} commands.sdnc.endpoints[endpoint.name] = endpoint commands.what_is('foo') commands.history_of('foo') commands.acls_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.remove_ignored('foo') endpoint2 = endpoint_factory('foo2') endpoint2.endpoint_data = { 'tenant': 'foo', 'mac': '00:00:00:00:00:00', 'segment': 'foo', 'port': '1' } commands.sdnc.endpoints[endpoint2.name] = endpoint2 commands.what_is('00:00:00:00:00:00')