import difflib

'''
Network Management
==================
The network module is used to create and manage network settings, 
interfaces can be set as either managed or ignored. By default 
all interfaces are ignored unless specified.

.. code-block:: yaml

eth0:
  network:
    - managed
    - enabled: True
    - type: eth
    - proto: none
    - ipaddr: 10.1.0.1
    - netmask: 255.255.255.0
    - dns:
      - 8.8.8.8
      - 8.8.4.4
eth2:
  network:
    - managed
    - type: slave
    
eth3:
  network:
    - managed
    - type: slave

bond0:
  network:
    - managed
    - type: bond
    - ipaddr: 10.1.0.1
    - netmask: 255.255.255.0
    - dns:
      - 8.8.8.8
      - 8.8.4.4
    - ipv6:
    - enabled: False
    - watch:
      - network: eth2
      - network: eth3
    - slaves:
      - eth2
      - eth3
    - mode: 802.3ad
    - miimon: 100
    - arp_interval: 250
    - downdelay: 200
    - lacp_rate: fast
    - max_bonds: 1
    - updelay: 0
    - use_carrier: on
    - xmit_hash_policy: layer2
    - mtu: 9000
    - autoneg: on
    - speed: 1000
    - duplex: full
    - offload:
      - rx: on
      - tx: off
      - sg: on
      - tso: off
      - ufo: off
      - gso: off
      - gro: off
      - lro: off
    - vlans:
      - 2
      - 3
      - 10
      - 12                
'''

def managed(
        name,
        type,
        enabled=True,
        **kwargs
        ):
    '''
    Ensure that the named interface is configured properly.
    
    name
        The name of the interface to manage
    
    type
        Type of interface and configuration.
    
    enabled
        Designates the state of this interface.
        
    kwargs
        The IP parameters for this interface.
        
    '''
    
    ret = {
        'name': name,
        'changes': {},
        'result': True,
        'comment': 'Interface {0} is up to date.'.format(name)
    }
           
    # get current iface run through settings filter
    # get proposed iface submit to builder
    # diff iface
    try:
        old = __salt__['network.get'](name)
        new = __salt__['network.build'](name, type, kwargs)
        if not old and new:
            ret['changes']['diff'] = 'Added ifcfg script'
        elif old != new:
            diff = difflib.unified_diff(old, new)
            ret['changes']['diff'] = ''.join(diff)
    except AttributeError, error:
        ret['result'] = False
        ret['comment'] = error.message

    return ret
           

@@ -1082,33 +1082,16 @@
    -
- offload:%0A      -
  rx: on%0A
     
@@ -1082,26 +1082,24 @@
    - rx: on%0A
-  
     - tx: of
@@ -1104,18 +1104,16 @@
 off%0A    
- 
- 
 - sg: on
@@ -1113,18 +1113,16 @@
  sg: on%0A
-  
     - ts
@@ -1132,18 +1132,16 @@
 off%0A    
- 
- 
 - ufo: o
@@ -1139,26 +1139,24 @@
  - ufo: off%0A
-  
     - gso: o
@@ -1162,18 +1162,16 @@
 off%0A    
- 
- 
 - gro: o
@@ -1173,18 +1173,16 @@
 ro: off%0A
-  
     - lr

Change the sls layout some more.