@@ -196,15 +196,16 @@ func filterPortsByNodeAddresses(nsxClients *NsxClients, ports *[]nsxtmgr.Logical
196196 if err != nil {
197197 return filteredPorts , err
198198 }
199- if len (logicalPort .RealizedBindings ) == 0 {
199+ if len (logicalPort .RealizedBindings ) == 0 && len ( logicalPort . DiscoveredBindings ) {
200200 continue
201201 }
202202 var collectedAddresses []string
203- for _ , realizedBinding := range logicalPort .RealizedBindings {
204- address := realizedBinding .Binding .IpAddress
203+ bindings := append (logicalPort .RealizedBindings , logicalPort .DiscoveredBindings )
204+ for _ , binding := range bindings {
205+ address := binding .Binding .IpAddress
205206 if inSlice (address , nodeAddresses ) && ! inSlice (address , collectedAddresses ) {
206207 log .Info (fmt .Sprintf ("Node address %s matches port %s" , address , port .Id ))
207- // The addresses in logicalPort.RealizedBindings may be duplicate so we use collectedAddresses to ensure the uniqueness in filteredPorts.
208+ // The addresses in bindings may be duplicate so we use collectedAddresses to ensure the uniqueness in filteredPorts.
208209 collectedAddresses = append (collectedAddresses , address )
209210 filteredPorts = append (filteredPorts , & port )
210211 }
@@ -220,69 +221,6 @@ func filterPortsByNodeAddresses(nsxClients *NsxClients, ports *[]nsxtmgr.Logical
220221 return filteredPorts , err
221222}
222223
223- func searchNodePortByVcNameAddress (nsxClients * NsxClients , nodeName string , nodeAddress string ) (* model.SegmentPort , error ) {
224- log .Info (fmt .Sprintf ("Searching segment port for node %s" , nodeName ))
225- connector := nsxClients .PolicyConnector
226- searchClient := search .NewDefaultQueryClient (connector )
227- // The format of node segment port display_name:
228- // <vmx file's parent directory name>/<node vSphere name>.vmx@<tn-id>
229- // The vmx file's parent directory name can include VM name or a uid string for a vSAN VM
230- searchString := fmt .Sprintf ("resource_type:SegmentPort AND display_name:*\\ /%s.vmx*" , nodeName )
231- ports , err := searchClient .List (searchString , nil , nil , nil , nil , nil )
232- if err != nil {
233- return nil , err
234- }
235- if len (ports .Results ) == 0 {
236- return nil , errors .Errorf ("segment port for node %s not found" , nodeName )
237- }
238- portIndex := 0
239- portIndex , err = filterSegmentPorts (nsxClients , ports .Results , nodeName , nodeAddress )
240- if err != nil {
241- return nil , errors .Errorf ("found %d segment ports for node %s, but none with address %s: %s" , len (ports .Results ), nodeName , nodeAddress , err )
242- }
243- portId , err := ports .Results [portIndex ].Field ("id" )
244- if err != nil {
245- return nil , err
246- }
247- portPath , err := ports .Results [portIndex ].Field ("parent_path" )
248- if err != nil {
249- return nil , err
250- }
251- portIdValue := (portId ).(* data.StringValue ).Value ()
252- portPathValue := (portPath ).(* data.StringValue ).Value ()
253- segmentPort := model.SegmentPort {
254- Id : & portIdValue ,
255- Path : & portPathValue ,
256- }
257- return & segmentPort , nil
258- }
259-
260- func filterSegmentPorts (nsxClients * NsxClients , ports []* data.StructValue , nodeName string , nodeAddress string ) (int , error ) {
261- log .Info (fmt .Sprintf ("Found %d segment ports for node %s, checking addresses" , len (ports ), nodeName ))
262- for idx , port := range ports {
263- portPolicyId , err := port .Field ("id" )
264- if err != nil {
265- return - 1 , err
266- }
267- portPolicyIdValue := (portPolicyId ).(* data.StringValue ).Value ()
268- // there's an assumption that the policy ID has format "default:<manager_id>"
269- portMgrId := string ([]byte (portPolicyIdValue )[8 :])
270- nsxClient := nsxClients .ManagerClient
271- logicalPort , _ , err := nsxClient .LogicalSwitchingApi .GetLogicalPortState (nsxClient .Context , portMgrId )
272- if err != nil {
273- return - 1 , err
274- }
275- if len (logicalPort .RealizedBindings ) == 0 {
276- continue
277- }
278- address := logicalPort .RealizedBindings [0 ].Binding .IpAddress
279- if address == nodeAddress {
280- return idx , nil
281- }
282- }
283- return - 1 , errors .Errorf ("no port matches" )
284- }
285-
286224func getConnectorTLSConfig (insecure bool , clientCertFile string , clientKeyFile string , caFile string ) (* tls.Config , error ) {
287225 tlsConfig := tls.Config {InsecureSkipVerify : insecure }
288226
0 commit comments