MCPcopy
hub / github.com/lxc/incus / askStoragePool

Method askStoragePool

cmd/incus/admin_init_interactive.go:261–536  ·  view source on GitHub ↗
(config *api.InitPreseed, d incus.InstanceServer, server *api.Server, poolType internalUtil.PoolType)

Source from the content-addressed store, hash-verified

259}
260
261func (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 }

Callers 1

askStorageMethod · 0.95

Calls 12

AvailableStorageDriversFunction · 0.92
GFunction · 0.92
DetectFilesystemFunction · 0.92
RunCommandFunction · 0.92
IsBlockdevPathFunction · 0.92
ErrorfMethod · 0.80
AskStringMethod · 0.80
AskChoiceMethod · 0.80
AskBoolMethod · 0.80
SplitMethod · 0.80
GetStoragePoolMethod · 0.65
ContainsMethod · 0.45

Tested by

no test coverage detected