-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2576 from taliesins/HyperV
Add Hyper-V builder
- Loading branch information
Showing
88 changed files
with
14,587 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
common/test-fixtures/root/* eol=lf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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())) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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{} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Oops, something went wrong.