@@ -19,13 +19,13 @@ package openstack
19
19
import (
20
20
"bytes"
21
21
"context"
22
+ "encoding/json"
22
23
"fmt"
23
24
"net"
24
25
sysos "os"
25
26
"regexp"
26
27
"sort"
27
28
"strings"
28
- "unsafe"
29
29
30
30
"github.com/gophercloud/gophercloud"
31
31
"github.com/gophercloud/gophercloud/openstack/compute/v2/flavors"
@@ -638,53 +638,50 @@ func nodeAddresses(srv *servers.Server, ports []neutronports.Port, client *gophe
638
638
639
639
// Add the addresses assigned on subports via trunk
640
640
// This exposes the vlan networks to which subports are attached
641
+ subportAddresses := make (map [string ][]Address )
642
+
641
643
type portWithTrunkDetails struct {
642
644
neutronports.Port
643
645
trunk_details.TrunkDetailsExt
644
646
}
647
+ var portDetails []portWithTrunkDetails
645
648
646
- var subports []neutronports.Port
647
- for _ , port := range ports {
648
- portExt := * ((* portWithTrunkDetails )(unsafe .Pointer (& port )))
649
- continue
650
- // under testing
651
- klog .V (5 ).Infof ("Node '%s' port '%s' trunk_details '%v'" , srv .Name , portExt .Name , portExt .TrunkDetails )
652
- for _ , subport := range portExt .TrunkDetails .SubPorts {
653
- p , err := neutronports .Get (client , subport .PortID ).Extract ()
654
- if err != nil {
655
- klog .Errorf ("Failed to get subport %s details: %v" , subport .PortID , err )
656
- continue
657
- }
658
- n , err := networks .Get (client , p .NetworkID ).Extract ()
659
- if err != nil {
660
- klog .Errorf ("Failed to get subport %s network details: %v" , subport .PortID , err )
661
- continue
649
+ bodyBytes , err := json .Marshal (ports )
650
+ if err == nil {
651
+ if json .Unmarshal (bodyBytes , & portDetails ) == nil {
652
+ for _ , portExt := range portDetails {
653
+ klog .V (5 ).Infof ("Node '%s' port '%s' trunk_details '%v'" , srv .Name , portExt .Name , portExt .TrunkDetails )
654
+ for _ , subport := range portExt .TrunkDetails .SubPorts {
655
+ p , err := neutronports .Get (client , subport .PortID ).Extract ()
656
+ if err != nil {
657
+ klog .Errorf ("Failed to get subport %s details: %v" , subport .PortID , err )
658
+ continue
659
+ }
660
+ n , err := networks .Get (client , p .NetworkID ).Extract ()
661
+ if err != nil {
662
+ klog .Errorf ("Failed to get subport %s network details: %v" , subport .PortID , err )
663
+ continue
664
+ }
665
+ for _ , fixedIP := range p .FixedIPs {
666
+ isIPv6 := net .ParseIP (fixedIP .IPAddress ).To4 () == nil
667
+ if ! (isIPv6 && networkingOpts .IPv6SupportDisabled ) {
668
+ addr := Address {IPType : "fixed" , Addr : fixedIP .IPAddress }
669
+ subportAddresses [n .Name ] = append (subportAddresses [n .Name ], addr )
670
+ }
671
+ }
672
+ }
662
673
}
663
- p .NetworkID = n .Name
664
- subports = append (subports , * p )
665
674
}
666
675
}
667
676
668
- if len (subports ) > 0 {
669
- subportAddresses := make (map [string ][]Address )
670
- for _ , subport := range subports {
671
- for _ , fixedIP := range subport .FixedIPs {
672
- isIPv6 := net .ParseIP (fixedIP .IPAddress ).To4 () == nil
673
- if ! (isIPv6 && networkingOpts .IPv6SupportDisabled ) {
674
- addr := Address {IPType : "fixed" , Addr : fixedIP .IPAddress }
675
- subportAddresses [subport .NetworkID ] = append (subportAddresses [subport .NetworkID ], addr )
676
- }
677
- }
678
- }
679
- for nw , ips := range subportAddresses {
680
- srvAddresses , ok := addresses [nw ]
681
- if ! ok {
682
- addresses [nw ] = ips
683
- } else {
684
- // this is to take care the corner case
685
- // where the same network is attached to the node both directly and via trunk
686
- addresses [nw ] = append (srvAddresses , ips ... )
687
- }
677
+ for nw , ips := range subportAddresses {
678
+ srvAddresses , ok := addresses [nw ]
679
+ if ! ok {
680
+ addresses [nw ] = ips
681
+ } else {
682
+ // this is to take care the corner case
683
+ // where the same network is attached to the node both directly and via trunk
684
+ addresses [nw ] = append (srvAddresses , ips ... )
688
685
}
689
686
}
690
687
0 commit comments