コード例 #1
0
ファイル: configNetwork.py プロジェクト: doronunu/vdsm
def addNetwork(network, vlan=None, bonding=None, nics=None, ipaddr=None,
               netmask=None, prefix=None, mtu=None, gateway=None,
               ipv6addr=None, ipv6gateway=None, force=False,
               configurator=None, bondingOptions=None, bridged=True,
               _netinfo=None, qosInbound=None, qosOutbound=None, **options):
    nics = nics or ()
    if _netinfo is None:
        _netinfo = netinfo.NetInfo()
    bridged = utils.tobool(bridged)
    vlan = _vlanToInternalRepresentation(vlan)

    if mtu:
        mtu = int(mtu)

    if prefix:
        if netmask:
            raise ConfigNetworkError(ne.ERR_BAD_PARAMS,
                                     'Both PREFIX and NETMASK supplied')
        else:
            try:
                netmask = netinfo.prefix2netmask(int(prefix))
            except ValueError as ve:
                raise ConfigNetworkError(ne.ERR_BAD_ADDR, "Bad prefix: %s" %
                                         ve)

    if not utils.tobool(force):
        logging.debug('validating network...')
        if network in _netinfo.networks:
            raise ConfigNetworkError(ne.ERR_USED_BRIDGE,
                                     'Network already exists')
        if bonding:
            _validateInterNetworkCompatibility(_netinfo, vlan, bonding,
                                               bridged)
        else:
            for nic in nics:
                _validateInterNetworkCompatibility(_netinfo, vlan, nic,
                                                   bridged)

    logging.info("Adding network %s with vlan=%s, bonding=%s, nics=%s,"
                 " bondingOptions=%s, mtu=%s, bridged=%s, options=%s",
                 network, vlan, bonding, nics, bondingOptions,
                 mtu, bridged, options)

    if configurator is None:
        configurator = Ifcfg()

    bootproto = options.pop('bootproto', None)

    defaultRoute = network == constants.MANAGEMENT_NETWORK

    netEnt = objectivizeNetwork(network if bridged else None, vlan, bonding,
                                bondingOptions, nics, mtu, ipaddr, netmask,
                                gateway, bootproto, ipv6addr, ipv6gateway,
                                _netinfo=_netinfo, configurator=configurator,
                                defaultRoute=defaultRoute, **options)

    netEnt.configure(**options)
    configurator.configureLibvirtNetwork(network, netEnt,
                                         qosInbound=qosInbound,
                                         qosOutbound=qosOutbound)
コード例 #2
0
ファイル: configNetwork.py プロジェクト: hackxay/vdsm
def addNetwork(network, vlan=None, bonding=None, nics=None, ipaddr=None,
               netmask=None, prefix=None, mtu=None, gateway=None, force=False,
               configurator=None, bondingOptions=None, bridged=True,
               _netinfo=None, qosInbound=None, qosOutbound=None, **options):
    nics = nics or ()
    if _netinfo is None:
        _netinfo = netinfo.NetInfo()
    bridged = utils.tobool(bridged)

    if mtu:
        mtu = int(mtu)

    if prefix:
        if netmask:
            raise ConfigNetworkError(ne.ERR_BAD_PARAMS,
                                     'Both PREFIX and NETMASK supplied')
        else:
            try:
                netmask = netinfo.prefix2netmask(int(prefix))
            except ValueError as ve:
                raise ConfigNetworkError(ne.ERR_BAD_ADDR, "Bad prefix: %s" %
                                         ve)

    if not utils.tobool(force):
        logging.debug('validating network...')
        if network in _netinfo.networks:
            raise ConfigNetworkError(ne.ERR_USED_BRIDGE,
                                     'Network already exists')
        if bonding:
            _validateInterNetworkCompatibility(_netinfo, vlan, bonding,
                                               bridged)
        else:
            for nic in nics:
                _validateInterNetworkCompatibility(_netinfo, vlan, nic,
                                                   bridged)
    logging.info("Adding network %s with vlan=%s, bonding=%s, nics=%s,"
                 " bondingOptions=%s, mtu=%s, bridged=%s, options=%s",
                 network, vlan, bonding, nics, bondingOptions,
                 mtu, bridged, options)

    if configurator is None:
        configurator = Ifcfg()

    bootproto = options.pop('bootproto', None)

    netEnt = objectivizeNetwork(network if bridged else None, vlan, bonding,
                                bondingOptions, nics, mtu, ipaddr, netmask,
                                gateway, bootproto, _netinfo, configurator,
                                **options)

    # libvirt net addition must be done before creation so that on dhcp ifup
    # the dhcp hook will already see the network as belonging to vdsm.
    configurator.configureLibvirtNetwork(network, netEnt,
                                         qosInbound=qosInbound,
                                         qosOutbound=qosOutbound)
    netEnt.configure(**options)
コード例 #3
0
ファイル: configNetwork.py プロジェクト: rexhsu/vdsm-ubuntu
def addNetwork(network,
               vlan=None,
               bonding=None,
               nics=None,
               ipaddr=None,
               netmask=None,
               prefix=None,
               mtu=None,
               gateway=None,
               force=False,
               configurator=None,
               bondingOptions=None,
               bridged=True,
               _netinfo=None,
               qosInbound=None,
               qosOutbound=None,
               **options):
    nics = nics or ()
    if _netinfo is None:
        _netinfo = netinfo.NetInfo()
    bridged = utils.tobool(bridged)

    if mtu:
        mtu = int(mtu)

    if prefix:
        if netmask:
            raise ConfigNetworkError(ne.ERR_BAD_PARAMS,
                                     'Both PREFIX and NETMASK supplied')
        else:
            try:
                netmask = netinfo.prefix2netmask(int(prefix))
            except ValueError as ve:
                raise ConfigNetworkError(ne.ERR_BAD_ADDR,
                                         "Bad prefix: %s" % ve)

    if not utils.tobool(force):
        logging.debug('validating network...')
        if network in _netinfo.networks:
            raise ConfigNetworkError(ne.ERR_USED_BRIDGE,
                                     'Network already exists')
        if bonding:
            _validateInterNetworkCompatibility(_netinfo, vlan, bonding,
                                               bridged)
        else:
            for nic in nics:
                _validateInterNetworkCompatibility(_netinfo, vlan, nic,
                                                   bridged)

    logging.info(
        "Adding network %s with vlan=%s, bonding=%s, nics=%s,"
        " bondingOptions=%s, mtu=%s, bridged=%s, options=%s", network, vlan,
        bonding, nics, bondingOptions, mtu, bridged, options)

    if configurator is None:
        configurator = Ifcfg()

    bootproto = options.pop('bootproto', None)

    defaultRoute = network == constants.MANAGEMENT_NETWORK

    netEnt = objectivizeNetwork(network if bridged else None,
                                vlan,
                                bonding,
                                bondingOptions,
                                nics,
                                mtu,
                                ipaddr,
                                netmask,
                                gateway,
                                bootproto,
                                _netinfo,
                                configurator,
                                defaultRoute=defaultRoute,
                                **options)

    netEnt.configure(**options)
    configurator.configureLibvirtNetwork(network,
                                         netEnt,
                                         qosInbound=qosInbound,
                                         qosOutbound=qosOutbound)