#NEWLINE# def insert( table = 'filter' , chain = None , position = None , rule = None , family = 'ipv4' ) : #NEWLINE# #INDENT# "\n    Insert a rule into the specified table/chain, at the specified position.\n\n    This function accepts a rule in a standard iptables command format,\n        starting with the chain. Trying to force users to adapt to a new\n        method of creating rules would be irritating at best, and we\n        already have a parser that can handle it.\n\n    If the position specified is a negative number, then the insert will be\n        performed counting from the end of the list. For instance, a position\n        of -1 will insert the rule as the second to last rule. To insert a rule\n        in the last position, use the append function instead.\n\n    CLI Examples:\n\n    .. code-block:: bash\n\n        salt '*' iptables.insert filter INPUT position=3 \\\n            rule='-m state --state RELATED,ESTABLISHED -j ACCEPT'\n\n        IPv6:\n        salt '*' iptables.insert filter INPUT position=3 \\\n            rule='-m state --state RELATED,ESTABLISHED -j ACCEPT' \\\n            family=ipv6\n    " #NEWLINE# if ( not chain ) : #NEWLINE# #INDENT# return 'Error: Chain needs to be specified' #NEWLINE# #UNINDENT# if ( not position ) : #NEWLINE# #INDENT# return 'Error: Position needs to be specified or use append (-A)' #NEWLINE# #UNINDENT# if ( not rule ) : #NEWLINE# #INDENT# return 'Error: Rule needs to be specified' #NEWLINE# #UNINDENT# if ( position < 0 ) : #NEWLINE# #INDENT# rules = get_rules ( family = family ) #NEWLINE# size = len ( rules [ table ] [ chain ] [ 'rules' ] ) #NEWLINE# position = ( ( size + position ) + 1 ) #NEWLINE# if ( position is 0 ) : #NEWLINE# #INDENT# position = 1 #NEWLINE# #UNINDENT# #UNINDENT# wait = ( '--wait' if _has_option ( '--wait' , family ) else '' ) #NEWLINE# returnCheck = check ( table , chain , rule , family ) #NEWLINE# if ( isinstance ( returnCheck , bool ) and returnCheck ) : #NEWLINE# #INDENT# return False #NEWLINE# #UNINDENT# cmd = '{0} {1} -t {2} -I {3} {4} {5}' . format ( _iptables_cmd ( family ) , wait , table , chain , rules , rule ) #NEWLINE# out = __salt__ [ 'cmd.run' ] ( cmd ) #NEWLINE# return out