Skip to content

Setting VM fixed IP on Hyper-V#8

Open
gaelcolas wants to merge 138 commits intotaliesins:HyperVfrom
gaelcolas:HyperV
Open

Setting VM fixed IP on Hyper-V#8
gaelcolas wants to merge 138 commits intotaliesins:HyperVfrom
gaelcolas:HyperV

Conversation

@gaelcolas
Copy link

@gaelcolas gaelcolas commented Oct 5, 2016

Hi,
I added support for setting fixed IP address, subnet mask, Gateway, DNS server on the VM as per this article:
http://www.ravichaganti.com/blog/set-or-inject-guest-network-configuration-from-hyper-v-host-windows-server-2012/

It's also what the Hyper-V driver for Test-Kitchen leverages (https://github.com/gaelcolas/kitchen-hyperv/blob/master/support/hyperv.ps1).

This works on Windows 10 Build 14931 using a NAT switch.
I reused @mwrock's hyperv-2016.json templates, adding the settings likeso:

"builders": [
    {
      "type": "hyperv-iso",
      "guest_additions_mode": "disable",
      "iso_url": "{{ user `iso_url` }}",
      "iso_checksum": "{{ user `iso_checksum` }}",
      "iso_checksum_type": "md5",
      "ram_size_mb": 1024,
      "communicator": "winrm",
      "winrm_username": "Administrator",
      "winrm_password": "vagrant",
      "winrm_timeout": "12h",
      "shutdown_command": "C:/Windows/Panther/Unattend/packer_shutdown.bat",
      "shutdown_timeout": "15m",
      "switch_name": "NAT",
      "ip_address": "10.111.111.123",
      "subnet_mask": "255.255.255.0",
      "gateway": "10.111.111.1",
      "dns_server": "8.8.8.8",
      "floppy_files": [
        "answer_files/2016/Autounattend.xml",
        "scripts/winrm.ps1"
      ]
    }

Feedback welcome! (this is my first go at it)

taliesins and others added 30 commits June 21, 2015 12:36
Remove steps that are windows specific
Move builder into correctly named folder
Use the convention for default hdd size
Tests added for builder
…s how other system like VeeWee do it.

Add support for number of cpus to use for vm
Add support for vm generation
Attempt to stop vm, before deleting it
Setup local http server
Add compaction of hard drive
GetHostAdapterIpAddress function added for hyperv
renamed step step_start_vm to step_run to fall in ine with naming conventions of other builders
…reate a dvd drive for os if it does not exist.

Allow secure boot mode to be configured from config.
Get VName out of state. This allows template replacement to be run on vmname
Don't want to be prompted for confirmation from powershell commandlets
Conflicts:
	helper/communicator/step_connect.go
	helper/communicator/step_connect_winrm.go
taliesins and others added 22 commits July 31, 2016 16:23
…ler location. This fixes the bug of first generation machines not being able to add more then 1 dvd drive.
Update documentation to include new key modifiers.
… -Name option. So avoid using it, as it will break on machines with different languages.
To enable nested virtualization, mac spoofing, no dynamic memory and at least 4gb of ram should be set for the vm. Set warning if this has not been done.
Detected Virtualization Extensions are supported by the machine your are running on, as it only works for Windows 10 and Windows Server 2016 onwards.
# Conflicts:
#	builder/qemu/builder.go
#	command/plugin.go
…eople to leave the switch in trunk mode and set a vlan for the vm.
@taliesins
Copy link
Owner

Why not set a static ip via unattended.xml file calling a powershell file? Or call it as part of the provisioning phase if windows updates are not required.

Surely setting a NAT up in hyperv switch with dhcp is preferable? I personally run pfsense in a vm for all my routing needs. Nice easy gui.

https://4sysops.com/archives/native-nat-in-windows-10-hyper-v-using-a-nat-virtual-switch/

@gaelcolas
Copy link
Author

While this is an option I use in other scenarios, I prefer not having to rely on yet another component, for different reasons:

  • why making it even more complex that it needs to be? 4 entries in the JSON seems easier to maintain than another VM and its configuration when managing different environments
  • I want this to be easier to try out for WinOps people, pfSense or other *nix flavor is yet another (mental) barrier (whether or not there's a nice GUI)
  • I have limited resource when running on my laptop (dev or demos), I'd rather not have another VM/dependency
  • I like the idea of Packer being somewhat consistent with Test-Kitchen (that is the HyperV builder with Kitchen-HyperV). While Test-Kitchen is great for provisioning development workflow, Packer is perfect for the next step, deployment / imaging (that sometimes end up being the source of another development cycle...).
  • I'd rather not 'pollute' the unattend.xml file with something that is not needed when using other builder.

I'm sure there would be other reasons in the wild, but those are why I went through the effort of adding this little convenience to your work.
Hope that makes sense?

@jcejohnson
Copy link

I've been meaning to test this with Linux guests but I've got deadlines looming. I didn't want you to think I was ignoring you :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants