@@ -735,68 +735,67 @@ func getAddressesByName(compute *gophercloud.ServiceClient, name types.NodeName,
735
735
return nodeAddresses (& srv .Server , interfaces , networkingOpts )
736
736
}
737
737
738
- // getSubInterfaces
739
- func getSubInterfaces (network * gophercloud.ServiceClient ) ([]attachinterfaces.Interface , error ) {
740
- var interfaces []attachinterfaces.Interface
741
-
742
- // Check if trunk ports are attached
743
- listOpts := trunks.ListOpts {}
744
- allPages , err := trunks .List (network , listOpts ).AllPages ()
745
- if err != nil {
746
- klog .Errorf ("Failed to list trunks: %v" , err )
747
- return interfaces , err
748
- }
749
- allTrunks , err := trunks .ExtractTrunks (allPages )
750
- if err != nil {
751
- klog .Errorf ("Failed to extract trunks: %v" , err )
752
- return interfaces , err
753
- }
738
+ // getSubInterfaces returns the sub-interfaces attached via trunks to the specified node interfaces
739
+ func getSubInterfaces (interfaces []attachinterfaces.Interface , network * gophercloud.ServiceClient ) ([]attachinterfaces.Interface , error ) {
740
+ klog .V (5 ).Infof ("Node has %d interfaces '%v'" , len (interfaces ), interfaces )
754
741
755
- // Get subports attached to the trunk
756
- var subports []trunks.Subport
757
- for _ , trunk := range allTrunks {
758
- for _ , iface := range interfaces {
759
- if iface .PortID == trunk .PortID {
760
- s , err := trunks .GetSubports (network , trunk .ID ).Extract ()
761
- if err != nil {
762
- klog .Errorf ("Failed to get subports for trunk %s: %v" , trunk .ID , err )
763
- return interfaces , err
764
- }
765
- subports = append (subports , s ... )
766
- }
742
+ for _ , iface := range interfaces {
743
+ // Check if trunk ports are attached
744
+ listOpts := trunks.ListOpts {
745
+ PortID : iface .PortID ,
767
746
}
768
- }
769
- klog .V (5 ).Infof ("subports %v" , subports )
770
-
771
- // Arrange subports as for directly attached ports
772
- for _ , sport := range subports {
773
- p , err := ports .Get (network , sport .PortID ).Extract ()
747
+ allPages , err := trunks .List (network , listOpts ).AllPages ()
774
748
if err != nil {
775
- klog .Errorf ("Failed to get port info for subport %s : %v" , sport . PortID , err )
749
+ klog .Errorf ("Failed to list trunks : %v" , err )
776
750
return interfaces , err
777
751
}
778
- n , err := networks . Get ( network , p . NetworkID ). Extract ( )
752
+ allTrunks , err := trunks . ExtractTrunks ( allPages )
779
753
if err != nil {
780
- klog .Errorf ("Failed to get network info for subport %s : %v" , sport . PortID , err )
754
+ klog .Errorf ("Failed to extract trunks : %v" , err )
781
755
return interfaces , err
782
756
}
783
- var iface = attachinterfaces.Interface {
784
- PortState : "ACTIVE" ,
785
- FixedIPs : []attachinterfaces.FixedIP {},
786
- PortID : p .ID ,
787
- NetID : n .Name ,
788
- MACAddr : p .MACAddress ,
789
- }
790
- for _ , ip := range p .FixedIPs {
791
- var ip2 = attachinterfaces.FixedIP {
792
- SubnetID : ip .SubnetID ,
793
- IPAddress : ip .IPAddress ,
757
+ // Get subports attached to the trunks
758
+ for _ , trunk := range allTrunks {
759
+ subports , err := trunks .GetSubports (network , trunk .ID ).Extract ()
760
+ if err != nil {
761
+ klog .Errorf ("Failed to get subports for trunk %s: %v" , trunk .ID , err )
762
+ return interfaces , err
763
+ }
764
+ if len (subports ) == 0 {
765
+ continue
766
+ }
767
+ klog .V (5 ).Infof ("Subports for trunk %s: %v" , trunk .ID , subports )
768
+ // Arrange subports as for directly attached ports
769
+ for _ , sport := range subports {
770
+ p , err := ports .Get (network , sport .PortID ).Extract ()
771
+ if err != nil {
772
+ klog .Errorf ("Failed to get port info for subport %s: %v" , sport .PortID , err )
773
+ return interfaces , err
774
+ }
775
+ n , err := networks .Get (network , p .NetworkID ).Extract ()
776
+ if err != nil {
777
+ klog .Errorf ("Failed to get network info for subport %s: %v" , sport .PortID , err )
778
+ return interfaces , err
779
+ }
780
+ var iface = attachinterfaces.Interface {
781
+ PortState : "ACTIVE" ,
782
+ FixedIPs : []attachinterfaces.FixedIP {},
783
+ PortID : p .ID ,
784
+ NetID : n .Name ,
785
+ MACAddr : p .MACAddress ,
786
+ }
787
+ for _ , ip := range p .FixedIPs {
788
+ var ip2 = attachinterfaces.FixedIP {
789
+ SubnetID : ip .SubnetID ,
790
+ IPAddress : ip .IPAddress ,
791
+ }
792
+ iface .FixedIPs = append (iface .FixedIPs , ip2 )
793
+ }
794
+ interfaces = append (interfaces , iface )
794
795
}
795
- iface .FixedIPs = append (iface .FixedIPs , ip2 )
796
796
}
797
- interfaces = append (interfaces , iface )
798
797
}
799
- klog .V (5 ).Infof ("interfaces %v" , interfaces )
798
+ klog .V (5 ).Infof ("Node has %d interfaces including subports '%v'" , len ( interfaces ) , interfaces )
800
799
return interfaces , nil
801
800
}
802
801
@@ -817,7 +816,7 @@ func getAttachedInterfacesByID(compute *gophercloud.ServiceClient, serviceID str
817
816
if mc .ObserveRequest (err ) != nil {
818
817
return interfaces , err
819
818
}
820
- subInterfaces , err := getSubInterfaces (network )
819
+ subInterfaces , err := getSubInterfaces (interfaces , network )
821
820
if err != nil {
822
821
return interfaces , err
823
822
}
0 commit comments