(config *api.InitPreseed, d incus.InstanceServer, server *api.Server, poolType internalUtil.PoolType)
| 259 | } |
| 260 | |
| 261 | func (c *cmdAdminInit) askStoragePool(config *api.InitPreseed, d incus.InstanceServer, server *api.Server, poolType internalUtil.PoolType) error { |
| 262 | // Figure out the preferred storage driver |
| 263 | availableBackends := linux.AvailableStorageDrivers(internalUtil.VarPath(), server.Environment.StorageSupportedDrivers, poolType) |
| 264 | |
| 265 | if len(availableBackends) == 0 { |
| 266 | if poolType != internalUtil.PoolTypeAny { |
| 267 | return errors.New(i18n.G("No storage backends available")) |
| 268 | } |
| 269 | |
| 270 | return fmt.Errorf(i18n.G("No %s storage backends available"), poolType) |
| 271 | } |
| 272 | |
| 273 | backingFs, err := linux.DetectFilesystem(internalUtil.VarPath()) |
| 274 | if err != nil { |
| 275 | backingFs = "dir" |
| 276 | } |
| 277 | |
| 278 | defaultStorage := "dir" |
| 279 | if backingFs == "btrfs" && slices.Contains(availableBackends, "btrfs") { |
| 280 | defaultStorage = "btrfs" |
| 281 | } else if slices.Contains(availableBackends, "zfs") { |
| 282 | defaultStorage = "zfs" |
| 283 | } else if slices.Contains(availableBackends, "btrfs") { |
| 284 | defaultStorage = "btrfs" |
| 285 | } |
| 286 | |
| 287 | for { |
| 288 | // Define the pool |
| 289 | pool := api.StoragePoolsPost{} |
| 290 | pool.Config = map[string]string{} |
| 291 | |
| 292 | if poolType == internalUtil.PoolTypeAny { |
| 293 | pool.Name, err = c.global.asker.AskString(i18n.G("Name of the new storage pool")+" [default=default]: ", "default", nil) |
| 294 | if err != nil { |
| 295 | return err |
| 296 | } |
| 297 | } else { |
| 298 | pool.Name = string(poolType) |
| 299 | } |
| 300 | |
| 301 | _, _, err := d.GetStoragePool(pool.Name) |
| 302 | if err == nil { |
| 303 | if poolType == internalUtil.PoolTypeAny { |
| 304 | fmt.Printf(i18n.G("The requested storage pool \"%s\" already exists. Please choose another name.")+"\n", pool.Name) |
| 305 | continue |
| 306 | } |
| 307 | |
| 308 | return fmt.Errorf(i18n.G("The %s storage pool already exists"), poolType) |
| 309 | } |
| 310 | |
| 311 | // Add to the default profile |
| 312 | if config.Profiles[0].Devices["root"] == nil { |
| 313 | config.Profiles[0].Devices["root"] = map[string]string{ |
| 314 | "type": "disk", |
| 315 | "path": "/", |
| 316 | "pool": pool.Name, |
| 317 | } |
| 318 | } |
no test coverage detected