Skip to content

Commit

Permalink
feat: merge ovn-nbctl request
Browse files Browse the repository at this point in the history
  • Loading branch information
oilbeater committed May 5, 2019
1 parent 5d54d8c commit 3c61745
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions pkg/ovs/ovn-nbctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,14 @@ func (c Client) CreatePort(ls, port, ip, mac string) (*nic, error) {
mac = address[0]
}
}
cidr, err := c.ovnNbCommand("get", "logical_switch", ls, "other_config:subnet")
output, err := c.ovnNbCommand("get", "logical_switch", ls, "other_config:subnet", "other_config:gateway")
if err != nil {
klog.Errorf("get switch %s failed %v", ls, err)
return nil, err
}
mask := strings.Split(cidr, "/")[1]

gw, err := c.ovnNbCommand("get", "logical_switch", ls, "other_config:gateway")
if err != nil {
klog.Errorf("get switch %s failed %v", ls, err)
return nil, err
}

return &nic{IpAddress: fmt.Sprintf("%s/%s", ip, mask), MacAddress: mac, CIDR: cidr, Gateway: gw}, nil
subnet, gw := strings.Trim(strings.Split(output, "\n")[0], "\""), strings.Trim(strings.Split(output, "\n")[1], "\"")
mask := strings.Split(subnet, "/")[1]
return &nic{IpAddress: fmt.Sprintf("%s/%s", ip, mask), MacAddress: mac, CIDR: subnet, Gateway: gw}, nil
}

type nic struct {
Expand Down

0 comments on commit 3c61745

Please sign in to comment.