Skip to content
This repository has been archived by the owner on Sep 26, 2021. It is now read-only.

Commit

Permalink
Merge pull request #4426 from beppler/4424-powershell-module-not-avai…
Browse files Browse the repository at this point in the history
…lable

Fix issue #4424 - Pre-create check: "Hyper-V PowerShell Module is not available"
  • Loading branch information
dgageot committed Mar 20, 2018
2 parents 51ed7e7 + 5163583 commit e501d1b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
34 changes: 17 additions & 17 deletions drivers/hyperv/hyperv.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func (d *Driver) GetURL() (string, error) {
}

func (d *Driver) GetState() (state.State, error) {
stdout, err := cmdOut("(", "hyper-v\\Get-VM", d.MachineName, ").state")
stdout, err := cmdOut("(", "Hyper-V\\Get-VM", d.MachineName, ").state")
if err != nil {
return state.None, fmt.Errorf("Failed to find the VM status")
}
Expand Down Expand Up @@ -205,7 +205,7 @@ func (d *Driver) Create() error {
return err
}

if err := cmd("hyper-v\\New-VM",
if err := cmd("Hyper-V\\New-VM",
d.MachineName,
"-Path", fmt.Sprintf("'%s'", d.ResolveStorePath(".")),
"-SwitchName", quote(virtualSwitch),
Expand All @@ -214,37 +214,37 @@ func (d *Driver) Create() error {
}

if d.CPU > 1 {
if err := cmd("hyper-v\\Set-VMProcessor",
if err := cmd("Hyper-V\\Set-VMProcessor",
d.MachineName,
"-Count", fmt.Sprintf("%d", d.CPU)); err != nil {
return err
}
}

if d.MacAddr != "" {
if err := cmd("hyper-v\\Set-VMNetworkAdapter",
if err := cmd("Hyper-V\\Set-VMNetworkAdapter",
"-VMName", d.MachineName,
"-StaticMacAddress", fmt.Sprintf("\"%s\"", d.MacAddr)); err != nil {
return err
}
}

if d.VLanID > 0 {
if err := cmd("hyper-v\\Set-VMNetworkAdapterVlan",
if err := cmd("Hyper-V\\Set-VMNetworkAdapterVlan",
"-VMName", d.MachineName,
"-Access",
"-VlanId", fmt.Sprintf("%d", d.VLanID)); err != nil {
return err
}
}

if err := cmd("hyper-v\\Set-VMDvdDrive",
if err := cmd("Hyper-V\\Set-VMDvdDrive",
"-VMName", d.MachineName,
"-Path", quote(d.ResolveStorePath("boot2docker.iso"))); err != nil {
return err
}

if err := cmd("hyper-v\\Add-VMHardDiskDrive",
if err := cmd("Hyper-V\\Add-VMHardDiskDrive",
"-VMName", d.MachineName,
"-Path", quote(diskImage)); err != nil {
return err
Expand All @@ -257,7 +257,7 @@ func (d *Driver) Create() error {
func (d *Driver) chooseVirtualSwitch() (string, error) {
if d.VSwitch == "" {
// Default to the first external switche and in the process avoid DockerNAT
stdout, err := cmdOut("(hyper-v\\Get-VMSwitch -SwitchType External).Name")
stdout, err := cmdOut("(Hyper-V\\Get-VMSwitch -SwitchType External).Name")
if err != nil {
return "", err
}
Expand All @@ -271,7 +271,7 @@ func (d *Driver) chooseVirtualSwitch() (string, error) {
return switches[0], nil
}

stdout, err := cmdOut("(hyper-v\\Get-VMSwitch).Name")
stdout, err := cmdOut("(Hyper-V\\Get-VMSwitch).Name")
if err != nil {
return "", err
}
Expand Down Expand Up @@ -327,7 +327,7 @@ func (d *Driver) waitStopped() error {

// Start starts an host
func (d *Driver) Start() error {
if err := cmd("hyper-v\\Start-VM", d.MachineName); err != nil {
if err := cmd("Hyper-V\\Start-VM", d.MachineName); err != nil {
return err
}

Expand All @@ -343,7 +343,7 @@ func (d *Driver) Start() error {

// Stop stops an host
func (d *Driver) Stop() error {
if err := cmd("hyper-v\\Stop-VM", d.MachineName); err != nil {
if err := cmd("Hyper-V\\Stop-VM", d.MachineName); err != nil {
return err
}

Expand All @@ -369,7 +369,7 @@ func (d *Driver) Remove() error {
}
}

return cmd("hyper-v\\Remove-VM", d.MachineName, "-Force")
return cmd("Hyper-V\\Remove-VM", d.MachineName, "-Force")
}

// Restart stops and starts an host
Expand All @@ -384,7 +384,7 @@ func (d *Driver) Restart() error {

// Kill force stops an host
func (d *Driver) Kill() error {
if err := cmd("hyper-v\\Stop-VM", d.MachineName, "-TurnOff"); err != nil {
if err := cmd("Hyper-V\\Stop-VM", d.MachineName, "-TurnOff"); err != nil {
return err
}

Expand All @@ -406,7 +406,7 @@ func (d *Driver) GetIP() (string, error) {
return "", drivers.ErrHostIsNotRunning
}

stdout, err := cmdOut("((", "hyper-v\\Get-VM", d.MachineName, ").networkadapters[0]).ipaddresses[0]")
stdout, err := cmdOut("((", "Hyper-V\\Get-VM", d.MachineName, ").networkadapters[0]).ipaddresses[0]")
if err != nil {
return "", err
}
Expand Down Expand Up @@ -440,7 +440,7 @@ func (d *Driver) generateDiskImage() (string, error) {
}

log.Infof("Creating VHD")
if err := cmd("hyper-v\\New-VHD", "-Path", quote(fixed), "-SizeBytes", fixedDiskSize, "-Fixed"); err != nil {
if err := cmd("Hyper-V\\New-VHD", "-Path", quote(fixed), "-SizeBytes", fixedDiskSize, "-Fixed"); err != nil {
return "", err
}

Expand All @@ -462,12 +462,12 @@ func (d *Driver) generateDiskImage() (string, error) {
}
file.Close()

if err := cmd("hyper-v\\Convert-VHD", "-Path", quote(fixed), "-DestinationPath", quote(diskImage), "-VHDType", "Dynamic", "-DeleteSource"); err != nil {
if err := cmd("Hyper-V\\Convert-VHD", "-Path", quote(fixed), "-DestinationPath", quote(diskImage), "-VHDType", "Dynamic", "-DeleteSource"); err != nil {
return "", err
}

if isWindowsAdmin {
if err := cmd("hyper-v\\Resize-VHD", "-Path", quote(diskImage), "-SizeBytes", toMb(d.DiskSize)); err != nil {
if err := cmd("Hyper-V\\Resize-VHD", "-Path", quote(diskImage), "-SizeBytes", toMb(d.DiskSize)); err != nil {
return "", err
}
}
Expand Down
2 changes: 1 addition & 1 deletion drivers/hyperv/powershell.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func parseLines(stdout string) []string {
}

func hypervAvailable() error {
stdout, err := cmdOut("@(Get-Command hyper-v\\Get-VM).ModuleName")
stdout, err := cmdOut("@(Get-Module -ListAvailable hyper-v).Name | Get-Unique")
if err != nil {
return err
}
Expand Down

0 comments on commit e501d1b

Please sign in to comment.