Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modified ChassisGroupChassisDelete to convert chassis_name #14904

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 33 additions & 4 deletions lxd/network/openvswitch/ovn.go
Original file line number Diff line number Diff line change
Expand Up @@ -1612,20 +1612,49 @@
}

// ChassisGroupChassisDelete deletes a chassis ID from an HA chassis group.
func (o *OVN) ChassisGroupChassisDelete(haChassisGroupName OVNChassisGroup, chassisID string) error {

Check failure on line 1615 in lxd/network/openvswitch/ovn.go

View workflow job for this annotation

GitHub Actions / Code

empty-lines: extra empty line at the start of a block (revive)
// Check if chassis group exists. ovn-nbctl doesn't provide an "--if-exists" option for this.
output, err := o.nbctl("--no-headings", "--data=bare", "--colum=name,ha_chassis", "find", "ha_chassis_group", fmt.Sprintf("name=%s", string(haChassisGroupName)))

var chassisUUID string

// find the _uuid of the received chassis_name
output, err := o.nbctl("--format=csv", "--no-headings", "--data=bare", "--column=chassis_name,_uuid", "list", "ha_chassis")
if err != nil {
return err
}

Check failure on line 1624 in lxd/network/openvswitch/ovn.go

View workflow job for this annotation

GitHub Actions / Code

File is not properly formatted (gci)
lines := shared.SplitNTrimSpace(output, "\n", -1, true)

for _, line := range lines {
// node2,a74125a8-b580-4763-b389-11ce2c8c5509
fields := strings.Split(line, ",")

if len(fields) != 2 {
return fmt.Errorf("Unrecognised ha_chassis output %q", line)
}

if fields[0] == chassisID {
chassisUUID = fields[1]
break
}
}

if chassisUUID == "" {
return fmt.Errorf("Could not find chassis with name %q", chassisID)
}

// Check if chassis group exists. ovn-nbctl doesn't provide an "--if-exists" option for this.
output, err = o.nbctl("--no-headings", "--data=bare", "--colum=name,ha_chassis", "find", "ha_chassis_group", fmt.Sprintf("name=%s", string(haChassisGroupName)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
output, err = o.nbctl("--no-headings", "--data=bare", "--colum=name,ha_chassis", "find", "ha_chassis_group", fmt.Sprintf("name=%s", string(haChassisGroupName)))
output, err = o.nbctl("--no-headings", "--data=bare", "--colum=name,ha_chassis", "find", "ha_chassis_group", "name="+string(haChassisGroupName))

fmt.Sprintf() is slow so we recently started replacing it with simpler/faster string concatenation.

if err != nil {
return err
}

Check failure on line 1650 in lxd/network/openvswitch/ovn.go

View workflow job for this annotation

GitHub Actions / Code

File is not properly formatted (gci)
lines = shared.SplitNTrimSpace(output, "\n", -1, true)
if len(lines) > 1 {
existingChassisGroup := lines[0]
members := shared.SplitNTrimSpace(lines[1], " ", -1, true)

// Remove chassis from group if exists.
if existingChassisGroup == string(haChassisGroupName) && shared.ValueInSlice(chassisID, members) {
if existingChassisGroup == string(haChassisGroupName) && shared.ValueInSlice(chassisUUID, members) {
_, err := o.nbctl("ha-chassis-group-remove-chassis", string(haChassisGroupName), chassisID)
if err != nil {
return err
Expand Down Expand Up @@ -1914,7 +1943,7 @@
return fmt.Errorf("Failed getting UUIDs: %w", err)
}

var args []string

Check failure on line 1946 in lxd/network/openvswitch/ovn.go

View workflow job for this annotation

GitHub Actions / Code

Consider pre-allocating `args` (prealloc)

for _, lbUUID := range lbUUIDs {
if len(args) > 0 {
Expand Down Expand Up @@ -2084,7 +2113,7 @@
// AddressSetAdd adds the supplied addresses to the address sets, or creates a new address sets if needed.
// The address set name used is "<addressSetPrefix>_ip<IP version>", e.g. "foo_ip4".
func (o *OVN) AddressSetAdd(addressSetPrefix OVNAddressSet, addresses ...net.IPNet) error {
var args []string

Check failure on line 2116 in lxd/network/openvswitch/ovn.go

View workflow job for this annotation

GitHub Actions / Code

Consider pre-allocating `args` (prealloc)
ipVersions := make(map[uint]struct{})

for _, address := range addresses {
Expand Down Expand Up @@ -2128,7 +2157,7 @@
// AddressSetRemove removes the supplied addresses from the address set.
// The address set name used is "<addressSetPrefix>_ip<IP version>", e.g. "foo_ip4".
func (o *OVN) AddressSetRemove(addressSetPrefix OVNAddressSet, addresses ...net.IPNet) error {
var args []string

Check failure on line 2160 in lxd/network/openvswitch/ovn.go

View workflow job for this annotation

GitHub Actions / Code

Consider pre-allocating `args` (prealloc)

for _, address := range addresses {
if len(args) > 0 {
Expand Down
Loading