Skip to content

Commit

Permalink
Merge pull request #750 from Abhiram824/libovsdb_integration
Browse files Browse the repository at this point in the history
incusd/network/ovn: rewrote LogicalRouterAdd to use o.client
  • Loading branch information
stgraber authored Apr 19, 2024
2 parents 46fd570 + ec288a6 commit 43c20cc
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
2 changes: 1 addition & 1 deletion internal/server/network/driver_ovn.go
Original file line number Diff line number Diff line change
Expand Up @@ -2071,7 +2071,7 @@ func (n *ovn) setup(update bool) error {
}

// Create logical router.
err = n.state.OVNNB.LogicalRouterAdd(n.getRouterName(), update)
err = n.state.OVNNB.CreateLogicalRouter(context.TODO(), n.getRouterName(), update)
if err != nil {
return fmt.Errorf("Failed adding router: %w", err)
}
Expand Down
38 changes: 32 additions & 6 deletions internal/server/network/ovn/ovn_nb_actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,15 +182,41 @@ type OVNRouterPeering struct {
TargetRouterRoutes []net.IPNet
}

// LogicalRouterAdd adds a named logical router.
func (o *NB) LogicalRouterAdd(routerName OVNRouter, mayExist bool) error {
args := []string{}

if mayExist {
args = append(args, "--may-exist")
// CreateLogicalRouter adds a named logical router.
// If mayExist is true, then an existing resource of the same name is not treated as an error.
func (o *NB) CreateLogicalRouter(ctx context.Context, routerName OVNRouter, mayExist bool) error {
logicalRouter := ovnNB.LogicalRouter{
Name: string(routerName),
}

_, err := o.nbctl(append(args, "lr-add", string(routerName))...)
// Check if already exists.
err := o.get(ctx, &logicalRouter)
if err != nil && err != ErrNotFound {
return err
}

if logicalRouter.UUID != "" {
if mayExist {
return nil
}

return ErrExists
}

// Create the record.
operations, err := o.client.Create(&logicalRouter)
if err != nil {
return err
}

// Apply the changes.
resp, err := o.client.Transact(ctx, operations...)
if err != nil {
return err
}

_, err = ovsdb.CheckOperationResults(resp, operations)
if err != nil {
return err
}
Expand Down

0 comments on commit 43c20cc

Please sign in to comment.