MCPcopy Create free account
hub / github.com/devnullvoid/pvetui / runGuestsCreateVM

Function runGuestsCreateVM

internal/cli/guests.go:835–925  ·  view source on GitHub ↗
(cmd *cobra.Command, _ []string)

Source from the content-addressed store, hash-verified

833}
834
835func runGuestsCreateVM(cmd *cobra.Command, _ []string) error {
836 session, err := initCLISession(cmd)
837 if err != nil {
838 return printError(err)
839 }
840 if session == nil {
841 return nil
842 }
843
844 nodeName, _ := cmd.Flags().GetString("node")
845 name, _ := cmd.Flags().GetString("name")
846 vmid, _ := cmd.Flags().GetInt("vmid")
847 memoryMB, _ := cmd.Flags().GetInt("memory")
848 cores, _ := cmd.Flags().GetInt("cores")
849 sockets, _ := cmd.Flags().GetInt("sockets")
850 diskStorage, _ := cmd.Flags().GetString("disk-storage")
851 diskSize, _ := cmd.Flags().GetInt("disk-size")
852 importFrom, _ := cmd.Flags().GetString("import-from")
853 iso, _ := cmd.Flags().GetString("iso")
854 bridge, _ := cmd.Flags().GetString("bridge")
855 start, _ := cmd.Flags().GetBool("start")
856
857 if importFrom == "" && diskSize <= 0 {
858 return printError(fmt.Errorf("--disk-size is required unless --import-from is specified"))
859 }
860
861 ctx := context.Background()
862
863 node, err := session.findNodeByName(ctx, nodeName)
864 if err != nil {
865 return printError(err)
866 }
867 if !node.Online {
868 return printError(fmt.Errorf("node %q is offline", nodeName))
869 }
870
871 client, err := session.clientForNode(ctx, nodeName)
872 if err != nil {
873 return printError(err)
874 }
875
876 if vmid == 0 {
877 vmid, err = client.GetNextID(0)
878 if err != nil {
879 return printError(fmt.Errorf("failed to get next VMID: %w", err))
880 }
881 }
882
883 options := api.VMCreateOptions{
884 VMID: vmid,
885 Name: name,
886 MemoryMB: memoryMB,
887 Cores: cores,
888 Sockets: sockets,
889 DiskStorage: diskStorage,
890 DiskSizeGB: diskSize,
891 ImportFrom: importFrom,
892 ISOVolume: iso,

Callers

nothing calls this directly

Calls 9

initCLISessionFunction · 0.85
printErrorFunction · 0.85
getNoWaitFunction · 0.85
printJSONFunction · 0.85
waitForTaskFunction · 0.85
findNodeByNameMethod · 0.80
clientForNodeMethod · 0.80
GetNextIDMethod · 0.45
CreateVMMethod · 0.45

Tested by

no test coverage detected