github.com/phobos182/packer@v0.2.3-0.20130819023704-c84d2aeffc68/builder/vmware/step_create_vmx.go (about) 1 package vmware 2 3 import ( 4 "bytes" 5 "fmt" 6 "github.com/mitchellh/multistep" 7 "github.com/mitchellh/packer/packer" 8 "log" 9 "path/filepath" 10 "text/template" 11 ) 12 13 type vmxTemplateData struct { 14 Name string 15 GuestOS string 16 DiskName string 17 ISOPath string 18 } 19 20 // This step creates the VMX file for the VM. 21 // 22 // Uses: 23 // config *config 24 // iso_path string 25 // ui packer.Ui 26 // 27 // Produces: 28 // vmx_path string - The path to the VMX file. 29 type stepCreateVMX struct{} 30 31 func (stepCreateVMX) Run(state map[string]interface{}) multistep.StepAction { 32 config := state["config"].(*config) 33 isoPath := state["iso_path"].(string) 34 ui := state["ui"].(packer.Ui) 35 36 ui.Say("Building and writing VMX file") 37 38 tplData := &vmxTemplateData{ 39 Name: config.VMName, 40 GuestOS: config.GuestOSType, 41 DiskName: config.DiskName, 42 ISOPath: isoPath, 43 } 44 45 var buf bytes.Buffer 46 t := template.Must(template.New("vmx").Parse(DefaultVMXTemplate)) 47 t.Execute(&buf, tplData) 48 49 vmxData := ParseVMX(buf.String()) 50 if config.VMXData != nil { 51 log.Println("Setting custom VMX data...") 52 for k, v := range config.VMXData { 53 log.Printf("Setting VMX: '%s' = '%s'", k, v) 54 vmxData[k] = v 55 } 56 } 57 58 if floppyPathRaw, ok := state["floppy_path"]; ok { 59 log.Println("Floppy path present, setting in VMX") 60 vmxData["floppy0.present"] = "TRUE" 61 vmxData["floppy0.fileType"] = "file" 62 vmxData["floppy0.fileName"] = floppyPathRaw.(string) 63 } 64 65 vmxPath := filepath.Join(config.OutputDir, config.VMName+".vmx") 66 if err := WriteVMX(vmxPath, vmxData); err != nil { 67 err := fmt.Errorf("Error creating VMX file: %s", err) 68 state["error"] = err 69 ui.Error(err.Error()) 70 return multistep.ActionHalt 71 } 72 73 state["vmx_path"] = vmxPath 74 75 return multistep.ActionContinue 76 } 77 78 func (stepCreateVMX) Cleanup(map[string]interface{}) { 79 } 80 81 // This is the default VMX template used if no other template is given. 82 // This is hardcoded here. If you wish to use a custom template please 83 // do so by specifying in the builder configuration. 84 const DefaultVMXTemplate = ` 85 .encoding = "UTF-8" 86 bios.bootOrder = "hdd,CDROM" 87 checkpoint.vmState = "" 88 cleanShutdown = "TRUE" 89 config.version = "8" 90 displayName = "{{ .Name }}" 91 ehci.pciSlotNumber = "34" 92 ehci.present = "TRUE" 93 ethernet0.addressType = "generated" 94 ethernet0.bsdName = "en0" 95 ethernet0.connectionType = "nat" 96 ethernet0.displayName = "Ethernet" 97 ethernet0.linkStatePropagation.enable = "FALSE" 98 ethernet0.pciSlotNumber = "33" 99 ethernet0.present = "TRUE" 100 ethernet0.virtualDev = "e1000" 101 ethernet0.wakeOnPcktRcv = "FALSE" 102 extendedConfigFile = "{{ .Name }}.vmxf" 103 floppy0.present = "FALSE" 104 guestOS = "{{ .GuestOS }}" 105 gui.fullScreenAtPowerOn = "FALSE" 106 gui.viewModeAtPowerOn = "windowed" 107 hgfs.linkRootShare = "TRUE" 108 hgfs.mapRootShare = "TRUE" 109 ide1:0.present = "TRUE" 110 ide1:0.fileName = "{{ .ISOPath }}" 111 ide1:0.deviceType = "cdrom-image" 112 isolation.tools.hgfs.disable = "FALSE" 113 memsize = "512" 114 nvram = "{{ .Name }}.nvram" 115 pciBridge0.pciSlotNumber = "17" 116 pciBridge0.present = "TRUE" 117 pciBridge4.functions = "8" 118 pciBridge4.pciSlotNumber = "21" 119 pciBridge4.present = "TRUE" 120 pciBridge4.virtualDev = "pcieRootPort" 121 pciBridge5.functions = "8" 122 pciBridge5.pciSlotNumber = "22" 123 pciBridge5.present = "TRUE" 124 pciBridge5.virtualDev = "pcieRootPort" 125 pciBridge6.functions = "8" 126 pciBridge6.pciSlotNumber = "23" 127 pciBridge6.present = "TRUE" 128 pciBridge6.virtualDev = "pcieRootPort" 129 pciBridge7.functions = "8" 130 pciBridge7.pciSlotNumber = "24" 131 pciBridge7.present = "TRUE" 132 pciBridge7.virtualDev = "pcieRootPort" 133 powerType.powerOff = "soft" 134 powerType.powerOn = "soft" 135 powerType.reset = "soft" 136 powerType.suspend = "soft" 137 proxyApps.publishToHost = "FALSE" 138 replay.filename = "" 139 replay.supported = "FALSE" 140 scsi0.pciSlotNumber = "16" 141 scsi0.present = "TRUE" 142 scsi0.virtualDev = "lsilogic" 143 scsi0:0.fileName = "{{ .DiskName }}.vmdk" 144 scsi0:0.present = "TRUE" 145 scsi0:0.redo = "" 146 sound.startConnected = "FALSE" 147 tools.syncTime = "TRUE" 148 tools.upgrade.policy = "upgradeAtPowerCycle" 149 usb.pciSlotNumber = "32" 150 usb.present = "FALSE" 151 virtualHW.productCompatibility = "hosted" 152 virtualHW.version = "9" 153 vmci0.id = "1861462627" 154 vmci0.pciSlotNumber = "35" 155 vmci0.present = "TRUE" 156 vmotion.checkpointFBSize = "65536000" 157 `