Skip to content

Commit 4cac804

Browse files
authored
Clean up EFLOW VM scripts and add readme (#1958)
1 parent a84be0c commit 4cac804

File tree

3 files changed

+104
-63
lines changed

3 files changed

+104
-63
lines changed

Tools/Eflow/install-hyperv.ps1

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<# .SYNOPSIS
2+
Hyper-V installation Script
3+
.DESCRIPTION
4+
This script automatically installs Hyper-V on a Windows Server VM to allow eflow provisioning.
5+
The VM requires a restart after this script is run before eflow can be provisioned.
6+
.NOTES
7+
Author :
8+
Mikhail Chatillon - chmikhai@microsoft.com
9+
Daniele Antonio Maggio - daniele.maggio@microsoft.com
10+
Nora Abi Akar - noraabiakar@microsoft.com
11+
#>
12+
13+
# Install Hyper-V
14+
Install-WindowsFeature -Name Hyper-V
15+
Install-WindowsFeature -Name Hyper-V-PowerShell
16+
Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform -All -NoRestart
17+
18+
Write-Host "Please reboot to finalize installation."

Tools/Eflow/provision-eflow.ps1

Lines changed: 39 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,109 +1,85 @@
11
<# .SYNOPSIS
22
EFLOW Windows Server provisioning Script
33
.DESCRIPTION
4-
THIS SCRIPT IS NOT RECOMMENDED TO BE USED AS IS, BUT SHOULD BE SEEN AS A COLLECTION OF STEPS TO BE RUN MANUALLY
5-
TO GET EFLOW UP AND RUNNING.
6-
This script automatically install Edge For Linux On Windows (EFLOW) on a new Windows Server VM
7-
The script might trigger a restart and might need to be rerun after a restart
4+
This script automatically installs Edge For Linux On Windows (EFLOW) on a new Windows Server VM.
5+
This script assumes that the Windows VM has Hyper-V already installed.
6+
The script accepts the following parameters:
7+
- iotEdgeDeviceConnectionString: (required) the iotedge device connection string.
8+
- switchName: (optional) the switch name.
9+
- startEflowIpRange: (optional) start of the IP range of eflow.
10+
- internalPort: (optional) the internal port of the Net Nat Static Mapping.
11+
- externalPort: (optional) the external port of the Net Nat Static Mapping.
812
.NOTES
913
Author :
10-
Mikhail Chatillon - chmikhai@microft.com
14+
Mikhail Chatillon - chmikhai@microsoft.com
1115
Daniele Antonio Maggio - daniele.maggio@microsoft.com
16+
Nora Abi Akar - noraabiakar@microsoft.com
1217
#>
1318

1419
param
1520
(
16-
[string]$switchName="EFLOW Switch",
17-
[string]$startEflowIpRange=100,
18-
[string]$endEflowIpRange=200,
1921
[string]$iotEdgeDeviceConnectionString,
22+
[string]$switchName,
23+
[string]$startEflowIpRange=100,
2024
[int]$internalPort=5000,
2125
[int]$externalPort=5000
2226
)
2327

24-
# Enable Windows Features
25-
if ((Get-WindowsFeature -Name "DHCP").Installed -eq $false)
26-
{
27-
Install-WindowsFeature -Name DHCP -IncludeManagementTools
28-
}
29-
if ((Get-WindowsFeature -Name "Hyper-V").Installed -eq $false)
28+
# Verify dependencies
29+
if (!$iotEdgeDeviceConnectionString)
3030
{
31-
Install-WindowsFeature -Name Hyper-V
32-
Install-WindowsFeature -Name Hyper-V-PowerShell
33-
Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform -All -NoRestart
34-
Write-Host "Restarting the computer in 30 seconds to finish Hyper-V installation"
35-
Start-Sleep -Seconds 30
36-
Restart-Computer
31+
throw "IoT Edge Device Connection String not provided."
3732
}
38-
if ((Get-WindowsFeature -Name "DHCP").Installed -eq $false)
33+
34+
if (!$switchName)
3935
{
40-
throw "DHCP not correctly installed."
36+
throw "Switch Name not provided."
4137
}
38+
4239
if ((Get-WindowsFeature -Name "Hyper-V").Installed -eq $false)
4340
{
4441
throw "Hyper-V not correctly installed."
4542
}
4643

47-
# Create the networking
48-
if(Get-VMSwitch -Name $switchName -ErrorAction SilentlyContinue)
44+
if(!(Get-VMSwitch -Name $switchName -ErrorAction SilentlyContinue))
4945
{
50-
throw "Switch already existing";
46+
throw "Switch $switchName not found";
5147
}
5248

53-
New-VMSwitch -Name $switchName -SwitchType internal
54-
Write-Host "Sleeping for 30sec before continuing for propagating the VMSwitch"
55-
Start-Sleep -Seconds 30
56-
Write-Host "Finished waiting for propagating the VMSwitch"
49+
# Create Nat
50+
Write-Host "Creating Nat"
51+
5752
$netAdapterIfIndex=(Get-NetAdapter -Name "*$switchName*").ifIndex
5853
$netAdapterIpAddress=Get-NetIPAddress -AddressFamily IPv4 -InterfaceIndex $netAdapterIfIndex
5954
$netAdapterIp=$netAdapterIpAddress.IPAddress
6055
$ipAddressFamily=$netAdapterIp.Substring(0, $netAdapterIp.lastIndexOf('.')+1)
61-
$gwIpCounter=1
62-
$gwIp=$ipAddressFamily+$gwIpCounter
63-
64-
while(!(get-NetIPAddress -IpAddress $gwIp -ErrorAction SilentlyContinue))
65-
{
66-
$gwIpCounter++
67-
if($gwIpCounter>9)
68-
{
69-
throw "All the IPs in the subnet range 1-9 on $ipAddressFamily were already taken";
70-
}
71-
72-
$gwIp=$ipAddressFamily+$gwIpCounter
73-
}
74-
56+
$gwIp=$ipAddressFamily+1
7557
$natIp=$ipAddressFamily+0
76-
77-
New-NetIPAddress -IPAddress $gwIp -PrefixLength 24 -InterfaceIndex $netAdapterIfIndex
78-
79-
if(Get-NetNat -Name "$switchName" -ErrorAction SilentlyContinue)
80-
{
81-
throw "Net Nat with name $switchName already existing";
82-
}
58+
$startIp=$ipAddressFamily+$startEflowIpRange
8359

8460
New-NetNat -Name "$switchName" -InternalIPInterfaceAddressPrefix "$natIp/24"
8561

86-
#Install DHCP
87-
netsh dhcp add securitygroups
88-
Restart-Service dhcpserver
89-
$startIp=$ipAddressFamily+$startEflowIpRange
90-
$endIp=$ipAddressFamily+$endEflowIpRange
91-
Add-DhcpServerV4Scope -Name "AzureIoTEdgeScope" -StartRange $startIp -EndRange $endIp -SubnetMask 255.255.255.0 -State Active
92-
Set-DhcpServerV4OptionValue -ScopeID $natIp -Router $gwIp
93-
Restart-Service dhcpserver
62+
# Install Eflow
63+
Write-Host "Installing Eflow"
9464

95-
# install Eflow
9665
Set-ExecutionPolicy -ExecutionPolicy AllSigned -Force
9766
$msiPath = $([io.Path]::Combine($env:TEMP, 'AzureIoTEdge.msi'))
9867
$ProgressPreference = 'SilentlyContinue'
9968
Invoke-WebRequest "https://aka.ms/AzEflowMSI" -OutFile $msiPath
69+
10070
Start-Process -Wait msiexec -ArgumentList "/i","$([io.Path]::Combine($env:TEMP, 'AzureIoTEdge.msi'))","/qn"
101-
Deploy-Eflow -acceptEula 'yes' -acceptOptionalTelemetry 'yes' -vswitchName $switchName -ip4Address $startIp -ip4GatewayAddress $gwIp -vswitchType 'Internal'
102-
if($iotEdgeDeviceConnectionString){
103-
Provision-EflowVm -provisioningType ManualConnectionString -devConnString "$iotEdgeDeviceConnectionString"
104-
}
71+
Deploy-Eflow -acceptEula 'yes' -acceptOptionalTelemetry 'yes' -vswitchName $switchName -ip4Address $startIp -ip4GatewayAddress $gwIp -vswitchType 'Internal' -ip4PrefixLength 24
72+
Provision-EflowVm -provisioningType ManualConnectionString -devConnString "$iotEdgeDeviceConnectionString"
73+
74+
# Add static mapping
75+
Write-Host "Creating static mapping"
10576

10677
if(!(Get-NetNatStaticMapping -NatName "$switchName" -ErrorAction SilentlyContinue))
10778
{
10879
Add-NetNatStaticMapping -ExternalIPAddress "0.0.0.0/0" -ExternalPort $externalPort -Protocol TCP -InternalIPAddress "$startip" -InternalPort $internalPort -NatName $switchName
10980
}
81+
82+
# Set DNS server
83+
Write-Host "Set DNS server"
84+
85+
Set-EflowVmDNSServers -dnsServers 168.63.129.16

Tools/Eflow/readme.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Eflow on Windows Server VM
2+
3+
## Install Eflow
4+
5+
1. Create new Windows Server VM.
6+
1. Connect to the Windows Server VM.
7+
1. Install hyper-V
8+
```
9+
.\install-hyperv.ps1
10+
```
11+
1. Restart the VM and reconnect
12+
1. Create VM Switch
13+
```
14+
$env:switchName = "EFLOW Switch"
15+
New-VMSwitch -Name $env:switchName -SwitchType internal
16+
```
17+
1. Enable Internet Connection Sharing
18+
- Open the Network Connections window.
19+
- Find the host VM's network that needs to be shared with EFLOW.
20+
- Open Properties.
21+
- Select the Sharing tab.
22+
- Check the box for "Allow other network users to connect through this computer’s Internet connection.”
23+
1. Provision Eflow
24+
```
25+
.\provision-eflow -iotEdgeDeviceConnectionString "HostName=****" -switchName $env:switchName
26+
```
27+
28+
## Verify Eflow installation
29+
30+
1. Connect to the eflow VM
31+
```
32+
Connect-EflowVm
33+
```
34+
35+
1. Check the configuration and connection of the VM.
36+
```
37+
sudo iotedge check
38+
```
39+
40+
1. Check that the deployment modules are running on the VM.
41+
```
42+
sudo iotedge list
43+
```
44+
45+
46+
## Reference
47+
1. [Create and provision an IoT Edge for Linux on Windows](https://learn.microsoft.com/en-us/azure/iot-edge/how-to-provision-single-device-linux-on-windows-symmetric?view=iotedge-1.4&tabs=azure-portal%2Cpowershell)

0 commit comments

Comments
 (0)