-
Notifications
You must be signed in to change notification settings - Fork 431
/
ovn-nb-logical_switch_port.go
666 lines (539 loc) · 18.9 KB
/
ovn-nb-logical_switch_port.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
package ovs
import (
"context"
"fmt"
"strings"
"github.com/ovn-org/libovsdb/client"
"github.com/ovn-org/libovsdb/ovsdb"
ovsclient "github.com/kubeovn/kube-ovn/pkg/ovsdb/client"
"github.com/kubeovn/kube-ovn/pkg/ovsdb/ovnnb"
"github.com/kubeovn/kube-ovn/pkg/util"
)
func (c *ovnClient) CreateLogicalSwitchPort(lsName, lspName, ip, mac, podName, namespace string, portSecurity bool, securityGroups string, vips string, enableDHCP bool, dhcpOptions *DHCPOptionsUUIDs, vpc string) error {
exist, err := c.LogicalSwitchPortExists(lspName)
if err != nil {
return err
}
// ignore
if exist {
return nil
}
/* normal lsp creation */
lsp := &ovnnb.LogicalSwitchPort{
UUID: ovsclient.NamedUUID(),
Name: lspName,
ExternalIDs: make(map[string]string),
}
ipList := strings.Split(ip, ",")
vipList := strings.Split(vips, ",")
addresses := make([]string, 0, len(ipList)+len(vipList)+1) // +1 is the mac length
addresses = append(addresses, mac)
addresses = append(addresses, ipList...)
// addresses is the first element of addresses
lsp.Addresses = []string{strings.Join(addresses, " ")}
if portSecurity {
if len(vips) != 0 {
addresses = append(addresses, vipList...)
}
// addresses is the first element of port_security
lsp.PortSecurity = []string{strings.Join(addresses, " ")}
// set security groups
if len(securityGroups) != 0 {
lsp.ExternalIDs[sgsKey] = strings.ReplaceAll(securityGroups, ",", "/")
sgList := strings.Split(securityGroups, ",")
for _, sg := range sgList {
lsp.ExternalIDs[associatedSgKeyPrefix+sg] = "true"
}
}
}
// add lsp which does not belong to default vpc to default-securitygroup when default-securitygroup configMap exist
if vpc != "" && vpc != util.DefaultVpc && !strings.Contains(securityGroups, util.DefaultSecurityGroupName) {
lsp.ExternalIDs[associatedSgKeyPrefix+util.DefaultSecurityGroupName] = "false"
}
// set vips info to external-ids
if len(vips) != 0 {
lsp.ExternalIDs["vips"] = vips
lsp.ExternalIDs["attach-vips"] = "true"
}
// set pod info to external-ids
if len(podName) != 0 && len(namespace) != 0 {
lsp.ExternalIDs["pod"] = namespace + "/" + podName
}
// set dhcp options
if enableDHCP && dhcpOptions != nil {
if len(dhcpOptions.DHCPv4OptionsUUID) != 0 {
lsp.Dhcpv4Options = &dhcpOptions.DHCPv4OptionsUUID
}
if len(dhcpOptions.DHCPv6OptionsUUID) != 0 {
lsp.Dhcpv6Options = &dhcpOptions.DHCPv6OptionsUUID
}
}
ops, err := c.CreateLogicalSwitchPortOp(lsp, lsName)
if err != nil {
return fmt.Errorf("generate operations for creating logical switch port %s: %v", lspName, err)
}
if err = c.Transact("lsp-add", ops); err != nil {
return fmt.Errorf("create logical switch port %s: %v", lspName, err)
}
return nil
}
// CreateLocalnetLogicalSwitchPort create localnet type logical switch port
func (c *ovnClient) CreateLocalnetLogicalSwitchPort(lsName, lspName, provider string, vlanID int) error {
exist, err := c.LogicalSwitchPortExists(lspName)
if err != nil {
return err
}
// ignore
if exist {
return nil
}
/* create logical switch port */
lsp := &ovnnb.LogicalSwitchPort{
UUID: ovsclient.NamedUUID(),
Name: lspName,
Type: "localnet",
Addresses: []string{"unknown"},
Options: map[string]string{
"network_name": provider,
},
}
if vlanID > 0 && vlanID < 4096 {
lsp.Tag = &vlanID
}
ops, err := c.CreateLogicalSwitchPortOp(lsp, lsName)
if err != nil {
return err
}
if err = c.Transact("lsp-add", ops); err != nil {
return fmt.Errorf("create localnet logical switch port %s: %v", lspName, err)
}
return nil
}
// CreateVirtualLogicalSwitchPorts create several virtual type logical switch port once
func (c *ovnClient) CreateVirtualLogicalSwitchPorts(lsName string, ips ...string) error {
ops := make([]ovsdb.Operation, 0, len(ips))
for _, ip := range ips {
lspName := fmt.Sprintf("%s-vip-%s", lsName, ip)
exist, err := c.LogicalSwitchPortExists(lspName)
if err != nil {
return err
}
// ignore
if exist {
continue
}
lsp := &ovnnb.LogicalSwitchPort{
UUID: ovsclient.NamedUUID(),
Name: lspName,
Type: "virtual",
Options: map[string]string{
"virtual-ip": ip,
},
}
op, err := c.CreateLogicalSwitchPortOp(lsp, lsName)
if err != nil {
return err
}
ops = append(ops, op...)
}
if err := c.Transact("lsp-add", ops); err != nil {
return fmt.Errorf("create virtual logical switch ports for logical switch %s: %v", lsName, err)
}
return nil
}
// CreateBareLogicalSwitchPort create logical switch port with basic configuration
func (c *ovnClient) CreateBareLogicalSwitchPort(lsName, lspName, ip, mac string) error {
exist, err := c.LogicalSwitchPortExists(lspName)
if err != nil {
return err
}
// ignore
if exist {
return nil
}
ipList := strings.Split(ip, ",")
addresses := make([]string, 0, len(ipList)+1) // +1 is the mac length
addresses = append(addresses, mac)
addresses = append(addresses, ipList...)
/* create logical switch port */
lsp := &ovnnb.LogicalSwitchPort{
UUID: ovsclient.NamedUUID(),
Name: lspName,
Addresses: []string{strings.Join(addresses, " ")}, // addresses is the first element of addresses
}
ops, err := c.CreateLogicalSwitchPortOp(lsp, lsName)
if err != nil {
return err
}
if err = c.Transact("lsp-add", ops); err != nil {
return fmt.Errorf("create logical switch port %s: %v", lspName, err)
}
return nil
}
// CreateVirtualLogicalSwitchPorts update several virtual type logical switch port virtual-parents once
func (c *ovnClient) SetLogicalSwitchPortVirtualParents(lsName, parents string, ips ...string) error {
ops := make([]ovsdb.Operation, 0, len(ips))
for _, ip := range ips {
lspName := fmt.Sprintf("%s-vip-%s", lsName, ip)
lsp, err := c.GetLogicalSwitchPort(lspName, true)
if err != nil {
return fmt.Errorf("get logical switch port %s: %v", lspName, err)
}
lsp.Options["virtual-parents"] = parents
if len(parents) == 0 {
delete(lsp.Options, "virtual-parents")
}
op, err := c.UpdateLogicalSwitchPortOp(lsp, &lsp.Options)
if err != nil {
return err
}
ops = append(ops, op...)
}
if err := c.Transact("lsp-update", ops); err != nil {
return fmt.Errorf("set logical switch port virtual-parents %v", err)
}
return nil
}
// SetLogicalSwitchPortSecurity set logical switch port port_security
func (c *ovnClient) SetLogicalSwitchPortSecurity(portSecurity bool, lspName, mac, ips, vips string) error {
lsp, err := c.GetLogicalSwitchPort(lspName, false)
if err != nil {
return fmt.Errorf("get logical switch port %s: %v", lspName, err)
}
lsp.PortSecurity = nil
if portSecurity {
ipList := strings.Split(ips, ",")
vipList := strings.Split(vips, ",")
addresses := make([]string, 0, len(ipList)+len(vipList)+1) // +1 is the mac length
addresses = append(addresses, mac)
addresses = append(addresses, ipList...)
// it's necessary to add vip to port_security
if vips != "" {
addresses = append(addresses, vipList...)
}
// addresses is the first element of port_security
lsp.PortSecurity = []string{strings.Join(addresses, " ")}
}
if vips != "" {
// be careful that don't overwrite origin ExternalIDs
if lsp.ExternalIDs == nil {
lsp.ExternalIDs = make(map[string]string)
}
lsp.ExternalIDs["vips"] = vips
lsp.ExternalIDs["attach-vips"] = "true"
} else {
delete(lsp.ExternalIDs, "vips")
delete(lsp.ExternalIDs, "attach-vips")
}
if err := c.UpdateLogicalSwitchPort(lsp, &lsp.PortSecurity, &lsp.ExternalIDs); err != nil {
return fmt.Errorf("set logical switch port %s port_security %v: %v", lspName, lsp.PortSecurity, err)
}
return nil
}
// SetLogicalSwitchPortExternalIds set logical switch port external ids
func (c *ovnClient) SetLogicalSwitchPortExternalIds(lspName string, externalIds map[string]string) error {
lsp, err := c.GetLogicalSwitchPort(lspName, false)
if err != nil {
return fmt.Errorf("get logical switch port %s: %v", lspName, err)
}
if lsp.ExternalIDs == nil {
lsp.ExternalIDs = make(map[string]string)
}
for k, v := range externalIds {
lsp.ExternalIDs[k] = v
}
if err := c.UpdateLogicalSwitchPort(lsp, &lsp.ExternalIDs); err != nil {
return fmt.Errorf("set logical switch port %s external ids %v: %v", lspName, externalIds, err)
}
return nil
}
// SetLogicalSwitchPortSecurityGroup set logical switch port security group,
// op is 'add' or 'remove'
func (c *ovnClient) SetLogicalSwitchPortSecurityGroup(lsp *ovnnb.LogicalSwitchPort, op string, sgs ...string) ([]string, error) {
if len(sgs) == 0 {
return nil, nil
}
if op != "add" && op != "remove" {
return nil, fmt.Errorf("op must be 'add' or 'remove'")
}
diffSgs := make([]string, 0, len(sgs))
oldSgs := getLogicalSwitchPortSgs(lsp)
for _, sgName := range sgs {
associatedSgKey := associatedSgKeyPrefix + sgName
if op == "add" {
if _, ok := oldSgs[sgName]; ok {
continue // ignore existent
}
lsp.ExternalIDs[associatedSgKey] = "true"
oldSgs[sgName] = struct{}{}
diffSgs = append(diffSgs, sgName)
} else {
if _, ok := oldSgs[sgName]; !ok {
continue // ignore non-existent
}
lsp.ExternalIDs[associatedSgKey] = "false"
delete(oldSgs, sgName)
diffSgs = append(diffSgs, sgName)
}
}
newSgs := ""
for sg := range oldSgs {
if len(newSgs) != 0 {
newSgs += "/" + sg
} else {
newSgs = sg
}
}
lsp.ExternalIDs[sgsKey] = newSgs
if len(newSgs) == 0 { // when all sgs had been removed, delete sgsKey
delete(lsp.ExternalIDs, sgsKey)
}
if err := c.UpdateLogicalSwitchPort(lsp, &lsp.ExternalIDs); err != nil {
return nil, fmt.Errorf("set logical switch port %s security group %v: %v", lsp.Name, newSgs, err)
}
return diffSgs, nil
}
// SetLogicalSwitchPortsSecurityGroup set logical switch port security group,
// op is 'add' or 'remove'
func (c *ovnClient) SetLogicalSwitchPortsSecurityGroup(sgName string, op string) error {
if op != "add" && op != "remove" {
return fmt.Errorf("op must be 'add' or 'remove'")
}
/* list sg port */
associatedSgKey := associatedSgKeyPrefix + sgName
associated := "false" // list false associated sg port when add sg to port external_ids
if op == "remove" { // list true associated sg port when remove sg from port external_ids
associated = "true"
}
externalIds := map[string]string{associatedSgKey: associated}
lsps, err := c.ListNormalLogicalSwitchPorts(true, externalIds)
if err != nil {
return fmt.Errorf("list logical switch ports with external_ids %v: %v", externalIds, err)
}
/* add to or remove from sgs form port external_ids */
for _, lsp := range lsps {
if _, err := c.SetLogicalSwitchPortSecurityGroup(&lsp, op, sgName); err != nil {
return fmt.Errorf("set logical switch port %s security group %s: %v", lsp.Name, sgName, err)
}
}
return nil
}
// EnablePortLayer2forward set logical switch port addresses as 'unknown'
func (c *ovnClient) EnablePortLayer2forward(lspName string) error {
lsp, err := c.GetLogicalSwitchPort(lspName, false)
if err != nil {
return fmt.Errorf("get logical switch port %s: %v", lspName, err)
}
lsp.Addresses = []string{"unknown"}
if err := c.UpdateLogicalSwitchPort(lsp, &lsp.Addresses); err != nil {
return fmt.Errorf("set logical switch port %s addressed=unknown: %v", lspName, err)
}
return nil
}
func (c *ovnClient) SetLogicalSwitchPortVlanTag(lspName string, vlanID int) error {
// valid vlan id is 0~4095
if vlanID < 0 || vlanID > 4095 {
return fmt.Errorf("invalid vlan id %d", vlanID)
}
lsp, err := c.GetLogicalSwitchPort(lspName, false)
if err != nil {
return fmt.Errorf("get logical switch port %s: %v", lspName, err)
}
// no need update vlan id when vlan id is the same
if lsp.Tag != nil && *lsp.Tag == vlanID {
return nil
}
lsp.Tag = &vlanID
if vlanID == 0 {
lsp.Tag = nil
}
if err := c.UpdateLogicalSwitchPort(lsp, &lsp.Tag); err != nil {
return fmt.Errorf("set logical switch port %s tag %d: %v", lspName, vlanID, err)
}
return nil
}
// UpdateLogicalSwitchPort update logical switch port
func (c *ovnClient) UpdateLogicalSwitchPort(lsp *ovnnb.LogicalSwitchPort, fields ...interface{}) error {
if lsp == nil {
return fmt.Errorf("logical_switch_port is nil")
}
op, err := c.Where(lsp).Update(lsp, fields...)
if err != nil {
return fmt.Errorf("generate operations for updating logical switch port %s: %v", lsp.Name, err)
}
if err = c.Transact("lsp-update", op); err != nil {
return fmt.Errorf("update logical switch port %s: %v", lsp.Name, err)
}
return nil
}
// DeleteLogicalSwitchPort delete logical switch port in ovn
func (c *ovnClient) DeleteLogicalSwitchPort(lspName string) error {
ops, err := c.DeleteLogicalSwitchPortOp(lspName)
if err != nil {
return err
}
if err = c.Transact("lsp-del", ops); err != nil {
return fmt.Errorf("delete logical switch port %s", lspName)
}
return nil
}
// GetLogicalSwitchPort get logical switch port by name
func (c *ovnClient) GetLogicalSwitchPort(lspName string, ignoreNotFound bool) (*ovnnb.LogicalSwitchPort, error) {
ctx, cancel := context.WithTimeout(context.Background(), c.Timeout)
defer cancel()
lsp := &ovnnb.LogicalSwitchPort{Name: lspName}
if err := c.Get(ctx, lsp); err != nil {
if ignoreNotFound && err == client.ErrNotFound {
return nil, nil
}
return nil, fmt.Errorf("get logical switch port %s: %v", lspName, err)
}
return lsp, nil
}
// ListNormalLogicalSwitchPorts list logical switch ports which type is ""
func (c *ovnClient) ListNormalLogicalSwitchPorts(needVendorFilter bool, externalIDs map[string]string) ([]ovnnb.LogicalSwitchPort, error) {
lsps, err := c.ListLogicalSwitchPorts(needVendorFilter, externalIDs, func(lsp *ovnnb.LogicalSwitchPort) bool {
return lsp.Type == ""
})
if err != nil {
return nil, fmt.Errorf("list logical switch ports: %v", err)
}
return lsps, nil
}
// ListLogicalSwitchPortsWithLegacyExternalIDs list logical switch ports with legacy external-ids
func (c *ovnClient) ListLogicalSwitchPortsWithLegacyExternalIDs() ([]ovnnb.LogicalSwitchPort, error) {
ctx, cancel := context.WithTimeout(context.Background(), c.Timeout)
defer cancel()
lspList := make([]ovnnb.LogicalSwitchPort, 0)
if err := c.WhereCache(func(lsp *ovnnb.LogicalSwitchPort) bool {
return len(lsp.ExternalIDs) == 0 || lsp.ExternalIDs[logicalSwitchKey] == "" || lsp.ExternalIDs["vendor"] == ""
}).List(ctx, &lspList); err != nil {
return nil, fmt.Errorf("failed to list logical switch ports with legacy external-ids: %v", err)
}
return lspList, nil
}
// ListLogicalSwitchPorts list logical switch ports
func (c *ovnClient) ListLogicalSwitchPorts(needVendorFilter bool, externalIDs map[string]string, filter func(lsp *ovnnb.LogicalSwitchPort) bool) ([]ovnnb.LogicalSwitchPort, error) {
ctx, cancel := context.WithTimeout(context.Background(), c.Timeout)
defer cancel()
lspList := make([]ovnnb.LogicalSwitchPort, 0)
if err := c.WhereCache(logicalSwitchPortFilter(needVendorFilter, externalIDs, filter)).List(ctx, &lspList); err != nil {
return nil, fmt.Errorf("list logical switch ports: %v", err)
}
return lspList, nil
}
func (c *ovnClient) LogicalSwitchPortExists(name string) (bool, error) {
lsp, err := c.GetLogicalSwitchPort(name, true)
return lsp != nil, err
}
// CreateLogicalSwitchPortOp create operations which create logical switch port
func (c *ovnClient) CreateLogicalSwitchPortOp(lsp *ovnnb.LogicalSwitchPort, lsName string) ([]ovsdb.Operation, error) {
if lsp == nil {
return nil, fmt.Errorf("logical_switch_port is nil")
}
if lsp.ExternalIDs == nil {
lsp.ExternalIDs = make(map[string]string)
}
// attach necessary info
lsp.ExternalIDs[logicalSwitchKey] = lsName
lsp.ExternalIDs["vendor"] = util.CniTypeName
/* create logical switch port */
lspCreateOp, err := c.Create(lsp)
if err != nil {
return nil, fmt.Errorf("generate operations for creating logical switch port %s: %v", lsp.Name, err)
}
/* add logical switch port to logical switch*/
lspAddOp, err := c.LogicalSwitchUpdatePortOp(lsName, lsp.UUID, ovsdb.MutateOperationInsert)
if err != nil {
return nil, err
}
ops := make([]ovsdb.Operation, 0, len(lspCreateOp)+len(lspAddOp))
ops = append(ops, lspCreateOp...)
ops = append(ops, lspAddOp...)
return ops, nil
}
// DeleteLogicalSwitchPortOp create operations which delete logical switch port
func (c *ovnClient) DeleteLogicalSwitchPortOp(lspName string) ([]ovsdb.Operation, error) {
lsp, err := c.GetLogicalSwitchPort(lspName, true)
if err != nil {
return nil, fmt.Errorf("get logical switch port %s when generate delete operations: %v", lspName, err)
}
// not found, skip
if lsp == nil {
return nil, nil
}
lsName, ok := lsp.ExternalIDs[logicalSwitchKey]
if !ok {
return nil, fmt.Errorf("no %s exist in lsp's external_ids", logicalSwitchKey)
}
// remove logical switch port from logical switch
lspRemoveOp, err := c.LogicalSwitchUpdatePortOp(lsName, lsp.UUID, ovsdb.MutateOperationDelete)
if err != nil {
return nil, fmt.Errorf("generate operations for removing port %s from logical switch %s: %v", lspName, lsName, err)
}
// delete logical switch port
lspDelOp, err := c.Where(lsp).Delete()
if err != nil {
return nil, fmt.Errorf("generate operations for deleting logical switch port %s: %v", lspName, err)
}
ops := make([]ovsdb.Operation, 0, len(lspRemoveOp)+len(lspDelOp))
ops = append(ops, lspRemoveOp...)
ops = append(ops, lspDelOp...)
return ops, nil
}
// UpdateLogicalSwitchPortOp create operations which update logical switch port
func (c *ovnClient) UpdateLogicalSwitchPortOp(lsp *ovnnb.LogicalSwitchPort, fields ...interface{}) ([]ovsdb.Operation, error) {
// not found, skip
if lsp == nil {
return nil, nil
}
op, err := c.Where(lsp).Update(lsp, fields...)
if err != nil {
return nil, fmt.Errorf("generate operations for updating logical switch port %s: %v", lsp.Name, err)
}
return op, nil
}
// logicalSwitchPortFilter filter logical_switch_port which match the given externalIDs and the custom filter
func logicalSwitchPortFilter(needVendorFilter bool, externalIDs map[string]string, filter func(lsp *ovnnb.LogicalSwitchPort) bool) func(lsp *ovnnb.LogicalSwitchPort) bool {
return func(lsp *ovnnb.LogicalSwitchPort) bool {
if needVendorFilter && (len(lsp.ExternalIDs) == 0 || lsp.ExternalIDs["vendor"] != util.CniTypeName) {
return false
}
if len(lsp.ExternalIDs) < len(externalIDs) {
return false
}
if len(lsp.ExternalIDs) != 0 {
for k, v := range externalIDs {
// if only key exist but not value in externalIDs, we should include this lsp,
// it's equal to shell command `ovn-nbctl --columns=xx find logical_switch_port external_ids:key!=\"\"`
if len(v) == 0 {
if len(lsp.ExternalIDs[k]) == 0 {
return false
}
} else {
if lsp.ExternalIDs[k] != v {
return false
}
}
}
}
if filter != nil {
return filter(lsp)
}
return true
}
}
// getLogicalSwitchPortSgs get logical switch port security group
func getLogicalSwitchPortSgs(lsp *ovnnb.LogicalSwitchPort) map[string]struct{} {
if lsp == nil {
return nil
}
sgs := make(map[string]struct{})
for key, value := range lsp.ExternalIDs {
if strings.HasPrefix(key, associatedSgKeyPrefix) && value == "true" {
sgName := strings.ReplaceAll(key, associatedSgKeyPrefix, "")
sgs[sgName] = struct{}{}
}
}
return sgs
}