-
Notifications
You must be signed in to change notification settings - Fork 0
/
proxmolito.ps1
197 lines (168 loc) · 8.38 KB
/
proxmolito.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
. $PSScriptRoot\config.ps1
function Show-Menu {
param (
[string]$Title
)
$VMSelected | Format-table -Property VMName,DomainName,IPAddress,DNSAddress,NetworkSwitches
Write-Host "================ $Title ================"
Write-Host " 1: Deploy Linux Servers" -ForegroundColor Green
Write-Host " 2: Install Required packaes and update the VM" -ForegroundColor Green
Write-Host " 3: Prepare VM for k8s" -ForegroundColor Green
Write-Host " 4: Clean VM and make Template" -ForegroundColor Green
Write-Host " 5: NAT Network Deployment" -ForegroundColor Green
Write-Host "99: Change the user config settings" -ForegroundColor Green
Write-Host " B: Back to main menu" -ForegroundColor Green
Write-Host " C: Clear the screen" -ForegroundColor Green
Write-Host " Q: To quit" -ForegroundColor Green
}
do {
Show-Menu -Title "P R O X M O L I T O"
$Selection = Read-Host "Please make a selection"
# Get the current location
$Location = Get-Location
switch ($Selection) {
"c" { Clear-Host }
"1"
{
################## Deploy Linux Servers ###################
Write-Host "1 = Debian 12 (Bookworm) `n2 = Ubuntu 22.04 (Jammy Jellyfish) `n3 = Fedora 39" -ForegroundColor Green
$SelectOS = Read-Host "Select the OS you want to deploy"
switch ($SelectOS) {
"1" { & $Location\vm-deployments\debian-12-cloudinit.ps1 }
"2" { & $Location\vm-deployments\ubuntu-2204-cloudinit.ps1 }
"3" { & $Location\vm-deployments\fedora-39-cloudinit.ps1 }
Default {}
}
}
"2"
{
################## Install Required packaes and update the VM ###################
Write-Host "Installing Required packaes and update the VM" -ForegroundColor Green
If ($Config.VM.Hardware.SnapShot -eq $true) {
$SnapDate = Get-Date -Format "yyyy_MM_dd_HHmm"
Write-Host "Creating a snapshot of the VM" -ForegroundColor Green
$VMID = Read-Host "Enter the VM ID"
write-host "Allowed Characters: [A-Z],[a-z][0-9],[_]" -ForegroundColor Yellow | Out-Host
write-host "[min character: 2],[Must start with letter]" -ForegroundColor Yellow | Out-Host
$SnapShotName = Read-Host -Prompt "Enter the snapshot name"
if ($SnapShotName -like "") {
$SnapShotName = "Before_Post_Deployment_$SnapDate"
}
Write-Host "Creating a snapshot of the VMID $VMID with the name $SnapShotName..."
qm snapshot $VMID $SnapShotName
if (!($?)) {
write-host "Error creating the snapshot, press any key to continue" -ForegroundColor Red
Pause
} else {
write-host "Snapshot created, press any key to continue" -ForegroundColor Green
Pause
}
}
if ($VMIP -like "") {
$VMIP = Read-Host "Enter the IP address for the VM"
} else {
Write-Host "Using the IP address from the previous step: $VMIP" -ForegroundColor Yellow
Pause
}
$SourceFolder = "$($Location)/bash-scripts"
$SourceFileName = "vm-post-deployment.sh"
$SourceFile = "$SourceFolder/$SourceFileName"
$DestinationFile = "/tmp/$SourceFileName"
scp -o "StrictHostKeyChecking=no" $SourceFile "$($Config.VM.CloudInit.UserName)@$($VMIP):$($DestinationFile)"
ssh "$($Config.VM.CloudInit.UserName)@$($VMIP)" $DestinationFile
}
"3"
{
################## Prepare VM for k8s ###################
Write-Host "Prepare VM for k8s" -ForegroundColor Green
If ($Config.VM.Hardware.SnapShot -eq $true) {
$SnapDate = Get-Date -Format "yyyy_MM_dd_HHmm"
Write-Host "Creating a snapshot of the VM" -ForegroundColor Green
$VMID = Read-Host "Enter the VM ID"
write-host "Allowed Characters: [A-Z],[a-z][0-9],[_]" -ForegroundColor Yellow | Out-Host
write-host "[min character: 2],[Must start with letter]" -ForegroundColor Yellow | Out-Host
$SnapShotName = Read-Host -Prompt "Enter the snapshot name"
if ($SnapShotName -like "") {
$SnapShotName = "Before_Post_Deployment_$SnapDate"
}
Write-Host "Creating a snapshot of the VMID $VMID with the name $SnapShotName..."
qm snapshot $VMID $SnapShotName
if (!($?)) {
write-host "Error creating the snapshot, press any key to continue" -ForegroundColor Red
Pause
} else {
write-host "Snapshot created, press any key to continue" -ForegroundColor Green
Pause
}
}
if ($VMIP -like "") {
$VMIP = Read-Host "Enter the IP address for the VM"
} else {
Write-Host "Using the IP address from the previous step: $VMIP" -ForegroundColor Yellow
Pause
}
$SourceFolder = "$($Location)/bash-scripts"
$SourceFileName = "k8s-deployment.sh"
$SourceFile = "$SourceFolder/$SourceFileName"
$DestinationFile = "/tmp/$SourceFileName"
scp -o "StrictHostKeyChecking=no" $SourceFile "$($Config.VM.CloudInit.UserName)@$($VMIP):$($DestinationFile)"
ssh "$($Config.VM.CloudInit.UserName)@$($VMIP)" $DestinationFile
}
"4"
{
################## Clean the machine to make a Template ###################
Write-Host "Cleaning the machine to make a Template" -ForegroundColor Green
If ($Config.VM.Hardware.SnapShot -eq $true) {
$SnapDate = Get-Date -Format "yyyy_MM_dd_HHmm"
Write-Host "Creating a snapshot of the VM" -ForegroundColor Green
$VMID = Read-Host "Enter the VM ID"
write-host "Allowed Characters: [A-Z],[a-z][0-9],[_]" -ForegroundColor Yellow | Out-Host
write-host "[min character: 2],[Must start with letter]" -ForegroundColor Yellow | Out-Host
$SnapShotName = Read-Host -Prompt "Enter the snapshot name"
if ($SnapShotName -like "") {
$SnapShotName = "Before_Post_Deployment_$SnapDate"
}
Write-Host "Creating a snapshot of the VMID $VMID with the name $SnapShotName..."
qm snapshot $VMID $SnapShotName
if (!($?)) {
write-host "Error creating the snapshot, press any key to continue" -ForegroundColor Red
Pause
} else {
write-host "Snapshot created, press any key to continue" -ForegroundColor Green
Pause
}
}
if ($VMIP -like "") {
$VMIP = Read-Host "Enter the IP address for the VM"
} else {
Write-Host "Using the IP address from the previous step: $VMIP" -ForegroundColor Yellow
Pause
}
$SourceFolder = "$($Location)/bash-scripts"
$SourceFileName = "machine-id-clean.sh"
$SourceFile = "$SourceFolder/$SourceFileName"
$DestinationFile = "/tmp/$SourceFileName"
scp -o "StrictHostKeyChecking=no" $SourceFile "$($Config.VM.CloudInit.UserName)@$($VMIP):$($DestinationFile)"
ssh "$($Config.VM.CloudInit.UserName)@$($VMIP)" $DestinationFile
Write-Host "Machine ID cleaned, You can now convert it to a Template." -ForegroundColor Green
Pause
}
"5"
{
& $Location\nat-network-deployment.ps1
}
"99"
{
Write-Host "Your current config settings:" -ForegroundColor Green
$ConfigView = ($Config).Global,($Config).VM.Hardware,($Config).VM.CloudInit | Format-List
$ConfigView | Out-Host
$Confirmation = Read-Host "Do you want to change the settings? (y/n)"
if ($Confirmation -like "y") {
& $Location/config-editor.ps1
}
}
Default {}
}
} until (
$Selection -eq "q"
)