diff --git a/cluster-provision/centos9/vmcli/cmd/root.go b/cluster-provision/centos9/vmcli/cmd/root.go index 9b944cc11d..49b21c1bf8 100644 --- a/cluster-provision/centos9/vmcli/cmd/root.go +++ b/cluster-provision/centos9/vmcli/cmd/root.go @@ -123,6 +123,33 @@ func addIptablesRules(iptables *iptables.IPTables, rootless bool, protocol strin return nil } +func createPrimaryDisk(forcedNextDiskPath string) (string, error) { + // For backward compatibility, so that we can just copy over the newer files + _, err := os.Stat(provisionedDiskPath) + + if err == nil { + os.Remove(firstDiskPath) + os.Symlink(provisionedDiskPath, firstDiskPath) + } + + diskFile, diskBackingFile, err := utils.CalcNextDisk(".", forcedNextDiskPath) + if err != nil { + return "", fmt.Errorf("Failed to calculate the next disk image path: %v", err) + } + + diskSize, err := qemu.GetDiskSize(diskBackingFile) + if err != nil { + return "", fmt.Errorf("Failed to get the disk image size of \"%s\": %v", diskBackingFile, err) + } + + if diskSize < defaultDiskSize { + diskSize = defaultDiskSize + } + + fmt.Printf("Creating disk \"%s backed by %s with size %d\"\n", diskFile, diskBackingFile, diskSize) + return diskFile, qemu.CreateDiskWithBackingFile(diskFile, "qcow2", diskSize, diskBackingFile, "qcow2") +} + // Creates raw disks to be used by secondary block devices func createSecondaryRawDisks(diskSizes []uint, deviceKind string) error { for i, size := range diskSizes { @@ -236,30 +263,7 @@ func run(cmd *cobra.Command, args []string) error { } } - // For backward compatibility, so that we can just copy over the newer files - _, err = os.Stat(provisionedDiskPath) - - if err == nil { - os.Remove(firstDiskPath) - os.Symlink(provisionedDiskPath, firstDiskPath) - } - - diskFile, diskBackingFile, err := utils.CalcNextDisk(".", nextDiskFlag) - if err != nil { - return fmt.Errorf("Failed to calculate the next disk image path: %v", err) - } - - diskSize, err := qemu.GetDiskSize(diskBackingFile) - if err != nil { - return fmt.Errorf("Failed to get the disk image size of \"%s\": %v", diskBackingFile, err) - } - - if diskSize < defaultDiskSize { - diskSize = defaultDiskSize - } - - fmt.Printf("Creating disk \"%s backed by %s with size %d\"\n", diskFile, diskBackingFile, diskSize) - err = qemu.CreateDiskWithBackingFile(diskFile, "qcow2", diskSize, diskBackingFile, "qcow2") + diskFile, err := createPrimaryDisk(nextDiskFlag) if err != nil { return err }