Esempio n. 1
0
def configure_interface():
    """
    Configure an ethernet interface
    """
    iface_name = action_get('iface-name')
    cidr = action_get('cidr')

    # cidr is optional
    if cidr:
        try:
            # Add may fail, but change seems to add or update
            router.ip('address', 'change', cidr, 'dev', iface_name)
        except subprocess.CalledProcessError as e:
            action_fail('Command failed: %s (%s)' %
                        (' '.join(e.cmd), str(e.output)))
            return
        finally:
            remove_state('vpe.configure-interface')
            status_set('active', 'ready!')

    try:
        router.ip('link', 'set', 'dev', iface_name, 'up')
    except subprocess.CalledProcessError as e:
        action_fail('Command failed: %s (%s)' %
                    (' '.join(e.cmd), str(e.output)))
    finally:
        remove_state('vpe.configure-interface')
        status_set('active', 'ready!')
Esempio n. 2
0
def add_corporation():
    '''
    Create and Activate the network corporation
    '''
    domain_name = action_get('domain-name')
    iface_name = action_get('iface-name')
    # HACK: python's list, used deeper, throws an exception on ints in a tuple
    vlan_id = str(action_get('vlan-id'))
    cidr = action_get('cidr')
    area = action_get('area')
    subnet_cidr = action_get('subnet-cidr')
    subnet_area = action_get('subnet-area')

    iface_vlanid = '%s.%s' % (iface_name, vlan_id)

    status_set('maintenance', 'adding corporation {}'.format(domain_name))
    """
    Attempt to run all commands to add the network corporation. If any step
    fails, abort and call `delete_corporation()` to undo.
    """
    try:
        """
        $ ip link add link eth3 name eth3.103 type vlan id 103
        """
        router.ip('link', 'add', 'link', iface_name, 'name', iface_vlanid,
                  'type', 'vlan', 'id', vlan_id)
        """
        $ ip netns add domain
        """
        router.ip('netns', 'add', domain_name)
        """
        $ ip link set dev eth3.103 netns corpB
        """
        router.ip('link', 'set', 'dev', iface_vlanid, 'netns', domain_name)
        """
        $ ifconfig eth3 up
        """
        router._run(['ifconfig', iface_name, 'up'])
        """
        $ ip netns exec corpB ip link set dev eth3.103 up
        """
        router.ip('netns', 'exec', domain_name, 'ip', 'link', 'set', 'dev',
                  iface_vlanid, 'up')
        """
        $ ip netns exec corpB ip address add 10.0.1.1/24 dev eth3.103
        """
        mask = cidr.split("/")[1]
        ip = '%s/%s' % (area, mask)
        router.ip('netns', 'exec', domain_name, 'ip', 'address', 'add', ip,
                  'dev', iface_vlanid)

        configure_ospf(domain_name, cidr, area, subnet_cidr, subnet_area, True)

    except subprocess.CalledProcessError as e:
        delete_corporation()
        action_fail('Command failed: %s (%s)' %
                    (' '.join(e.cmd), str(e.output)))
    finally:
        remove_state('vpe.add-corporation')
        status_set('active', 'ready!')
Esempio n. 3
0
def delete_domain_connection():
    ''' Remove the tunnel to another router where the domain is present '''
    domain = action_get('domain-name')
    tunnel_name = action_get('tunnel-name')

    status_set('maintenance', 'deleting domain connection: {}'.format(domain))

    """
    $ ip netns exec domain_name ip link set tunnel_name down
    """
    router.ip('netns',
              'exec',
              domain,
              'ip',
              'link',
              'set',
              tunnel_name,
              'down')

    """
    $ ip netns exec domain_name ip tunnel del tunnel_name
    """
    router.ip('netns',
              'exec',
              domain,
              'ip',
              'tunnel',
              'del',
              tunnel_name)

    status_set('active', 'ready!')
