Ejemplo n.º 1
0
def setupNetworks(networks, bondings, options):
    """Add/Edit/Remove configuration for networks and bondings.

    Params:
        networks - dict of key=network, value=attributes
            where 'attributes' is a dict with the following optional items:
                        vlan=<id>
                        bonding="<name>" | nic="<name>"
                        (bonding and nics are mutually exclusive)
                        ipaddr="<ipv4>"
                        netmask="<ipv4>" | prefix=<prefixlen>
                        gateway="<ipv4>"
                        bootproto="..."
                        ipv6addr="<ipv6>[/<prefixlen>]"
                        ipv6gateway="<ipv6>"
                        ipv6autoconf="0|1"
                        dhcpv6="0|1"
                        defaultRoute=True|False
                        nameservers=[<dns1>, <dns2> ...]"
                        switch="legacy|..."
                        (other options will be passed to the config file AS-IS)
                        -- OR --
                        remove=True (other attributes can't be specified)

        bondings - dict of key=bonding, value=attributes
            where 'attributes' is a dict with the following optional items:
                        nics=["<nic1>" , "<nic2>", ...]
                        options="<bonding-options>"
                        hwaddr="<mac address>"
                        switch="legacy|..."
                        -- OR --
                        remove=True (other attributes can't be specified)

        options - dict of options, such as:
                        connectivityCheck=0|1
                        connectivityTimeout=<int>
                        _inRollback=True|False
                        commitOnSuccess=True|False

    Notes:
        When you edit a network that is attached to a bonding, it's not
        necessary to re-specify the bonding (you need only to note
        the attachment in the network's attributes). Similarly, if you edit
        a bonding, it's not necessary to specify its networks.
    """
    networks = copy.deepcopy(networks)
    bondings = copy.deepcopy(bondings)
    options = copy.deepcopy(options)

    logging.info('Setting up network according to configuration: '
                 'networks:%r, bondings:%r, options:%r' %
                 (networks, bondings, options))
    try:
        canonicalize.canonicalize_networks(networks)
        canonicalize.canonicalize_external_bonds_used_by_nets(
            networks, bondings)
        canonicalize.canonicalize_bondings(bondings)

        net_info = netswitch.configurator.netinfo()
        running_config = netconfpersistence.RunningConfig()

        validator.validate(networks, bondings, net_info, running_config)

        if netswitch.configurator.switch_type_change_needed(
                networks, bondings, running_config):
            _change_switch_type(networks, bondings, options, running_config)
        else:
            _setup_networks(networks, bondings, options)
    except:
        # TODO: it might be useful to pass failure description in 'response'
        # field
        network_config_dict = {
            'request': {
                'networks': dict(networks),
                'bondings': dict(bondings),
                'options': dict(options),
            }
        }
        hooks.after_network_setup_fail(network_config_dict)
        raise
    else:
        hooks.after_network_setup(
            _build_setup_hook_dict(networks, bondings, options))
Ejemplo n.º 2
0
Archivo: api.py Proyecto: oVirt/vdsm
def setupNetworks(networks, bondings, options):
    """Add/Edit/Remove configuration for networks and bondings.

    Params:
        networks - dict of key=network, value=attributes
            where 'attributes' is a dict with the following optional items:
                        vlan=<id>
                        bonding="<name>" | nic="<name>"
                        (bonding and nics are mutually exclusive)
                        ipaddr="<ipv4>"
                        netmask="<ipv4>" | prefix=<prefixlen>
                        gateway="<ipv4>"
                        bootproto="..."
                        ipv6addr="<ipv6>[/<prefixlen>]"
                        ipv6gateway="<ipv6>"
                        ipv6autoconf="0|1"
                        dhcpv6="0|1"
                        defaultRoute=True|False
                        nameservers=[<dns1>, <dns2> ...]"
                        switch="legacy|..."
                        (other options will be passed to the config file AS-IS)
                        -- OR --
                        remove=True (other attributes can't be specified)

        bondings - dict of key=bonding, value=attributes
            where 'attributes' is a dict with the following optional items:
                        nics=["<nic1>" , "<nic2>", ...]
                        options="<bonding-options>"
                        hwaddr="<mac address>"
                        switch="legacy|..."
                        -- OR --
                        remove=True (other attributes can't be specified)

        options - dict of options, such as:
                        connectivityCheck=0|1
                        connectivityTimeout=<int>
                        _inRollback=True|False
                        commitOnSuccess=True|False

    Notes:
        When you edit a network that is attached to a bonding, it's not
        necessary to re-specify the bonding (you need only to note
        the attachment in the network's attributes). Similarly, if you edit
        a bonding, it's not necessary to specify its networks.
    """
    networks = copy.deepcopy(networks)
    bondings = copy.deepcopy(bondings)
    options = copy.deepcopy(options)

    logging.info('Setting up network according to configuration: '
                 'networks:%r, bondings:%r, options:%r' % (networks,
                                                           bondings, options))
    try:
        canonicalize.canonicalize_networks(networks)
        canonicalize.canonicalize_external_bonds_used_by_nets(networks,
                                                              bondings)
        canonicalize.canonicalize_bondings(bondings)

        net_info = netswitch.configurator.netinfo()

        validator.validate(networks, bondings, net_info)

        running_config = netconfpersistence.RunningConfig()
        if netswitch.configurator.switch_type_change_needed(
                networks, bondings, running_config):
            _change_switch_type(
                networks, bondings, options, running_config, net_info)
        else:
            _setup_networks(networks, bondings, options, net_info)
    except:
        # TODO: it might be useful to pass failure description in 'response'
        # field
        network_config_dict = {
            'request': {'networks': dict(networks),
                        'bondings': dict(bondings),
                        'options': dict(options)}}
        hooks.after_network_setup_fail(network_config_dict)
        raise
    else:
        hooks.after_network_setup(
            _build_setup_hook_dict(networks, bondings, options))