Change in vdsm[master]: net: api: keep consistent naming and quotes
phoracek at redhat.com
phoracek at redhat.com
Fri Mar 4 11:08:02 UTC 2016
Petr Horáček has uploaded a new change for review.
Change subject: net: api: keep consistent naming and quotes
......................................................................
net: api: keep consistent naming and quotes
Change-Id: I4cfbd8a9ecfbde9964d378449df9e9b0c227c0d6
Signed-off-by: Petr Horáček <phoracek at redhat.com>
---
M lib/vdsm/network/api.py
M lib/vdsm/network/legacy_switch.py
2 files changed, 97 insertions(+), 95 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/51/54351/1
diff --git a/lib/vdsm/network/api.py b/lib/vdsm/network/api.py
index 746ecb3..952631a 100644
--- a/lib/vdsm/network/api.py
+++ b/lib/vdsm/network/api.py
@@ -24,7 +24,6 @@
import time
import logging
-
from vdsm.config import config
from vdsm import commands
from vdsm import constants
@@ -87,24 +86,25 @@
def change_numvfs(pci_path, numvfs, net_name):
"""Change number of virtual functions of a device.
+
The persistence is stored in the same place as other network persistence is
stored. A call to setSafeNetworkConfig() will persist it across reboots.
"""
# TODO: net_name is here only because it is hard to call pf_to_net_name
# TODO: from here. once all our code will be under lib/vdsm this should be
# TODO: removed.
- logging.info("changing number of vfs on device %s -> %s.",
+ logging.info('changing number of vfs on device %s -> %s.',
pci_path, numvfs)
_update_numvfs(pci_path, numvfs)
- logging.info("changing number of vfs on device %s -> %s. succeeded.",
+ logging.info('changing number of vfs on device %s -> %s. succeeded.',
pci_path, numvfs)
_persist_numvfs(pci_path, numvfs)
ipwrapper.linkSet(net_name, ['up'])
-def _buildSetupHookDict(req_networks, req_bondings, req_options):
+def _build_setup_hook_dict(req_networks, req_bondings, req_options):
hook_dict = {'request': {'networks': dict(req_networks),
'bondings': dict(req_bondings),
@@ -121,13 +121,13 @@
def _check_connectivity(networks, bondings, options):
if utils.tobool(options.get('connectivityCheck', True)):
_logger.debug('Checking connectivity...')
- if not _clientSeen(_get_connectivity_timeout(options)):
+ if not _client_seen(_get_connectivity_timeout(options)):
_logger.info('Connectivity check failed, rolling back')
raise ConfigNetworkError(ne.ERR_LOST_CONNECTION,
'connectivity check failed')
-def _clientSeen(timeout):
+def _client_seen(timeout):
start = time.time()
while timeout >= 0:
try:
@@ -144,9 +144,8 @@
def _apply_hook(bondings, networks, options):
- results = hooks.before_network_setup(_buildSetupHookDict(networks,
- bondings,
- options))
+ results = hooks.before_network_setup(
+ _build_setup_hook_dict(networks, bondings, options))
# gather any changes that could have been done by the hook scripts
networks = results['request']['networks']
bondings = results['request']['bondings']
@@ -194,14 +193,14 @@
the attachment in the network's attributes). Similarly, if you edit
a bonding, it's not necessary to specify its networks.
"""
- _logger.debug("Setting up network according to configuration: "
- "networks:%r, bondings:%r, options:%r" % (networks,
+ _logger.debug('Setting up network according to configuration: '
+ 'networks:%r, bondings:%r, options:%r' % (networks,
bondings, options))
canonize_networks(networks)
# TODO: Add canonize_bondings(bondings)
- logging.debug("Validating configuration")
+ logging.debug('Validating configuration')
legacy_switch.validateNetworkSetup(networks, bondings)
bondings, networks, options = _apply_hook(bondings, networks, options)
@@ -210,7 +209,7 @@
_netinfo = CachingNetInfo(_netinfo=netinfo_get(
libvirtNets2vdsm(libvirt_nets)))
- _logger.debug("Applying...")
+ _logger.debug('Applying...')
in_rollback = options.get('_inRollback', False)
with legacy_switch.ConfiguratorClass(in_rollback) as configurator:
# from this point forward, any exception thrown will be handled by
@@ -227,7 +226,8 @@
_check_connectivity(networks, bondings, options)
- hooks.after_network_setup(_buildSetupHookDict(networks, bondings, options))
+ hooks.after_network_setup(
+ _build_setup_hook_dict(networks, bondings, options))
def setSafeNetworkConfig():
diff --git a/lib/vdsm/network/legacy_switch.py b/lib/vdsm/network/legacy_switch.py
index 8d45b95..29b9178 100644
--- a/lib/vdsm/network/legacy_switch.py
+++ b/lib/vdsm/network/legacy_switch.py
@@ -1,5 +1,5 @@
# Copyright 2011-2016 Red Hat, Inc.
-#
+/
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
@@ -46,7 +46,7 @@
_logger = logging.getLogger('network_legacy_switch')
-def _getPersistenceModule():
+def _get_persistence_module():
persistence = config.get('vars', 'net_persistence')
if persistence == 'unified':
return netconfpersistence
@@ -55,7 +55,7 @@
return ifcfg
-def _getConfiguratorClass():
+def _get_configurator_class():
configurator = config.get('vars', 'net_configurator')
if configurator == 'iproute2':
from .configurators.iproute2 import Iproute2
@@ -78,17 +78,17 @@
return Ifcfg
-_persistence = _getPersistenceModule()
-ConfiguratorClass = _getConfiguratorClass()
+_persistence = _get_persistence_module()
+ConfiguratorClass = _get_configurator_class()
-def _objectivizeNetwork(bridge=None, vlan=None, vlan_id=None, bonding=None,
- nic=None, mtu=None, ipaddr=None,
- netmask=None, gateway=None, bootproto=None,
- ipv6addr=None, ipv6gateway=None, ipv6autoconf=None,
- dhcpv6=None, defaultRoute=None, _netinfo=None,
- configurator=None, blockingdhcp=None,
- opts=None):
+def _objectivize_network(bridge=None, vlan=None, vlan_id=None, bonding=None,
+ nic=None, mtu=None, ipaddr=None,
+ netmask=None, gateway=None, bootproto=None,
+ ipv6addr=None, ipv6gateway=None, ipv6autoconf=None,
+ dhcpv6=None, defaultRoute=None, _netinfo=None,
+ configurator=None, blockingdhcp=None,
+ opts=None):
"""
Constructs an object hierarchy that describes the network configuration
that is passed in the parameters.
@@ -134,8 +134,9 @@
elif nic:
bond = _netinfo.getBondingForNic(nic)
if bond:
- raise ConfigNetworkError(ne.ERR_USED_NIC, 'nic %s already '
- 'enslaved to %s' % (nic, 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 is not None:
tag = _netinfo.vlans[vlan]['vlanid'] if vlan_id is None else vlan_id
@@ -149,8 +150,8 @@
if topNetDev.port and bootproto == 'dhcp':
_inherit_dhcp_unique_identifier(topNetDev, _netinfo)
if topNetDev is None:
- raise ConfigNetworkError(ne.ERR_BAD_PARAMS, 'Network defined without '
- 'devices.')
+ raise ConfigNetworkError(ne.ERR_BAD_PARAMS,
+ 'Network defined without devices.')
topNetDev.ipv4 = IPv4(ipaddr, netmask, gateway, defaultRoute, bootproto)
topNetDev.ipv6 = IPv6(ipv6addr, ipv6gateway, defaultRoute, ipv6autoconf,
dhcpv6)
@@ -179,16 +180,15 @@
break
-def _alterRunningConfig(func):
+def _alter_running_config(func):
"""
- Wrapper for _addNetwork and _delNetwork that abstracts away all current
+ Wrapper for _add_network and _del_network that abstracts away all current
configuration handling from the wrapped methods.
"""
-
@wraps(func)
def wrapped(network, configurator, **kwargs):
if config.get('vars', 'net_persistence') == 'unified':
- if func.__name__ == '_delNetwork':
+ if func.__name__ == '_del_network':
configurator.runningConfig.removeNetwork(network)
else:
configurator.runningConfig.setNetwork(network, kwargs)
@@ -196,13 +196,13 @@
return wrapped
- at _alterRunningConfig
-def _addNetwork(network, configurator,
- vlan=None, bonding=None, nic=None, ipaddr=None,
- netmask=None, prefix=None, mtu=None, gateway=None, dhcpv6=None,
- ipv6addr=None, ipv6gateway=None, ipv6autoconf=None,
- bridged=True, _netinfo=None, hostQos=None,
- defaultRoute=None, blockingdhcp=False, **options):
+ at _alter_running_config
+def _add_network(network, configurator,
+ vlan=None, bonding=None, nic=None, ipaddr=None,
+ netmask=None, prefix=None, mtu=None, gateway=None,
+ dhcpv6=None, ipv6addr=None, ipv6gateway=None,
+ ipv6autoconf=None, bridged=True, _netinfo=None, hostQos=None,
+ defaultRoute=None, blockingdhcp=False, **options):
if _netinfo is None:
_netinfo = CachingNetInfo()
if dhcpv6 is not None:
@@ -221,17 +221,17 @@
try:
netmask = addresses.prefix2netmask(int(prefix))
except ValueError as ve:
- raise ConfigNetworkError(ne.ERR_BAD_ADDR, "Bad prefix: %s" %
+ raise ConfigNetworkError(ne.ERR_BAD_ADDR, 'Bad prefix: %s' %
ve)
- logging.debug('validating network...')
+ logging.debug('Validating network...')
if network in _netinfo.networks:
raise ConfigNetworkError(
ne.ERR_USED_BRIDGE, 'Network already exists (%s)' % (network,))
if bonding:
- _validateInterNetworkCompatibility(_netinfo, vlan, bonding)
+ _validate_inter_network_compatibility(_netinfo, vlan, bonding)
elif nic:
- _validateInterNetworkCompatibility(_netinfo, vlan, nic)
+ _validate_inter_network_compatibility(_netinfo, vlan, nic)
logging.info('Adding network %s with vlan=%s, bonding=%s, nic=%s, '
'mtu=%s, bridged=%s, defaultRoute=%s, options=%s', network,
@@ -239,7 +239,7 @@
bootproto = options.pop('bootproto', None)
- net_ent = _objectivizeNetwork(
+ net_ent = _objectivize_network(
bridge=network if bridged else None, vlan_id=vlan, bonding=bonding,
nic=nic, mtu=mtu, ipaddr=ipaddr,
netmask=netmask, gateway=gateway, bootproto=bootproto, dhcpv6=dhcpv6,
@@ -254,28 +254,28 @@
# devices attached to it (for the VMs).
# (expecting the bridge running mtu to be updated by the kernel when
# the device attached under it has its mtu updated)
- logging.info("Bridge %s already exists.", network)
+ logging.info('Bridge %s already exists.', network)
net_ent_to_configure = net_ent.port
_update_mtu_for_an_existing_bridge(network, configurator, mtu)
else:
net_ent_to_configure = net_ent
if net_ent_to_configure is not None:
- logging.info("Configuring device %s", net_ent_to_configure)
+ logging.info('Configuring device %s', net_ent_to_configure)
net_ent_to_configure.configure(**options)
configurator.configureLibvirtNetwork(network, net_ent)
if hostQos is not None:
configurator.configureQoS(hostQos, net_ent)
-def _validateInterNetworkCompatibility(ni, vlan, iface):
+def _validate_inter_network_compatibility(ni, vlan, iface):
iface_nets_by_vlans = dict((vlan, net) # None is also a valid key
for (net, vlan)
in ni.getNetworksAndVlansForIface(iface))
if vlan in iface_nets_by_vlans:
raise ConfigNetworkError(ne.ERR_BAD_PARAMS,
- 'interface %r cannot be defined with this '
+ 'Interface %r cannot be defined with this '
'network since it is already defined with '
'network %s' % (iface,
iface_nets_by_vlans[vlan]))
@@ -292,7 +292,7 @@
ipwrapper.linkSet(port, ['mtu', str(mtu)])
-def _assertBridgeClean(bridge, vlan, bonding, nics):
+def _assert_bridge_clean(bridge, vlan, bonding, nics):
ports = set(bridges.ports(bridge))
ifaces = set(nics)
if vlan is not None:
@@ -303,14 +303,14 @@
brifs = ports - ifaces
if brifs:
- raise ConfigNetworkError(ne.ERR_USED_BRIDGE, 'bridge %s has interfaces'
+ raise ConfigNetworkError(ne.ERR_USED_BRIDGE, 'Bridge %s has interfaces'
' %s connected' % (bridge, brifs))
- at _alterRunningConfig
-def _delNetwork(network, configurator, vlan=None, bonding=None,
- bypassValidation=False,
- _netinfo=None, keep_bridge=False, **options):
+ at _alter_running_config
+def _del_network(network, configurator, vlan=None, bonding=None,
+ bypassValidation=False,
+ _netinfo=None, keep_bridge=False, **options):
if _netinfo is None:
_netinfo = CachingNetInfo()
@@ -318,20 +318,20 @@
network)
bridged = _netinfo.networks[network]['bridged']
- logging.info("Removing network %s with vlan=%s, bonding=%s, nics=%s,"
- "keep_bridge=%s options=%s", network, vlan, bonding,
+ logging.info('Removing network %s with vlan=%s, bonding=%s, nics=%s,'
+ 'keep_bridge=%s options=%s', network, vlan, bonding,
nics, keep_bridge, options)
if not bypassValidation:
_validateDelNetwork(network, vlan, bonding, nics,
bridged and not keep_bridge, _netinfo)
- net_ent = _objectivizeNetwork(bridge=network if bridged else None,
- vlan=vlan, vlan_id=vlan_id, bonding=bonding,
- nic=nics[0] if nics and not bonding
- else None,
- _netinfo=_netinfo,
- configurator=configurator)
+ net_ent = _objectivize_network(bridge=network if bridged else None,
+ vlan=vlan, vlan_id=vlan_id, bonding=bonding,
+ nic=nics[0] if nics and not bonding
+ else None,
+ _netinfo=_netinfo,
+ configurator=configurator)
net_ent.ipv4.bootproto = (
'dhcp' if _netinfo.networks[network]['dhcpv4'] else 'none')
@@ -367,12 +367,12 @@
def _validateDelNetwork(network, vlan, bonding, nics, bridge_should_be_clean,
_netinfo):
if bonding:
- if set(nics) != set(_netinfo.bondings[bonding]["slaves"]):
- raise ConfigNetworkError(ne.ERR_BAD_NIC, '_delNetwork: %s are '
+ if set(nics) != set(_netinfo.bondings[bonding]['slaves']):
+ raise ConfigNetworkError(ne.ERR_BAD_NIC, '_del_network: %s are '
'not all nics enslaved to %s' %
(nics, bonding))
if bridge_should_be_clean:
- _assertBridgeClean(network, vlan, bonding, nics)
+ _assert_bridge_clean(network, vlan, bonding, nics)
def _disconnect_bridge_port(port):
@@ -387,16 +387,16 @@
for network, attrs in networks.items():
if network in _netinfo.networks:
- _logger.debug("Removing network %r", network)
+ _logger.debug('Removing network %r', network)
keep_bridge = _should_keep_bridge(
network_attrs=normalized_config.networks[network],
currently_bridged=_netinfo.networks[network]['bridged'],
net_kernel_config=kernel_config.networks[network]
)
- _delNetwork(network, configurator,
- _netinfo=_netinfo,
- keep_bridge=keep_bridge)
+ _del_network(network, configurator,
+ _netinfo=_netinfo,
+ keep_bridge=keep_bridge)
_netinfo.del_network(network)
_netinfo.updateDevices()
elif network in libvirt_nets:
@@ -404,18 +404,20 @@
# returned by libvirt, it means that we are dealing with
# a broken network.
_logger.debug('Removing broken network %r', network)
- _delBrokenNetwork(network, libvirt_nets[network],
- configurator=configurator)
+ _del_broken_network(network, libvirt_nets[network],
+ configurator=configurator)
_netinfo.updateDevices()
elif 'remove' in attrs:
- raise ConfigNetworkError(ne.ERR_BAD_BRIDGE, "Cannot delete "
- "network %r: It doesn't exist in the "
- "system" % network)
+ raise ConfigNetworkError(ne.ERR_BAD_BRIDGE, 'Cannot delete '
+ 'network %r: It doesn't exist in the '
+ 'system' % network)
-def _delBrokenNetwork(network, netAttr, configurator):
- '''Adapts the network information of broken networks so that they can be
- deleted via _delNetwork.'''
+def _del_broken_network(network, netAttr, configurator):
+ """
+ Adapts the network information of broken networks so that they can be
+ deleted via _del_network.
+ """
_netinfo = CachingNetInfo()
_netinfo.networks[network] = netAttr
_netinfo.networks[network]['dhcpv4'] = False
@@ -433,8 +435,8 @@
if config.get('vars', 'net_persistence') == 'unified':
configurator.runningConfig.removeNetwork(network)
return
- _delNetwork(network, configurator, bypassValidation=True,
- _netinfo=_netinfo)
+ _del_network(network, configurator, bypassValidation=True,
+ _netinfo=_netinfo)
def _should_keep_bridge(network_attrs, currently_bridged, net_kernel_config):
@@ -459,7 +461,7 @@
if currently_bridged and _bridge_reconfigured(net_kernel_config,
network_attrs):
- logging.debug("the bridge is being reconfigured")
+ logging.debug('The bridge is being reconfigured')
return False
return True
@@ -477,22 +479,22 @@
if bond:
_check_bonding_availability(bond, bondings, _netinfo)
- _logger.debug("Adding network %r", network)
+ _logger.debug('Adding network %r', network)
try:
- _addNetwork(network, configurator,
- _netinfo=_netinfo, **attrs)
+ _add_network(network, configurator,
+ _netinfo=_netinfo, **attrs)
except ConfigNetworkError as cne:
if cne.errCode == ne.ERR_FAILED_IFUP:
- _logger.debug("Adding network %r failed. Running "
- "orphan-devices cleanup", network)
- _emergencyNetworkCleanup(network, attrs,
- configurator)
+ _logger.debug('Adding network %r failed. Running '
+ 'orphan-devices cleanup', network)
+ _emergency_network_cleanup(network, attrs,
+ configurator)
raise
_netinfo.updateDevices() # Things like a bond mtu can change
-def _emergencyNetworkCleanup(network, networkAttrs, configurator):
+def _emergency_network_cleanup(network, networkAttrs, configurator):
"""Remove all leftovers after failed setupNetwork"""
_netinfo = CachingNetInfo()
@@ -623,7 +625,7 @@
configurator.configureBond(bond)
-def validateNetworkSetup(networks, bondings):
+def validate_network_setup(networks, bondings):
for network, networkAttrs in networks.iteritems():
if networkAttrs.get('remove', False):
_validate_network_remove(networkAttrs)
@@ -642,10 +644,10 @@
nics = bondingAttrs.get('nics', None)
if not nics:
raise ConfigNetworkError(ne.ERR_BAD_PARAMS,
- "Must specify nics for bonding")
+ 'Must specify nics for bonding')
if not set(nics).issubset(currentNicsSet):
raise ConfigNetworkError(ne.ERR_BAD_NIC,
- "Unknown nics in: %r" % list(nics))
+ 'Unknown nics in: %r' % list(nics))
def _validate_network_remove(networkAttrs):
@@ -654,6 +656,6 @@
['remove', 'custom']):
raise ConfigNetworkError(
ne.ERR_BAD_PARAMS,
- "Cannot specify any attribute when removing (other "
- "than custom properties). specified attributes: %s" % (
+ 'Cannot specify any attribute when removing (other '
+ 'than custom properties). specified attributes: %s' % (
networkAttrs,))
--
To view, visit https://gerrit.ovirt.org/54351
To unsubscribe, visit https://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I4cfbd8a9ecfbde9964d378449df9e9b0c227c0d6
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Petr Horáček <phoracek at redhat.com>
More information about the vdsm-patches
mailing list