Esempio n. 4
0
def configure_interface():
    """
    Configure an ethernet interface
    """
    iface_name = action_get('iface-name')
    cidr = action_get('cidr')

    # cidr is optional
    if cidr:
        try:
            # Add may fail, but change seems to add or update
            router.ip('address', 'change', cidr, 'dev', iface_name)
        except subprocess.CalledProcessError as e:
            action_fail('Command failed: %s (%s)' %
                        (' '.join(e.cmd), str(e.output)))
            return
        finally:
            remove_state('vpe.configure-interface')
            status_set('active', 'ready!')

    try:
        router.ip('link', 'set', 'dev', iface_name, 'up')
    except subprocess.CalledProcessError as e:
        action_fail('Command failed: %s (%s)' %
                    (' '.join(e.cmd), str(e.output)))
    finally:
        remove_state('vpe.configure-interface')
        status_set('active', 'ready!')
Esempio n. 5
0
def delete_domain_connection():
    ''' Remove the tunnel to another router where the domain is present '''
    domain = action_get('domain-name')
    tunnel_name = action_get('tunnel-name')

    status_set('maintenance', 'deleting domain connection: {}'.format(domain))

    try:

        try:
            """
            $ ip netns exec domain_name ip link set tunnel_name down
            """
            router.ip('netns', 'exec', domain, 'ip', 'link', 'set',
                      tunnel_name, 'down')
        except subprocess.CalledProcessError as e:
            action_fail('Command failed: %s (%s)' %
                        (' '.join(e.cmd), str(e.output)))

        try:
            """
            $ ip netns exec domain_name ip tunnel del tunnel_name
            """
            router.ip('netns', 'exec', domain, 'ip', 'tunnel', 'del',
                      tunnel_name)
        except subprocess.CalledProcessError as e:
            action_fail('Command failed: %s (%s)' %
                        (' '.join(e.cmd), str(e.output)))
    except:
        pass
    finally:
        remove_state('vpe.delete-domain-connection')
        status_set('active', 'ready!')
Esempio n. 6
0
def delete_domain_connection():
    ''' Remove the tunnel to another router where the domain is present '''
    domain = action_get('domain-name')
    tunnel_name = action_get('tunnel-name')

    status_set('maintenance', 'deleting domain connection: {}'.format(domain))

    try:

        try:
            """
            $ ip netns exec domain_name ip link set tunnel_name down
            """
            router.ip('netns',
                      'exec',
                      domain,
                      'ip',
                      'link',
                      'set',
                      tunnel_name,
                      'down')
        except subprocess.CalledProcessError as e:
            action_fail('Command failed: %s (%s)' %
                        (' '.join(e.cmd), str(e.output)))

        try:
            """
            $ ip netns exec domain_name ip tunnel del tunnel_name
            """
            router.ip('netns',
                      'exec',
                      domain,
                      'ip',
                      'tunnel',
                      'del',
                      tunnel_name)
        except subprocess.CalledProcessError as e:
            action_fail('Command failed: %s (%s)' %
                        (' '.join(e.cmd), str(e.output)))
    except:
        pass
    finally:
        remove_state('vpe.delete-domain-connection')
        status_set('active', 'ready!')
Esempio n. 7
0
def delete_domain_connection():
    ''' Remove the tunnel to another router where the domain is present '''
    domain = action_get('domain-name')
    tunnel_name = action_get('tunnel-name')

    # ip netns exec domain_name ip link set tunnel_name down
    router.ip('netns',
              'exec',
              domain,
              'ip',
              'link',
              'set',
              tunnel_name,
              'down')

    # ip netns exec domain_name ip tunnel del tunnel_name
    router.ip('netns',
              'exec',
              domain,
              'ip',
              'tunnel',
              'del',
              tunnel_name)
Esempio n. 8
0
def delete_corporation():

    domain_name = action_get('domain-name')
    cidr = action_get('cidr')
    area = action_get('area')
    subnet_cidr = action_get('subnet-cidr')
    subnet_area = action_get('subnet-area')

    status_set('maintenance', 'deleting corporation {}'.format(domain_name))

    try:
        """
        Remove all tunnels defined for this domain

        $ ip netns exec domain_name ip tun show
            | grep gre
            | grep -v "remote any"
            | cut -d":" -f1
        """
        p = router.ip('netns', 'exec', domain_name, 'ip', 'tun', 'show', '|',
                      'grep', 'gre', '|', 'grep', '-v', '"remote any"', '|',
                      'cut -d":" -f1')

        # `p` should be a tuple of (stdout, stderr)
        tunnels = p[0].split('\n')

        for tunnel in tunnels:
            try:
                """
                $ ip netns exec domain_name ip link set $tunnel_name down
                """
                router.ip('netns', 'exec', domain_name, 'ip', 'link', 'set',
                          tunnel, 'down')
            except subprocess.CalledProcessError as e:
                log('Command failed: %s (%s)' %
                    (' '.join(e.cmd), str(e.output)))
                pass

            try:
                """
                $ ip netns exec domain_name ip tunnel del $tunnel_name
                """
                router.ip('netns', 'exec', domain_name, 'ip', 'tunnel', 'del',
                          tunnel)
            except subprocess.CalledProcessError as e:
                log('Command failed: %s (%s)' %
                    (' '.join(e.cmd), str(e.output)))
                pass
        """
        Remove all interfaces associated to the domain

        $ ip netns exec domain_name ifconfig | grep mtu | cut -d":" -f1
        """
        p = router.ip('netns', 'exec', domain_name, 'ifconfig', '|',
                      'grep mtu', '|', 'cut -d":" -f1')

        ifaces = p[0].split('\n')
        for iface in ifaces:

            try:
                """
                $ ip netns exec domain_name ip link set $iface down
                """
                router.ip('netns', 'exec', domain_name, 'ip', 'link', 'set',
                          iface, 'down')
            except subprocess.CalledProcessError as e:
                log('Command failed: %s (%s)' %
                    (' '.join(e.cmd), str(e.output)))

            try:
                """
                $ ifconfig eth3 down
                """
                router._run(['ifconfig', iface, 'down'])
            except subprocess.CalledProcessError as e:
                log('Command failed: %s (%s)' %
                    (' '.join(e.cmd), str(e.output)))
                pass

            try:
                """
                $ ip link del dev $iface
                """
                router.ip('link', 'del', 'dev', iface)
            except subprocess.CalledProcessError as e:
                log('Command failed: %s (%s)' %
                    (' '.join(e.cmd), str(e.output)))
                pass

        try:
            """
            Remove the domain

            $ ip netns del domain_name
            """
            router.ip('netns', 'del', domain_name)
        except subprocess.CalledProcessError as e:
            log('Command failed: %s (%s)' % (' '.join(e.cmd), str(e.output)))
            pass

        try:
            configure_ospf(domain_name, cidr, area, subnet_cidr, subnet_area,
                           False)
        except subprocess.CalledProcessError as e:
            action_fail('Command failed: %s (%s)' %
                        (' '.join(e.cmd), str(e.output)))

    except:
        # Do nothing
        log('delete-corporation failed.')
        pass

    finally:
        remove_state('vpe.delete-corporation')
        status_set('active', 'ready!')
Esempio n. 9
0
def connect_domains():

    params = [
        'domain-name',
        'iface-name',
        'tunnel-name',
        'local-ip',
        'remote-ip',
        'tunnel-key',
        'internal-local-ip',
        'internal-remote-ip',
        'tunnel-type',
    ]

    config = {}
    for p in params:
        config[p] = action_get(p)

    status_set('maintenance', 'connecting domains')

    try:
        """
        $ ip tunnel add tunnel_name mode gre local local_ip remote remote_ip
            dev iface_name key tunnel_key csum
        """
        router.ip(
            'tunnel',
            'add',
            config['tunnel-name'],
            'mode',
            config['tunnel-type'],
            'local',
            config['local-ip'],
            'remote',
            config['remote-ip'],
            'dev',
            config['iface-name'],
            'key',
            config['tunnel-key'],
            'csum'
        )

    except subprocess.CalledProcessError as e:
        log('Command failed (retrying with ip tunnel change): %s (%s)' %
            (' '.join(e.cmd), str(e.output)))
        try:
            """
            If the tunnel already exists (like gre0) and can't be deleted,
            modify it instead of trying to add it.
            """
            router.ip(
                'tunnel',
                'change',
                config['tunnel-name'],
                'mode',
                config['tunnel-type'],
                'local',
                config['local-ip'],
                'remote',
                config['remote-ip'],
                'dev',
                config['iface-name'],
                'key',
                config['tunnel-key'],
                'csum'
            )
        except subprocess.CalledProcessError as e:
            delete_domain_connection()
            action_fail('Command failed: %s (%s)' %
                        (' '.join(e.cmd), str(e.output)))
        finally:
            remove_state('vpe.connect-domains')
            status_set('active', 'ready!')

    try:
        """
        $ ip link set dev tunnel_name netns domain_name
        """
        router.ip(
            'link',
            'set',
            'dev',
            config['tunnel-name'],
            'netns',
            config['domain-name']
        )

        """
        $ ip netns exec domain_name ip link set dev tunnel_name up
        """
        router.ip(
            'netns',
            'exec',
            config['domain-name'],
            'ip',
            'link',
            'set',
            'dev',
            config['tunnel-name'],
            'up'
        )

        """
        $ ip netns exec domain_name ip address add internal_local_ip peer
            internal_remote_ip dev tunnel_name
        """
        router.ip(
            'netns',
            'exec',
            config['domain-name'],
            'ip',
            'address',
            'add',
            config['internal-local-ip'],
            'peer',
            config['internal-remote-ip'],
            'dev',
            config['tunnel-name']
        )
    except subprocess.CalledProcessError as e:
        delete_domain_connection()
        action_fail('Command failed: %s (%s)' %
                    (' '.join(e.cmd), str(e.output)))
    finally:
        remove_state('vpe.connect-domains')
        status_set('active', 'ready!')
Esempio n. 10
0
def connect_domains():

    params = [
        'domain-name',
        'iface-name',
        'tunnel-name',
        'local-ip',
        'remote-ip',
        'tunnel-key',
        'internal-local-ip',
        'internal-remote-ip',
        'tunnel-type'
    ]

    config = {}
    for p in params:
        config[p] = action_get(p)

    status_set('maintenance', 'connecting domains')

    """
    $ ip tunnel add tunnel_name mode gre local local_ip remote remote_ip dev
        iface_name key tunnel_key csum
    """
    router.ip(
        'tunnel',
        'add',
        config['tunnel-name'],
        'mode',
        config['tunnel-type'],
        'local',
        config['local-ip'],
        'remote',
        config['remote-ip'],
        'dev',
        config['iface-name'],
        'key',
        config['tunnel-key'],
        'csum'
    )

    """
    $ ip link set dev tunnel_name netns domain_name
    """
    router.ip(
        'link',
        'set',
        'dev',
        config['tunnel-name'],
        'netns',
        config['domain-name']
    )

    """
    $ ip netns exec domain_name ip link set dev tunnel_name up
    """
    router.ip(
        'netns',
        'exec',
        config['domain-name'],
        'ip',
        'link',
        'set',
        'dev',
        config['tunnel-name'],
        'up'
    )

    """
    $ ip netns exec domain_name ip address add internal_local_ip peer
        internal_remote_ip dev tunnel_name
    """
    router.ip(
        'netns',
        'exec',
        config['domain-name'],
        'ip',
        'address',
        'add',
        config['internal-local-ip'],
        'peer',
        config['internal-remote-ip'],
        'dev',
        config['tunnel-name']
    )
    status_set('active', 'ready!')
Esempio n. 11
0
def add_corporation():
    '''
    Create and Activate the network corporation
    '''
    domain_name = action_get('domain-name')
    iface_name = action_get('iface-name')
    # HACK: python's list, used deeper, throws an exception on ints in a tuple
    vlan_id = str(action_get('vlan-id'))
    cidr = action_get('cidr')
    area = action_get('area')
    subnet_cidr = action_get('subnet-cidr')
    subnet_area = action_get('subnet-area')

    iface_vlanid = '%s.%s' % (iface_name, vlan_id)

    status_set('maintenance', 'adding corporation {}'.format(domain_name))

    """
    Attempt to run all commands to add the network corporation. If any step
    fails, abort and call `delete_corporation()` to undo.
    """
    try:
        """
        $ ip link add link eth3 name eth3.103 type vlan id 103
        """
        router.ip('link',
                  'add',
                  'link',
                  iface_name,
                  'name',
                  iface_vlanid,
                  'type',
                  'vlan',
                  'id',
                  vlan_id)

        """
        $ ip netns add domain
        """
        router.ip('netns',
                  'add',
                  domain_name)

        """
        $ ip link set dev eth3.103 netns corpB
        """
        router.ip('link',
                  'set',
                  'dev',
                  iface_vlanid,
                  'netns',
                  domain_name)

        """
        $ ifconfig eth3 up
        """
        router._run(['ifconfig', iface_name, 'up'])

        """
        $ ip netns exec corpB ip link set dev eth3.103 up
        """
        router.ip('netns',
                  'exec',
                  domain_name,
                  'ip',
                  'link',
                  'set',
                  'dev',
                  iface_vlanid,
                  'up')

        """
        $ ip netns exec corpB ip address add 10.0.1.1/24 dev eth3.103
        """
        mask = cidr.split("/")[1]
        ip = '%s/%s' % (area, mask)
        router.ip('netns',
                  'exec',
                  domain_name,
                  'ip',
                  'address',
                  'add',
                  ip,
                  'dev',
                  iface_vlanid)

        configure_ospf(domain_name, cidr, area, subnet_cidr, subnet_area, True)

    except subprocess.CalledProcessError as e:
        delete_corporation()
        action_fail('Command failed: %s (%s)' %
                    (' '.join(e.cmd), str(e.output)))
    finally:
        remove_state('vpe.add-corporation')
        status_set('active', 'ready!')
Esempio n. 12
0
def delete_corporation():

    domain_name = action_get('domain-name')

    # Remove all tunnels defined for this domain
    p = router.ip(
        'netns',
        'exec',
        'domain_name',
        'ip',
        'tun',
        'show',
        '|',
        'grep',
        'gre',
        '|',
        'grep',
        '-v',
        '"remote any"',
        '|',
        'cut -d":" -f1'
    )

    # `p` should be a tuple of (stdout, stderr)
    tunnels = p[0]

    for tunnel in tunnels:
        router.ip(
            'netns',
            'exec',
            domain_name,
            'ip',
            'link',
            'set',
            tunnel,
            'down'
        )

        router.ip(
            'netns',
            'exec',
            domain_name,
            'ip',
            'tunnel',
            'del',
            tunnel
        )

    # Remove all interfaces associated to the domain
    p = router.ip(
        'netns',
        'exec',
        'domain_name',
        'ifconfig',
        '|',
        'grep mtu',
        '|',
        'cut -d":" -f1'
    )

    ifaces = p[0]
    for iface in ifaces:

        # ip netns exec domain_name ip link set $iface down
        router.ip(
            'netns',
            'exec',
            domain_name,
            'ip',
            'link',
            'set',
            iface,
            'down'
        )

        # ip link del dev $iface
        router.ip(
            'link',
            'del',
            'dev',
            iface
        )

    # Remove the domain
    # ip netns del domain_name
    router.ip(
        'netns',
        'del',
        domain_name
    )
Esempio n. 13
0
def add_corporation():
    '''
    Create and Activate the network corporation
    '''

    domain_name = action_get('domain_name')
    iface_name = action_get('iface_name')
    vlan_id = action_get('vlan_id')
    cidr = action_get('cidr')

    missing = []
    for item in [domain_name, iface_name, vlan_id, cidr]:
        if not item:
            missing.append(item)

    if len(missing) > 0:
        log('CRITICAL', 'Unable to complete operation due to missing required'
            'param: {}'.format('item'))

    iface_vlanid = '%s.%s' % (iface_name, vlan_id)

    status_set('maintenance', 'Adding corporation {}'.format(domain_name))

    # ip link add link iface_name domain_name vlan_id type vlan id vlan_id
    router.ip('link',
              'add',
              'link',
              iface_name,
              domain_name,
              vlan_id,
              'type',
              'vlan',
              'id',
              vlan_id)

    # ip link set dev iface_vlanid netns domain_name
    router.ip('link',
              'set',
              'dev',
              iface_vlanid,
              'netns',
              domain_name)

    # ip netns exec domain_name ip link set dev iface_vlanid up
    router.ip('netns',
              'exec',
              domain_name,
              'ip',
              'link',
              'set',
              'dev',
              iface_vlanid,
              'up')

    # ip netns exec domain_name ip address add cidr dev iface_vlanid
    router.ip('netns',
              'exec',
              domain_name,
              'ip',
              'address',
              'add',
              cidr,
              'dev',
              iface_vlanid)
Esempio n. 14
0
def connect_domains():
    params = [
        'domain-name',
        'iface-name',
        'tunnel-name',
        'local-ip',
        'remote-ip',
        'tunnel-key',
        'internal-local-ip',
        'internal-remote-ip',
        'tunnel-type'
    ]
    config = {}
    for p in params:
        config[p] = action_get(p)
        if not config[p]:
            return action_fail('Missing required value for parameter %s' % p)

    # ip tunnel add tunnel_name mode gre local local_ip remote remote_ip dev
    #    iface_name key tunnel_key csum
    router.ip(
        'tunnel',
        'add',
        config['tunnel-name'],
        'mode',
        config['tunnel-type'],
        'local',
        config['local-ip'],
        'remote',
        config['remote-ip'],
        'dev',
        config['iface-name'],
        'key',
        config['tunnel-key'],
        'csum'
    )
    # ip link set dev tunnel_name netns domain_name
    router.ip(
        'link',
        'set',
        'dev',
        config['tunnel-name'],
        'up'
    )

    # ip netns exec domain_name ip link set dev tunnel_name up
    router.ip(
        'netns',
        'exec',
        config['domain-name'],
        'ip',
        'link',
        'set',
        'dev',
        config['tunnel-name'],
        'up'
    )

    # ip netns exec domain_name ip address add internal_local_ip peer \
    # internal_remote_ip dev tunnel_name
    router.ip(
        'netns',
        'exec',
        config['domain-name'],
        'ip',
        'address',
        'add',
        config['internal-local-ip'],
        'peer',
        config['internal-remote-ip'],
        'dev',
        config['tunnel-name']
    )
Esempio n. 15
0
def add_corporation():
    '''
    Create and Activate the network corporation
    '''

    domain_name = action_get('domain-name')
    iface_name = action_get('iface-name')
    # HACK: python's list, used deeper, throws an exception on ints in a tuple
    vlan_id = str(action_get('vlan-id'))
    cidr = action_get('cidr')

    iface_vlanid = '%s.%s' % (iface_name, vlan_id)

    status_set('maintenance', 'adding corporation {}'.format(domain_name))

    """
    $ ip link add link eth3 name eth3.103 type vlan id 103
    """
    router.ip('link',
              'add',
              'link',
              iface_name,
              'name',
              iface_vlanid,
              'type',
              'vlan',
              'id',
              vlan_id)


    """
    $ ip netns add domain
    """
    router.ip('netns',
              'add',
              domain_name)

    """
    $ ip link set dev eth3.103 netns corpB
    """
    router.ip('link',
              'set',
              'dev',
              iface_vlanid,
              'netns',
              domain_name)

    """
    $ ip netns exec corpB ip link set dev eth3.103 up
    """
    router.ip('netns',
              'exec',
              domain_name,
              'ip',
              'link',
              'set',
              'dev',
              iface_vlanid,
              'up')

    """
    $ ip netns exec corpB ip address add 10.0.1.1/24 dev eth3.103
    """
    router.ip('netns',
              'exec',
              domain_name,
              'ip',
              'address',
              'add',
              cidr,
              'dev',
              iface_vlanid)
    status_set('active', 'ready!')
Esempio n. 16
0
def connect_domains():

    params = [
        'domain-name',
        'iface-name',
        'tunnel-name',
        'local-ip',
        'remote-ip',
        'tunnel-key',
        'internal-local-ip',
        'internal-remote-ip',
        'tunnel-type',
    ]

    config = {}
    for p in params:
        config[p] = action_get(p)

    status_set('maintenance', 'connecting domains')

    try:
        """
        $ ip tunnel add tunnel_name mode gre local local_ip remote remote_ip
            dev iface_name key tunnel_key csum
        """
        router.ip('tunnel', 'add', config['tunnel-name'], 'mode',
                  config['tunnel-type'], 'local', config['local-ip'], 'remote',
                  config['remote-ip'], 'dev', config['iface-name'], 'key',
                  config['tunnel-key'], 'csum')

    except subprocess.CalledProcessError as e:
        log('Command failed (retrying with ip tunnel change): %s (%s)' %
            (' '.join(e.cmd), str(e.output)))
        try:
            """
            If the tunnel already exists (like gre0) and can't be deleted,
            modify it instead of trying to add it.
            """
            router.ip('tunnel', 'change', config['tunnel-name'], 'mode',
                      config['tunnel-type'], 'local', config['local-ip'],
                      'remote', config['remote-ip'], 'dev',
                      config['iface-name'], 'key', config['tunnel-key'],
                      'csum')
        except subprocess.CalledProcessError as e:
            delete_domain_connection()
            action_fail('Command failed: %s (%s)' %
                        (' '.join(e.cmd), str(e.output)))
        finally:
            remove_state('vpe.connect-domains')
            status_set('active', 'ready!')

    try:
        """
        $ ip link set dev tunnel_name netns domain_name
        """
        router.ip('link', 'set', 'dev', config['tunnel-name'], 'netns',
                  config['domain-name'])
        """
        $ ip netns exec domain_name ip link set dev tunnel_name up
        """
        router.ip('netns', 'exec', config['domain-name'], 'ip', 'link', 'set',
                  'dev', config['tunnel-name'], 'up')
        """
        $ ip netns exec domain_name ip address add internal_local_ip peer
            internal_remote_ip dev tunnel_name
        """
        router.ip('netns', 'exec', config['domain-name'], 'ip', 'address',
                  'add', config['internal-local-ip'], 'peer',
                  config['internal-remote-ip'], 'dev', config['tunnel-name'])
    except subprocess.CalledProcessError as e:
        delete_domain_connection()
        action_fail('Command failed: %s (%s)' %
                    (' '.join(e.cmd), str(e.output)))
    finally:
        remove_state('vpe.connect-domains')
        status_set('active', 'ready!')
