Skip to content

Commit

Permalink
common
Browse files Browse the repository at this point in the history
  • Loading branch information
sergey-shandar committed Sep 7, 2017
1 parent a321a65 commit 6571649
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ RequiredModules = @(
# NestedModules = @()

# 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.
FunctionsToExport = 'New-AzVm2','New-AzVm', 'New-AzVm3'
FunctionsToExport = 'New-AzVm'

# 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.
# CmdletsToExport =
Expand Down
80 changes: 80 additions & 0 deletions experiments/Compute.Experiments/AzureRM.Compute.Experiments.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,86 @@ function Set-ResourceGroup {
}
}

class Common {
[string] $Location;
[string] $ResourceGroupName;

[void] Update([string] $location, [string] $resourceGroupName) {
if (-not $this.Location) {
$this.Location = $location
}
if (-not $this.ResourceGroupName) {
$this.ResourceGroupName = $resourceGroupName
}
}
}

class VirtualNetwork {
[string] $Name;

[bool] UpdateCommon([Common] $common) {
if ($this.Name) {
$virtualNetwork = Get-AzureRMVirtualNetwork `
| Where-Object { $_.Name -eq $Name } `
| Select-Object -First 1 -Wait;
$common.Update($virtualNetwork.Location, $virtualNetwork.ResourceGroupName)
return $true
}
return $false
}
}

class PublicIpAddress {
[string] $Name;

[bool] UpdateCommon([Common] $common) {
if ($this.Name) {
$virtualNetwork = Get-AzureRMPublicIpAddress `
| Where-Object { $_.Name -eq $Name } `
| Select-Object -First 1 -Wait;
$common.Update($virtualNetwork.Location, $virtualNetwork.ResourceGroupName)
return $true
}
return $false
}
}

class SecurityGroup {
[string] $Name;

[bool] UpdateCommon([Common] $common) {
if ($this.Name) {
$virtualNetwork = Get-AzureRMSecurityGroup `
| Where-Object { $_.Name -eq $Name } `
| Select-Object -First 1 -Wait;
$common.Update($virtualNetwork.Location, $virtualNetwork.ResourceGroupName);
return $true;
}
return $false;
}
}

class NetworkInterface {
[string] $Name;
[VirtualNetwork] $VirtualNetwork;
[PublicIpAddress] $PublicIpAddress;
[SecurityGroup] $SecurityGroupName;

[bool] UpdateCommon([Common] $common) {
if ($this.Name) {
$networkInterface = Get-AzureRMNetworkInterface `
| Where-Object { $_.Name -eq $Name } `
| Select-Object -First 1 -Wait;
$common.Update($networkInterface.Location, $networkInterface.ResourceGroupName);
return $true;
} else {
return $this.VirtualNetwork.UpdateCommon($common) `
-or $this.PublicIpAddress.UpdateCommon($common) `
-or $this.SecurityGroup.UpdateCommon($common);
}
}
}

function New-PsObject {
param([hashtable] $property)

Expand Down

0 comments on commit 6571649

Please sign in to comment.