Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
109 commits
Select commit Hold shift + click to select a range
5390251
Port of https://github.com/pbolduc/packer-hyperv/
taliesins Jun 21, 2015
2f08e60
Use the same configuration style as existing builders
taliesins Jun 21, 2015
36840b7
The test is meant to fail if the folder already exists
taliesins Jun 21, 2015
f4b8af5
Tests where for an old version of powershell class. Changed for the n…
taliesins Jun 21, 2015
c8c3bf7
Use the convention for default vmname
taliesins Jun 21, 2015
36cc54a
Wait until WinRM is available, before continuing with install. This i…
taliesins Jun 21, 2015
fe32de5
Throw error if we can't get mac or ip address during steps
taliesins Jun 22, 2015
ca30485
Remove devices after it has been shut down
taliesins Jun 24, 2015
4e1e06d
Support for boot_command
taliesins Jun 27, 2015
c65f831
With generation 2 machine by default a dvd drive is not created. So c…
taliesins Jun 29, 2015
d28df30
Set the dvd to the first boot device
taliesins Jun 29, 2015
e5a4c9f
When redirecting local ports to hyper visor ports we need to configur…
Jun 30, 2015
291cb2a
Add a little safety around variables that are passed into provisioner.
Jul 1, 2015
b09ca49
Quote powershell so that it does not try to interpret command to be run
Jul 1, 2015
fbb56b2
Pass in any iso images to add as dvd drives during boot
taliesins Jul 12, 2015
408bae3
Hyperv generation 2 machines use scsi for dvd drives. Allow gen 1 mac…
taliesins Jul 12, 2015
095e76c
Need to expose generation as a public property
taliesins Jul 12, 2015
72ab029
Check the floppy files and not the dvd files attached
taliesins Jul 12, 2015
fe3c140
No need to remove floppy controller for 2nd generation vms
taliesins Jul 14, 2015
5940f79
Copy the folder structure correctly
taliesins Jul 16, 2015
9d38d8f
Use simple naming convention for now
taliesins Jul 24, 2015
86b4698
Use plain text password
taliesins Jul 24, 2015
83cd0ba
fix vagrant box structure
vvchik Oct 9, 2015
d986d74
Should only default to first controller if its not 1 of the 2 control…
taliesins Oct 18, 2015
4893a2b
Use correct formatting for printf
taliesins Oct 18, 2015
720f7ff
Quoting of powershell commands and associated tests
taliesins Oct 18, 2015
a1caff6
Must escape string formatting for string fmt
taliesins Oct 18, 2015
f5eeede
Fix disk size test
taliesins Oct 18, 2015
a31ac35
If there is only one ip address on a card we need to force it to be a…
taliesins Oct 25, 2015
43f7b4b
Incude hyperv as part of the plugins
taliesins Oct 25, 2015
b83fd6b
Must point to iso hyperv plugin
taliesins Oct 25, 2015
1e652d3
Always force turn off vm
taliesins Oct 27, 2015
0727d9e
Seems like we do need to escape the double quote
taliesins Oct 28, 2015
d424556
Make use of driver instead of directly referencing hyper
taliesins Oct 30, 2015
0bdfb27
GuestAdditionsMode and GuestAdditionsPath can be set in config. If Gu…
Oct 30, 2015
bd1cb01
Forgot to check in these files.
Oct 30, 2015
bc92ace
Include cache in the state bag.
taliesins Oct 30, 2015
6b9a78f
Build agents might not have guest additions
taliesins Oct 30, 2015
bcd65a0
Setting boot drive message
taliesins Oct 31, 2015
a59e0bf
Get rid of mount and unmount that does not specify controller locatio…
taliesins Nov 1, 2015
33aea80
If we are not getting the exit code assigned then default to it being…
taliesins Nov 1, 2015
a6207af
Using Write-Output instead of Write-Host since PS v5 now leaks the ho…
Nov 2, 2015
b0564cd
Write output will put ouput from function, so we don't want to be get…
Nov 2, 2015
8344ed7
Use correct quotation of variables
taliesins Nov 2, 2015
8170775
If exit code = 1 and the length of the stderr is 0, then we can assum…
taliesins Nov 3, 2015
3539e28
Accidentally included bracket
taliesins Nov 3, 2015
b1dea34
The default for wait is 1 second
taliesins Nov 4, 2015
1d13e29
Fix gen 1 creation of dvd
taliesins Nov 7, 2015
77fd89f
Setting boot drive is generation specific
taliesins Nov 7, 2015
578e3ba
By default a gen 1 vm get a dvd drive. Remove it on creation so that …
taliesins Nov 7, 2015
c7a952c
Echo output when its used
taliesins Nov 7, 2015
d0cee32
removed unused reference
taliesins Nov 7, 2015
241dda7
Need to sleep after sending previous characters, not before
taliesins Nov 7, 2015
e836cda
Remove all Dvd Drives on Generation 1
Nov 30, 2015
434bee3
Do not try to type scancodes if there are none. We haven't figured ou…
taliesins Dec 1, 2015
0b36a70
try to get the virtual keyboard a number of different ways. This shou…
taliesins Dec 5, 2015
6aea6b1
A workaround for bug in Windows 10 and Windows 2016 where you have to…
taliesins Dec 5, 2015
34ed9a9
Export of Hyper-V/VMCX machines
Dec 1, 2015
6d4e5dd
Forget to pass in the dvd drive to eject the iso from
taliesins Dec 5, 2015
c297fdb
Windows Server 2016 won't let you set the first boot device
taliesins Dec 5, 2015
61e37b9
http server has moved to common step
taliesins Jan 25, 2016
9069772
Try to match style of other builders
taliesins Jun 29, 2016
04e26d8
Make hiding of progress backward compatible with old versions of powe…
taliesins Jun 29, 2016
41c738c
Generate switch name using uuid v1
taliesins Mar 29, 2016
b9277e7
On windows a lot of git clients will convert LF to CRLF. This would b…
taliesins Apr 1, 2016
f78aca6
Added file with correct line endings
taliesins Apr 1, 2016
9ad5565
Fix duplicate imports
taliesins Jun 30, 2016
baa748c
Skip these tests on platforms that don't have powershell installed
taliesins Jun 30, 2016
da69ac8
Test should run and pass even when run on an environment that does no…
taliesins Jun 30, 2016
1526524
Base64 encode powershell to avoid any necessary escaping
taliesins Jul 4, 2016
9e2f922
Encode powershell using utf8
taliesins Jul 12, 2016
4ec9997
Pattern for infrastructure changed to quote filename and execute file…
taliesins Jul 13, 2016
3894865
Powershell uses UTF16Le for encodedCommand
taliesins Jul 24, 2016
38f157d
Builds in AppVeyor are failing as they do not have enough free memory…
taliesins Jul 24, 2016
3f868d1
Add type scan support for ctrl, shift, alt.
taliesins Jul 30, 2016
2a95c43
Dvd drive creation will auto select the controller number and control…
taliesins Jul 31, 2016
581a6e0
Add special key modifiers to log output when used.
taliesins Jul 31, 2016
99a0a9e
Enable-VMIntegrationService cmdlet has a language dependent value for…
taliesins Aug 2, 2016
791564c
s/EnabeSecureBoot/EnableSecureBoot/g
PatrickLang Aug 6, 2016
f72a2b0
Adding nested virtualization support
PatrickLang Aug 6, 2016
a2f314a
Adding support for nested Hyper-V
PatrickLang Aug 6, 2016
1b67753
Fix type casting
PatrickLang Aug 6, 2016
ec7d470
Add support for mac spoofing and dynamic memory.
taliesins Aug 7, 2016
b876f01
Add documentation for: enable_mac_spoofing, enable_dynamic_memory and…
taliesins Aug 7, 2016
766f913
Enable VlanID
efx-jjohnson Sep 21, 2016
7ca6476
Added the ability to independently configure switch vlan. This will p…
taliesins Sep 29, 2016
a8f2832
Add vendoring for unicode:
taliesins Oct 26, 2016
eaeb335
Address documentation layout and copy issues
taliesins Oct 26, 2016
1c501df
Fix spelling mistake
taliesins Oct 26, 2016
ad581c8
Remove trailing tabs
taliesins Oct 26, 2016
b41fd06
SSHKeyPath and SSHWaitTimeout have been deprecated in favor of commun…
taliesins Nov 6, 2016
0769fe4
Fix comment left over from initial import
taliesins Nov 6, 2016
8d2ecd6
We are using powershell and Msvm to send keys to virtual keyboard so …
taliesins Nov 6, 2016
b103690
Do not specify a default username or password
taliesins Nov 6, 2016
8c15056
Configuration settings are no longer used
taliesins Nov 6, 2016
0c2b4de
Remove inconsistent "_mb" from ram size
taliesins Nov 6, 2016
e7054ef
Add missing configuration elements.
taliesins Nov 6, 2016
c6fb0f3
Remove headless option as it is not used.
taliesins Nov 6, 2016
151d2ae
Remove unused import
taliesins Nov 6, 2016
d73e725
Remove unused import
taliesins Nov 6, 2016
0c38dec
Changed ram_size_mb to ram_size
taliesins Nov 6, 2016
19824bb
Run go fmt on files
taliesins Nov 6, 2016
f05fdc5
Make it clear iso is downloaded
taliesins Nov 6, 2016
baa380b
guest_os_type is no longer used
taliesins Nov 14, 2016
1b4030f
headless is no longer used
taliesins Nov 14, 2016
a7b3106
Be smarter about loading guest additions iso. Windows 10 and Windows …
taliesins Nov 14, 2016
66f00b6
Builders don't need to set this up anymore
taliesins Nov 22, 2016
bc8dff3
Porting over paulmey changes to license and copyright headers. Good g…
taliesins Nov 23, 2016
5f85193
Remove any network adapters from the boot order before setting the de…
watsonlu Nov 25, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

