Skip to content

Commit 6571649

Browse files
common
1 parent a321a65 commit 6571649

File tree

2 files changed

+81
-1
lines changed

2 files changed

+81
-1
lines changed

experiments/Compute.Experiments/AzureRM.Compute.Experiments.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ RequiredModules = @(
7373
# NestedModules = @()
7474

7575
# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export.
76-
FunctionsToExport = 'New-AzVm2','New-AzVm', 'New-AzVm3'
76+
FunctionsToExport = 'New-AzVm'
7777

7878
# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
7979
# CmdletsToExport =

experiments/Compute.Experiments/AzureRM.Compute.Experiments.psm1

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,86 @@ function Set-ResourceGroup {
139139
}
140140
}
141141

142+
class Common {
143+
[string] $Location;
144+
[string] $ResourceGroupName;
145+
146+
[void] Update([string] $location, [string] $resourceGroupName) {
147+
if (-not $this.Location) {
148+
$this.Location = $location
149+
}
150+
if (-not $this.ResourceGroupName) {
151+
$this.ResourceGroupName = $resourceGroupName
152+
}
153+
}
154+
}
155+
156+
class VirtualNetwork {
157+
[string] $Name;
158+
159+
[bool] UpdateCommon([Common] $common) {
160+
if ($this.Name) {
161+
$virtualNetwork = Get-AzureRMVirtualNetwork `
162+
| Where-Object { $_.Name -eq $Name } `
163+
| Select-Object -First 1 -Wait;
164+
$common.Update($virtualNetwork.Location, $virtualNetwork.ResourceGroupName)
165+
return $true
166+
}
167+
return $false
168+
}
169+
}
170+
171+
class PublicIpAddress {
172+
[string] $Name;
173+
174+
[bool] UpdateCommon([Common] $common) {
175+
if ($this.Name) {
176+
$virtualNetwork = Get-AzureRMPublicIpAddress `
177+
| Where-Object { $_.Name -eq $Name } `
178+
| Select-Object -First 1 -Wait;
179+
$common.Update($virtualNetwork.Location, $virtualNetwork.ResourceGroupName)
180+
return $true
181+
}
182+
return $false
183+
}
184+
}
185+
186+
class SecurityGroup {
187+
[string] $Name;
188+
189+
[bool] UpdateCommon([Common] $common) {
190+
if ($this.Name) {
191+
$virtualNetwork = Get-AzureRMSecurityGroup `
192+
| Where-Object { $_.Name -eq $Name } `
193+
| Select-Object -First 1 -Wait;
194+
$common.Update($virtualNetwork.Location, $virtualNetwork.ResourceGroupName);
195+
return $true;
196+
}
197+
return $false;
198+
}
199+
}
200+
201+
class NetworkInterface {
202+
[string] $Name;
203+
[VirtualNetwork] $VirtualNetwork;
204+
[PublicIpAddress] $PublicIpAddress;
205+
[SecurityGroup] $SecurityGroupName;
206+
207+
[bool] UpdateCommon([Common] $common) {
208+
if ($this.Name) {
209+
$networkInterface = Get-AzureRMNetworkInterface `
210+
| Where-Object { $_.Name -eq $Name } `
211+
| Select-Object -First 1 -Wait;
212+
$common.Update($networkInterface.Location, $networkInterface.ResourceGroupName);
213+
return $true;
214+
} else {
215+
return $this.VirtualNetwork.UpdateCommon($common) `
216+
-or $this.PublicIpAddress.UpdateCommon($common) `
217+
-or $this.SecurityGroup.UpdateCommon($common);
218+
}
219+
}
220+
}
221+
142222
function New-PsObject {
143223
param([hashtable] $property)
144224

0 commit comments

Comments
 (0)