Skip to content

Commit

Permalink
replace api for get lsp id by name
Browse files Browse the repository at this point in the history
  • Loading branch information
hongzhen-ma committed Oct 13, 2021
1 parent c086dbd commit f459ca9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 15 deletions.
13 changes: 8 additions & 5 deletions pkg/controller/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -698,14 +698,17 @@ func (c *Controller) checkPodsChangedOnNode(pgName string, ports []string) (bool
return false, err
}

nameIdMap, err := c.ovnClient.ListLspForNodePortgroup()
if err != nil {
klog.Errorf("failed to list lsp info, %v", err)
return false, err
}

portIds := make([]string, 0, len(ports))
for _, port := range ports {
portId, err := c.ovnClient.ConvertLspNameToUuid(port)
if err != nil && !strings.Contains(err.Error(), "not found") {
klog.Errorf("failed to convert lsp name to uuid, %v", err)
continue
if portId, ok := nameIdMap[port]; ok {
portIds = append(portIds, portId)
}
portIds = append(portIds, portId)
}

for _, portId := range portIds {
Expand Down
29 changes: 19 additions & 10 deletions pkg/ovs/ovn-nbctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -1319,18 +1319,27 @@ func (c Client) ListPgPorts(pgName string) ([]string, error) {
return result, nil
}

func (c Client) ConvertLspNameToUuid(name string) (string, error) {
output, err := c.ovnNbCommand("--data=bare", "--no-heading", "--columns=_uuid", "find", "logical_switch_port", fmt.Sprintf("name=%s", name))
lines := strings.Split(output, "\n")
if len(lines) == 0 {
klog.Errorf("failed to get lsp uuid by name, %v", err)
return "", err
func (c Client) ListLspForNodePortgroup() (map[string]string, error) {
output, err := c.ovnNbCommand("--data=bare", "--format=csv", "--no-heading", "--columns=name,_uuid", "list", "logical_switch_port")
if err != nil {
klog.Errorf("failed to list logical-switch-port, %v", err)
return nil, err
}
if uuid := strings.TrimSpace(lines[0]); uuid != "" {
return uuid, nil
lines := strings.Split(output, "\n")
result := make(map[string]string, len(lines))
for _, l := range lines {
if len(strings.TrimSpace(l)) == 0 {
continue
}
parts := strings.Split(strings.TrimSpace(l), ",")
if len(parts) != 2 {
continue
}
name := strings.TrimSpace(parts[0])
uuid := strings.TrimSpace(parts[1])
result[name] = uuid
}

return "", fmt.Errorf("logical switch port %s not found", name)
return result, nil
}

func (c Client) SetPortsToPortGroup(portGroup string, portNames []string) error {
Expand Down

0 comments on commit f459ca9

Please sign in to comment.