<s> """<STR_LIT>""" <EOL> from __future__ import absolute_import <EOL> from __future__ import division <EOL> from __future__ import print_function <EOL> from __future__ import unicode_literals <EOL> import socket <EOL> import struct <EOL> import gnlpy . netlink as netlink <EOL> IPVS_MASQUERADING = <NUM_LIT:0> <EOL> IPVS_LOCAL = <NUM_LIT:1> <EOL> IPVS_TUNNELING = <NUM_LIT:2> <EOL> IPVS_ROUTING = <NUM_LIT:3> <EOL> IPVS_METHODS = set ( [ <EOL> IPVS_MASQUERADING , <EOL> IPVS_LOCAL , <EOL> IPVS_TUNNELING , <EOL> IPVS_ROUTING <EOL> ] ) <EOL> IpvsStatsAttrList = netlink . create_attr_list_type ( <EOL> '<STR_LIT>' , <EOL> ( '<STR_LIT>' , netlink . U32Type ) , <EOL> ( '<STR_LIT>' , netlink . U32Type ) , <EOL> ( '<STR_LIT>' , netlink . U32Type ) , <EOL> ( '<STR_LIT>' , netlink . U64Type ) , <EOL> ( '<STR_LIT>' , netlink . U64Type ) , <EOL> ( '<STR_LIT>' , netlink . U32Type ) , <EOL> ( '<STR_LIT>' , netlink . U32Type ) , <EOL> ( '<STR_LIT>' , netlink . U32Type ) , <EOL> ( '<STR_LIT>' , netlink . U32Type ) , <EOL> ( '<STR_LIT>' , netlink . U32Type ) , <EOL> ) <EOL> IpvsStatsAttrList64 = netlink . create_attr_list_type ( <EOL> '<STR_LIT>' , <EOL> ( '<STR_LIT>' , netlink . U64Type ) , <EOL> ( '<STR_LIT>' , netlink . U64Type ) , <EOL> ( '<STR_LIT>' , netlink . U64Type ) , <EOL> ( '<STR_LIT>' , netlink . U64Type ) , <EOL> ( '<STR_LIT>' , netlink . U64Type ) , <EOL> ( '<STR_LIT>' , netlink . U64Type ) , <EOL> ( '<STR_LIT>' , netlink . U64Type ) , <EOL> ( '<STR_LIT>' , netlink . U64Type ) , <EOL> ( '<STR_LIT>' , netlink . U64Type ) , <EOL> ( '<STR_LIT>' , netlink . U64Type ) , <EOL> ) <EOL> IpvsServiceAttrList = netlink . create_attr_list_type ( <EOL> '<STR_LIT>' , <EOL> ( '<STR_LIT>' , netlink . U16Type ) , <EOL> ( '<STR_LIT>' , netlink . U16Type ) , <EOL> ( '<STR_LIT>' , netlink . BinaryType ) , <EOL> ( '<STR_LIT>' , netlink . Net16Type ) , <EOL> ( '<STR_LIT>' , netlink . U32Type ) , <EOL> ( '<STR_LIT>' , netlink . NulStringType ) , <EOL> ( '<STR_LIT>' , netlink . BinaryType ) , <EOL> ( '<STR_LIT>' , netlink . U32Type ) , <EOL> ( '<STR_LIT>' , netlink . U32Type ) , <EOL> ( '<STR_LIT>' , IpvsStatsAttrList ) , <EOL> ( '<STR_LIT>' , netlink . NulStringType ) , <EOL> ( '<STR_LIT>' , IpvsStatsAttrList64 ) , <EOL> ) <EOL> IpvsDestAttrList = netlink . create_attr_list_type ( <EOL> '<STR_LIT>' , <EOL> ( '<STR_LIT>' , netlink . BinaryType ) , <EOL> ( '<STR_LIT>' , netlink . Net16Type ) , <EOL> ( '<STR_LIT>' , netlink . U32Type ) , <EOL> ( '<STR_LIT>' , netlink . I32Type ) , <EOL> ( '<STR_LIT>' , netlink . U32Type ) , <EOL> ( '<STR_LIT>' , netlink . U32Type ) , <EOL> ( '<STR_LIT>' , netlink . U32Type ) , <EOL> ( '<STR_LIT>' , netlink . U32Type ) , <EOL> ( '<STR_LIT>' , netlink . U32Type ) , <EOL> ( '<STR_LIT>' , IpvsStatsAttrList ) , <EOL> ( '<STR_LIT>' , netlink . U16Type ) , <EOL> ( '<STR_LIT>' , IpvsStatsAttrList64 ) , <EOL> ) <EOL> IpvsDaemonAttrList = netlink . create_attr_list_type ( <EOL> '<STR_LIT>' , <EOL> ( '<STR_LIT>' , netlink . U32Type ) , <EOL> ( '<STR_LIT>' , netlink . NulStringType ) , <EOL> ( '<STR_LIT>' , netlink . U32Type ) , <EOL> ) <EOL> IpvsInfoAttrList = netlink . create_attr_list_type ( <EOL> '<STR_LIT>' , <EOL> ( '<STR_LIT>' , netlink . U32Type ) , <EOL> ( '<STR_LIT>' , netlink . U32Type ) , <EOL> ) <EOL> IpvsCmdAttrList = netlink . create_attr_list_type ( <EOL> '<STR_LIT>' , <EOL> ( '<STR_LIT>' , IpvsServiceAttrList ) , <EOL> ( '<STR_LIT>' , IpvsDestAttrList ) , <EOL> ( '<STR_LIT>' , IpvsDaemonAttrList ) , <EOL> ( '<STR_LIT>' , netlink . U32Type ) , <EOL> ( '<STR_LIT>' , netlink . U32Type ) , <EOL> ( '<STR_LIT>' , netlink . U32Type ) , <EOL> ) <EOL> IpvsMessage = netlink . create_genl_message_type ( <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> ( '<STR_LIT>' , IpvsCmdAttrList ) , <EOL> ( '<STR_LIT>' , IpvsCmdAttrList ) , <EOL> ( '<STR_LIT>' , IpvsCmdAttrList ) , <EOL> ( '<STR_LIT>' , IpvsCmdAttrList ) , <EOL> ( '<STR_LIT>' , IpvsCmdAttrList ) , <EOL> ( '<STR_LIT>' , IpvsCmdAttrList ) , <EOL> ( '<STR_LIT>' , IpvsCmdAttrList ) , <EOL> ( '<STR_LIT>' , IpvsCmdAttrList ) , <EOL> ( '<STR_LIT>' , IpvsCmdAttrList ) , <EOL> ( '<STR_LIT>' , IpvsCmdAttrList ) , <EOL> ( '<STR_LIT>' , IpvsCmdAttrList ) , <EOL> ( '<STR_LIT>' , IpvsCmdAttrList ) , <EOL> ( '<STR_LIT>' , IpvsCmdAttrList ) , <EOL> ( '<STR_LIT>' , IpvsCmdAttrList ) , <EOL> ( '<STR_LIT>' , IpvsCmdAttrList ) , <EOL> ( '<STR_LIT>' , IpvsCmdAttrList ) , <EOL> ( '<STR_LIT>' , IpvsCmdAttrList ) , <EOL> required_modules = [ '<STR_LIT>' ] , <EOL> ) <EOL> def verbose ( f ) : <EOL> def g ( self , * args , ** kwargs ) : <EOL> if self . verbose : <EOL> s_args = [ repr ( a ) for a in args ] <EOL> s_args . extend ( [ '<STR_LIT>' . format ( k , repr ( v ) ) <EOL> for k , v in kwargs . items ( ) ] ) <EOL> print ( '<STR_LIT>' . format ( f . __name__ , '<STR_LIT:U+002CU+0020>' . join ( s_args ) ) ) <EOL> return f ( self , * args , ** kwargs ) <EOL> return g <EOL> def _validate_ip ( ip ) : <EOL> try : <EOL> socket . inet_pton ( _to_af ( ip ) , ip ) <EOL> return True <EOL> except socket . error : <EOL> return False <EOL> def _to_af ( ip ) : <EOL> return socket . AF_INET6 if '<STR_LIT::>' in ip else socket . AF_INET <EOL> def _to_af_union ( ip ) : <EOL> af = _to_af ( ip ) <EOL> return af , socket . inet_pton ( af , ip ) . ljust ( <NUM_LIT:16> , str ( '<STR_LIT>' ) ) <EOL> def _from_af_union ( af , addr ) : <EOL> n = <NUM_LIT:4> if af == socket . AF_INET else <NUM_LIT:16> <EOL> return socket . inet_ntop ( af , addr [ : n ] ) <EOL> def _to_proto_num ( proto ) : <EOL> if proto is None : <EOL> return None <EOL> if proto . lower ( ) == '<STR_LIT>' : <EOL> return socket . IPPROTO_TCP <EOL> elif proto . lower ( ) == '<STR_LIT>' : <EOL> return socket . IPPROTO_UDP <EOL> else : <EOL> assert False , '<STR_LIT>' % proto <EOL> def _from_proto_num ( n ) : <EOL> if n is None : <EOL> return None <EOL> if n == socket . IPPROTO_TCP : <EOL> return '<STR_LIT>' <EOL> elif n == socket . IPPROTO_UDP : <EOL> return '<STR_LIT>' <EOL> else : <EOL> assert False , '<STR_LIT>' % n <EOL> class Dest ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , d = { } , validate = False ) : <EOL> self . ip_ = d . get ( '<STR_LIT>' , None ) <EOL> self . weight_ = d . get ( '<STR_LIT>' , None ) <EOL> self . port_ = d . get ( '<STR_LIT:port>' , None ) <EOL> self . fwd_method_ = d . get ( '<STR_LIT>' , IPVS_TUNNELING ) <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' % ( self . ip ( ) , self . weight ( ) ) <EOL> def ip ( self ) : <EOL> return self . ip_ <EOL> def weight ( self ) : <EOL> return self . weight_ <EOL> def port ( self ) : <EOL> return self . port_ <EOL> def fwd_method ( self ) : <EOL> return self . fwd_method_ <EOL> def validate ( self ) : <EOL> assert _validate_ip ( self . ip_ ) <EOL> assert isinstance ( self . weight_ , int ) <EOL> assert self . weight_ >= - <NUM_LIT:1> <EOL> assert self . fwd_method_ in IPVS_METHODS <EOL> def to_dict ( self ) : <EOL> return { <EOL> '<STR_LIT>' : self . ip_ , <EOL> '<STR_LIT>' : self . weight_ , <EOL> } <EOL> def to_attr_list ( self ) : <EOL> af , addr = _to_af_union ( self . ip_ ) <EOL> return IpvsDestAttrList ( addr_family = af , <EOL> addr = addr , <EOL> port = self . port_ , <EOL> fwd_method = self . fwd_method_ ) <EOL> def __eq__ ( self , other ) : <EOL> return isinstance ( other , Dest ) and self . to_dict ( ) == other . to_dict ( ) <EOL> def __ne__ ( self , other ) : <EOL> return not self . __eq__ ( other ) <EOL> @ staticmethod <EOL> def from_attr_list ( lst , default_af = None ) : <EOL> return Dest ( <EOL> d = { <EOL> '<STR_LIT>' : _from_af_union ( lst . get ( '<STR_LIT>' , default_af ) , <EOL> lst . get ( '<STR_LIT>' ) ) , <EOL> '<STR_LIT>' : lst . get ( '<STR_LIT>' ) , <EOL> '<STR_LIT:port>' : lst . get ( '<STR_LIT:port>' ) , <EOL> '<STR_LIT>' : lst . get ( '<STR_LIT>' ) <EOL> } , <EOL> validate = True , <EOL> ) <EOL> class Service ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , d = { } , validate = False ) : <EOL> self . proto_ = d . get ( '<STR_LIT>' , None ) <EOL> self . vip_ = d . get ( '<STR_LIT>' , None ) <EOL> self . port_ = d . get ( '<STR_LIT:port>' , None ) <EOL> self . sched_ = d . get ( '<STR_LIT>' , None ) <EOL> self . fwmark_ = d . get ( '<STR_LIT>' , None ) <EOL> default_af = None <EOL> if self . vip_ : <EOL> default_af = _to_af ( self . vip_ ) <EOL> self . af_ = d . get ( '<STR_LIT>' , default_af ) <EOL> if validate : <EOL> self . validate ( ) <EOL> def __repr__ ( self ) : <EOL> if self . fwmark_ is not None : <EOL> return '<STR_LIT>' % ( <EOL> self . fwmark ( ) , self . sched ( ) , self . af ( ) ) <EOL> return '<STR_LIT>' % ( <EOL> self . proto ( ) , self . vip ( ) , self . port ( ) , self . sched ( ) ) <EOL> def af ( self ) : <EOL> return self . af_ <EOL> def fwmark ( self ) : <EOL> return self . fwmark_ <EOL> def proto ( self ) : <EOL> return self . proto_ <EOL> def proto_num ( self ) : <EOL> return _to_proto_num ( self . proto_ ) <EOL> def port ( self ) : <EOL> return self . port_ <EOL> def vip ( self ) : <EOL> return self . vip_ <EOL> def sched ( self ) : <EOL> return self . sched_ <EOL> def validate ( self ) : <EOL> assert self . af_ in [ socket . AF_INET , socket . AF_INET6 ] <EOL> if self . vip_ or self . port_ or self . proto_ : <EOL> assert self . proto_ . lower ( ) in [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> assert _validate_ip ( self . vip_ ) <EOL> assert isinstance ( self . port_ , int ) <EOL> assert self . port_ > <NUM_LIT:0> and self . port_ < ( <NUM_LIT:2> ** <NUM_LIT:16> ) <EOL> assert self . fwmark_ is None <EOL> else : <EOL> assert isinstance ( self . fwmark_ , int ) <EOL> assert self . proto_ is None <EOL> assert self . port_ is None <EOL> assert self . vip_ is None <EOL> assert self . fwmark_ > <NUM_LIT:0> and self . fwmark_ < ( <NUM_LIT:2> ** <NUM_LIT:32> ) <EOL> def to_dict ( self ) : <EOL> self . validate ( ) <EOL> if self . fwmark_ is None : <EOL> return { <EOL> '<STR_LIT>' : self . proto_ , <EOL> '<STR_LIT>' : self . vip_ , <EOL> '<STR_LIT:port>' : self . port_ , <EOL> '<STR_LIT>' : self . sched_ , <EOL> '<STR_LIT>' : self . af_ <EOL> } <EOL> else : <EOL> return { <EOL> '<STR_LIT>' : self . fwmark_ , <EOL> '<STR_LIT>' : self . sched_ , <EOL> '<STR_LIT>' : self . af_ <EOL> } <EOL> def to_attr_list ( self ) : <EOL> if self . fwmark_ is None : <EOL> af , addr = _to_af_union ( self . vip_ ) <EOL> netmask = ( ( <NUM_LIT:1> << <NUM_LIT:32> ) - <NUM_LIT:1> ) if af == socket . AF_INET else <NUM_LIT> <EOL> proto = self . proto_num ( ) <EOL> return IpvsServiceAttrList ( af = af , addr = addr , protocol = proto , <EOL> netmask = netmask , port = self . port_ , <EOL> sched_name = self . sched_ , <EOL> flags = struct . pack ( str ( '<STR_LIT>' ) , <NUM_LIT:0> , <NUM_LIT:0> ) ) <EOL> else : <EOL> netmask = ( ( <NUM_LIT:1> << <NUM_LIT:32> ) - <NUM_LIT:1> ) <EOL> return IpvsServiceAttrList ( fwmark = self . fwmark_ , af = self . af_ , <EOL> netmask = netmask , sched_name = self . sched_ , <EOL> flags = struct . pack ( str ( '<STR_LIT>' ) , <NUM_LIT:0> , <NUM_LIT:0> ) ) <EOL> def __eq__ ( self , other ) : <EOL> return isinstance ( other , Service ) and self . to_dict ( ) == other . to_dict ( ) <EOL> def __ne__ ( self , other ) : <EOL> return not self . __eq__ ( other ) <EOL> @ staticmethod <EOL> def from_attr_list ( lst ) : <EOL> if lst . get ( '<STR_LIT>' , None ) is not None : <EOL> d = dict ( <EOL> vip = _from_af_union ( lst . get ( '<STR_LIT>' ) , lst . get ( '<STR_LIT>' ) ) , <EOL> proto = _from_proto_num ( lst . get ( '<STR_LIT>' ) ) , <EOL> port = lst . get ( '<STR_LIT:port>' ) , <EOL> sched = lst . get ( '<STR_LIT>' ) , <EOL> af = lst . get ( '<STR_LIT>' ) , <EOL> ) <EOL> else : <EOL> d = dict ( <EOL> fwmark = lst . get ( '<STR_LIT>' ) , <EOL> sched = lst . get ( '<STR_LIT>' ) , <EOL> af = lst . get ( '<STR_LIT>' ) , <EOL> ) <EOL> return Service ( d = d , validate = True ) <EOL> class Pool ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , d = { } , validate = False ) : <EOL> self . service_ = Service ( d . get ( '<STR_LIT>' , { } ) , validate ) <EOL> self . dests_ = [ Dest ( x , validate ) for x in d . get ( '<STR_LIT>' , [ ] ) ] <EOL> def service ( self ) : <EOL> return self . service_ <EOL> def dests ( self ) : <EOL> return self . dests_ <EOL> def validate ( self ) : <EOL> self . service_ . validate ( ) <EOL> for dest in self . dests_ : <EOL> dest . validate ( ) <EOL> def to_dict ( self ) : <EOL> self . validate ( ) <EOL> return { <EOL> '<STR_LIT>' : self . service_ . to_dict ( ) , <EOL> '<STR_LIT>' : [ d . to_dict ( ) for d in self . dests_ ] , <EOL> } <EOL> @ staticmethod <EOL> def from_args ( service = None , dests = [ ] ) : <EOL> assert isinstance ( service , Service ) <EOL> assert isinstance ( dests , list ) <EOL> p = Pool ( ) <EOL> p . service_ = service <EOL> p . dests_ = dests <EOL> return p <EOL> @ staticmethod <EOL> def load_pools_from_json_list ( lst ) : <EOL> return [ Pool ( i , True ) for i in lst ] <EOL> class IpvsClient ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , verbose = False ) : <EOL> self . verbose = verbose <EOL> self . nlsock = netlink . NetlinkSocket ( verbose = verbose ) <EOL> def __modify_service ( self , method , vip , port , protocol , ** svc_kwargs ) : <EOL> af , addr = _to_af_union ( vip ) <EOL> netmask = ( ( <NUM_LIT:1> << <NUM_LIT:32> ) - <NUM_LIT:1> ) if af == socket . AF_INET else <NUM_LIT> <EOL> out_msg = IpvsMessage ( <EOL> method , flags = netlink . MessageFlags . ACK_REQUEST , <EOL> attr_list = IpvsCmdAttrList ( <EOL> service = IpvsServiceAttrList ( <EOL> af = af , <EOL> port = port , <EOL> protocol = protocol , <EOL> addr = addr , <EOL> netmask = netmask , <EOL> flags = struct . pack ( str ( '<STR_LIT>' ) , <NUM_LIT:0> , <NUM_LIT:0> ) , <EOL> ** svc_kwargs <EOL> ) <EOL> ) <EOL> ) <EOL> self . nlsock . execute ( out_msg ) <EOL> @ verbose <EOL> def add_service ( self , vip , port , protocol = socket . IPPROTO_TCP , <EOL> sched_name = '<STR_LIT>' ) : <EOL> self . __modify_service ( '<STR_LIT>' , vip , port , protocol , <EOL> sched_name = sched_name , timeout = <NUM_LIT:0> ) <EOL> @ verbose <EOL> def del_service ( self , vip , port , protocol = socket . IPPROTO_TCP ) : <EOL> self . __modify_service ( '<STR_LIT>' , vip , port , protocol ) <EOL> def __modify_fwm_service ( self , method , fwmark , af , ** svc_kwargs ) : <EOL> netmask = ( ( <NUM_LIT:1> << <NUM_LIT:32> ) - <NUM_LIT:1> ) if af == socket . AF_INET else <NUM_LIT> <EOL> out_msg = IpvsMessage ( <EOL> method , flags = netlink . MessageFlags . ACK_REQUEST , <EOL> attr_list = IpvsCmdAttrList ( <EOL> service = IpvsServiceAttrList ( <EOL> fwmark = fwmark , <EOL> flags = struct . pack ( str ( '<STR_LIT>' ) , <NUM_LIT:0> , <NUM_LIT:0> ) , <EOL> af = af , <EOL> netmask = netmask , <EOL> ** svc_kwargs <EOL> ) <EOL> ) <EOL> ) <EOL> self . nlsock . execute ( out_msg ) <EOL> @ verbose <EOL> def add_fwm_service ( self , fwmark , sched_name = '<STR_LIT>' , af = socket . AF_INET ) : <EOL> self . __modify_fwm_service ( '<STR_LIT>' , fwmark , <EOL> sched_name = sched_name , timeout = <NUM_LIT:0> , af = af ) <EOL> @ verbose <EOL> def del_fwm_service ( self , fwmark , af = socket . AF_INET ) : <EOL> self . __modify_fwm_service ( '<STR_LIT>' , fwmark , af = af ) <EOL> def __modify_dest ( self , method , vip , port , rip , rport = None , <EOL> protocol = socket . IPPROTO_TCP , ** dest_kwargs ) : <EOL> vaf , vaddr = _to_af_union ( vip ) <EOL> raf , raddr = _to_af_union ( rip ) <EOL> rport = rport or port <EOL> out_msg = IpvsMessage ( <EOL> method , flags = netlink . MessageFlags . ACK_REQUEST , <EOL> attr_list = IpvsCmdAttrList ( <EOL> service = IpvsServiceAttrList ( <EOL> af = vaf , <EOL> port = port , <EOL> protocol = protocol , <EOL> addr = vaddr , <EOL> ) , <EOL> dest = IpvsDestAttrList ( <EOL> addr_family = raf , <EOL> addr = raddr , <EOL> port = rport , <EOL> ** dest_kwargs <EOL> ) , <EOL> ) , <EOL> ) <EOL> self . nlsock . execute ( out_msg ) <EOL> @ verbose <EOL> def add_dest ( self , vip , port , rip , rport = None , <EOL> protocol = socket . IPPROTO_TCP , weight = <NUM_LIT:1> , method = IPVS_TUNNELING ) : <EOL> self . __modify_dest ( '<STR_LIT>' , vip , port , rip , rport , <EOL> protocol = protocol , weight = weight , <EOL> fwd_method = method , l_thresh = <NUM_LIT:0> , u_thresh = <NUM_LIT:0> ) <EOL> @ verbose <EOL> def update_dest ( self , vip , port , rip , rport = None , <EOL> protocol = socket . IPPROTO_TCP , weight = None , <EOL> method = IPVS_TUNNELING ) : <EOL> self . __modify_dest ( '<STR_LIT>' , vip , port , rip , rport , protocol , <EOL> weight = weight , l_thresh = <NUM_LIT:0> , u_thresh = <NUM_LIT:0> , <EOL> fwd_method = method ) <EOL> @ verbose <EOL> def del_dest ( self , vip , port , rip , rport = None , <EOL> protocol = socket . IPPROTO_TCP ) : <EOL> self . __modify_dest ( '<STR_LIT>' , vip , port , rip , rport , protocol ) <EOL> def __modify_fwm_dest ( self , method , fwmark , rip , vaf , port , <EOL> ** dest_kwargs ) : <EOL> raf , raddr = _to_af_union ( rip ) <EOL> out_msg = IpvsMessage ( <EOL> method , flags = netlink . MessageFlags . ACK_REQUEST , <EOL> attr_list = IpvsCmdAttrList ( <EOL> service = IpvsServiceAttrList ( <EOL> fwmark = fwmark , <EOL> af = vaf , <EOL> ) , <EOL> dest = IpvsDestAttrList ( <EOL> addr_family = raf , <EOL> addr = raddr , <EOL> port = port , <EOL> ** dest_kwargs <EOL> ) , <EOL> ) , <EOL> ) <EOL> self . nlsock . execute ( out_msg ) <EOL> @ verbose <EOL> def add_fwm_dest ( self , fwmark , rip , vaf = socket . AF_INET , port = <NUM_LIT:0> , weight = <NUM_LIT:1> ) : <EOL> self . __modify_fwm_dest ( '<STR_LIT>' , fwmark , rip , weight = weight , <EOL> port = port , vaf = vaf , l_thresh = <NUM_LIT:0> , u_thresh = <NUM_LIT:0> , <EOL> fwd_method = <NUM_LIT:2> ) <EOL> @ verbose <EOL> def update_fwm_dest ( self , fwmark , rip , vaf = socket . AF_INET , weight = None , <EOL> port = <NUM_LIT:0> ) : <EOL> self . __modify_fwm_dest ( '<STR_LIT>' , fwmark , rip , weight = weight , <EOL> vaf = vaf , port = port , l_thresh = <NUM_LIT:0> , u_thresh = <NUM_LIT:0> , <EOL> fwd_method = <NUM_LIT:2> ) <EOL> @ verbose <EOL> def del_fwm_dest ( self , fwmark , rip , vaf = socket . AF_INET , port = <NUM_LIT:0> ) : <EOL> self . __modify_fwm_dest ( '<STR_LIT>' , fwmark , rip , vaf = vaf , port = port ) <EOL> def flush ( self ) : <EOL> out_msg = IpvsMessage ( '<STR_LIT>' , flags = netlink . MessageFlags . ACK_REQUEST ) <EOL> self . nlsock . execute ( out_msg ) <EOL> def get_pools ( self ) : <EOL> """<STR_LIT>""" <EOL> pools = [ ] <EOL> req = IpvsMessage ( <EOL> '<STR_LIT>' , flags = netlink . MessageFlags . MATCH_ROOT_REQUEST ) <EOL> for msg in self . nlsock . query ( req ) : <EOL> svc_lst = msg . get_attr_list ( ) . get ( '<STR_LIT>' ) <EOL> service = Service . from_attr_list ( svc_lst ) <EOL> dests = self . get_dests ( svc_lst ) <EOL> pools . append ( Pool . from_args ( <EOL> service = service , <EOL> dests = dests <EOL> ) ) <EOL> return pools <EOL> def get_pool ( self , svc_lst ) : <EOL> s = self . get_service ( svc_lst ) <EOL> if s is None : <EOL> return None <EOL> dests = self . get_dests ( s . to_attr_list ( ) ) <EOL> return Pool . from_args ( service = s , dests = dests ) <EOL> def get_service ( self , svc_lst ) : <EOL> out_msg = IpvsMessage ( <EOL> '<STR_LIT>' , flags = netlink . MessageFlags . REQUEST , <EOL> attr_list = IpvsCmdAttrList ( service = svc_lst ) ) <EOL> try : <EOL> res = self . nlsock . query ( out_msg ) <EOL> svc_lst = res [ <NUM_LIT:0> ] . get_attr_list ( ) . get ( '<STR_LIT>' ) <EOL> return Service . from_attr_list ( svc_lst ) <EOL> except RuntimeError : <EOL> return None <EOL> def get_dests ( self , svc_lst ) : <EOL> assert isinstance ( svc_lst , IpvsServiceAttrList ) <EOL> dests = [ ] <EOL> out_msg = IpvsMessage ( <EOL> '<STR_LIT>' , flags = netlink . MessageFlags . MATCH_ROOT_REQUEST , <EOL> attr_list = IpvsCmdAttrList ( service = svc_lst ) <EOL> ) <EOL> try : <EOL> for dst_msg in self . nlsock . query ( out_msg ) : <EOL> dst_lst = dst_msg . get_attr_list ( ) . get ( '<STR_LIT>' ) <EOL> dests . append ( Dest . from_attr_list ( dst_lst , svc_lst . get ( '<STR_LIT>' ) ) ) <EOL> return dests <EOL> except RuntimeError : <EOL> return None </s>
