Skip to content

Commit

Permalink
Add inst_type parameter
Browse files Browse the repository at this point in the history
Add inst_type parameter in order to generate the bandwidth tag into
the libvirt configuration.

Change-Id: I63c1fb51ea637d461755b309c7464f4b4d49a4b2
Fixes: bug #1185030
  • Loading branch information
ylamgarchal committed Jul 3, 2013
1 parent aaa871c commit 08f8773
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 46 deletions.
2 changes: 1 addition & 1 deletion nova/tests/fake_network.py
Expand Up @@ -57,7 +57,7 @@ def __init__(self, *args, **kwargs):
def setattr(self, key, val):
self.__setattr__(key, val)

def get_config(self, instance, network, mapping, image_meta):
def get_config(self, instance, network, mapping, image_meta, inst_type):
conf = libvirt_config.LibvirtConfigGuestInterface()

for attr, val in conf.__dict__.iteritems():
Expand Down
22 changes: 21 additions & 1 deletion nova/tests/virt/libvirt/test_libvirt_vif.py
Expand Up @@ -17,6 +17,7 @@
from lxml import etree
from oslo.config import cfg

from nova.compute import flavors
from nova import exception
from nova.network import model as network_model
from nova import test
Expand Down Expand Up @@ -171,6 +172,15 @@ class LibvirtVifTestCase(test.TestCase):
'uuid': 'instance-uuid'
}

bandwidth = {
'quota:vif_inbound_peak': '102400',
'quota:vif_outbound_peak': '102400',
'quota:vif_inbound_average': '102400',
'quota:vif_outbound_average': '102400',
'quota:vif_inbound_burst': '102400',
'quota:vif_inbound_burst': '102400'
}

def setUp(self):
super(LibvirtVifTestCase, self).setUp()
self.flags(allow_same_net_traffic=True)
Expand All @@ -190,7 +200,13 @@ def _get_instance_xml(self, driver, net, mapping, image_meta=None):
conf.memory = 100 * 1024
conf.vcpus = 4

nic = driver.get_config(self.instance, net, mapping, image_meta)
default_inst_type = flavors.get_default_flavor()
extra_specs = default_inst_type['extra_specs'].items()
quota_bandwith = self.bandwidth.items()
default_inst_type['extra_specs'] = dict(extra_specs + quota_bandwith)

nic = driver.get_config(self.instance, net, mapping, image_meta,
default_inst_type)
conf.add_device(nic)
return conf.to_xml()

Expand Down Expand Up @@ -333,6 +349,10 @@ def get_connection():
self.mapping_bridge)

doc = etree.fromstring(xml)

ret = doc.findall('./devices/interface/bandwidth')
self.assertEqual(len(ret), 1)

ret = doc.findall('./devices/interface')
self.assertEqual(len(ret), 1)
node = ret[0]
Expand Down
4 changes: 2 additions & 2 deletions nova/virt/libvirt/designer.py
Expand Up @@ -106,7 +106,7 @@ def set_vif_host_backend_802qbh_config(conf, devname, profileid,
conf.target_dev = tapname


def set_vif_bandwidth_config(conf, extra_specs):
def set_vif_bandwidth_config(conf, inst_type):
"""Config vif inbound/outbound bandwidth limit. parameters are
set in instance_type_extra_specs table, key is in the format
quota:vif_inbound_average.
Expand All @@ -115,7 +115,7 @@ def set_vif_bandwidth_config(conf, extra_specs):
bandwidth_items = ['vif_inbound_average', 'vif_inbound_peak',
'vif_inbound_burst', 'vif_outbound_average', 'vif_outbound_peak',
'vif_outbound_burst']
for key, value in extra_specs.iteritems():
for key, value in inst_type['extra_specs'].iteritems():
scope = key.split(':')
if len(scope) > 1 and scope[0] == 'quota':
if scope[1] in bandwidth_items:
Expand Down
3 changes: 2 additions & 1 deletion nova/virt/libvirt/driver.py
Expand Up @@ -2335,7 +2335,8 @@ def get_guest_config(self, instance, network_info, image_meta,
for (network, mapping) in network_info:
cfg = self.vif_driver.get_config(instance,
network, mapping,
image_meta)
image_meta,
inst_type)
guest.add_device(cfg)

if CONF.libvirt_type == "qemu" or CONF.libvirt_type == "kvm":
Expand Down
108 changes: 67 additions & 41 deletions nova/virt/libvirt/vif.py
Expand Up @@ -93,7 +93,7 @@ def get_vif_devname(self, mapping):
return mapping['vif_devname']
return ("nic" + mapping['vif_uuid'])[:network_model.NIC_NAME_LEN]

def get_config(self, instance, network, mapping, image_meta):
def get_config(self, instance, network, mapping, image_meta, inst_type):
conf = vconfig.LibvirtConfigGuestInterface()
# Default to letting libvirt / the hypervisor choose the model
model = None
Expand Down Expand Up @@ -160,13 +160,14 @@ def get_firewall_required(self):
return True
return False

def get_config_bridge(self, instance, network, mapping, image_meta):
def get_config_bridge(self, instance, network, mapping, image_meta,
inst_type):
"""Get VIF configurations for bridge type."""
conf = super(LibvirtGenericVIFDriver,
self).get_config(instance,
network,
mapping,
image_meta)
image_meta, inst_type)

designer.set_vif_host_backend_bridge_config(
conf, self.get_bridge_name(network),
Expand All @@ -176,28 +177,30 @@ def get_config_bridge(self, instance, network, mapping, image_meta):
name = "nova-instance-" + instance['name'] + "-" + mac_id
if self.get_firewall_required():
conf.filtername = name
designer.set_vif_bandwidth_config(conf, instance)
designer.set_vif_bandwidth_config(conf, inst_type)

return conf

def get_config_ovs_ethernet(self, instance, network, mapping, image_meta):
def get_config_ovs_ethernet(self, instance, network, mapping,
image_meta, inst_type):
conf = super(LibvirtGenericVIFDriver,
self).get_config(instance,
network,
mapping,
image_meta)
image_meta, inst_type)

dev = self.get_vif_devname(mapping)
designer.set_vif_host_backend_ethernet_config(conf, dev)

return conf

def get_config_ovs_bridge(self, instance, network, mapping, image_meta):
def get_config_ovs_bridge(self, instance, network, mapping, image_meta,
inst_type):
conf = super(LibvirtGenericVIFDriver,
self).get_config(instance,
network,
mapping,
image_meta)
image_meta, inst_type)

designer.set_vif_host_backend_ovs_config(
conf, self.get_bridge_name(network),
Expand All @@ -206,64 +209,77 @@ def get_config_ovs_bridge(self, instance, network, mapping, image_meta):

return conf

def get_config_ovs_hybrid(self, instance, network, mapping, image_meta):
def get_config_ovs_hybrid(self, instance, network, mapping, image_meta,
inst_type):
newnet = copy.deepcopy(network)
newnet['bridge'] = self.get_br_name(mapping['vif_uuid'])
return self.get_config_bridge(instance,
newnet,
mapping,
image_meta)
image_meta, inst_type)

def get_config_ovs(self, instance, network, mapping, image_meta):
def get_config_ovs(self, instance, network, mapping, image_meta,
inst_type):
if self.get_firewall_required():
return self.get_config_ovs_hybrid(instance, network,
mapping,
image_meta)
image_meta,
inst_type)
elif self.has_libvirt_version(LIBVIRT_OVS_VPORT_VERSION):
return self.get_config_ovs_bridge(instance, network,
mapping,
image_meta)
image_meta,
inst_type)
else:
return self.get_config_ovs_ethernet(instance, network,
mapping,
image_meta)
image_meta,
inst_type)

def get_config_ivs_hybrid(self, instance, network, mapping, image_meta):
def get_config_ivs_hybrid(self, instance, network, mapping, image_meta,
inst_type):
newnet = copy.deepcopy(network)
newnet['bridge'] = self.get_br_name(mapping['vif_uuid'])
return self.get_config_bridge(instance,
newnet,
mapping,
image_meta)
image_meta,
inst_type)

def get_config_ivs_ethernet(self, instance, network, mapping, image_meta):
def get_config_ivs_ethernet(self, instance, network, mapping, image_meta,
inst_type):
conf = super(LibvirtGenericVIFDriver,
self).get_config(instance,
network,
mapping,
image_meta)
image_meta,
inst_type)

dev = self.get_vif_devname(mapping)
designer.set_vif_host_backend_ethernet_config(conf, dev)

return conf

def get_config_ivs(self, instance, network, mapping, image_meta):
def get_config_ivs(self, instance, network, mapping, image_meta,
inst_type):
if self.get_firewall_required():
return self.get_config_ivs_hybrid(instance, network,
mapping,
image_meta)
image_meta,
inst_type)
else:
return self.get_config_ivs_ethernet(instance, network,
mapping,
image_meta)
image_meta,
inst_type)

def get_config_802qbg(self, instance, network, mapping, image_meta):
def get_config_802qbg(self, instance, network, mapping, image_meta,
inst_type):
conf = super(LibvirtGenericVIFDriver,
self).get_config(instance,
network,
mapping,
image_meta)
image_meta, inst_type)

params = mapping["qbg_params"]
designer.set_vif_host_backend_802qbg_config(
Expand All @@ -275,12 +291,13 @@ def get_config_802qbg(self, instance, network, mapping, image_meta):

return conf

def get_config_802qbh(self, instance, network, mapping, image_meta):
def get_config_802qbh(self, instance, network, mapping, image_meta,
inst_type):
conf = super(LibvirtGenericVIFDriver,
self).get_config(instance,
network,
mapping,
image_meta)
image_meta, inst_type)

params = mapping["qbh_params"]
designer.set_vif_host_backend_802qbh_config(
Expand All @@ -289,7 +306,7 @@ def get_config_802qbh(self, instance, network, mapping, image_meta):

return conf

def get_config(self, instance, network, mapping, image_meta):
def get_config(self, instance, network, mapping, image_meta, inst_type):
vif_type = mapping.get('vif_type')

LOG.debug(_('vif_type=%(vif_type)s instance=%(instance)s '
Expand All @@ -304,23 +321,28 @@ def get_config(self, instance, network, mapping, image_meta):
elif vif_type == network_model.VIF_TYPE_BRIDGE:
return self.get_config_bridge(instance,
network, mapping,
image_meta)
image_meta,
inst_type)
elif vif_type == network_model.VIF_TYPE_OVS:
return self.get_config_ovs(instance,
network, mapping,
image_meta)
image_meta,
inst_type)
elif vif_type == network_model.VIF_TYPE_802_QBG:
return self.get_config_802qbg(instance,
network, mapping,
image_meta)
image_meta,
inst_type)
elif vif_type == network_model.VIF_TYPE_802_QBH:
return self.get_config_802qbh(instance,
network, mapping,
image_meta)
image_meta,
inst_type)
elif vif_type == network_model.VIF_TYPE_IVS:
return self.get_config_ivs(instance,
network, mapping,
image_meta)
image_meta,
inst_type)
else:
raise exception.NovaException(
_("Unexpected vif_type=%s") % vif_type)
Expand Down Expand Up @@ -620,13 +642,14 @@ class LibvirtBridgeDriver(LibvirtGenericVIFDriver):
Will be deprecated in Havana, and removed in Ixxxx.
"""

def get_config(self, instance, network, mapping, image_meta):
def get_config(self, instance, network, mapping, image_meta, inst_type):
LOG.deprecated(_("The LibvirtBridgeDriver VIF driver is now "
"deprecated and will be removed in the next release. "
"Please use the LibvirtGenericVIFDriver VIF driver, "
"together with a network plugin that reports the "
"'vif_type' attribute"))
return self.get_config_bridge(instance, network, mapping, image_meta)
return self.get_config_bridge(instance, network, mapping, image_meta,
inst_type)

def plug(self, instance, vif):
self.plug_bridge(instance, vif)
Expand All @@ -647,15 +670,15 @@ def get_bridge_name(self, network):
def get_ovs_interfaceid(self, mapping):
return mapping.get('ovs_interfaceid') or mapping['vif_uuid']

def get_config(self, instance, network, mapping, image_meta):
def get_config(self, instance, network, mapping, image_meta, inst_type):
LOG.deprecated(_("The LibvirtOpenVswitchDriver VIF driver is now "
"deprecated and will be removed in the next release. "
"Please use the LibvirtGenericVIFDriver VIF driver, "
"together with a network plugin that reports the "
"'vif_type' attribute"))
return self.get_config_ovs_ethernet(instance,
network, mapping,
image_meta)
image_meta, inst_type)

