99 "os"
1010 "os/exec"
1111 "path"
12+ "path/filepath"
1213 "regexp"
1314 "strconv"
1415 "strings"
@@ -722,6 +723,15 @@ func vsphere_init() {
722723 vsphere_template_dir := path .Dir (config .Vsphere_Template )
723724 vsphere_template_base := path .Base (config .Vsphere_Template )
724725
726+ path_json_opts := filepath .Join (os .TempDir (), "options.json" )
727+ json_opts := []byte (fmt .Sprintf ("{\" NetworkMapping\" :[{\" Name\" : \" VM Network (Standard)\" ,\" Network\" : \" %s\" }]}" , config .Vsphere_Network ))
728+
729+ err := os .WriteFile (path_json_opts , json_opts , 0644 )
730+ if err != nil {
731+ fmt .Println (Red + "ERROR writing import options file" + Reset )
732+ return
733+ }
734+
725735 govc_opts = append (govc_opts , fmt .Sprintf ("GOVC_URL=%s" , config .Vsphere_Host ))
726736 govc_opts = append (govc_opts , fmt .Sprintf ("GOVC_INSECURE=1" ))
727737 govc_opts = append (govc_opts , fmt .Sprintf ("GOVC_RESOURCE_POOL=%s" , config .Vsphere_Resource_Pool ))
@@ -734,12 +744,12 @@ func vsphere_init() {
734744 govc_opts = append (govc_opts , fmt .Sprintf ("GOVC_FOLDER=%s" , vsphere_template_dir ))
735745 }
736746 fmt .Printf ("Importing new template to VM %s_tmp\n (source %stemplate.ova)\n " , config .Vsphere_Template , config .Vsphere_Repo )
737- cmd := exec .Command ("govc" , "import.ova" , "-name=" + vsphere_template_base + "_tmp" , config .Vsphere_Repo + "template.ova" )
747+ cmd := exec .Command ("govc" , "import.ova" , "-options=" + path_json_opts , "- name="+ vsphere_template_base + "_tmp" , config .Vsphere_Repo + "template.ova" )
738748 cmd .Env = os .Environ ()
739749 cmd .Env = append (cmd .Env , govc_opts ... )
740750 cmd .Stdout = os .Stdout
741751 cmd .Stderr = os .Stderr
742- err : = cmd .Run ()
752+ err = cmd .Run ()
743753 if err != nil {
744754 fmt .Println (Red + "ERROR importing px-deploy base template" + Reset )
745755 return
0 commit comments