github.com/tonnydourado/packer@v0.6.1-0.20140701134019-5d0cd9676a37/builder/parallels/common/driver.go (about) 1 package common 2 3 import ( 4 "log" 5 "os/exec" 6 ) 7 8 // A driver is able to talk to Parallels and perform certain 9 // operations with it. Some of the operations on here may seem overly 10 // specific, but they were built specifically in mind to handle features 11 // of the Parallels builder for Packer, and to abstract differences in 12 // versions out of the builder steps, so sometimes the methods are 13 // extremely specific. 14 type Driver interface { 15 // Import a VM 16 Import(string, string, string) error 17 18 // Checks if the VM with the given name is running. 19 IsRunning(string) (bool, error) 20 21 // Stop stops a running machine, forcefully. 22 Stop(string) error 23 24 // Prlctl executes the given Prlctl command 25 Prlctl(...string) error 26 27 // Verify checks to make sure that this driver should function 28 // properly. If there is any indication the driver can't function, 29 // this will return an error. 30 Verify() error 31 32 // Version reads the version of Parallels that is installed. 33 Version() (string, error) 34 35 // Send scancodes to the vm using the prltype tool. 36 SendKeyScanCodes(string, ...string) error 37 38 // Finds the MAC address of the NIC nic0 39 Mac(string) (string, error) 40 41 // Finds the IP address of a VM connected that uses DHCP by its MAC address 42 IpAddress(string) (string, error) 43 } 44 45 func NewDriver() (Driver, error) { 46 var prlctlPath string 47 48 if prlctlPath == "" { 49 var err error 50 prlctlPath, err = exec.LookPath("prlctl") 51 if err != nil { 52 return nil, err 53 } 54 } 55 56 log.Printf("prlctl path: %s", prlctlPath) 57 driver := &Parallels9Driver{prlctlPath} 58 if err := driver.Verify(); err != nil { 59 return nil, err 60 } 61 62 return driver, nil 63 }