Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Hyper-V builder #2576

Merged
merged 108 commits into from
Dec 13, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
108 commits
Select commit Hold shift + click to select a range
1fe4c50
Port of https://github.com/pbolduc/packer-hyperv/
taliesins Jun 21, 2015
ca16f33
Use the same configuration style as existing builders
taliesins Jun 21, 2015
a422159
The test is meant to fail if the folder already exists
taliesins Jun 21, 2015
469415f
Tests where for an old version of powershell class. Changed for the n…
taliesins Jun 21, 2015
79a5f90
Use the convention for default vmname
taliesins Jun 21, 2015
87b3dec
Wait until WinRM is available, before continuing with install. This i…
taliesins Jun 21, 2015
2d7cfcd
Throw error if we can't get mac or ip address during steps
taliesins Jun 22, 2015
03b0698
Remove devices after it has been shut down
taliesins Jun 24, 2015
aa1f1da
Support for boot_command
taliesins Jun 27, 2015
02db768
With generation 2 machine by default a dvd drive is not created. So c…
taliesins Jun 29, 2015
f3cc413
Set the dvd to the first boot device
taliesins Jun 29, 2015
bd0b119
When redirecting local ports to hyper visor ports we need to configur…
Jun 30, 2015
6c3030c
Add a little safety around variables that are passed into provisioner.
Jul 1, 2015
3051ea6
Quote powershell so that it does not try to interpret command to be run
Jul 1, 2015
ef507c7
Pass in any iso images to add as dvd drives during boot
taliesins Jul 12, 2015
e18594f
Hyperv generation 2 machines use scsi for dvd drives. Allow gen 1 mac…
taliesins Jul 12, 2015
4e8074d
Need to expose generation as a public property
taliesins Jul 12, 2015
837f9ad
Check the floppy files and not the dvd files attached
taliesins Jul 12, 2015
5f2c123
No need to remove floppy controller for 2nd generation vms
taliesins Jul 14, 2015
efafed4
Copy the folder structure correctly
taliesins Jul 16, 2015
c24c882
Use simple naming convention for now
taliesins Jul 24, 2015
8e18baf
Use plain text password
taliesins Jul 24, 2015
d57517d
fix vagrant box structure
vvchik Oct 9, 2015
5473332
Should only default to first controller if its not 1 of the 2 control…
taliesins Oct 18, 2015
9f94834
Use correct formatting for printf
taliesins Oct 18, 2015
5285a81
Quoting of powershell commands and associated tests
taliesins Oct 18, 2015
1513731
Must escape string formatting for string fmt
taliesins Oct 18, 2015
730c621
Fix disk size test
taliesins Oct 18, 2015
9cf8b18
If there is only one ip address on a card we need to force it to be a…
taliesins Oct 25, 2015
25baa26
Incude hyperv as part of the plugins
taliesins Oct 25, 2015
ccf506e
Must point to iso hyperv plugin
taliesins Oct 25, 2015
9fd6357
Always force turn off vm
taliesins Oct 27, 2015
cd6213e
Seems like we do need to escape the double quote
taliesins Oct 28, 2015
422efee
Make use of driver instead of directly referencing hyper
taliesins Oct 30, 2015
010d171
GuestAdditionsMode and GuestAdditionsPath can be set in config. If Gu…
Oct 30, 2015
50a8d1b
Forgot to check in these files.
Oct 30, 2015
aaf9007
Include cache in the state bag.
taliesins Oct 30, 2015
4b6ce3d
Build agents might not have guest additions
taliesins Oct 30, 2015
31ac1da
Setting boot drive message
taliesins Oct 31, 2015
3cb621f
Get rid of mount and unmount that does not specify controller locatio…
taliesins Nov 1, 2015
fe8d99f
If we are not getting the exit code assigned then default to it being…
taliesins Nov 1, 2015
c42cb88
Using Write-Output instead of Write-Host since PS v5 now leaks the ho…
Nov 2, 2015
4b394c8
Write output will put ouput from function, so we don't want to be get…
Nov 2, 2015
e8c2b49
Use correct quotation of variables
taliesins Nov 2, 2015
e0c10de
If exit code = 1 and the length of the stderr is 0, then we can assum…
taliesins Nov 3, 2015
8477a0b
Accidentally included bracket
taliesins Nov 3, 2015
07764c6
The default for wait is 1 second
taliesins Nov 4, 2015
93a2615
Fix gen 1 creation of dvd
taliesins Nov 7, 2015
18241e5
Setting boot drive is generation specific
taliesins Nov 7, 2015
f8e3970
By default a gen 1 vm get a dvd drive. Remove it on creation so that …
taliesins Nov 7, 2015
d1961b7
Echo output when its used
taliesins Nov 7, 2015
bda2468
removed unused reference
taliesins Nov 7, 2015
199bee6
Need to sleep after sending previous characters, not before
taliesins Nov 7, 2015
8734c5b
Remove all Dvd Drives on Generation 1
Nov 30, 2015
056fc59
Do not try to type scancodes if there are none. We haven't figured ou…
taliesins Dec 1, 2015
4ab2e8b
try to get the virtual keyboard a number of different ways. This shou…
taliesins Dec 5, 2015
d878f4d
A workaround for bug in Windows 10 and Windows 2016 where you have to…
taliesins Dec 5, 2015
872fc55
Export of Hyper-V/VMCX machines
Dec 1, 2015
181132f
Forget to pass in the dvd drive to eject the iso from
taliesins Dec 5, 2015
de44777
Windows Server 2016 won't let you set the first boot device
taliesins Dec 5, 2015
fb098fc
http server has moved to common step
taliesins Jan 25, 2016
7c754bf
Try to match style of other builders
taliesins Jun 29, 2016
5d5809b
Make hiding of progress backward compatible with old versions of powe…
taliesins Jun 29, 2016
4d22bd1
Generate switch name using uuid v1
taliesins Mar 29, 2016
807d7ea
On windows a lot of git clients will convert LF to CRLF. This would b…
taliesins Apr 1, 2016
e551087
Added file with correct line endings
taliesins Apr 1, 2016
4721327
Fix duplicate imports
taliesins Jun 30, 2016
8c32397
Skip these tests on platforms that don't have powershell installed
taliesins Jun 30, 2016
52c6cd5
Test should run and pass even when run on an environment that does no…
taliesins Jun 30, 2016
17597b4
Base64 encode powershell to avoid any necessary escaping
taliesins Jul 4, 2016
d61513b
Encode powershell using utf8
taliesins Jul 12, 2016
e36051d
Pattern for infrastructure changed to quote filename and execute file…
taliesins Jul 13, 2016
f38d787
Powershell uses UTF16Le for encodedCommand
taliesins Jul 24, 2016
c1538c5
Builds in AppVeyor are failing as they do not have enough free memory…
taliesins Jul 24, 2016
5f7290c
Add type scan support for ctrl, shift, alt.
taliesins Jul 30, 2016
e636c3d
Dvd drive creation will auto select the controller number and control…
taliesins Jul 31, 2016
9c53df1
Add special key modifiers to log output when used.
taliesins Jul 31, 2016
7ce9203
Enable-VMIntegrationService cmdlet has a language dependent value for…
taliesins Aug 2, 2016
6342e15
s/EnabeSecureBoot/EnableSecureBoot/g
PatrickLang Aug 6, 2016
f94c2cd
Adding nested virtualization support
PatrickLang Aug 6, 2016
6d391fc
Adding support for nested Hyper-V
PatrickLang Aug 6, 2016
1277a25
Fix type casting
PatrickLang Aug 6, 2016
9fbd1e4
Add support for mac spoofing and dynamic memory.
taliesins Aug 7, 2016
b8554da
Add documentation for: enable_mac_spoofing, enable_dynamic_memory and…
taliesins Aug 7, 2016
48b6cc0
Enable VlanID
efx-jjohnson Sep 21, 2016
c2d1f6b
Added the ability to independently configure switch vlan. This will p…
taliesins Sep 29, 2016
d56d683
Add vendoring for unicode:
taliesins Oct 26, 2016
ffc7f3f
Address documentation layout and copy issues
taliesins Oct 26, 2016
55353fa
Fix spelling mistake
taliesins Oct 26, 2016
c88a2ef
Remove trailing tabs
taliesins Oct 26, 2016
501845c
SSHKeyPath and SSHWaitTimeout have been deprecated in favor of commun…
taliesins Nov 6, 2016
a27d75f
Fix comment left over from initial import
taliesins Nov 6, 2016
d711756
We are using powershell and Msvm to send keys to virtual keyboard so …
taliesins Nov 6, 2016
20643e3
Do not specify a default username or password
taliesins Nov 6, 2016
0515487
Configuration settings are no longer used
taliesins Nov 6, 2016
3c1df5a
Remove inconsistent "_mb" from ram size
taliesins Nov 6, 2016
7add6d3
Add missing configuration elements.
taliesins Nov 6, 2016
3f0835a
Remove headless option as it is not used.
taliesins Nov 6, 2016
04a6880
Remove unused import
taliesins Nov 6, 2016
fb192ce
Remove unused import
taliesins Nov 6, 2016
44f73fa
Changed ram_size_mb to ram_size
taliesins Nov 6, 2016
3356154
Run go fmt on files
taliesins Nov 6, 2016
602c207
Make it clear iso is downloaded
taliesins Nov 6, 2016
24e9810
guest_os_type is no longer used
taliesins Nov 14, 2016
143ac30
headless is no longer used
taliesins Nov 14, 2016
74255c5
Be smarter about loading guest additions iso. Windows 10 and Windows …
taliesins Nov 14, 2016
e357c56
Builders don't need to set this up anymore
taliesins Nov 22, 2016
e50fe9f
Porting over paulmey changes to license and copyright headers. Good g…
taliesins Nov 23, 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