func (in *VMSpec) MergePorts(p []PortMapping) {
	portCount := len(in.PortMappings)
	for _, port := range p {
		var i int
		for i = 0; i < portCount; i++ {
			if port.Guest == in.PortMappings[i].Guest {
				break
			}
		}
		if i == portCount {
			in.PortMappings = append(in.PortMappings, port)
		} else {
			in.PortMappings[i] = port
		}
	}
}
MergePorts merges a slice of ports into an existing VMSpec.  Ports
supplied in the p parameter override existing ports in the VMSpec.
package types
import (
	"fmt"
	"net"
	"os"
	"path"
	"github.com/pkg/errors"
)
type PortMapping struct {
	Host  int `yaml:"host"`
	Guest int `yaml:"guest"`
}
func (p PortMapping) String() string {
	return fmt.Sprintf("%d-%d", p.Host, p.Guest)
}
type Mount struct {
	Tag           string `yaml:"tag"`
	SecurityModel string `yaml:"security_model"`
	Path          string `yaml:"path"`
}
func (m Mount) String() string {
	return fmt.Sprintf("%s,%s,%s", m.Tag, m.SecurityModel, m.Path)
}
type Drive struct {
	Path    string
	Format  string
	Options string
}
func (d Drive) String() string {
	return fmt.Sprintf("%s,%s,%s", d.Path, d.Format, d.Options)
}
type VMSpec struct {
	MemMiB       int           `yaml:"mem_mib"`
	DiskGiB      int           `yaml:"disk_gib"`
	CPUs         int           `yaml:"cpus"`
	PortMappings []PortMapping `yaml:"ports"`
	Mounts       []Mount       `yaml:"mounts"`
	Drives       []Drive       `yaml:"drives"`
	Qemuport     uint          `yaml:"qemuport"`
	HostIP       net.IP        `yaml:"host_ip"`
}
func CheckDirectory(dir string) error {
	if dir == "" {
		return nil
	}
	if !path.IsAbs(dir) {
		return fmt.Errorf("%s is not an absolute path", dir)
	}
	fi, err := os.Stat(dir)
	if err != nil {
		return errors.Wrapf(err, "Unable to stat %s", dir)
	}
	if !fi.IsDir() {
		return fmt.Errorf("%s is not a directory", dir)
	}
	return nil
}
func (in *VMSpec) MergeMounts(m []Mount) {
	mountCount := len(in.Mounts)
	for _, mount := range m {
		var i int
		for i = 0; i < mountCount; i++ {
			if mount.Tag == in.Mounts[i].Tag {
				break
			}
		}
		if i == mountCount {
			in.Mounts = append(in.Mounts, mount)
		} else {
			in.Mounts[i] = mount
		}
	}
}