3
^ @ sh d dl mZ ddlmZ ddlmZ ddlmZmZ edddd gZ G d
d deZ
G dd
d
eZdS ) )
namedtuple )ContextWrapper)DiffResultDescriptor)
DifferenceWrapperZmodified_portconZruleZ
added_contextZremoved_contextc @ s8 e Zd ZdZedZedZedZdd Zdd Z dS )PortconsDifferencez:Determine the difference in portcons between two policies.
diff_portconsc C s | j jdj| | jdd | jj D dd | jj D \| _| _}g | _ x<|D ]4\}}t
|jt
|jkrT| j jt
||j|j qTW dS )z9Generate the difference in portcons between the policies.zGGenerating portcon differences from {0.left_policy} to {0.right_policy}c s s | ]}t |V qd S )N)PortconWrapper).0n r
/usr/lib64/python3.6/portcon.py . s z3PortconsDifference.diff_portcons..c s s | ]}t |V qd S )N)r
)r r r
r
r r / s N)loginfoformatZ _set_diffZleft_policyZportconsZright_policyadded_portconsremoved_portconsmodified_portconsr contextappendmodified_portcon_record)selfZmatched_portconsZleft_portconZ
right_portconr
r
r r ' s
z PortconsDifference.diff_portconsc C s" | j jd d| _d| _d| _dS )z%Reset diff results on policy changes.zResetting portcon differencesN)r debugr r r )r r
r
r _reset_diff> s zPortconsDifference._reset_diffN)
__name__
__module____qualname____doc__r r r r r r r
r
r
r r s r c @ s4 e Zd ZdZdZdd Zdd Zd d
Zdd Zd
S )r
z*Wrap portcon statements for diff purposes.protocollowhighc C s* || _ |j| _|j\| _| _t|| _d S )N)originr Zportsr! r" hashkey)r Zoconr
r
r __init__L s zPortconWrapper.__init__c C s | j S )N)r% )r r
r
r __hash__R s zPortconWrapper.__hash__c C s | j |j k S )N)r# )r otherr
r
r __lt__U s zPortconWrapper.__lt__c C s$ | j |j ko"| j|jko"| j|jkS )N)r r! r" )r r( r
r
r __eq__X s zPortconWrapper.__eq__N)r r! r" ) r r r r __slots__r&