common/test-fixtures/root/* eol=lf
65 changes: 65 additions & 0 deletions builder/hyperv/common/artifact.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package common

import (
"fmt"
"os"
"path/filepath"

"github.com/mitchellh/packer/packer"
)

// This is the common builder ID to all of these artifacts.
const BuilderId = "MSOpenTech.hyperv"

// Artifact is the result of running the hyperv builder, namely a set
// of files associated with the resulting machine.
type artifact struct {
dir string
f []string
}

// NewArtifact returns a hyperv artifact containing the files
// in the given directory.
func NewArtifact(dir string) (packer.Artifact, error) {
files := make([]string, 0, 5)
visit := func(path string, info os.FileInfo, err error) error {
if !info.IsDir() {
files = append(files, path)
}

return err
}

if err := filepath.Walk(dir, visit); err != nil {
return nil, err
}

return &artifact{
dir: dir,
f: files,
}, nil
}

func (*artifact) BuilderId() string {
return BuilderId
}

func (a *artifact) Files() []string {
return a.f
}

func (*artifact) Id() string {
return "VM"
}

func (a *artifact) String() string {
return fmt.Sprintf("VM files in directory: %s", a.dir)
}

func (a *artifact) State(name string) interface{} {
return nil
}

func (a *artifact) Destroy() error {
return os.RemoveAll(a.dir)
}
43 changes: 43 additions & 0 deletions builder/hyperv/common/artifact_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package common

import (
"io/ioutil"
"os"
"path/filepath"
"testing"

"github.com/mitchellh/packer/packer"
)

func TestArtifact_impl(t *testing.T) {
var _ packer.Artifact = new(artifact)
}

func TestNewArtifact(t *testing.T) {
td, err := ioutil.TempDir("", "packer")
if err != nil {
t.Fatalf("err: %s", err)
}
defer os.RemoveAll(td)

err = ioutil.WriteFile(filepath.Join(td, "a"), []byte("foo"), 0644)
if err != nil {
t.Fatalf("err: %s", err)
}

if err := os.Mkdir(filepath.Join(td, "b"), 0755); err != nil {
t.Fatalf("err: %s", err)
}

a, err := NewArtifact(td)
if err != nil {
t.Fatalf("err: %s", err)
}

if a.BuilderId() != BuilderId {
t.Fatalf("bad: %#v", a.BuilderId())
}
if len(a.Files()) != 1 {
t.Fatalf("should length 1: %d", len(a.Files()))
}
}
11 changes: 11 additions & 0 deletions builder/hyperv/common/config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package common

import (
"testing"

"github.com/mitchellh/packer/template/interpolate"
)

func testConfigTemplate(t *testing.T) *interpolate.Context {
return &interpolate.Context{}
}
104 changes: 104 additions & 0 deletions builder/hyperv/common/driver.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package common

// A driver is able to talk to HyperV and perform certain
// operations with it. Some of the operations on here may seem overly
// specific, but they were built specifically in mind to handle features
// of the HyperV builder for Packer, and to abstract differences in
// versions out of the builder steps, so sometimes the methods are
// extremely specific.
type Driver interface {

// Checks if the VM named is running.
IsRunning(string) (bool, error)

// Checks if the VM named is off.
IsOff(string) (bool, error)

//How long has VM been on
Uptime(vmName string) (uint64, error)

// Start starts a VM specified by the name given.
Start(string) error

// Stop stops a VM specified by the name given.
Stop(string) error

// Verify checks to make sure that this driver should function
// properly. If there is any indication the driver can't function,
// this will return an error.
Verify() error

// Finds the MAC address of the NIC nic0
Mac(string) (string, error)

// Finds the IP address of a VM connected that uses DHCP by its MAC address
IpAddress(string) (string, error)

// Finds the hostname for the ip address
GetHostName(string) (string, error)

// Finds the IP address of a host adapter connected to switch
GetHostAdapterIpAddressForSwitch(string) (string, error)

// Type scan codes to virtual keyboard of vm
TypeScanCodes(string, string) error

//Get the ip address for network adaptor
GetVirtualMachineNetworkAdapterAddress(string) (string, error)

//Set the vlan to use for switch
SetNetworkAdapterVlanId(string, string) error

//Set the vlan to use for machine
SetVirtualMachineVlanId(string, string) error

UntagVirtualMachineNetworkAdapterVlan(string, string) error

CreateExternalVirtualSwitch(string, string) error

GetVirtualMachineSwitchName(string) (string, error)

ConnectVirtualMachineNetworkAdapterToSwitch(string, string) error

CreateVirtualSwitch(string, string) (bool, error)

DeleteVirtualSwitch(string) error

CreateVirtualMachine(string, string, int64, int64, string, uint) error

DeleteVirtualMachine(string) error

SetVirtualMachineCpuCount(string, uint) error

SetVirtualMachineMacSpoofing(string, bool) error

SetVirtualMachineDynamicMemory(string, bool) error

SetVirtualMachineSecureBoot(string, bool) error

SetVirtualMachineVirtualizationExtensions(string, bool) error

EnableVirtualMachineIntegrationService(string, string) error

ExportVirtualMachine(string, string) error

CompactDisks(string, string) error

CopyExportedVirtualMachine(string, string, string, string) error

RestartVirtualMachine(string) error

CreateDvdDrive(string, string, uint) (uint, uint, error)

MountDvdDrive(string, string, uint, uint) error

SetBootDvdDrive(string, uint, uint, uint) error

UnmountDvdDrive(string, uint, uint) error

DeleteDvdDrive(string, uint, uint) error

MountFloppyDrive(string, string) error

UnmountFloppyDrive(string) error
}
Loading