Skip to content

Commit 815dce3

Browse files
committed
fix network issue on vm template import
closes #721
1 parent 181d95e commit 815dce3

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ RUN wget -P / https://releases.hashicorp.com/terraform/1.9.8/terraform_1.9.8_lin
99
RUN wget -P / https://releases.hashicorp.com/terraform/1.9.8/terraform_1.9.8_linux_arm64.zip
1010
RUN unzip /terraform_1.9.8_linux_amd64.zip -d /linux/amd64
1111
RUN unzip /terraform_1.9.8_linux_arm64.zip -d /linux/arm64
12-
RUN wget -P / https://github.com/vmware/govmomi/releases/download/v0.37.1/govc_Linux_x86_64.tar.gz
13-
RUN wget -P / https://github.com/vmware/govmomi/releases/download/v0.37.1/govc_Linux_arm64.tar.gz
12+
RUN wget -P / https://github.com/vmware/govmomi/releases/download/v0.52.0/govc_Linux_x86_64.tar.gz
13+
RUN wget -P / https://github.com/vmware/govmomi/releases/download/v0.52.0/govc_Linux_arm64.tar.gz
1414
RUN tar -xzf /govc_Linux_x86_64.tar.gz -C /linux/amd64
1515
RUN tar -xzf /govc_Linux_arm64.tar.gz -C /linux/arm64
1616
RUN mkdir -p /root/go/src/px-deploy

vsphere.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
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

Comments
 (0)