Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ RUN wget -P / https://releases.hashicorp.com/terraform/1.9.8/terraform_1.9.8_lin
RUN wget -P / https://releases.hashicorp.com/terraform/1.9.8/terraform_1.9.8_linux_arm64.zip
RUN unzip /terraform_1.9.8_linux_amd64.zip -d /linux/amd64
RUN unzip /terraform_1.9.8_linux_arm64.zip -d /linux/arm64
RUN wget -P / https://github.com/vmware/govmomi/releases/download/v0.37.1/govc_Linux_x86_64.tar.gz
RUN wget -P / https://github.com/vmware/govmomi/releases/download/v0.37.1/govc_Linux_arm64.tar.gz
RUN wget -P / https://github.com/vmware/govmomi/releases/download/v0.52.0/govc_Linux_x86_64.tar.gz
RUN wget -P / https://github.com/vmware/govmomi/releases/download/v0.52.0/govc_Linux_arm64.tar.gz
RUN tar -xzf /govc_Linux_x86_64.tar.gz -C /linux/amd64
RUN tar -xzf /govc_Linux_arm64.tar.gz -C /linux/arm64
RUN mkdir -p /root/go/src/px-deploy
Expand Down
14 changes: 12 additions & 2 deletions vsphere.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"os"
"os/exec"
"path"
"path/filepath"
"regexp"
"strconv"
"strings"
Expand Down Expand Up @@ -722,6 +723,15 @@ func vsphere_init() {
vsphere_template_dir := path.Dir(config.Vsphere_Template)
vsphere_template_base := path.Base(config.Vsphere_Template)

path_json_opts := filepath.Join(os.TempDir(), "options.json")
json_opts := []byte(fmt.Sprintf("{\"NetworkMapping\":[{\"Name\": \"VM Network (Standard)\",\"Network\": \"%s\"}]}", config.Vsphere_Network))

err := os.WriteFile(path_json_opts, json_opts, 0644)
if err != nil {
fmt.Println(Red + "ERROR writing import options file" + Reset)
return
}

govc_opts = append(govc_opts, fmt.Sprintf("GOVC_URL=%s", config.Vsphere_Host))
govc_opts = append(govc_opts, fmt.Sprintf("GOVC_INSECURE=1"))
govc_opts = append(govc_opts, fmt.Sprintf("GOVC_RESOURCE_POOL=%s", config.Vsphere_Resource_Pool))
Expand All @@ -734,12 +744,12 @@ func vsphere_init() {
govc_opts = append(govc_opts, fmt.Sprintf("GOVC_FOLDER=%s", vsphere_template_dir))
}
fmt.Printf("Importing new template to VM %s_tmp\n (source %stemplate.ova)\n", config.Vsphere_Template, config.Vsphere_Repo)
cmd := exec.Command("govc", "import.ova", "-name="+vsphere_template_base+"_tmp", config.Vsphere_Repo+"template.ova")
cmd := exec.Command("govc", "import.ova", "-options="+path_json_opts, "-name="+vsphere_template_base+"_tmp", config.Vsphere_Repo+"template.ova")
cmd.Env = os.Environ()
cmd.Env = append(cmd.Env, govc_opts...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err := cmd.Run()
err = cmd.Run()
if err != nil {
fmt.Println(Red + "ERROR importing px-deploy base template" + Reset)
return
Expand Down