Skip to content

Instantly share code, notes, and snippets.

@altrive
Last active February 7, 2016 13:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save altrive/5161152 to your computer and use it in GitHub Desktop.
Save altrive/5161152 to your computer and use it in GitHub Desktop.
Create Vyatta VirtualMachine on Hyper-V. Vyatta configuration is loaded from virtual floppy(.vfd)

Usage:

$params=@{
  VmName = "Vyatta"
  ExternalSwitchName   = "外部LAN"
  InternalSwitchName   = "内部LAN"
  VyattaLiveCDPath    = "D:\Shared\Images\vyatta-livecd-virt_VC6.5R1_i386.iso"
  VyattaConfigVfdPath = "D:\Hyper-V\Shared\Vyatta.vfd"
}

New-VyattaVM @params | Start-VM
vmconnect.exe localhost $params.VmName

Vyatta config scripts sample

Save following scripts to VFD root directory as "configure.sh" and create empty directory "config"

#!/bin/sh

configure

#NIC Interface Settings 
set interfaces ethernet eth0 address dhcp
set interfaces ethernet eth1 address 172.16.255.254/16

#NAT Settings
set nat source rule 10
set nat source rule 10 outbound-interface eth0
set nat source rule 10 source address 0.0.0.0/0
set nat source rule 10 translation address masquerade

#DNS Service Settings
set service dns forwarding dhcp eth0
set service dns forwarding listen-on eth1

#DHCP Service Settings
set service dhcp-server shared-network-name ETH1_POOL subnet 172.16.0.0/16 start 172.16.100.0 stop 172.16.199.255
set service dhcp-server shared-network-name ETH1_POOL subnet 172.16.0.0/16 default-router 172.16.255.254
set service dhcp-server shared-network-name ETH1_POOL subnet 172.16.0.0/16 dns-server 172.16.255.254

#NTP Settings
delete system ntp
set system ntp server ntp.jst.mfeed.ad.jp
set system time-zone Asia/Tokyo

commit
save

How to setup Vyatta VM

Execute Following command in vyatta console to apply config and save config file to floppy disk

config
. /media/floppy/configure.sh
commit
save /media/floppy/config/config.boot
exit
reboot
function New-VyattaVM
{
[Cmdletbinding()]
param(
[string]$VmName,
[string]$ExternalSwitchName,
[string]$InternalSwitchName,
[string]$VyattaLiveCDPath,
[string]$VyattaConfigVfdPath
)
Set-StrictMode -Version Latest
$ErrorActionPreference ="Stop"
#Error if same vm name exists
$vms = Get-VM $VmName -ErrorAction SilentlyContinue
if($vms -ne $null)
{
Write-Error "Virtual machine '$($VmName)' is already exists!"
}
#VM config location
$vmLocation = (Get-VMHost).VirtualMachinePath
$vmPath = Join-Path $vmLocation $VmName #TODO:vmName should be escaped?
Write-Host $vmPath
#Create VM
$vm = New-Vm -Name $VmName -Path $vmPath
#CPU Settings
$cpuCount =1
Set-VMProcessor -VMName $VmName -Count $cpuCount -CompatibilityForMigrationEnabled $true
#Memory Settings
$memoryStartupBytes = 512MB
Set-VMMemory -VMName $VmName -StartupBytes $memoryStartupBytes
#Connect *External* Network Adapter
Connect-VMNetworkAdapter -VmName $VmName -SwitchName $ExternalSwitchName
#Add *Internal* Network Adapter
Add-VMNetworkAdapter -VMName $VmName -SwitchName $InternalSwitchName
#Set Vyatta LiveCD
Set-VMDvdDrive -VMName $VmName -Path $VyattaLiveCDPath
#Set Vyatta config Virtual Floppy Disk
Set-VMFloppyDiskDrive -VMName $VmName -Path $VyattaConfigVfdPath
#Set Start Action
Set-VM -VMName $VmName -AutomaticStartAction Start -AutomaticStopAction ShutDown
return $vm
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment