Ejemplo n.º 1
0
    def testIsIpValid(self):
        addresses = ('10.18.1.254', '10.50.25.177', '250.0.0.1', '20.20.25.25')
        badAddresses = ('192.168.1.256', '10.50.25.1777', '256.0.0.1',
                        '20.20.25.25.25')

        for address in badAddresses:
            with self.assertRaises(neterrors.ConfigNetworkError) \
                    as cneContext:
                IPv4.validateAddress(address)
            self.assertEqual(cneContext.exception.errCode,
                             neterrors.ERR_BAD_ADDR)

        for address in addresses:
            self.assertEqual(IPv4.validateAddress(address), None)
Ejemplo n.º 2
0
    def testIsNetmaskValid(self):
        masks = ('254.0.0.0', '255.255.255.0', '255.255.255.128',
                 '255.255.255.224')
        badMasks = ('192.168.1.0', '10.50.25.17', '255.0.255.0', '253.0.0.0')

        for mask in badMasks:
            with self.assertRaises(neterrors.ConfigNetworkError) \
                    as cneContext:
                IPv4.validateNetmask(mask)
            self.assertEqual(cneContext.exception.errCode,
                             neterrors.ERR_BAD_ADDR)

        for mask in masks:
            self.assertEqual(IPv4.validateNetmask(mask), None)
Ejemplo n.º 3
0
    def testIsNetmaskValid(self):
        masks = ('254.0.0.0', '255.255.255.0', '255.255.255.128',
                 '255.255.255.224')
        badMasks = ('192.168.1.0', '10.50.25.17', '255.0.255.0',
                    '253.0.0.0')

        for mask in badMasks:
            with self.assertRaises(neterrors.ConfigNetworkError) \
                    as cneContext:
                IPv4.validateNetmask(mask)
            self.assertEqual(cneContext.exception.errCode,
                             neterrors.ERR_BAD_ADDR)

        for mask in masks:
            self.assertEqual(IPv4.validateNetmask(mask), None)
Ejemplo n.º 4
0
    def testIsIpValid(self):
        addresses = ('10.18.1.254', '10.50.25.177', '250.0.0.1',
                     '20.20.25.25')
        badAddresses = ('192.168.1.256', '10.50.25.1777', '256.0.0.1',
                        '20.20.25.25.25')

        for address in badAddresses:
            with self.assertRaises(neterrors.ConfigNetworkError) \
                    as cneContext:
                IPv4.validateAddress(address)
            self.assertEqual(cneContext.exception.errCode,
                             neterrors.ERR_BAD_ADDR)

        for address in addresses:
            self.assertEqual(IPv4.validateAddress(address), None)
Ejemplo n.º 5
0
def objectivizeNetwork(bridge=None,
                       vlan=None,
                       bonding=None,
                       bondingOptions=None,
                       nics=None,
                       mtu=None,
                       ipaddr=None,
                       netmask=None,
                       gateway=None,
                       bootproto=None,
                       _netinfo=None,
                       configurator=None,
                       blockingdhcp=None,
                       implicitBonding=None,
                       defaultRoute=None,
                       **opts):
    """
    Constructs an object hierarchy that describes the network configuration
    that is passed in the parameters.

    :param bridge: name of the bridge.
    :param vlan: vlan tag id.
    :param bonding: name of the bond.
    :param bondingOptions: bonding options separated by spaces.
    :param nics: list of nic names.
    :param mtu: the desired network maximum transmission unit.
    :param ipaddr: IPv4 address in dotted decimal format.
    :param netmask: IPv4 mask in dotted decimal format.
    :param gateway: IPv4 address in dotted decimal format.
    :param bootproto: protocol for getting IP config for the net, e.g., 'dhcp'
    :param _netinfo: network information snapshot.
    :param configurator: instance to use to apply the network configuration.
    :param blockingdhcp: whether to acquire dhcp IP config in a synced manner.
    :param implicitBonding: whether the bond's existance is tied to it's
                            master's.
    :param defaultRoute: Should this network's gateway be set in the main
                         routing table?

    :returns: the top object of the hierarchy.
    """
    if configurator is None:
        configurator = Ifcfg()
    if _netinfo is None:
        _netinfo = netinfo.NetInfo()
    if bondingOptions and not bonding:
        raise ConfigNetworkError(
            ne.ERR_BAD_BONDING, 'Bonding options '
            'specified without bonding')
    topNetDev = None
    if bonding:
        topNetDev = Bond.objectivize(bonding, configurator, bondingOptions,
                                     nics, mtu, _netinfo, implicitBonding)
    elif nics:
        try:
            nic, = nics
        except ValueError:
            raise ConfigNetworkError(
                ne.ERR_BAD_BONDING, 'Multiple nics '
                'require a bonding device')
        else:
            bond = _netinfo.getBondingForNic(nic)
            if bond:
                raise ConfigNetworkError(
                    ne.ERR_USED_NIC, 'nic %s already '
                    'enslaved to %s' % (nic, bond))
            topNetDev = Nic(nic, configurator, mtu=mtu, _netinfo=_netinfo)
    if vlan:
        topNetDev = Vlan(topNetDev, vlan, configurator, mtu=mtu)
    if bridge:
        topNetDev = Bridge(bridge,
                           configurator,
                           port=topNetDev,
                           mtu=mtu,
                           stp=opts.get('stp'),
                           forwardDelay=int(opts.get('forward_delay', 0)))
    if topNetDev is None:
        raise ConfigNetworkError(ne.ERR_BAD_PARAMS, 'Network defined without'
                                 'devices.')
    topNetDev.ip = IpConfig(inet=IPv4(ipaddr, netmask, gateway, defaultRoute),
                            bootproto=bootproto,
                            blocking=utils.tobool(blockingdhcp))
    return topNetDev