@@ -204,7 +204,7 @@ func (i *Instances) AddSSHKeyToAllInstances(ctx context.Context, user string, ke
204
204
func (i * Instances ) NodeAddresses (ctx context.Context , name types.NodeName ) ([]v1.NodeAddress , error ) {
205
205
klog .V (4 ).Infof ("NodeAddresses(%v) called" , name )
206
206
207
- addrs , err := getAddressesByName (i .compute , name , i . networkingOpts , i . network )
207
+ addrs , err := getAddressesByName (i .compute , i . network , name , i . networkingOpts )
208
208
if err != nil {
209
209
return nil , err
210
210
}
@@ -237,7 +237,7 @@ func (i *Instances) NodeAddressesByProviderID(ctx context.Context, providerID st
237
237
return []v1.NodeAddress {}, err
238
238
}
239
239
240
- interfaces , err := getAttachedInterfacesByID (i .compute , server . ID , i . network )
240
+ interfaces , err := getAttachedInterfacesByID (i .compute , i . network , server . ID )
241
241
if err != nil {
242
242
return []v1.NodeAddress {}, err
243
243
}
@@ -343,7 +343,7 @@ func (i *Instances) InstanceMetadata(ctx context.Context, node *v1.Node) (*cloud
343
343
return nil , err
344
344
}
345
345
346
- interfaces , err := getAttachedInterfacesByID (i .compute , srv . ID , i . network )
346
+ interfaces , err := getAttachedInterfacesByID (i .compute , i . network , srv . ID )
347
347
if err != nil {
348
348
return nil , err
349
349
}
@@ -644,33 +644,33 @@ func nodeAddresses(srv *servers.Server, interfaces []attachinterfaces.Interface,
644
644
if len (addresses ) < len (allPrivates ) {
645
645
extraPrivates := make (map [string ][]Address )
646
646
// For each private network
647
- for k , v := range allPrivates {
648
- ok := false
647
+ for network , interfaceAddresses := range allPrivates {
648
+ found := false
649
649
// For each address in the private network
650
- for _ , a := range v {
651
- // Check if the address is directly connected
652
- for _ , v1 := range addresses {
653
- for _ , a1 := range v1 {
654
- if a .Addr == a1 .Addr {
655
- ok = true
650
+ for _ , interfaceAddress := range interfaceAddresses {
651
+ // Check if the address is directly assigned
652
+ for _ , srvAddresses := range addresses {
653
+ for _ , srvAddress := range srvAddresses {
654
+ if interfaceAddress .Addr == srvAddress .Addr {
655
+ found = true
656
656
break
657
657
}
658
658
}
659
659
}
660
660
}
661
- // All the addresses in the private network are not directly connected
661
+ // All the addresses in the private network are not directly assigned
662
662
// Save the private network
663
- if ! ok {
664
- extraPrivates [k ] = v
663
+ if ! found {
664
+ extraPrivates [network ] = interfaceAddresses
665
665
}
666
666
}
667
- klog .V (5 ).Infof ("Node '%s' extraPrivates '%s'" , srv .Name , extraPrivates )
668
- for k , v := range extraPrivates {
669
- v1 , ok := addresses [k ]
667
+ klog .V (5 ).Infof ("Node '%s' extra private interfaces '%s'" , srv .Name , extraPrivates )
668
+ for network , interfaceAddresses := range extraPrivates {
669
+ srvAddresses , ok := addresses [network ]
670
670
if ! ok {
671
- addresses [k ] = v
671
+ addresses [network ] = interfaceAddresses
672
672
} else {
673
- addresses [k ] = append (v1 , v ... )
673
+ addresses [network ] = append (srvAddresses , interfaceAddresses ... )
674
674
}
675
675
}
676
676
}
@@ -728,13 +728,13 @@ func nodeAddresses(srv *servers.Server, interfaces []attachinterfaces.Interface,
728
728
return addrs , nil
729
729
}
730
730
731
- func getAddressesByName (compute * gophercloud.ServiceClient , name types.NodeName , networkingOpts NetworkingOpts , network * gophercloud. ServiceClient ) ([]v1.NodeAddress , error ) {
731
+ func getAddressesByName (compute * gophercloud.ServiceClient , network * gophercloud. ServiceClient , name types.NodeName , networkingOpts NetworkingOpts ) ([]v1.NodeAddress , error ) {
732
732
srv , err := getServerByName (compute , name )
733
733
if err != nil {
734
734
return nil , err
735
735
}
736
736
737
- interfaces , err := getAttachedInterfacesByID (compute , srv .ID , network )
737
+ interfaces , err := getAttachedInterfacesByID (compute , network , srv .ID )
738
738
if err != nil {
739
739
return nil , err
740
740
}
@@ -754,56 +754,56 @@ func getSubInterfaces(interfaces []attachinterfaces.Interface, network *gophercl
754
754
}
755
755
allPages , err := trunks .List (network , listOpts ).AllPages ()
756
756
if err != nil {
757
- klog .Errorf ("Failed to list trunks: %v" , err )
757
+ klog .Infof ("Failed to list trunks: %v" , err )
758
758
return subports , nil
759
759
}
760
760
allTrunks , err := trunks .ExtractTrunks (allPages )
761
761
if err != nil {
762
762
klog .Errorf ("Failed to extract trunks: %v" , err )
763
763
return subports , err
764
764
}
765
+ if len (allTrunks ) > 1 {
766
+ klog .Errorf ("It is not expected to see more than one trunk on a single port %s" , iface .PortID )
767
+ return subports , err
768
+ }
765
769
// Get subports attached to the trunks
766
- for _ , trunk := range allTrunks {
767
- if len (trunk .Subports ) == 0 {
768
- continue
770
+ trunk := allTrunks [0 ]
771
+ klog .V (5 ).Infof ("Subports for trunk %s: %v" , trunk .ID , trunk .Subports )
772
+ // Arrange subports as for directly attached ports
773
+ for _ , sport := range trunk .Subports {
774
+ p , err := ports .Get (network , sport .PortID ).Extract ()
775
+ if err != nil {
776
+ klog .Errorf ("Failed to get port info for subport %s: %v" , sport .PortID , err )
777
+ return subports , err
769
778
}
770
- klog .V (5 ).Infof ("Subports for trunk %s: %v" , trunk .ID , trunk .Subports )
771
- // Arrange subports as for directly attached ports
772
- for _ , sport := range trunk .Subports {
773
- p , err := ports .Get (network , sport .PortID ).Extract ()
774
- if err != nil {
775
- klog .Errorf ("Failed to get port info for subport %s: %v" , sport .PortID , err )
776
- return subports , err
777
- }
778
- n , err := networks .Get (network , p .NetworkID ).Extract ()
779
- if err != nil {
780
- klog .Errorf ("Failed to get network info for subport %s: %v" , sport .PortID , err )
781
- return subports , err
782
- }
783
- var sface = 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 ,
794
- }
795
- sface .FixedIPs = append (sface .FixedIPs , ip2 )
779
+ n , err := networks .Get (network , p .NetworkID ).Extract ()
780
+ if err != nil {
781
+ klog .Errorf ("Failed to get network info for subport %s: %v" , sport .PortID , err )
782
+ return subports , err
783
+ }
784
+ var sface = attachinterfaces.Interface {
785
+ PortState : "ACTIVE" ,
786
+ FixedIPs : []attachinterfaces.FixedIP {},
787
+ PortID : p .ID ,
788
+ NetID : n .Name ,
789
+ MACAddr : p .MACAddress ,
790
+ }
791
+ for _ , ip := range p .FixedIPs {
792
+ var ip2 = attachinterfaces.FixedIP {
793
+ SubnetID : ip .SubnetID ,
794
+ IPAddress : ip .IPAddress ,
796
795
}
797
- subports = append (subports , sface )
796
+ sface . FixedIPs = append (sface . FixedIPs , ip2 )
798
797
}
798
+ subports = append (subports , sface )
799
799
}
800
800
}
801
801
klog .V (5 ).Infof ("Node has %d sub-interfaces '%v'" , len (subports ), subports )
802
802
return subports , nil
803
803
}
804
804
805
805
// getAttachedInterfacesByID returns the node interfaces of the specified instance.
806
- func getAttachedInterfacesByID (compute * gophercloud.ServiceClient , serviceID string , network * gophercloud.ServiceClient ) ([]attachinterfaces.Interface , error ) {
806
+ func getAttachedInterfacesByID (compute * gophercloud.ServiceClient , network * gophercloud.ServiceClient , serviceID string ) ([]attachinterfaces.Interface , error ) {
807
807
var interfaces []attachinterfaces.Interface
808
808
809
809
mc := metrics .NewMetricContext ("server_os_interface" , "list" )
0 commit comments