<commit_before>package provision

import (
	"errors"

	"github.com/docker/machine/drivers"
	"github.com/docker/machine/libmachine/provision/pkgaction"
	"github.com/docker/machine/log"
	"github.com/docker/machine/state"
	"github.com/docker/machine/utils"
)

var (
	ErrUnknownDriver = errors.New("unknown driver")
)

func init() {
	Register("boot2docker", &RegisteredProvisioner{
		New: NewBoot2DockerProvisioner,
	})
}

func NewBoot2DockerProvisioner(d drivers.Driver) Provisioner {
	g := GenericProvisioner{
		DockerOptionsDir:  "/etc/docker",
		DaemonOptionsFile: "/etc/systemd/system/docker.service",
		OsReleaseId:       "docker",
		Packages:          []string{},
		Driver:            d,
	}
	p := &Boot2DockerProvisioner{
		DebianProvisioner{
			GenericProvisioner: g,
		},
	}
	return p
}

type Boot2DockerProvisioner struct {
	DebianProvisioner
}

func (provisioner *Boot2DockerProvisioner) upgradeIso() error {
	log.Info("Stopping machine to do the upgrade...")

	if err := provisioner.Driver.Stop(); err != nil {
		return err

	}

	if err := utils.WaitFor(drivers.MachineInState(provisioner.Driver, state.Stopped)); err != nil {
		return err

	}

	machineName := provisioner.GetDriver().GetMachineName()

	log.Infof("Upgrading machine %s...", machineName)

	isoFilename := ""
	switch provisioner.GetDriver().DriverName() {
	case "virtualbox":
		isoFilename = "boot2docker-virtualbox.iso"
	case "vmwarefusion", "vmwarevsphere":
		isoFilename = "boot2docker-vmware.iso"
	case "hyperv":
		isoFilename = "boot2docker-hyperv.iso"
	default:
		return ErrUnknownDriver
	}

	b2dutils := utils.NewB2dUtils("", "", isoFilename)

	// Usually we call this implicitly, but call it here explicitly to get
	// the latest boot2docker ISO.
	if err := b2dutils.DownloadLatestBoot2Docker(); err != nil {
		return err

	}

	// Copy the latest version of boot2docker ISO to the machine's directory
	if err := b2dutils.CopyIsoToMachineDir("", machineName); err != nil {
		return err

	}

	if err := provisioner.Driver.Start(); err != nil {
		return err

	}

	return utils.WaitFor(drivers.MachineInState(provisioner.Driver, state.Running))

}

func (provisioner *Boot2DockerProvisioner) Package(name string, action pkgaction.PackageAction) error {
	if name == "docker" && action == pkgaction.Upgrade {
		if err := provisioner.upgradeIso(); err != nil {
			return err

		}

	}
	return nil

}
<commit_msg>proper check for hyper-v during upgrade<commit_after>package provision

import (
	"errors"

	"github.com/docker/machine/drivers"
	"github.com/docker/machine/libmachine/provision/pkgaction"
	"github.com/docker/machine/log"
	"github.com/docker/machine/state"
	"github.com/docker/machine/utils"
)

var (
	ErrUnknownDriver = errors.New("unknown driver")
)

func init() {
	Register("boot2docker", &RegisteredProvisioner{
		New: NewBoot2DockerProvisioner,
	})
}

func NewBoot2DockerProvisioner(d drivers.Driver) Provisioner {
	g := GenericProvisioner{
		DockerOptionsDir:  "/etc/docker",
		DaemonOptionsFile: "/etc/systemd/system/docker.service",
		OsReleaseId:       "docker",
		Packages:          []string{},
		Driver:            d,
	}
	p := &Boot2DockerProvisioner{
		DebianProvisioner{
			GenericProvisioner: g,
		},
	}
	return p
}

type Boot2DockerProvisioner struct {
	DebianProvisioner
}

func (provisioner *Boot2DockerProvisioner) upgradeIso() error {
	log.Info("Stopping machine to do the upgrade...")

	if err := provisioner.Driver.Stop(); err != nil {
		return err

	}

	if err := utils.WaitFor(drivers.MachineInState(provisioner.Driver, state.Stopped)); err != nil {
		return err

	}

	machineName := provisioner.GetDriver().GetMachineName()

	log.Infof("Upgrading machine %s...", machineName)

	isoFilename := ""
	switch provisioner.GetDriver().DriverName() {
	case "virtualbox":
		isoFilename = "boot2docker-virtualbox.iso"
	case "vmwarefusion", "vmwarevsphere":
		isoFilename = "boot2docker-vmware.iso"
	case "hyper-v":
		isoFilename = "boot2docker-hyperv.iso"
	default:
		return ErrUnknownDriver
	}

	b2dutils := utils.NewB2dUtils("", "", isoFilename)

	// Usually we call this implicitly, but call it here explicitly to get
	// the latest boot2docker ISO.
	if err := b2dutils.DownloadLatestBoot2Docker(); err != nil {
		return err

	}

	// Copy the latest version of boot2docker ISO to the machine's directory
	if err := b2dutils.CopyIsoToMachineDir("", machineName); err != nil {
		return err

	}

	if err := provisioner.Driver.Start(); err != nil {
		return err

	}

	return utils.WaitFor(drivers.MachineInState(provisioner.Driver, state.Running))

}

func (provisioner *Boot2DockerProvisioner) Package(name string, action pkgaction.PackageAction) error {
	if name == "docker" && action == pkgaction.Upgrade {
		if err := provisioner.upgradeIso(); err != nil {
			return err

		}

	}
	return nil

}

{'fraction_non_alphanumeric': 0.12632895559724827, 'fraction_numerical': 0.007087763185324161, 'mean_word_length': 4.260964912280702, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4873834', 'n_tokens_mistral': 1744, 'n_tokens_neox': 1612, 'n_words': 353}