23
23
import os_vif
24
24
from os_vif import exception as osv_exception
25
25
from os_vif .objects import fields as osv_fields
26
+ from os_vif .objects import vif as osv_vifs
26
27
from oslo_concurrency import processutils
27
28
from oslo_log import log as logging
28
29
from oslo_utils import strutils
@@ -120,9 +121,6 @@ def set_vf_interface_vlan(pci_addr, mac_addr, vlan=0):
120
121
class LibvirtGenericVIFDriver (object ):
121
122
"""Generic VIF driver for libvirt networking."""
122
123
123
- def _normalize_vif_type (self , vif_type ):
124
- return vif_type .replace ('2.1q' , '2q' )
125
-
126
124
def get_vif_devname (self , vif ):
127
125
if 'devname' in vif :
128
126
return vif ['devname' ]
@@ -432,6 +430,10 @@ def get_config_tap(self, instance, vif, image_meta,
432
430
433
431
return conf
434
432
433
+ def get_config_ib_hostdev (self , instance , vif , image_meta ,
434
+ inst_type , virt_type , host ):
435
+ return self .get_base_hostdev_pci_config (vif )
436
+
435
437
def _get_virtio_queue_sizes (self , host ):
436
438
"""Returns rx/tx queue sizes configured or (None, None)
437
439
@@ -464,10 +466,6 @@ def _get_virtio_queue_sizes(self, host):
464
466
tx = None
465
467
return rx , tx
466
468
467
- def get_config_ib_hostdev (self , instance , vif , image_meta ,
468
- inst_type , virt_type , host ):
469
- return self .get_base_hostdev_pci_config (vif )
470
-
471
469
def _set_config_VIFGeneric (self , instance , vif , conf , host ):
472
470
dev = vif .vif_name
473
471
designer .set_vif_host_backend_ethernet_config (conf , dev , host )
@@ -522,14 +520,12 @@ def _set_config_VIFPortProfileOpenVSwitch(self, profile, conf):
522
520
523
521
def _set_config_VIFPortProfile (self , instance , vif , conf ):
524
522
# Set any port profile that may be required
525
- profilefunc = "_set_config_" + vif .port_profile .obj_name ()
526
- func = getattr (self , profilefunc , None )
527
- if not func :
523
+ profile_name = vif .port_profile .obj_name ()
524
+ if profile_name == 'VIFPortProfileOpenVSwitch' :
525
+ self ._set_config_VIFPortProfileOpenVSwitch (vif .port_profile , conf )
526
+ else :
528
527
raise exception .InternalError (
529
- _ ("Unsupported VIF port profile type %(obj)s func %(func)s" ) %
530
- {'obj' : vif .port_profile .obj_name (), 'func' : profilefunc })
531
-
532
- func (vif .port_profile , conf )
528
+ _ ('Unsupported VIF port profile type %s' ) % profile_name )
533
529
534
530
def _get_config_os_vif (self , instance , vif , image_meta , inst_type ,
535
531
virt_type , host , vnic_type ):
@@ -552,13 +548,19 @@ def _get_config_os_vif(self, instance, vif, image_meta, inst_type,
552
548
host )
553
549
554
550
# Do the VIF type specific config
555
- viffunc = "_set_config_" + vif .obj_name ()
556
- func = getattr (self , viffunc , None )
557
- if not func :
551
+ if isinstance (vif , osv_vifs .VIFGeneric ):
552
+ self ._set_config_VIFGeneric (instance , vif , conf , host )
553
+ elif isinstance (vif , osv_vifs .VIFBridge ):
554
+ self ._set_config_VIFBridge (instance , vif , conf , host )
555
+ elif isinstance (vif , osv_vifs .VIFOpenVSwitch ):
556
+ self ._set_config_VIFOpenVSwitch (instance , vif , conf , host )
557
+ elif isinstance (vif , osv_vifs .VIFVHostUser ):
558
+ self ._set_config_VIFVHostUser (instance , vif , conf , host )
559
+ elif isinstance (vif , osv_vifs .VIFHostDevice ):
560
+ self ._set_config_VIFHostDevice (instance , vif , conf , host )
561
+ else :
558
562
raise exception .InternalError (
559
- _ ("Unsupported VIF type %(obj)s func %(func)s" ) %
560
- {'obj' : vif .obj_name (), 'func' : viffunc })
561
- func (instance , vif , conf , host )
563
+ _ ("Unsupported VIF type %s" ) % vif .obj_name ())
562
564
563
565
# not all VIF types support bandwidth configuration
564
566
# https://github.com/libvirt/libvirt/blob/568a41722/src/conf/netdev_bandwidth_conf.h#L38
@@ -596,13 +598,29 @@ def get_config(self, instance, vif, image_meta,
596
598
vnic_type )
597
599
598
600
# Legacy non-os-vif codepath
599
- vif_slug = self ._normalize_vif_type (vif_type )
600
- func = getattr (self , 'get_config_%s' % vif_slug , None )
601
- if not func :
602
- raise exception .InternalError (
603
- _ ("Unexpected vif_type=%s" ) % vif_type )
604
- return func (instance , vif , image_meta ,
605
- inst_type , virt_type , host )
601
+ args = (instance , vif , image_meta , inst_type , virt_type , host )
602
+ if vif_type == network_model .VIF_TYPE_IOVISOR :
603
+ return self .get_config_iovisor (* args )
604
+ elif vif_type == network_model .VIF_TYPE_BRIDGE :
605
+ return self .get_config_bridge (* args )
606
+ elif vif_type == network_model .VIF_TYPE_802_QBG :
607
+ return self .get_config_802qbg (* args )
608
+ elif vif_type == network_model .VIF_TYPE_802_QBH :
609
+ return self .get_config_802qbh (* args )
610
+ elif vif_type == network_model .VIF_TYPE_HW_VEB :
611
+ return self .get_config_hw_veb (* args )
612
+ elif vif_type == network_model .VIF_TYPE_HOSTDEV :
613
+ return self .get_config_hostdev_physical (* args )
614
+ elif vif_type == network_model .VIF_TYPE_MACVTAP :
615
+ return self .get_config_macvtap (* args )
616
+ elif vif_type == network_model .VIF_TYPE_MIDONET :
617
+ return self .get_config_midonet (* args )
618
+ elif vif_type == network_model .VIF_TYPE_TAP :
619
+ return self .get_config_tap (* args )
620
+ elif vif_type == network_model .VIF_TYPE_IB_HOSTDEV :
621
+ return self .get_config_ib_hostdev (* args )
622
+
623
+ raise exception .InternalError (_ ('Unexpected vif_type=%s' ) % vif_type )
606
624
607
625
def plug_ib_hostdev (self , instance , vif ):
608
626
fabric = vif .get_physical_network ()
@@ -621,12 +639,6 @@ def plug_ib_hostdev(self, instance, vif):
621
639
LOG .exception (_ ("Failed while plugging ib hostdev vif" ),
622
640
instance = instance )
623
641
624
- def plug_802qbg (self , instance , vif ):
625
- pass
626
-
627
- def plug_802qbh (self , instance , vif ):
628
- pass
629
-
630
642
def plug_hw_veb (self , instance , vif ):
631
643
# TODO(vladikr): This code can be removed once the minimum version of
632
644
# Libvirt is incleased above 1.3.5, as vlan will be set by libvirt
@@ -642,9 +654,6 @@ def plug_hw_veb(self, instance, vif):
642
654
if trusted :
643
655
linux_net .set_vf_trusted (vif ['profile' ]['pci_slot' ], True )
644
656
645
- def plug_hostdev_physical (self , instance , vif ):
646
- pass
647
-
648
657
def plug_macvtap (self , instance , vif ):
649
658
vif_details = vif ['details' ]
650
659
vlan = vif_details .get (network_model .VIF_DETAILS_VLAN )
@@ -726,13 +735,27 @@ def plug(self, instance, vif):
726
735
return
727
736
728
737
# Legacy non-os-vif codepath
729
- vif_slug = self ._normalize_vif_type (vif_type )
730
- func = getattr (self , 'plug_%s' % vif_slug , None )
731
- if not func :
738
+ if vif_type == network_model .VIF_TYPE_IB_HOSTDEV :
739
+ self .plug_ib_hostdev (instance , vif )
740
+ elif vif_type == network_model .VIF_TYPE_HW_VEB :
741
+ self .plug_hw_veb (instance , vif )
742
+ elif vif_type == network_model .VIF_TYPE_MACVTAP :
743
+ self .plug_macvtap (instance , vif )
744
+ elif vif_type == network_model .VIF_TYPE_MIDONET :
745
+ self .plug_midonet (instance , vif )
746
+ elif vif_type == network_model .VIF_TYPE_IOVISOR :
747
+ self .plug_iovisor (instance , vif )
748
+ elif vif_type == network_model .VIF_TYPE_TAP :
749
+ self .plug_tap (instance , vif )
750
+ elif vif_type in {network_model .VIF_TYPE_802_QBG ,
751
+ network_model .VIF_TYPE_802_QBH ,
752
+ network_model .VIF_TYPE_HOSTDEV }:
753
+ # These are no-ops
754
+ pass
755
+ else :
732
756
raise exception .VirtualInterfacePlugException (
733
- _ ("Plug vif failed because of unexpected "
757
+ _ ("Plug VIF failed because of unexpected "
734
758
"vif_type=%s" ) % vif_type )
735
- func (instance , vif )
736
759
737
760
def unplug_ib_hostdev (self , instance , vif ):
738
761
fabric = vif .get_physical_network ()
@@ -746,12 +769,6 @@ def unplug_ib_hostdev(self, instance, vif):
746
769
except Exception :
747
770
LOG .exception (_ ("Failed while unplugging ib hostdev vif" ))
748
771
749
- def unplug_802qbg (self , instance , vif ):
750
- pass
751
-
752
- def unplug_802qbh (self , instance , vif ):
753
- pass
754
-
755
772
def unplug_hw_veb (self , instance , vif ):
756
773
# TODO(sean-k-mooney): remove in Train after backporting 0 mac
757
774
# change as this should no longer be needed with libvirt >= 3.2.0.
@@ -770,12 +787,6 @@ def unplug_hw_veb(self, instance, vif):
770
787
if "trusted" in vif ['profile' ]:
771
788
linux_net .set_vf_trusted (vif ['profile' ]['pci_slot' ], False )
772
789
773
- def unplug_hostdev_physical (self , instance , vif ):
774
- pass
775
-
776
- def unplug_macvtap (self , instance , vif ):
777
- pass
778
-
779
790
def unplug_midonet (self , instance , vif ):
780
791
"""Unplug from MidoNet network port
781
792
@@ -842,9 +853,25 @@ def unplug(self, instance, vif):
842
853
return
843
854
844
855
# Legacy non-os-vif codepath
845
- vif_slug = self ._normalize_vif_type (vif_type )
846
- func = getattr (self , 'unplug_%s' % vif_slug , None )
847
- if not func :
848
- msg = _ ("Unexpected vif_type=%s" ) % vif_type
849
- raise exception .InternalError (msg )
850
- func (instance , vif )
856
+ if vif_type == network_model .VIF_TYPE_IB_HOSTDEV :
857
+ self .unplug_ib_hostdev (instance , vif )
858
+ elif vif_type == network_model .VIF_TYPE_HW_VEB :
859
+ self .unplug_hw_veb (instance , vif )
860
+ elif vif_type == network_model .VIF_TYPE_MIDONET :
861
+ self .unplug_midonet (instance , vif )
862
+ elif vif_type == network_model .VIF_TYPE_IOVISOR :
863
+ self .unplug_iovisor (instance , vif )
864
+ elif vif_type == network_model .VIF_TYPE_TAP :
865
+ self .unplug_tap (instance , vif )
866
+ elif vif_type in {network_model .VIF_TYPE_802_QBG ,
867
+ network_model .VIF_TYPE_802_QBH ,
868
+ network_model .VIF_TYPE_HOSTDEV ,
869
+ network_model .VIF_TYPE_MACVTAP }:
870
+ # These are no-ops
871
+ pass
872
+ else :
873
+ # TODO(stephenfin): This should probably raise
874
+ # VirtualInterfaceUnplugException
875
+ raise exception .InternalError (
876
+ _ ("Unplug VIF failed because of unexpected "
877
+ "vif_type=%s" ) % vif_type )
0 commit comments