def _restore_default_bond_options(bond_name, desired_options): """ Restore the bond's options to defaults corresponding to the intended bonding mode. The logic of handling the defaults is embedded in the link.bond set options therefore, we use set options as a whole. This works around an initscripts design limitation: ifup only touches declared options and leaves other (possibly non-default) options as-is. """ Bond(bond_name).set_options(parse_bond_options(desired_options))
def _restore_default_bond_options(bond_name, desired_options): """ Restore the bond's options to defaults corresponding to the intended bonding mode. The logic of handling the defaults is embedded in the link.bond set options therefore, we use set options as a whole. This works around an initscripts design limitation: ifup only touches declared options and leaves other (possibly non-default) options as-is. """ Bond(bond_name).set_options(parse_bond_options(desired_options))
def init_nets(): persistence = config.get('vars', 'net_persistence') if persistence != 'unified': logging.info('Skipping: Unified persistence is not used.') return if _nets_already_restored(NETS_RESTORED_MARK): logging.info('Skipping: Networks were already restored.') return logging.info('Starting initial network setup.') persistent_config = PersistentConfig() nets = _persisted_ovs_entries(persistent_config.networks) logging.info('Restoring networks configuration: {}'.format(nets)) _set_blocking_dhcp(nets) bonds = _persisted_ovs_entries(persistent_config.bonds) logging.info('Restoring bondings configuration: {}'.format(bonds)) for net, attrs in six.iteritems(nets): with _try2execute('IPv6autoconf for {} failed.'.format(net)): netswitch.configurator.setup_ipv6autoconf({net: attrs}) for bond_name, attrs in six.iteritems(bonds): with _try2execute('Restoration of bond {} failed.'.format(bond_name)): requested_slaves = set(attrs['nics']) requested_options = ( setup.parse_bond_options(attrs['options']) if 'options' in attrs else None ) with Bond( bond_name, slaves=requested_slaves, options=requested_options ) as bond: bond.create() for bond, attrs in six.iteritems(bonds): with _try2execute('Setting links up for {} failed.'.format(bond)): netswitch.configurator.set_ovs_links_up({}, {bond: attrs}, {}) for net, attrs in six.iteritems(nets): with _try2execute('Setting links up for {} failed.'.format(net)): netswitch.configurator.set_ovs_links_up({net: attrs}, {}, {}) for net, attrs in six.iteritems(nets): with _try2execute('IP config for {} failed.'.format(net)): netswitch.configurator.setup_ovs_ip_config({net: attrs}, {}) logging.info('Initial network setup is done.')
def _create(self): iface_state = {Interface.STATE: InterfaceState.UP} mac = self._attrs.get('hwaddr') if mac: iface_state[Interface.MAC] = mac bond_state = iface_state[BondSchema.CONFIG_SUBTREE] = {} bond_state[BondSchema.SLAVES] = sorted(self._attrs['nics']) options = parse_bond_options(self._attrs.get('options')) if options: bond_state[BondSchema.OPTIONS_SUBTREE] = options mode = self._translate_mode(mode=options.pop('mode', 'balance-rr')) bond_state[BondSchema.MODE] = mode return iface_state
def _create_bond(bondname, bondattrs): iface_state = { 'name': bondname, 'type': 'bond', 'state': 'up', 'link-aggregation': {}, } iface_state['link-aggregation']['slaves'] = bondattrs['nics'] bond_options = parse_bond_options(bondattrs.get('options')) bond_mode = bond_options.pop('mode', 'balance-rr') _set_bond_mode(iface_state, bond_mode) if bond_options: iface_state['link-aggregation']['options'] = bond_options return iface_state
def _create_bond(bondname, bondattrs): iface_state = { 'name': bondname, 'type': 'bond', 'state': 'up', 'link-aggregation': {}, } iface_state['link-aggregation']['slaves'] = bondattrs['nics'] bond_options = parse_bond_options(bondattrs.get('options')) bond_mode = bond_options.pop('mode', 'balance-rr') _set_bond_mode(iface_state, bond_mode) if bond_options: iface_state['link-aggregation']['options'] = bond_options return iface_state
def init_nets(): persistence = config.get('vars', 'net_persistence') if persistence != 'unified': logging.info('Skipping: Unified persistence is not used.') return if _nets_already_restored(NETS_RESTORED_MARK): logging.info('Skipping: Networks were already restored.') return logging.info('Starting initial network setup.') persistent_config = PersistentConfig() nets = _persisted_ovs_entries(persistent_config.networks) logging.info('Restoring networks configuration: {}'.format(nets)) _set_blocking_dhcp(nets) bonds = _persisted_ovs_entries(persistent_config.bonds) logging.info('Restoring bondings configuration: {}'.format(bonds)) for net, attrs in six.iteritems(nets): with _try2execute('IPv6autoconf for {} failed.'.format(net)): netswitch.setup_ipv6autoconf({net: attrs}) for bond_name, attrs in six.iteritems(bonds): with _try2execute('Restoration of bond {} failed.'.format(bond_name)): requested_slaves = set(attrs['nics']) requested_options = (setup.parse_bond_options(attrs['options']) if 'options' in attrs else None) with Bond(bond_name, slaves=requested_slaves, options=requested_options) as bond: bond.create() for bond, attrs in six.iteritems(bonds): with _try2execute('Setting links up for {} failed.'.format(bond)): netswitch.set_ovs_links_up({}, {bond: attrs}, {}) for net, attrs in six.iteritems(nets): with _try2execute('Setting links up for {} failed.'.format(net)): netswitch.set_ovs_links_up({net: attrs}, {}, {}) for net, attrs in six.iteritems(nets): with _try2execute('IP config for {} failed.'.format(net)): netswitch.setup_ovs_ip_config({net: attrs}, {}) logging.info('Initial network setup is done.')
def _create_bond(bondname, bondattrs): iface_state = { 'name': bondname, 'type': 'bond', 'state': 'up', 'link-aggregation': {}, 'ipv4': {'enabled': False}, 'ipv6': {'enabled': False} } mac = bondattrs.get('hwaddr') if mac: iface_state['mac-address'] = mac iface_state['link-aggregation']['slaves'] = sorted(bondattrs['nics']) bond_options = parse_bond_options(bondattrs.get('options')) bond_mode = bond_options.pop('mode', 'balance-rr') _set_bond_mode(iface_state, bond_mode) if bond_options: iface_state['link-aggregation']['options'] = bond_options return iface_state
def _create_bond(bondname, bondattrs): iface_state = { Interface.NAME: bondname, Interface.TYPE: 'bond', Interface.STATE: 'up', 'link-aggregation': {}, Interface.IPV4: { 'enabled': False }, Interface.IPV6: { 'enabled': False } } mac = bondattrs.get('hwaddr') if mac: iface_state['mac-address'] = mac iface_state['link-aggregation']['slaves'] = sorted(bondattrs['nics']) bond_options = parse_bond_options(bondattrs.get('options')) bond_mode = bond_options.pop('mode', 'balance-rr') _set_bond_mode(iface_state, bond_mode) if bond_options: iface_state['link-aggregation']['options'] = bond_options return iface_state