def plug(self, instance, vif):
self.plug_ovs_ethernet(instance, vif)
Expand All @@ -676,15 +699,16 @@ def get_bridge_name(self, network):
def get_ovs_interfaceid(self, mapping):
return mapping.get('ovs_interfaceid') or mapping['vif_uuid']

def get_config(self, instance, network, mapping, image_meta):
def get_config(self, instance, network, mapping, image_meta, inst_type):
LOG.deprecated(_("The LibvirtHybridOVSBridgeDriver VIF driver is now "
"deprecated and will be removed in the next release. "
"Please use the LibvirtGenericVIFDriver VIF driver, "
"together with a network plugin that reports the "
"'vif_type' attribute"))
return self.get_config_ovs_hybrid(instance,
network, mapping,
image_meta)
image_meta,
inst_type)

def plug(self, instance, vif):
return self.plug_ovs_hybrid(instance, vif)
Expand All @@ -705,15 +729,16 @@ def get_bridge_name(self, network):
def get_ovs_interfaceid(self, mapping):
return mapping.get('ovs_interfaceid') or mapping['vif_uuid']

def get_config(self, instance, network, mapping, image_meta):
def get_config(self, instance, network, mapping, image_meta, inst_type):
LOG.deprecated(_("The LibvirtOpenVswitchVirtualPortDriver VIF driver "
"is now deprecated and will be removed in the next "
"release. Please use the LibvirtGenericVIFDriver VIF "
"driver, together with a network plugin that reports "
"the 'vif_type' attribute"))
return self.get_config_ovs_bridge(instance,
network, mapping,
image_meta)
image_meta,
inst_type)

def plug(self, instance, vif):
return self.plug_ovs_bridge(instance, vif)
Expand All @@ -732,7 +757,7 @@ def get_bridge_name(self, network):
def_bridge = ("brq" + network['id'])[:network_model.NIC_NAME_LEN]
return network.get('bridge') or def_bridge

def get_config(self, instance, network, mapping, image_meta):
def get_config(self, instance, network, mapping, image_meta, inst_type):
LOG.deprecated(_("The QuantumLinuxBridgeVIFDriver VIF driver is now "
"deprecated and will be removed in the next release. "
"Please use the LibvirtGenericVIFDriver VIF driver, "
Expand All @@ -742,7 +767,8 @@ def get_config(self, instance, network, mapping, image_meta):
# to ensure that the bridge exists
if 'should_create_bridge' not in mapping:
mapping['should_create_bridge'] = True
return self.get_config_bridge(instance, network, mapping, image_meta)
return self.get_config_bridge(instance, network, mapping, image_meta,
inst_type)

def plug(self, instance, vif):
self.plug_bridge(instance, vif)
Expand Down

0 comments on commit 08f8773

Please sign in to comment.