Esempio n. 17
0
def delete_corporation():

    domain_name = action_get('domain-name')
    cidr = action_get('cidr')
    area = action_get('area')
    subnet_cidr = action_get('subnet-cidr')
    subnet_area = action_get('subnet-area')

    status_set('maintenance', 'deleting corporation {}'.format(domain_name))

    try:
        """
        Remove all tunnels defined for this domain

        $ ip netns exec domain_name ip tun show
            | grep gre
            | grep -v "remote any"
            | cut -d":" -f1
        """
        p = router.ip(
            'netns',
            'exec',
            domain_name,
            'ip',
            'tun',
            'show',
            '|',
            'grep',
            'gre',
            '|',
            'grep',
            '-v',
            '"remote any"',
            '|',
            'cut -d":" -f1'
        )

        # `p` should be a tuple of (stdout, stderr)
        tunnels = p[0].split('\n')

        for tunnel in tunnels:
            try:
                """
                $ ip netns exec domain_name ip link set $tunnel_name down
                """
                router.ip(
                    'netns',
                    'exec',
                    domain_name,
                    'ip',
                    'link',
                    'set',
                    tunnel,
                    'down'
                )
            except subprocess.CalledProcessError as e:
                log('Command failed: %s (%s)' %
                    (' '.join(e.cmd), str(e.output)))
                pass

            try:
                """
                $ ip netns exec domain_name ip tunnel del $tunnel_name
                """
                router.ip(
                    'netns',
                    'exec',
                    domain_name,
                    'ip',
                    'tunnel',
                    'del',
                    tunnel
                )
            except subprocess.CalledProcessError as e:
                log('Command failed: %s (%s)' %
                    (' '.join(e.cmd), str(e.output)))
                pass

        """
        Remove all interfaces associated to the domain

        $ ip netns exec domain_name ifconfig | grep mtu | cut -d":" -f1
        """
        p = router.ip(
            'netns',
            'exec',
            domain_name,
            'ifconfig',
            '|',
            'grep mtu',
            '|',
            'cut -d":" -f1'
        )

        ifaces = p[0].split('\n')
        for iface in ifaces:

            try:
                """
                $ ip netns exec domain_name ip link set $iface down
                """
                router.ip(
                    'netns',
                    'exec',
                    domain_name,
                    'ip',
                    'link',
                    'set',
                    iface,
                    'down'
                )
            except subprocess.CalledProcessError as e:
                log('Command failed: %s (%s)' %
                    (' '.join(e.cmd), str(e.output)))

            try:
                """
                $ ifconfig eth3 down
                """
                router._run(['ifconfig', iface, 'down'])
            except subprocess.CalledProcessError as e:
                log('Command failed: %s (%s)' %
                    (' '.join(e.cmd), str(e.output)))
                pass

            try:
                """
                $ ip link del dev $iface
                """
                router.ip(
                    'link',
                    'del',
                    'dev',
                    iface
                )
            except subprocess.CalledProcessError as e:
                log('Command failed: %s (%s)' %
                    (' '.join(e.cmd), str(e.output)))
                pass

        try:
            """
            Remove the domain

            $ ip netns del domain_name
            """
            router.ip(
                'netns',
                'del',
                domain_name
            )
        except subprocess.CalledProcessError as e:
            log('Command failed: %s (%s)' % (' '.join(e.cmd), str(e.output)))
            pass

        try:
            configure_ospf(domain_name,
                           cidr,
                           area,
                           subnet_cidr,
                           subnet_area,
                           False)
        except subprocess.CalledProcessError as e:
            action_fail('Command failed: %s (%s)' %
                        (' '.join(e.cmd), str(e.output)))

    except:
        # Do nothing
        log('delete-corporation failed.')
        pass

    finally:
        remove_state('vpe.delete-corporation')
        status_set('active', 'ready!')
Esempio n. 18
0
def delete_corporation():

    domain_name = action_get('domain-name')

    status_set('maintenance', 'deleting corporation {}'.format(domain_name))

    """
    Remove all tunnels defined for this domain

    $ ip netns exec domain_name ip tun show
        | grep gre
        | grep -v "remote any"
        | cut -d":" -f1`
    """
    p = router.ip(
        'netns',
        'exec',
        domain_name,
        'ip',
        'tun',
        'show',
        '|',
        'grep',
        'gre',
        '|',
        'grep',
        '-v',
        '"remote any"',
        '|',
        'cut -d":" -f1'
    )

    # `p` should be a tuple of (stdout, stderr)
    tunnels = p[0].split('\n')

    for tunnel in tunnels:
        """
        $ ip netns exec domain_name ip link set $tunnel_name down
        """
        router.ip(
            'netns',
            'exec',
            domain_name,
            'ip',
            'link',
            'set',
            tunnel,
            'down'
        )

        """
        $ ip netns exec domain_name ip tunnel del $tunnel_name
        """
        router.ip(
            'netns',
            'exec',
            domain_name,
            'ip',
            'tunnel',
            'del',
            tunnel
        )

    """
    Remove all interfaces associated to the domain

    $ ip netns exec domain_name ifconfig | grep mtu | cut -d":" -f1
    """
    p = router.ip(
        'netns',
        'exec',
        domain_name,
        'ifconfig',
        '|',
        'grep mtu',
        '|',
        'cut -d":" -f1'
    )

    ifaces = p[0].split('\n')
    for iface in ifaces:

        """
        $ ip netns exec domain_name ip link set $iface down
        """
        router.ip(
            'netns',
            'exec',
            domain_name,
            'ip',
            'link',
            'set',
            iface,
            'down'
        )

        """
        $ ip link del dev $iface
        """
        router.ip(
            'link',
            'del',
            'dev',
            iface
        )

    """
    Remove the domain

    $ ip netns del domain_name
    """
    router.ip(
        'netns',
        'del',
        domain_name
    )
    status_set('active', 'ready!')