Esempio n. 1
0
func createRenderOpts(c *cli.Context, config *configuration.InductorConfiguration) (*renderer.RenderOptions, error) {
	var osname string
	if len(c.Args()) > 0 {
		osname = c.Args()[0]
	} else {
		fmt.Println("Available Operating Systems:")
		fmt.Println()
		for _, s := range config.List() {
			fmt.Println(fmt.Sprintf("  %s", s))
		}
		fmt.Println()
		return nil, errors.New("You must specify an operating system argument")
	}

	// create the default options set based on the inductor config
	var edition string
	if len(c.String("edition")) > 0 {
		edition = c.String("edition")
	}
	opts, err := renderer.NewRenderOptions(osname, edition, config)

	// apply any command line overrides to the options set
	opts.WindowsUpdates = !c.Bool("skipwindowsupdates")
	opts.Headless = !c.Bool("gui")
	if len(c.String("productkey")) > 0 {
		opts.ProductKey = c.String("productkey")
	}
	if c.Bool("ssh") {
		opts.Communicator = "ssh"
	}

	return opts, err
}
Esempio n. 2
0
// NewRenderOptions creates render options using the base OS
// registry with any provided overrides.
func NewRenderOptions(osname string, edition string, config *configuration.InductorConfiguration) (*RenderOptions, error) {
	os, ok := config.Get(osname)
	if !ok {
		return nil, fmt.Errorf("Couldn't find OS configuration for '%s'", osname)
	}

	// set global config
	opts := NewDefaultRenderOptions()
	opts.Communicator = config.Communicator
	opts.Headless = config.Headless
	opts.WindowsUpdates = config.WindowsUpdates
	opts.Username = config.Username
	opts.Password = config.Password
	opts.DiskSize = config.DiskSize
	opts.RAM = config.RAM
	opts.CPU = config.CPU

	// default all rendering options to values in the OS registry
	opts.OSName = os.Name
	opts.IsoChecksum = os.IsoChecksum
	opts.IsoChecksumType = os.IsoChecksumType
	opts.IsoURL = os.IsoURL
	opts.VirtualboxGuestOsType = os.VirtualboxGuestOsType
	opts.VmwareGuestOsType = os.VmwareGuestOsType

	// edition specific attributes
	if len(edition) == 0 {
		for k := range os.Editions {
			edition = k
			break
		}
	}

	// TODO: validate that the edition is valid
	opts.Edition = edition
	opts.WindowsImageName = os.Editions[edition].WindowsImageName
	opts.ProductKey = os.Editions[edition].ProductKey

	return opts, nil
}
package configuration_test

import (
	"strings"

	"github.com/joefitzgerald/inductor/configuration"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("Configuration", func() {
	var (
		err    error
		config *configuration.InductorConfiguration
	)
	BeforeEach(func() {
		config, err = configuration.New(strings.NewReader(testData))
		Expect(err).NotTo(HaveOccurred())
	})
	It("should show the gui", func() {
		Expect(config.Headless).To(BeFalse())
	})
	It("should skip windows updates", func() {
		Expect(config.WindowsUpdates).To(BeFalse())
	})
	It("should use the SSH communicator", func() {
		Expect(config.Communicator).To(Equal("ssh"))
	})
	It("should have an output dir of /tmp/foo/bar", func() {
		Expect(config.OutDir).To(Equal("/tmp/foo/bar"))