Skip to content

Commit

Permalink
Merge pull request #480 from stgraber/migrate
Browse files Browse the repository at this point in the history
lxd-to-incus: Indicate what existing configuration was found
  • Loading branch information
hallyn authored Feb 11, 2024
2 parents 4577279 + 149b0c6 commit c982c14
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions cmd/lxd-to-incus/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,70 +127,70 @@ func (c *cmdMigrate) validate(source source, target target) error {
}

// Validate target empty.
targetCheckEmpty := func() (bool, error) {
targetCheckEmpty := func() (bool, string, error) {
// Check if more than one project.
names, err := targetClient.GetProjectNames()
if err != nil {
return false, err
return false, "", err
}

if len(names) > 1 {
return false, nil
return false, "projects", nil
}

// Check if more than one profile.
names, err = targetClient.GetProfileNames()
if err != nil {
return false, err
return false, "", err
}

if len(names) > 1 {
return false, nil
return false, "profiles", nil
}

// Check if any instance is present.
names, err = targetClient.GetInstanceNames(api.InstanceTypeAny)
if err != nil {
return false, err
return false, "", err
}

if len(names) > 0 {
return false, nil
return false, "instances", nil
}

// Check if any storage pool is present.
names, err = targetClient.GetStoragePoolNames()
if err != nil {
return false, err
return false, "", err
}

if len(names) > 0 {
return false, nil
return false, "storage pools", nil
}

// Check if any network is present.
networks, err := targetClient.GetNetworks()
if err != nil {
return false, err
return false, "", err
}

for _, network := range networks {
if network.Managed {
return false, nil
return false, "networks", nil
}
}

return true, nil
return true, "", nil
}

fmt.Println("=> Checking that the target server is empty")
isEmpty, err = targetCheckEmpty()
isEmpty, found, err := targetCheckEmpty()
if err != nil {
return fmt.Errorf("Failed to check target server: %w", err)
}

if !isEmpty {
return fmt.Errorf("Target server isn't empty, can't proceed with migration.")
return fmt.Errorf("Target server isn't empty (%s found), can't proceed with migration.", found)
}

// Validate configuration.
Expand Down

0 comments on commit c982c14

Please sign in to comment.