<s> from netaddr import IPNetwork <EOL> from netaddr . ip import IPAddress <EOL> from fake_switches . brocade . command_processor . config_interface import ConfigInterfaceCommandProcessor <EOL> from fake_switches . brocade . command_processor . config_virtual_interface_vrrp import ConfigVirtualInterfaceVrrpCommandProcessor <EOL> class ConfigVirtualInterfaceCommandProcessor ( ConfigInterfaceCommandProcessor ) : <EOL> def get_prompt ( self ) : <EOL> return "<STR_LIT>" % ( self . switch_configuration . name , self . port . vlan_id ) <EOL> def do_ip ( self , * args ) : <EOL> if "<STR_LIT:address>" . startswith ( args [ <NUM_LIT:0> ] ) : <EOL> new_ip = IPNetwork ( args [ <NUM_LIT:1> ] ) <EOL> ip_owner , existing_ip = self . switch_configuration . get_port_and_ip_by_ip ( new_ip . ip ) <EOL> if not ip_owner : <EOL> self . port . add_ip ( new_ip ) <EOL> else : <EOL> if ip_owner == self . port : <EOL> for ip in self . port . ips : <EOL> if new_ip . ip == ip . ip : <EOL> self . write_line ( "<STR_LIT>" ) <EOL> break <EOL> else : <EOL> if new_ip . ip in ip : <EOL> if len ( args ) > <NUM_LIT:2> and "<STR_LIT>" . startswith ( args [ <NUM_LIT:2> ] ) : <EOL> if not next ( ( ip for ip in self . port . secondary_ips if ip . ip == new_ip . ip ) , False ) : <EOL> self . port . add_secondary_ip ( new_ip ) <EOL> else : <EOL> self . write_line ( "<STR_LIT>" ) <EOL> break <EOL> else : <EOL> self . write_line ( <EOL> "<STR_LIT>" ) <EOL> break <EOL> else : <EOL> self . write_line ( "<STR_LIT>" ) <EOL> if "<STR_LIT>" . startswith ( args [ <NUM_LIT:0> ] ) : <EOL> if "<STR_LIT>" . startswith ( args [ <NUM_LIT:2> ] ) : <EOL> self . port . access_group_in = args [ <NUM_LIT:1> ] <EOL> elif "<STR_LIT>" . startswith ( args [ <NUM_LIT:2> ] ) : <EOL> self . port . access_group_out = args [ <NUM_LIT:1> ] <EOL> self . write_line ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> . format ( self . port . vlan_id ) ) <EOL> if "<STR_LIT>" . startswith ( args [ <NUM_LIT:0> ] ) : <EOL> if "<STR_LIT>" . startswith ( args [ <NUM_LIT:1> ] ) : <EOL> group = args [ <NUM_LIT:2> ] <EOL> vrrp = self . port . get_vrrp_group ( group ) <EOL> if vrrp is None : <EOL> vrrp = self . switch_configuration . new ( "<STR_LIT>" , group ) <EOL> self . port . vrrps . append ( vrrp ) <EOL> self . move_to ( ConfigVirtualInterfaceVrrpCommandProcessor , self . port , vrrp ) <EOL> if "<STR_LIT>" . startswith ( args [ <NUM_LIT:1> ] ) : <EOL> if "<STR_LIT>" . startswith ( args [ <NUM_LIT:2> ] ) : <EOL> self . port . vrrp_common_authentication = args [ <NUM_LIT:3> ] <EOL> elif "<STR_LIT>" . startswith ( args [ <NUM_LIT:2> ] ) : <EOL> self . port . vrrp_common_authentication = None <EOL> if "<STR_LIT>" . startswith ( args [ <NUM_LIT:0> ] ) : <EOL> if len ( args ) == <NUM_LIT:1> : <EOL> self . write_line ( "<STR_LIT>" ) <EOL> elif len ( args ) > <NUM_LIT:2> : <EOL> self . write_line ( "<STR_LIT>" . format ( "<STR_LIT:U+0020>" . join ( args [ <NUM_LIT:2> : ] ) ) ) <EOL> self . write_line ( "<STR_LIT>" ) <EOL> else : <EOL> ip_address = IPAddress ( args [ <NUM_LIT:1> ] ) <EOL> if ip_address not in self . port . ip_helpers : <EOL> self . port . ip_helpers . append ( ip_address ) <EOL> else : <EOL> self . write_line ( "<STR_LIT>" ) <EOL> if "<STR_LIT>" . startswith ( args [ <NUM_LIT:0> ] ) : <EOL> self . port . ip_redirect = True <EOL> def do_no_ip ( self , * args ) : <EOL> if "<STR_LIT:address>" . startswith ( args [ <NUM_LIT:0> ] ) : <EOL> deleting_ip = IPNetwork ( args [ <NUM_LIT:1> ] ) <EOL> if next ( ( ip for ip in self . port . secondary_ips if ip . ip == deleting_ip . ip ) , False ) : <EOL> self . port . remove_secondary_ip ( deleting_ip ) <EOL> else : <EOL> if not next ( ( ip for ip in self . port . secondary_ips if ip in deleting_ip ) , False ) : <EOL> self . port . remove_ip ( deleting_ip ) <EOL> else : <EOL> self . write_line ( "<STR_LIT>" ) <EOL> if "<STR_LIT>" . startswith ( args [ <NUM_LIT:0> ] ) : <EOL> if len ( args ) < <NUM_LIT:3> : <EOL> self . write_line ( "<STR_LIT>" % args [ <NUM_LIT:1> ] ) <EOL> else : <EOL> if "<STR_LIT>" . startswith ( args [ <NUM_LIT:2> ] ) : <EOL> if self . port . access_group_in == args [ <NUM_LIT:1> ] : <EOL> self . port . access_group_in = None <EOL> else : <EOL> self . write_line ( "<STR_LIT>" % args [ <NUM_LIT:1> ] ) <EOL> elif "<STR_LIT>" . startswith ( args [ <NUM_LIT:2> ] ) : <EOL> if self . port . access_group_out == args [ <NUM_LIT:1> ] : <EOL> self . port . access_group_out = None <EOL> else : <EOL> self . write_line ( "<STR_LIT>" % args [ <NUM_LIT:1> ] ) <EOL> if "<STR_LIT>" . startswith ( args [ <NUM_LIT:0> ] ) : <EOL> if "<STR_LIT>" . startswith ( args [ <NUM_LIT:1> ] ) : <EOL> group = args [ <NUM_LIT:2> ] <EOL> vrrp = self . port . get_vrrp_group ( group ) <EOL> if vrrp : <EOL> self . port . vrrps . remove ( vrrp ) <EOL> if "<STR_LIT>" . startswith ( args [ <NUM_LIT:1> ] ) : <EOL> if "<STR_LIT>" . startswith ( args [ <NUM_LIT:2> ] ) and len ( args ) == <NUM_LIT:4> : <EOL> self . do_ip ( * "<STR_LIT>" . split ( ) ) <EOL> else : <EOL> self . write_line ( "<STR_LIT>" ) <EOL> if "<STR_LIT>" . startswith ( args [ <NUM_LIT:0> ] ) : <EOL> if len ( args ) == <NUM_LIT:1> : <EOL> self . write_line ( "<STR_LIT>" ) <EOL> elif len ( args ) > <NUM_LIT:2> : <EOL> self . write_line ( "<STR_LIT>" . format ( "<STR_LIT:U+0020>" . join ( args [ <NUM_LIT:2> : ] ) ) ) <EOL> self . write_line ( "<STR_LIT>" ) <EOL> else : <EOL> ip_address = IPAddress ( args [ <NUM_LIT:1> ] ) <EOL> if ip_address in self . port . ip_helpers : <EOL> self . port . ip_helpers . remove ( ip_address ) <EOL> else : <EOL> self . write_line ( "<STR_LIT>" ) <EOL> if "<STR_LIT>" . startswith ( args [ <NUM_LIT:0> ] ) : <EOL> self . port . ip_redirect = False </s>
