From 42ddd90594097c76d764f537a48b86063a1df90f Mon Sep 17 00:00:00 2001 From: Sergey Shandar Date: Wed, 20 Sep 2017 22:34:45 -0700 Subject: [PATCH 01/29] some bug fixes --- .../AzureRM.Compute.Experiments.Tests.ps1 | 4 +- .../AzureRM.Compute.Experiments.psm1 | 130 +++++++++++------- 2 files changed, 83 insertions(+), 51 deletions(-) diff --git a/experiments/Compute.Experiments/AzureRM.Compute.Experiments.Tests.ps1 b/experiments/Compute.Experiments/AzureRM.Compute.Experiments.Tests.ps1 index 7129be2d677d..4c821faadc15 100644 --- a/experiments/Compute.Experiments/AzureRM.Compute.Experiments.Tests.ps1 +++ b/experiments/Compute.Experiments/AzureRM.Compute.Experiments.Tests.ps1 @@ -16,7 +16,7 @@ $vmComputerUser = $credentials.vmUser; $password = ConvertTo-SecureString $vmComputerPassword -AsPlainText -Force; $vmCredential = New-Object System.Management.Automation.PSCredential ($vmComputerUser, $password); -New-AzVm -Name MyVM -Credential $vmCredential -WhatIf +# New-AzVm -Name MyVM -Credential $vmCredential -WhatIf # $job = New-AzVm -Name MyVMA -Credential $vmCredential -AsJob # Receive-Job $job @@ -37,4 +37,4 @@ $vm # Write-Host "" # clean-up -Remove-AzureRmResourceGroup -ResourceId $vm.ResourceGroupId \ No newline at end of file +Remove-AzureRmResourceGroup -Name $vm.ResourceGroupName \ No newline at end of file diff --git a/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psm1 b/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psm1 index b82bfef37acf..a57f7c2d4b17 100644 --- a/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psm1 +++ b/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psm1 @@ -7,20 +7,20 @@ function New-AzVm { [Parameter(Mandatory=$true, Position=0)][string] $Name = "VM", [Parameter(Mandatory=$true)][PSCredential] $Credential, - [Parameter()][string] $ResourceGroupName, + [Parameter()][string] $ResourceGroupName = $Name, [Parameter()][string] $Location, - [Parameter()][string] $VirtualNetworkName, + [Parameter()][string] $VirtualNetworkName = $Name, [Parameter()][string] $AddressPrefix = "192.168.0.0/16", - [Parameter()][string] $SubnetName, + [Parameter()][string] $SubnetName = $Name, [Parameter()][string] $SubnetAddressPrefix = "192.168.1.0/24", - [Parameter()][string] $PublicIpAddressName, + [Parameter()][string] $PublicIpAddressName = $Name, [Parameter()][string] $DomainNameLabel = $Name, [Parameter()][string] $AllocationMethod = "Static", - [Parameter()][string] $SecurityGroupName, + [Parameter()][string] $SecurityGroupName = $Name, [Parameter()][int[]] $OpenPorts = @(3389, 5985), [Parameter()][string] $ImageName = "Win2016Datacenter", @@ -47,7 +47,7 @@ function New-AzVm { # we don't allow to reuse NetworkInterface so $name is $null. $nii = [NetworkInterface]::new( - $null, + $Name, $rgi, $subnet, $piai, @@ -55,7 +55,7 @@ function New-AzVm { # the purpouse of the New-AzVm cmdlet is to create (not get) a VM so $name is $null. $vmi = [VirtualMachine]::new( - $null, + $Name, $rgi, $nii, $Credential, @@ -74,7 +74,7 @@ function New-AzVm { $locationi.Value = $Location } - $createParams = [CreateParams]::new($Name, $locationi.Value, $context) + $createParams = [CreateParams]::new($locationi.Value, $context) if ($PSCmdlet.ShouldProcess($Name, "Creating a virtual machine")) { if ($AsJob) { @@ -91,13 +91,7 @@ function New-AzVm { } return Start-Job $script -ArgumentList $arguments } else { - # Force to create Resource Group before anything else. - $rg = $rgi.GetOrCreate($createParams) - $vmResponse = $vmi.Create($createParams) - return [PSAzureVm]::new( - $rg.ResourceId, - $VirtualMachine.Name - ) + return $vmi.GetOrCreate($createParams) } } } @@ -124,16 +118,13 @@ class Location { } class CreateParams { - [string] $Name; [string] $Location; [object] $Context; CreateParams( - [string] $name, [string] $location, [object] $context) { - $this.Name = $name $this.Location = $location $this.Context = $context } @@ -143,6 +134,8 @@ class AzureObject { [string] $Name; [AzureObject[]] $Children; [int] $Priority; + + [bool] $GetInfoCalled = $false; [object] $info = $null; AzureObject([string] $name, [AzureObject[]] $children) { @@ -157,6 +150,10 @@ class AzureObject { $this.Priority++ } + [string] GetResourceType() { + return $null + } + [object] GetInfoOrThrow([object] $context) { return $null } @@ -165,9 +162,9 @@ class AzureObject { return $null } - # This function should be called only when $this.Name is not $null. [object] GetInfo([object] $context) { - if (!$this.Info) { + if (!$this.GetInfoCalled) { + $this.GetInfoCalled = $true try { $this.Info = $this.GetInfoOrThrow($context) } catch { @@ -198,15 +195,8 @@ class AzureObject { if ($i) { return $i } - if ($this.Name) { - $p = [CreateParams]::new( - $this.Name, - $p.Location, - $p.Context - ) - } + Write-Host ("creating " + $this.GetResourceType() + ": " + $this.Name) $this.Info = $this.Create($p) - $this.Name = $p.Name return $this.Info } } @@ -215,6 +205,10 @@ class ResourceGroup: AzureObject { ResourceGroup([string] $name): base($name, @()) { } + [string] GetResourceType() { + return "Resource Group" + } + [object] GetInfoOrThrow([object] $context) { return Get-AzureRmResourceGroup ` -Name $this.Name ` @@ -224,7 +218,7 @@ class ResourceGroup: AzureObject { [object] Create([CreateParams] $p) { return New-AzureRmResourceGroup ` - -Name $p.Name ` + -Name $this.Name ` -Location $p.Location ` -AzureRmContext $p.Context ` -WarningAction SilentlyContinue ` @@ -266,8 +260,13 @@ class VirtualNetwork: Resource1 { $this.AddressPrefix = $addressPrefix } + [string] GetResourceType() { + return "Virtual Network" + } + [object] GetInfoOrThrow([object] $context) { return Get-AzureRmVirtualNetwork ` + -ResourceGroupName $this.ResourceGroup.Name ` -Name $this.Name ` -AzureRmContext $context ` -ErrorAction Stop @@ -277,7 +276,7 @@ class VirtualNetwork: Resource1 { return New-AzureRmVirtualNetwork ` -ResourceGroupName $this.GetResourceGroupName($p) ` -Location $p.Location ` - -Name $p.Name ` + -Name $this.Name ` -AddressPrefix $this.AddressPrefix ` -AzureRmContext $p.Context ` -WarningAction SilentlyContinue ` @@ -299,8 +298,13 @@ class PublicIpAddress: Resource1 { $this.AllocationMethod = $allocationMethod } + [string] GetResourceType() { + return "Public IP Address" + } + [object] GetInfoOrThrow([object] $context) { return Get-AzureRMPublicIpAddress ` + -ResourceGroupName $this.ResourceGroup.Name ` -Name $this.Name ` -AzureRmContext $context ` -ErrorAction Stop @@ -310,7 +314,7 @@ class PublicIpAddress: Resource1 { return New-AzureRmPublicIpAddress ` -ResourceGroupName $this.GetResourceGroupName($p) ` -Location $p.Location ` - -Name $p.Name ` + -Name $this.Name ` -DomainNameLabel $this.DomainNameLabel.ToLower() ` -AllocationMethod $this.AllocationMethod ` -AzureRmContext $p.Context ` @@ -330,8 +334,13 @@ class SecurityGroup: Resource1 { $this.OpenPorts = $OpenPorts } + [string] GetResourceType() { + return "Security Group" + } + [object] GetInfoOrThrow([object] $context) { - return Get-AzureRMSecurityGroup ` + return Get-AzureRmNetworkSecurityGroup ` + -ResourceGroupName $this.ResourceGroup.Name ` -Name $this.Name ` -AzureRmContext $context ` -ErrorAction Stop @@ -342,7 +351,7 @@ class SecurityGroup: Resource1 { "System.Collections.Generic.List[Microsoft.Azure.Commands.Network.Models.PSSecurityRule]" $priority = 1000 foreach ($port in $this.OpenPorts) { - $name = $p.Name + $port + $name = $this.Name + $port $securityRuleConfig = New-AzureRmNetworkSecurityRuleConfig ` -Name $name ` -Protocol "Tcp" ` @@ -360,7 +369,7 @@ class SecurityGroup: Resource1 { return New-AzureRmNetworkSecurityGroup ` -ResourceGroupName $this.GetResourceGroupName($p) ` -Location $p.Location ` - -Name $p.Name ` + -Name $this.Name ` -SecurityRules $rules ` -AzureRmContext $p.Context ` -WarningAction SilentlyContinue ` @@ -378,28 +387,38 @@ class Subnet: AzureObject { $this.SubnetAddressPrefix = $subnetAddressPrefix } + [string] GetResourceType() { + return "Subnet" + } + + [object] GetInfoFromVirtualNetworkInfo([object] $virtualNetworkInfo) { + return $virtualNetworkInfo ` + | Get-AzureRmVirtualNetworkSubnetConfig -Name $this.Name -ErrorAction Stop + } + [object] GetInfoOrThrow([object] $context) { - $virutalNetworkInfo = $this.VirtualNetwork.GetInfo($context) - if (!$virutalNetworkInfo) { - return $null + $virtualNetworkInfo = $this.VirtualNetwork.GetInfo($context) + if ($virtualNetworkInfo) { + return $this.GetInfoFromVirtualNetworkInfo($virtualNetworkInfo) } - return $virutalNetworkInfo ` - | Get-AzureRmVirtualNetworkSubnetConfig -Name $this.Name -ErrorAction Stop + return $null } [object] Create([CreateParams] $p) { $virtualNetworkInfo = $this.VirtualNetwork.GetOrCreate($p) + try { + return $this.GetInfoFromVirtualNetworkInfo($virtualNetworkInfo) + } catch { + } Add-AzureRmVirtualNetworkSubnetConfig ` -VirtualNetwork $virtualNetworkInfo ` - -Name $p.Name ` + -Name $this.Name ` -AddressPrefix $this.SubnetAddressPrefix $virtualNetworkInfo = Set-AzureRmVirtualNetwork ` -VirtualNetwork $virtualNetworkInfo ` -AzureRmContext $p.Context ` -ErrorAction Stop - return Get-AzureRmVirtualNetworkSubnetConfig ` - -VirtualNetwork $virtualNetworkInfo ` - -Name $p.Name + return $this.GetInfoFromVirtualNetworkInfo($virtualNetworkInfo) } } @@ -420,8 +439,13 @@ class NetworkInterface: Resource1 { $this.SecurityGroup = $securityGroup } + [string] GetResourceType() { + return "Network Interface" + } + [object] GetInfoOrThrow([object] $context) { return Get-AzureRMNetworkInterface ` + -ResourceGroupName $this.ResourceGroup.Name ` -Name $this.Name ` -AzureRmContext $context ` -ErrorAction Stop @@ -434,7 +458,7 @@ class NetworkInterface: Resource1 { return New-AzureRmNetworkInterface ` -ResourceGroupName $this.GetResourceGroupName($p) ` -Location $p.Location ` - -Name $p.Name ` + -Name $this.Name ` -PublicIpAddressId $publicIpAddressInfo.Id ` -SubnetId $subnetInfo.Id ` -NetworkSecurityGroupId $securityGroupInfo.Id ` @@ -468,8 +492,13 @@ class VirtualMachine: Resource1 { $this.Size = $size } + [string] GetResourceType() { + return "Virtual Machine" + } + [object] GetInfoOrThrow([object] $context) { - return Get-AzureRMVirtualMachine ` + return Get-AzureRmVM ` + -ResourceGroupName $this.ResourceGroup.Name ` -Name $this.Name ` -AzureRmContext $context ` -ErrorAction Stop @@ -483,8 +512,8 @@ class VirtualMachine: Resource1 { throw "Unknown image: " + $this.ImageName } - $vmConfig = New-AzureRmVMConfig -VMName $p.Name -VMSize $this.Size -ErrorAction Stop - $vmComputerName = $p.Name + $vmConfig = New-AzureRmVMConfig -VMName $this.Name -VMSize $this.Size -ErrorAction Stop + $vmComputerName = $this.Name switch ($vmImage.Type) { "Windows" { $vmConfig = $vmConfig | Set-AzureRmVMOperatingSystem ` @@ -514,13 +543,16 @@ class VirtualMachine: Resource1 { -Id $networkInterfaceInstance.Id ` -ErrorAction Stop - return New-AzureRmVm ` - -ResourceGroupName $this.GetResourceGroupName($p) ` + $rgName = $this.GetResourceGroupName($p) + New-AzureRmVm ` + -ResourceGroupName $rgName ` -Location $p.Location ` -VM $vmConfig ` -AzureRmContext $p.Context ` -WarningAction SilentlyContinue ` -ErrorAction Stop + + return Get-AzureRmVM -ResourceGroupName $rgName -Name $this.Name } } From 4ff5ed71e1d70744c0f2268ff488593d1f5418b2 Mon Sep 17 00:00:00 2001 From: Sergey Shandar Date: Thu, 21 Sep 2017 07:09:03 -0700 Subject: [PATCH 02/29] subnet bug fix --- .../Compute.Experiments/AzureRM.Compute.Experiments.psm1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psm1 b/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psm1 index a57f7c2d4b17..4a74079d3d3d 100644 --- a/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psm1 +++ b/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psm1 @@ -410,7 +410,7 @@ class Subnet: AzureObject { return $this.GetInfoFromVirtualNetworkInfo($virtualNetworkInfo) } catch { } - Add-AzureRmVirtualNetworkSubnetConfig ` + $virtualNetworkInfo = Add-AzureRmVirtualNetworkSubnetConfig ` -VirtualNetwork $virtualNetworkInfo ` -Name $this.Name ` -AddressPrefix $this.SubnetAddressPrefix From a9a144d2d4057ce48bc29d9a99727f993c7b1b23 Mon Sep 17 00:00:00 2001 From: Sergey Shandar Date: Thu, 21 Sep 2017 11:23:05 -0700 Subject: [PATCH 03/29] Output --- .../AzureRM.Compute.Experiments.psm1 | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psm1 b/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psm1 index 4a74079d3d3d..6d527b1a0bf9 100644 --- a/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psm1 +++ b/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psm1 @@ -91,19 +91,18 @@ function New-AzVm { } return Start-Job $script -ArgumentList $arguments } else { - return $vmi.GetOrCreate($createParams) + $vm = $vmi.GetOrCreate($createParams) + return [PSAzureVm]::new($vm) } } } } class PSAzureVm { - [string] $ResourceGroupId; - [string] $Name; + [Microsoft.Azure.Commands.Compute.Models.PSVirtualMachine] $Vm; - PSAzureVm([string] $resourceGroupId, [string] $name) { - $this.ResourceGroupId = $resourceGroupId - $this.Name = $name + PSAzureVm([Microsoft.Azure.Commands.Compute.Models.PSVirtualMachine] $vm) { + $this.Vm = $vm } } From 033e9ab206fa8a0e65c8c095644c2d159707f03b Mon Sep 17 00:00:00 2001 From: Sergey Shandar Date: Thu, 21 Sep 2017 11:29:31 -0700 Subject: [PATCH 04/29] FQDN --- .../AzureRM.Compute.Experiments.psm1 | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psm1 b/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psm1 index 6d527b1a0bf9..1085542c7764 100644 --- a/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psm1 +++ b/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psm1 @@ -92,7 +92,9 @@ function New-AzVm { return Start-Job $script -ArgumentList $arguments } else { $vm = $vmi.GetOrCreate($createParams) - return [PSAzureVm]::new($vm) + return [PSAzureVm]::new( + $vm, + $piai.DomainNameLabel + "." + locationi.Value + ".cloudapp.azure.com") } } } @@ -100,9 +102,11 @@ function New-AzVm { class PSAzureVm { [Microsoft.Azure.Commands.Compute.Models.PSVirtualMachine] $Vm; + [string] $Fqdn; - PSAzureVm([Microsoft.Azure.Commands.Compute.Models.PSVirtualMachine] $vm) { + PSAzureVm([Microsoft.Azure.Commands.Compute.Models.PSVirtualMachine] $vm, [string] $fqdn) { $this.Vm = $vm + $this.Fqdn = $fqdn } } @@ -293,7 +297,7 @@ class PublicIpAddress: Resource1 { [string] $domainNameLabel, [string] $allocationMethod ): base($name, $resourceGroup) { - $this.DomainNameLabel = $domainNameLabel + $this.DomainNameLabel = $domainNameLabel.ToLower() $this.AllocationMethod = $allocationMethod } @@ -314,7 +318,7 @@ class PublicIpAddress: Resource1 { -ResourceGroupName $this.GetResourceGroupName($p) ` -Location $p.Location ` -Name $this.Name ` - -DomainNameLabel $this.DomainNameLabel.ToLower() ` + -DomainNameLabel $this.DomainNameLabel ` -AllocationMethod $this.AllocationMethod ` -AzureRmContext $p.Context ` -WarningAction SilentlyContinue ` From ed365689f6e743be1ab5cacd261edc4a5cd48b6c Mon Sep 17 00:00:00 2001 From: Sergey Shandar Date: Thu, 21 Sep 2017 11:35:45 -0700 Subject: [PATCH 05/29] output --- .../AzureRM.Compute.Experiments.Tests.ps1 | 2 +- .../Compute.Experiments/AzureRM.Compute.Experiments.psm1 | 6 +++++- .../AzureRM.Compute.Experiments.test.ps1 | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/experiments/Compute.Experiments/AzureRM.Compute.Experiments.Tests.ps1 b/experiments/Compute.Experiments/AzureRM.Compute.Experiments.Tests.ps1 index 4c821faadc15..89a24c169237 100644 --- a/experiments/Compute.Experiments/AzureRM.Compute.Experiments.Tests.ps1 +++ b/experiments/Compute.Experiments/AzureRM.Compute.Experiments.Tests.ps1 @@ -37,4 +37,4 @@ $vm # Write-Host "" # clean-up -Remove-AzureRmResourceGroup -Name $vm.ResourceGroupName \ No newline at end of file +Remove-AzureRmResourceGroup -Name $vm.Vm.ResourceGroupName \ No newline at end of file diff --git a/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psm1 b/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psm1 index 1085542c7764..8aed341a96fa 100644 --- a/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psm1 +++ b/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psm1 @@ -94,7 +94,7 @@ function New-AzVm { $vm = $vmi.GetOrCreate($createParams) return [PSAzureVm]::new( $vm, - $piai.DomainNameLabel + "." + locationi.Value + ".cloudapp.azure.com") + $piai.DomainNameLabel + "." + $locationi.Value + ".cloudapp.azure.com") } } } @@ -102,10 +102,14 @@ function New-AzVm { class PSAzureVm { [Microsoft.Azure.Commands.Compute.Models.PSVirtualMachine] $Vm; + [string] $Name; + [string] $ResourceGroupName; [string] $Fqdn; PSAzureVm([Microsoft.Azure.Commands.Compute.Models.PSVirtualMachine] $vm, [string] $fqdn) { $this.Vm = $vm + $this.Name = $vm.Name + $this.ResourceGroupName = $vm.ResourceGroupName $this.Fqdn = $fqdn } } diff --git a/experiments/Compute.Experiments/AzureRM.Compute.Experiments.test.ps1 b/experiments/Compute.Experiments/AzureRM.Compute.Experiments.test.ps1 index 8763d3de5c11..fc1ad746fcf7 100644 --- a/experiments/Compute.Experiments/AzureRM.Compute.Experiments.test.ps1 +++ b/experiments/Compute.Experiments/AzureRM.Compute.Experiments.test.ps1 @@ -6,4 +6,4 @@ $vm = New-AzVm -Name myVm1234 -Credential $pscredentials $vm #Cleanup -Remove-AzureRmResourceGroup -ResourceId $vm.ResourceGroupId -Force \ No newline at end of file +Remove-AzureRmResourceGroup -ResourceName $vm.Vm.ResourceGroupName -Force \ No newline at end of file From 853caa336cd3bdf676f6beec15e327931731f6ac Mon Sep 17 00:00:00 2001 From: Sergey Shandar Date: Thu, 21 Sep 2017 12:07:47 -0700 Subject: [PATCH 06/29] progress using Write-Host --- .../Compute.Experiments/AzureRM.Compute.Experiments.psm1 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psm1 b/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psm1 index 8aed341a96fa..58633f28fa63 100644 --- a/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psm1 +++ b/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psm1 @@ -202,6 +202,9 @@ class AzureObject { if ($i) { return $i } + foreach ($child in $this.Children) { + $child.GetOrCreate($p) | Out-Null + } Write-Host ("creating " + $this.GetResourceType() + ": " + $this.Name) $this.Info = $this.Create($p) return $this.Info From 3c128df36e9f83bc5342e532d23dbb09e52a1a5d Mon Sep 17 00:00:00 2001 From: Sergey Shandar Date: Thu, 21 Sep 2017 15:08:40 -0700 Subject: [PATCH 07/29] progress --- .../AzureRM.Compute.Experiments.Tests.ps1 | 2 +- .../AzureRM.Compute.Experiments.psm1 | 57 +++++++++++++------ 2 files changed, 41 insertions(+), 18 deletions(-) diff --git a/experiments/Compute.Experiments/AzureRM.Compute.Experiments.Tests.ps1 b/experiments/Compute.Experiments/AzureRM.Compute.Experiments.Tests.ps1 index 89a24c169237..2339799965f5 100644 --- a/experiments/Compute.Experiments/AzureRM.Compute.Experiments.Tests.ps1 +++ b/experiments/Compute.Experiments/AzureRM.Compute.Experiments.Tests.ps1 @@ -25,7 +25,7 @@ $vmCredential = New-Object System.Management.Automation.PSCredential ($vmCompute # $vm = New-AzVm # $vm = New-AzVm -Credential $vmCredential -$vm = New-AzVm -Name MyVMA1 -Credential $vmCredential -ResourceGroupName Crocodile +$vm = New-AzVm -Name MyVMA8 -Credential $vmCredential -ResourceGroupName Something8 # $vm = New-AzVm -Name MyVMA $vm diff --git a/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psm1 b/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psm1 index 58633f28fa63..ebbfac554305 100644 --- a/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psm1 +++ b/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psm1 @@ -91,7 +91,8 @@ function New-AzVm { } return Start-Job $script -ArgumentList $arguments } else { - $vm = $vmi.GetOrCreate($createParams) + $vm = $vmi.GetOrCreate($createParams, [ProgressRange]::new(0.0, 1.0)) + Write-Progress "Done." -PercentComplete 100 -Status "100% Complete:" return [PSAzureVm]::new( $vm, $piai.DomainNameLabel + "." + $locationi.Value + ".cloudapp.azure.com") @@ -137,10 +138,21 @@ class CreateParams { } } +class ProgressRange { + [double] $Start; + [double] $Size; + + ProgressRange([double] $start, [double] $size) { + $this.Start = $start; + $this.Size = $size; + } +} + class AzureObject { [string] $Name; [AzureObject[]] $Children; [int] $Priority; + [int] $Size; [bool] $GetInfoCalled = $false; [object] $info = $null; @@ -153,8 +165,10 @@ class AzureObject { if ($this.Priority -lt $child.Priority) { $this.Priority = $child.Priority } + $this.Size += $child.Size } $this.Priority++ + $this.Size++ } [string] GetResourceType() { @@ -197,15 +211,24 @@ class AzureObject { } } - [object] GetOrCreate([CreateParams] $p) { + [object] GetOrCreate([CreateParams] $p, [ProgressRange] $progressRange) { $i = $this.GetInfo($p.Context) if ($i) { return $i } + $size = $this.Children.Length + 1.0; + $pSizeI = $progressRange.Size / $size + $i = 0.0 foreach ($child in $this.Children) { - $child.GetOrCreate($p) | Out-Null + $start = $progressRange.Start + $pSizeI * $i + $pc = [ProgressRange]::new($start, $pSizeI) + $child.GetOrCreate($p, $pc) | Out-Null + $i++ } - Write-Host ("creating " + $this.GetResourceType() + ": " + $this.Name) + $message = "Creating '" + $this.Name + "' " + $this.GetResourceType() + "." + $percent = [convert]::ToInt32(($progressRange.Start + $pSizeI * $i) * 100) + Write-Progress $message -PercentComplete $percent -Status "$percent% Complete:" + Write-Verbose $message $this.Info = $this.Create($p) return $this.Info } @@ -243,7 +266,7 @@ class Resource1: AzureObject { [string] $name, [ResourceGroup] $resourceGroup, [AzureObject[]] $children - ): base($name, @($children)) { + ): base($name, $children) { $this.ResourceGroup = $resourceGroup } @@ -254,8 +277,8 @@ class Resource1: AzureObject { $this.ResourceGroup = $resourceGroup } - [string] GetResourceGroupName([CreateParams] $p) { - return $this.ResourceGroup.GetOrCreate($p).ResourceGroupName; + [string] GetResourceGroupName() { + return $this.ResourceGroup.Info.ResourceGroupName; } } @@ -284,7 +307,7 @@ class VirtualNetwork: Resource1 { [object] Create([CreateParams] $p) { return New-AzureRmVirtualNetwork ` - -ResourceGroupName $this.GetResourceGroupName($p) ` + -ResourceGroupName $this.GetResourceGroupName() ` -Location $p.Location ` -Name $this.Name ` -AddressPrefix $this.AddressPrefix ` @@ -322,7 +345,7 @@ class PublicIpAddress: Resource1 { [object] Create([CreateParams] $p) { return New-AzureRmPublicIpAddress ` - -ResourceGroupName $this.GetResourceGroupName($p) ` + -ResourceGroupName $this.GetResourceGroupName() ` -Location $p.Location ` -Name $this.Name ` -DomainNameLabel $this.DomainNameLabel ` @@ -377,7 +400,7 @@ class SecurityGroup: Resource1 { ++$priority } return New-AzureRmNetworkSecurityGroup ` - -ResourceGroupName $this.GetResourceGroupName($p) ` + -ResourceGroupName $this.GetResourceGroupName() ` -Location $p.Location ` -Name $this.Name ` -SecurityRules $rules ` @@ -415,7 +438,7 @@ class Subnet: AzureObject { } [object] Create([CreateParams] $p) { - $virtualNetworkInfo = $this.VirtualNetwork.GetOrCreate($p) + $virtualNetworkInfo = $this.VirtualNetwork.Info try { return $this.GetInfoFromVirtualNetworkInfo($virtualNetworkInfo) } catch { @@ -462,11 +485,11 @@ class NetworkInterface: Resource1 { } [object] Create([CreateParams] $p) { - $publicIpAddressInfo = $this.PublicIpAddress.GetOrCreate($p) - $subnetInfo = $this.Subnet.GetOrCreate($p) - $securityGroupInfo = $this.SecurityGroup.GetOrCreate($p) + $publicIpAddressInfo = $this.PublicIpAddress.Info + $subnetInfo = $this.Subnet.Info + $securityGroupInfo = $this.SecurityGroup.Info return New-AzureRmNetworkInterface ` - -ResourceGroupName $this.GetResourceGroupName($p) ` + -ResourceGroupName $this.GetResourceGroupName() ` -Location $p.Location ` -Name $this.Name ` -PublicIpAddressId $publicIpAddressInfo.Id ` @@ -515,7 +538,7 @@ class VirtualMachine: Resource1 { } [object] Create([CreateParams] $p) { - $networkInterfaceInstance = $this.NetworkInterface.GetOrCreate($p) + $networkInterfaceInstance = $this.NetworkInterface.Info $vmImage = $this.Images | Where-Object { $_.Name -eq $this.ImageName } | Select-Object -First 1 if (-not $vmImage) { @@ -553,7 +576,7 @@ class VirtualMachine: Resource1 { -Id $networkInterfaceInstance.Id ` -ErrorAction Stop - $rgName = $this.GetResourceGroupName($p) + $rgName = $this.GetResourceGroupName() New-AzureRmVm ` -ResourceGroupName $rgName ` -Location $p.Location ` From cb9649e1e2fd262b18a9ac60fa008ea4f691086b Mon Sep 17 00:00:00 2001 From: Sergey Shandar Date: Thu, 21 Sep 2017 15:23:10 -0700 Subject: [PATCH 08/29] progress --- .../AzureRM.Compute.Experiments.Tests.ps1 | 2 +- .../AzureRM.Compute.Experiments.psm1 | 19 +++++++++---------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/experiments/Compute.Experiments/AzureRM.Compute.Experiments.Tests.ps1 b/experiments/Compute.Experiments/AzureRM.Compute.Experiments.Tests.ps1 index 2339799965f5..ac7d6c26159b 100644 --- a/experiments/Compute.Experiments/AzureRM.Compute.Experiments.Tests.ps1 +++ b/experiments/Compute.Experiments/AzureRM.Compute.Experiments.Tests.ps1 @@ -25,7 +25,7 @@ $vmCredential = New-Object System.Management.Automation.PSCredential ($vmCompute # $vm = New-AzVm # $vm = New-AzVm -Credential $vmCredential -$vm = New-AzVm -Name MyVMA8 -Credential $vmCredential -ResourceGroupName Something8 +$vm = New-AzVm -Name MyVMA0 -Credential $vmCredential -ResourceGroupName Something0 # $vm = New-AzVm -Name MyVMA $vm diff --git a/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psm1 b/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psm1 index ebbfac554305..512f77beb3d8 100644 --- a/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psm1 +++ b/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psm1 @@ -152,7 +152,7 @@ class AzureObject { [string] $Name; [AzureObject[]] $Children; [int] $Priority; - [int] $Size; + [int] $ObjectSize; [bool] $GetInfoCalled = $false; [object] $info = $null; @@ -161,14 +161,14 @@ class AzureObject { $this.Name = $name $this.Children = $children $this.Priority = 0 + $this.ObjectSize = 1 foreach ($child in $this.Children) { if ($this.Priority -lt $child.Priority) { $this.Priority = $child.Priority } - $this.Size += $child.Size + $this.ObjectSize += $child.ObjectSize } $this.Priority++ - $this.Size++ } [string] GetResourceType() { @@ -216,17 +216,16 @@ class AzureObject { if ($i) { return $i } - $size = $this.Children.Length + 1.0; - $pSizeI = $progressRange.Size / $size - $i = 0.0 + $pSize = $progressRange.Size / $this.ObjectSize + $offset = $progressRange.Start foreach ($child in $this.Children) { - $start = $progressRange.Start + $pSizeI * $i - $pc = [ProgressRange]::new($start, $pSizeI) + $pChildSize = $pSize * $child.ObjectSize + $pc = [ProgressRange]::new($offset, $pChildSize) $child.GetOrCreate($p, $pc) | Out-Null - $i++ + $offset += $pChildSize } $message = "Creating '" + $this.Name + "' " + $this.GetResourceType() + "." - $percent = [convert]::ToInt32(($progressRange.Start + $pSizeI * $i) * 100) + $percent = [convert]::ToInt32($offset * 100) Write-Progress $message -PercentComplete $percent -Status "$percent% Complete:" Write-Verbose $message $this.Info = $this.Create($p) From d1584d0abcacee21a50c8c5500fbf5da44b37911 Mon Sep 17 00:00:00 2001 From: Sergey Shandar Date: Thu, 21 Sep 2017 15:26:46 -0700 Subject: [PATCH 09/29] version update --- .../Compute.Experiments/AzureRM.Compute.Experiments.psd1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psd1 b/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psd1 index 10881a43238b..c740e54fcef2 100644 --- a/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psd1 +++ b/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psd1 @@ -12,7 +12,7 @@ RootModule = ".\AzureRM.Compute.Experiments.psm1" # Version number of this module. -ModuleVersion = '1.0.19' +ModuleVersion = '1.0.20' # Supported PSEditions # CompatiblePSEditions = @() From 54e3b4698a26dce3359aa07632209cec4487c2dd Mon Sep 17 00:00:00 2001 From: Sergey Shandar Date: Thu, 21 Sep 2017 15:27:29 -0700 Subject: [PATCH 10/29] 1.0.21 --- .../Compute.Experiments/AzureRM.Compute.Experiments.psd1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psd1 b/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psd1 index c740e54fcef2..31f05290dae4 100644 --- a/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psd1 +++ b/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psd1 @@ -12,7 +12,7 @@ RootModule = ".\AzureRM.Compute.Experiments.psm1" # Version number of this module. -ModuleVersion = '1.0.20' +ModuleVersion = '1.0.21' # Supported PSEditions # CompatiblePSEditions = @() From 0baf9152beacdb2146cc82f2966503cbed4236a6 Mon Sep 17 00:00:00 2001 From: Sergey Shandar Date: Thu, 21 Sep 2017 16:49:35 -0700 Subject: [PATCH 11/29] Progress. --- .../Compute.Experiments/AzureRM.Compute.Experiments.Tests.ps1 | 2 +- .../Compute.Experiments/AzureRM.Compute.Experiments.psm1 | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/experiments/Compute.Experiments/AzureRM.Compute.Experiments.Tests.ps1 b/experiments/Compute.Experiments/AzureRM.Compute.Experiments.Tests.ps1 index ac7d6c26159b..2475d7c0bfd4 100644 --- a/experiments/Compute.Experiments/AzureRM.Compute.Experiments.Tests.ps1 +++ b/experiments/Compute.Experiments/AzureRM.Compute.Experiments.Tests.ps1 @@ -25,7 +25,7 @@ $vmCredential = New-Object System.Management.Automation.PSCredential ($vmCompute # $vm = New-AzVm # $vm = New-AzVm -Credential $vmCredential -$vm = New-AzVm -Name MyVMA0 -Credential $vmCredential -ResourceGroupName Something0 +$vm = New-AzVm -Name MyVMA1 -Credential $vmCredential -ResourceGroupName Something1 # $vm = New-AzVm -Name MyVMA $vm diff --git a/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psm1 b/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psm1 index 512f77beb3d8..1b4e4037d1ee 100644 --- a/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psm1 +++ b/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psm1 @@ -17,7 +17,7 @@ function New-AzVm { [Parameter()][string] $SubnetAddressPrefix = "192.168.1.0/24", [Parameter()][string] $PublicIpAddressName = $Name, - [Parameter()][string] $DomainNameLabel = $Name, + [Parameter()][string] $DomainNameLabel = $ResourceGroupName + $Name, [Parameter()][string] $AllocationMethod = "Static", [Parameter()][string] $SecurityGroupName = $Name, @@ -92,7 +92,7 @@ function New-AzVm { return Start-Job $script -ArgumentList $arguments } else { $vm = $vmi.GetOrCreate($createParams, [ProgressRange]::new(0.0, 1.0)) - Write-Progress "Done." -PercentComplete 100 -Status "100% Complete:" + Write-Progress "Done." -Completed return [PSAzureVm]::new( $vm, $piai.DomainNameLabel + "." + $locationi.Value + ".cloudapp.azure.com") From 33f21d544003217e36dd0b56050cbd02ceb34972 Mon Sep 17 00:00:00 2001 From: Sergey Shandar Date: Fri, 22 Sep 2017 10:32:34 -0700 Subject: [PATCH 12/29] 1.0.22 --- .../Compute.Experiments/AzureRM.Compute.Experiments.psd1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psd1 b/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psd1 index 31f05290dae4..b2508e9b0ffa 100644 --- a/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psd1 +++ b/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psd1 @@ -12,7 +12,7 @@ RootModule = ".\AzureRM.Compute.Experiments.psm1" # Version number of this module. -ModuleVersion = '1.0.21' +ModuleVersion = '1.0.22' # Supported PSEditions # CompatiblePSEditions = @() From 25704b9aa5435fcaffd3eb51100741161ccba3c6 Mon Sep 17 00:00:00 2001 From: Sergey Shandar Date: Fri, 22 Sep 2017 10:57:44 -0700 Subject: [PATCH 13/29] 1.0.23 --- .../Compute.Experiments/AzureRM.Compute.Experiments.psd1 | 2 +- experiments/Compute.Experiments/publish-dev.ps1 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psd1 b/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psd1 index b2508e9b0ffa..589bd84b6e98 100644 --- a/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psd1 +++ b/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psd1 @@ -12,7 +12,7 @@ RootModule = ".\AzureRM.Compute.Experiments.psm1" # Version number of this module. -ModuleVersion = '1.0.22' +ModuleVersion = '1.0.23' # Supported PSEditions # CompatiblePSEditions = @() diff --git a/experiments/Compute.Experiments/publish-dev.ps1 b/experiments/Compute.Experiments/publish-dev.ps1 index 06a866960e94..be188be87ef2 100644 --- a/experiments/Compute.Experiments/publish-dev.ps1 +++ b/experiments/Compute.Experiments/publish-dev.ps1 @@ -5,7 +5,7 @@ Remove-Item $out -Recurse mkdir $out Copy-Item .\AzureRM.Compute.Experiments.psd1 $out Copy-Item .\AzureRM.Compute.Experiments.psm1 $out -New-ExternalHelp -Path .\docs\ -OutputPath $out +New-ExternalHelp -Path .\help\ -OutputPath $out # foreach ($d in $dep) { # Install-Module $d -Repository $repository # } From ec4ce1efe22b144d705c6a317c7cc807bf95d7d3 Mon Sep 17 00:00:00 2001 From: Sergey Shandar Date: Mon, 25 Sep 2017 14:25:39 -0700 Subject: [PATCH 14/29] ResourceGroup has to be a direct dependency --- .../Compute.Experiments/AzureRM.Compute.Experiments.psm1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psm1 b/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psm1 index 7efc21386c37..c986aea64a0e 100644 --- a/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psm1 +++ b/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psm1 @@ -267,7 +267,7 @@ class Resource1: AzureObject { [string] $name, [ResourceGroup] $resourceGroup, [AzureObject[]] $children - ): base($name, $children) { + ): base($name, @($resourceGroup) + $children) { $this.ResourceGroup = $resourceGroup } @@ -586,7 +586,7 @@ class VirtualMachine: Resource1 { -WarningAction SilentlyContinue ` -ErrorAction Stop - return Get-AzureRmVM -ResourceGroupName $rgName -Name $this.Name + return $this.GetInfoOrThrow($p.Context) } } From 1a55ed394250ba2a0e28c2f848b55da8577e813f Mon Sep 17 00:00:00 2001 From: Sergey Shandar Date: Mon, 25 Sep 2017 14:39:12 -0700 Subject: [PATCH 15/29] clean output --- .../AzureRM.Compute.Experiments.psm1 | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psm1 b/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psm1 index c986aea64a0e..68621820a8fd 100644 --- a/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psm1 +++ b/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psm1 @@ -579,12 +579,13 @@ class VirtualMachine: Resource1 { $rgName = $this.GetResourceGroupName() New-AzureRmVm ` - -ResourceGroupName $rgName ` - -Location $p.Location ` - -VM $vmConfig ` - -AzureRmContext $p.Context ` - -WarningAction SilentlyContinue ` - -ErrorAction Stop + -ResourceGroupName $rgName ` + -Location $p.Location ` + -VM $vmConfig ` + -AzureRmContext $p.Context ` + -WarningAction SilentlyContinue ` + -ErrorAction Stop ` + | Out-Null return $this.GetInfoOrThrow($p.Context) } From 967e69dfef282540d3fa68c448b835c8fcb41658 Mon Sep 17 00:00:00 2001 From: Sergey Shandar Date: Mon, 25 Sep 2017 18:34:03 -0700 Subject: [PATCH 16/29] 1.0.26 --- .../AzureRM.Compute.Experiments.psd1 | 2 +- .../AzureRM.Compute.Experiments.psm1 | 29 ++++++++++++++++++- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psd1 b/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psd1 index 589bd84b6e98..97b5571009c8 100644 --- a/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psd1 +++ b/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psd1 @@ -12,7 +12,7 @@ RootModule = ".\AzureRM.Compute.Experiments.psm1" # Version number of this module. -ModuleVersion = '1.0.23' +ModuleVersion = '1.0.26' # Supported PSEditions # CompatiblePSEditions = @() diff --git a/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psm1 b/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psm1 index 68621820a8fd..ef62cfd42d4b 100644 --- a/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psm1 +++ b/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psm1 @@ -18,7 +18,7 @@ function New-AzVm { [Parameter()][string] $PublicIpAddressName = $Name, [Parameter()][string] $DomainNameLabel = $ResourceGroupName + $Name, - [Parameter()][string] $AllocationMethod = "Static", + [Parameter()][ValidateSet("Static", "Dynamic")][string] $AllocationMethod = "Static", [Parameter()][string] $SecurityGroupName = $Name, [Parameter()][int[]] $OpenPorts = @(3389, 5985), @@ -689,3 +689,30 @@ $images = $staticImages.psobject.Properties | ForEach-Object { } Export-ModuleMember -Function New-AzVm + +$locations = $null + +function Get-WordToCompleteList { + param($List, $WordToComplete) + + return $List ` + | Where-Object { $_ -like "$WordToComplete*" } ` + | ForEach-Object { [System.Management.Automation.CompletionResult]::new($_) } +} + +Register-ArgumentCompleter -CommandName New-AzVm -ParameterName Location -ScriptBlock { + param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter) + + if (!$global:locations) { + $global:locations = Get-AzureRmLocation ` + | ForEach-Object { $_.Location } + } + return Get-WordToCompleteList -List $global:locations -WordToComplete $wordToComplete +} + +Register-ArgumentCompleter -CommandName New-AzVm -ParameterName ImageName -ScriptBlock { + param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter) + + $list = $images | ForEach-Object { $_.Name } + return Get-WordToCompleteList -List $list -WordToComplete $wordToComplete +} From ace90c3d0cb5e9591e59675f3deebb9238b85b98 Mon Sep 17 00:00:00 2001 From: Sergey Shandar Date: Wed, 4 Oct 2017 15:10:29 -0700 Subject: [PATCH 17/29] ports --- .../AzureRM.Compute.Experiments.Tests.ps1 | 3 +- .../AzureRM.Compute.Experiments.psm1 | 46 ++++++++++++------- 2 files changed, 31 insertions(+), 18 deletions(-) diff --git a/experiments/Compute.Experiments/AzureRM.Compute.Experiments.Tests.ps1 b/experiments/Compute.Experiments/AzureRM.Compute.Experiments.Tests.ps1 index 2475d7c0bfd4..d75a5ce6c60a 100644 --- a/experiments/Compute.Experiments/AzureRM.Compute.Experiments.Tests.ps1 +++ b/experiments/Compute.Experiments/AzureRM.Compute.Experiments.Tests.ps1 @@ -25,7 +25,8 @@ $vmCredential = New-Object System.Management.Automation.PSCredential ($vmCompute # $vm = New-AzVm # $vm = New-AzVm -Credential $vmCredential -$vm = New-AzVm -Name MyVMA1 -Credential $vmCredential -ResourceGroupName Something1 +$vm = New-AzVm -Name MyVMA1 -Credential $vmCredential -ResourceGroupName Something1 -Verbose +$linux = New-AzVm -Name MyVMA2 -Credential $vmCredential -ResourceGroupName Something1 -ImageName UbuntuLTS -Verbose # $vm = New-AzVm -Name MyVMA $vm diff --git a/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psm1 b/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psm1 index ef62cfd42d4b..1cfb8a60e440 100644 --- a/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psm1 +++ b/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psm1 @@ -17,11 +17,11 @@ function New-AzVm { [Parameter()][string] $SubnetAddressPrefix = "192.168.1.0/24", [Parameter()][string] $PublicIpAddressName = $Name, - [Parameter()][string] $DomainNameLabel = $ResourceGroupName + $Name, + [Parameter()][string] $DomainNameLabel = $Name + $ResourceGroupName, [Parameter()][ValidateSet("Static", "Dynamic")][string] $AllocationMethod = "Static", [Parameter()][string] $SecurityGroupName = $Name, - [Parameter()][int[]] $OpenPorts = @(3389, 5985), + [Parameter()][int[]] $OpenPorts, [Parameter()][string] $ImageName = "Win2016Datacenter", [Parameter()][string] $Size = "Standard_DS1_v2", @@ -38,6 +38,19 @@ function New-AzVm { Get-AzureRmContext } + $image = Get-Image($ImageName) + + if (!$OpenPorts) { + switch ($image.Type) { + "Windows" { + $OpenPorts = @(3389, 5985) + } + "Linux" { + $OpenPorts = @(22) + } + } + } + $rgi = [ResourceGroup]::new($ResourceGroupName) $vni = [VirtualNetwork]::new($VirtualNetworkName, $rgi, $AddressPrefix) @@ -59,8 +72,7 @@ function New-AzVm { $rgi, $nii, $Credential, - $ImageName, - $images, + $image, $Size) # infer a location @@ -505,8 +517,7 @@ class NetworkInterface: Resource1 { class VirtualMachine: Resource1 { [NetworkInterface] $NetworkInterface; [pscredential] $Credential; - [string] $ImageName; - [object] $Images; + [object] $Image; [string] $Size; VirtualMachine( @@ -514,15 +525,13 @@ class VirtualMachine: Resource1 { [ResourceGroup] $resourceGroup, [NetworkInterface] $networkInterface, [PSCredential] $credential, - [string] $imageName, - [object] $images, + [object] $image, [string] $size): base($name, $resourceGroup, @($networkInterface)) { $this.Credential = $credential - $this.ImageName = $imageName $this.NetworkInterface = $networkInterface - $this.Images = $images + $this.Image = $image $this.Size = $size } @@ -541,14 +550,9 @@ class VirtualMachine: Resource1 { [object] Create([CreateParams] $p) { $networkInterfaceInstance = $this.NetworkInterface.Info - $vmImage = $this.Images | Where-Object { $_.Name -eq $this.ImageName } | Select-Object -First 1 - if (-not $vmImage) { - throw "Unknown image: " + $this.ImageName - } - $vmConfig = New-AzureRmVMConfig -VMName $this.Name -VMSize $this.Size -ErrorAction Stop $vmComputerName = $this.Name - switch ($vmImage.Type) { + switch ($this.Image.Type) { "Windows" { $vmConfig = $vmConfig | Set-AzureRmVMOperatingSystem ` -Windows ` @@ -565,7 +569,7 @@ class VirtualMachine: Resource1 { } } - $vmImageImage = $vmImage.Image + $vmImageImage = $this.Image.Image $vmConfig = $vmConfig ` | Set-AzureRmVMSourceImage ` -PublisherName $vmImageImage.publisher ` @@ -688,6 +692,14 @@ $images = $staticImages.psobject.Properties | ForEach-Object { } } +function Get-Image([string] $imageName) { + $vmImage = $images | Where-Object { $_.Name -eq $imageName } | Select-Object -First 1 + if (-not $vmImage) { + throw "Unknown image: " + $this.ImageName + } + return $vmImage +} + Export-ModuleMember -Function New-AzVm $locations = $null From fdb48f6739f5b6a2ad1442c0ee194cdad72679d6 Mon Sep 17 00:00:00 2001 From: Sergey Shandar Date: Wed, 4 Oct 2017 16:22:24 -0700 Subject: [PATCH 18/29] messages --- .../AzureRM.Compute.Experiments.psm1 | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psm1 b/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psm1 index 1cfb8a60e440..e6113ca8346a 100644 --- a/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psm1 +++ b/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psm1 @@ -107,9 +107,16 @@ function New-AzVm { } else { $vm = $vmi.GetOrCreate($createParams, [ProgressRange]::new(0.0, 1.0)) Write-Progress "Done." -Completed - return [PSAzureVm]::new( - $vm, - $piai.DomainNameLabel + "." + $locationi.Value + ".cloudapp.azure.com") + $fqdn = $piai.DomainNameLabel + "." + $locationi.Value + ".cloudapp.azure.com" + switch ($image.Type) { + "Windows" { + Write-Verbose ("To connect to the VM, use '$fqdn' as a computer name in the 'Remote Desktop Connection' application." ) + } + "Linux" { + Write-Verbose ("To connect to the VM, type 'ssh $($Credential.UserName)@$fqdn' in a Bash console." ) + } + } + return [PSAzureVm]::new($vm, $fqdn) } } } @@ -202,6 +209,9 @@ class AzureObject { $this.GetInfoCalled = $true try { $this.Info = $this.GetInfoOrThrow($context) + if ($this.Info) { + Write-Verbose ("Found '" + $this.Name + "' " + $this.GetResourceType() + ".") + } } catch { # ignore all errors } From 4a460c42ef9487407f3150a9eb08c342babacceb Mon Sep 17 00:00:00 2001 From: Sergey Shandar Date: Wed, 4 Oct 2017 16:40:56 -0700 Subject: [PATCH 19/29] minor --- .../Compute.Experiments/AzureRM.Compute.Experiments.psm1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psm1 b/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psm1 index e6113ca8346a..8eb7fce2b364 100644 --- a/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psm1 +++ b/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psm1 @@ -110,10 +110,10 @@ function New-AzVm { $fqdn = $piai.DomainNameLabel + "." + $locationi.Value + ".cloudapp.azure.com" switch ($image.Type) { "Windows" { - Write-Verbose ("To connect to the VM, use '$fqdn' as a computer name in the 'Remote Desktop Connection' application." ) + Write-Verbose ("Use 'mstsc /v:$fqdn' to connect to the VM." ) } "Linux" { - Write-Verbose ("To connect to the VM, type 'ssh $($Credential.UserName)@$fqdn' in a Bash console." ) + Write-Verbose ("Use 'ssh $($Credential.UserName)@$fqdn' to connect to the VM." ) } } return [PSAzureVm]::new($vm, $fqdn) From a4c6057a1f88f8fb38c9cfa1200598eb7909c284 Mon Sep 17 00:00:00 2001 From: Sergey Shandar Date: Wed, 4 Oct 2017 17:16:53 -0700 Subject: [PATCH 20/29] 1.0.27 --- .../Compute.Experiments/AzureRM.Compute.Experiments.psd1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psd1 b/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psd1 index 97b5571009c8..d80663219640 100644 --- a/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psd1 +++ b/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psd1 @@ -12,7 +12,7 @@ RootModule = ".\AzureRM.Compute.Experiments.psm1" # Version number of this module. -ModuleVersion = '1.0.26' +ModuleVersion = '1.0.27' # Supported PSEditions # CompatiblePSEditions = @() From c0bc96b1d53ed75b9ef5c2f0feabb3b0ee752c70 Mon Sep 17 00:00:00 2001 From: Sergey Shandar Date: Thu, 5 Oct 2017 16:47:25 -0700 Subject: [PATCH 21/29] First Pester Tests. --- .../AzureRM.Compute.Experiments.Tests.ps1 | 37 ++++++++----------- .../AzureRM.Compute.Experiments.psm1 | 4 +- 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/experiments/Compute.Experiments/AzureRM.Compute.Experiments.Tests.ps1 b/experiments/Compute.Experiments/AzureRM.Compute.Experiments.Tests.ps1 index d75a5ce6c60a..28fc97cbc43d 100644 --- a/experiments/Compute.Experiments/AzureRM.Compute.Experiments.Tests.ps1 +++ b/experiments/Compute.Experiments/AzureRM.Compute.Experiments.Tests.ps1 @@ -16,26 +16,21 @@ $vmComputerUser = $credentials.vmUser; $password = ConvertTo-SecureString $vmComputerPassword -AsPlainText -Force; $vmCredential = New-Object System.Management.Automation.PSCredential ($vmComputerUser, $password); -# New-AzVm -Name MyVM -Credential $vmCredential -WhatIf - -# $job = New-AzVm -Name MyVMA -Credential $vmCredential -AsJob -# Receive-Job $job - -# exit - -# $vm = New-AzVm -# $vm = New-AzVm -Credential $vmCredential -$vm = New-AzVm -Name MyVMA1 -Credential $vmCredential -ResourceGroupName Something1 -Verbose -$linux = New-AzVm -Name MyVMA2 -Credential $vmCredential -ResourceGroupName Something1 -ImageName UbuntuLTS -Verbose -# $vm = New-AzVm -Name MyVMA - -$vm - -# Write-Host "" -# $job = New-AzVm -Name MyVMA3 -Credential $vmCredential -AsJob -# $vm = Receive-Job $job -Wait -# $vm -# Write-Host "" +Describe 'New-AzVm' { + It 'WhatIf' { + New-AzVm -Name MyVM -Credential $vmCredential -WhatIf + } + It 'Create Windows VM' { + New-AzVm -Name MyVMA1 -Credential $vmCredential -ResourceGroupName Something1 -Verbose + } + It 'Create Linux VM' { + New-AzVm -Name MyVMA2 -Credential $vmCredential -ResourceGroupName Something1 -ImageName UbuntuLTS -Verbose + } + It 'Create Linux VM AsJob' { + $job = New-AzVm -Name MyVMA3 -Credential $vmCredential -AsJob -ImageName UbuntuLTS -Verbose + Receive-Job $job -Wait + } +} # clean-up -Remove-AzureRmResourceGroup -Name $vm.Vm.ResourceGroupName \ No newline at end of file +# Remove-AzureRmResourceGroup -Name Something1 \ No newline at end of file diff --git a/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psm1 b/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psm1 index 8eb7fce2b364..7189be97b038 100644 --- a/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psm1 +++ b/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psm1 @@ -38,8 +38,10 @@ function New-AzVm { Get-AzureRmContext } + # find image $image = Get-Image($ImageName) + # ports if (!$OpenPorts) { switch ($image.Type) { "Windows" { @@ -58,7 +60,7 @@ function New-AzVm { $piai = [PublicIpAddress]::new($PublicIpAddressName, $rgi, $DomainNameLabel, $AllocationMethod) $sgi = [SecurityGroup]::new($SecurityGroupName, $rgi, $OpenPorts) - # we don't allow to reuse NetworkInterface so $name is $null. + # we don't allow to reuse NetworkInterface $nii = [NetworkInterface]::new( $Name, $rgi, From 77c0a57704b43b062d206f90b19d9226bffb96aa Mon Sep 17 00:00:00 2001 From: Sergey Shandar Date: Fri, 6 Oct 2017 10:41:14 -0700 Subject: [PATCH 22/29] first validation --- .../AzureRM.Compute.Experiments.Tests.ps1 | 16 +++++++++------- .../AzureRM.Compute.Experiments.psd1 | 6 +++--- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/experiments/Compute.Experiments/AzureRM.Compute.Experiments.Tests.ps1 b/experiments/Compute.Experiments/AzureRM.Compute.Experiments.Tests.ps1 index 28fc97cbc43d..26350130d264 100644 --- a/experiments/Compute.Experiments/AzureRM.Compute.Experiments.Tests.ps1 +++ b/experiments/Compute.Experiments/AzureRM.Compute.Experiments.Tests.ps1 @@ -18,19 +18,21 @@ $vmCredential = New-Object System.Management.Automation.PSCredential ($vmCompute Describe 'New-AzVm' { It 'WhatIf' { - New-AzVm -Name MyVM -Credential $vmCredential -WhatIf + $result = New-AzVm -Name MyVM -Credential $vmCredential -WhatIf } It 'Create Windows VM' { - New-AzVm -Name MyVMA1 -Credential $vmCredential -ResourceGroupName Something1 -Verbose + Remove-AzureRmResourceGroup -Name Something1 -Force + $result = New-AzVm -Name MyVMA1 -Credential $vmCredential -ResourceGroupName Something1 -Verbose + $result.Name | Should -Be MyVMA1 } It 'Create Linux VM' { - New-AzVm -Name MyVMA2 -Credential $vmCredential -ResourceGroupName Something1 -ImageName UbuntuLTS -Verbose + $result = New-AzVm -Name MyVMA2 -Credential $vmCredential -ResourceGroupName Something1 -ImageName UbuntuLTS -Verbose + $result.Name | Should -Be MyVMA2 } It 'Create Linux VM AsJob' { + Remove-AzureRmResourceGroup -Name MyVMA3 -Force $job = New-AzVm -Name MyVMA3 -Credential $vmCredential -AsJob -ImageName UbuntuLTS -Verbose - Receive-Job $job -Wait + $result = Receive-Job $job -Wait + $result.Name | Should -Be MyVMA3 } } - -# clean-up -# Remove-AzureRmResourceGroup -Name Something1 \ No newline at end of file diff --git a/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psd1 b/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psd1 index d80663219640..c8453c832081 100644 --- a/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psd1 +++ b/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psd1 @@ -52,9 +52,9 @@ PowerShellVersion = '5.0' # Modules that must be imported into the global environment prior to importing this module RequiredModules = @( - @{ ModuleName = "AzureRM.Resources"; ModuleVersion = "4.3.2"; }, - @{ ModuleName = "AzureRM.Network"; ModuleVersion = "4.3.2"; }, - @{ ModuleName = "AzureRM.Compute"; ModuleVersion = "3.3.2"; } + @{ ModuleName = "AzureRM.Resources"; ModuleVersion = "4.4.0"; }, + @{ ModuleName = "AzureRM.Network"; ModuleVersion = "4.4.0"; }, + @{ ModuleName = "AzureRM.Compute"; ModuleVersion = "3.4.0"; } ) # Assemblies that must be loaded prior to importing this module From 0eefdf80e6f774610ea3ecda497976ca25dbf228 Mon Sep 17 00:00:00 2001 From: Sergey Shandar Date: Fri, 6 Oct 2017 11:00:51 -0700 Subject: [PATCH 23/29] bug fix --- .../AzureRM.Compute.Experiments.Tests.ps1 | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/experiments/Compute.Experiments/AzureRM.Compute.Experiments.Tests.ps1 b/experiments/Compute.Experiments/AzureRM.Compute.Experiments.Tests.ps1 index 26350130d264..7a651a53da64 100644 --- a/experiments/Compute.Experiments/AzureRM.Compute.Experiments.Tests.ps1 +++ b/experiments/Compute.Experiments/AzureRM.Compute.Experiments.Tests.ps1 @@ -22,17 +22,21 @@ Describe 'New-AzVm' { } It 'Create Windows VM' { Remove-AzureRmResourceGroup -Name Something1 -Force + $result = New-AzVm -Name MyVMA1 -Credential $vmCredential -ResourceGroupName Something1 -Verbose - $result.Name | Should -Be MyVMA1 + + $result.Name | Should Be MyVMA1 } It 'Create Linux VM' { $result = New-AzVm -Name MyVMA2 -Credential $vmCredential -ResourceGroupName Something1 -ImageName UbuntuLTS -Verbose - $result.Name | Should -Be MyVMA2 + $result.Name | Should Be MyVMA2 } It 'Create Linux VM AsJob' { Remove-AzureRmResourceGroup -Name MyVMA3 -Force + $job = New-AzVm -Name MyVMA3 -Credential $vmCredential -AsJob -ImageName UbuntuLTS -Verbose - $result = Receive-Job $job -Wait - $result.Name | Should -Be MyVMA3 + $result = Receive-Job $job -Wait -Verbose + + $result.Name | Should Be MyVMA3 } } From 274777c5d957d6f0495617cfbfbd9c2f30a5f477 Mon Sep 17 00:00:00 2001 From: Sergey Shandar Date: Fri, 6 Oct 2017 11:22:03 -0700 Subject: [PATCH 24/29] 1.0.28 --- .../Compute.Experiments/AzureRM.Compute.Experiments.psd1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psd1 b/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psd1 index c8453c832081..2357d6fb5248 100644 --- a/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psd1 +++ b/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psd1 @@ -12,7 +12,7 @@ RootModule = ".\AzureRM.Compute.Experiments.psm1" # Version number of this module. -ModuleVersion = '1.0.27' +ModuleVersion = '1.0.28' # Supported PSEditions # CompatiblePSEditions = @() From 193e92cf039f9efa8d03203c3bd6d01047108976 Mon Sep 17 00:00:00 2001 From: Sergey Shandar Date: Fri, 6 Oct 2017 17:35:11 -0700 Subject: [PATCH 25/29] minor --- .../AzureRM.Compute.Experiments.Tests.ps1 | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/experiments/Compute.Experiments/AzureRM.Compute.Experiments.Tests.ps1 b/experiments/Compute.Experiments/AzureRM.Compute.Experiments.Tests.ps1 index 7a651a53da64..39b48f129c09 100644 --- a/experiments/Compute.Experiments/AzureRM.Compute.Experiments.Tests.ps1 +++ b/experiments/Compute.Experiments/AzureRM.Compute.Experiments.Tests.ps1 @@ -28,8 +28,16 @@ Describe 'New-AzVm' { $result.Name | Should Be MyVMA1 } It 'Create Linux VM' { - $result = New-AzVm -Name MyVMA2 -Credential $vmCredential -ResourceGroupName Something1 -ImageName UbuntuLTS -Verbose - $result.Name | Should Be MyVMA2 + $context = Get-AzureRmContext + $result = New-AzVm ` + -Name X2 ` + -Credential $vmCredential ` + -Location westus2 ` + -ResourceGroupName Something1 ` + -AzureRmContext $context ` + -ImageName UbuntuLTS ` + -Verbose + $result.Name | Should Be X2 } It 'Create Linux VM AsJob' { Remove-AzureRmResourceGroup -Name MyVMA3 -Force From 36a51fee3d076c0adfd5a7781d18a814cd36c367 Mon Sep 17 00:00:00 2001 From: Sergey Shandar Date: Fri, 6 Oct 2017 18:18:14 -0700 Subject: [PATCH 26/29] Disable Boot Diagnostics #4735 --- .../Compute.Experiments/AzureRM.Compute.Experiments.psd1 | 2 +- .../Compute.Experiments/AzureRM.Compute.Experiments.psm1 | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psd1 b/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psd1 index 2357d6fb5248..dbb14501494c 100644 --- a/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psd1 +++ b/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psd1 @@ -12,7 +12,7 @@ RootModule = ".\AzureRM.Compute.Experiments.psm1" # Version number of this module. -ModuleVersion = '1.0.28' +ModuleVersion = '1.0.29' # Supported PSEditions # CompatiblePSEditions = @() diff --git a/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psm1 b/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psm1 index 7189be97b038..0ef33697707b 100644 --- a/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psm1 +++ b/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psm1 @@ -562,7 +562,11 @@ class VirtualMachine: Resource1 { [object] Create([CreateParams] $p) { $networkInterfaceInstance = $this.NetworkInterface.Info - $vmConfig = New-AzureRmVMConfig -VMName $this.Name -VMSize $this.Size -ErrorAction Stop + $vmConfig = New-AzureRmVMConfig ` + -VMName $this.Name ` + -VMSize $this.Size ` + -ErrorAction Stop ` + -DisableBootDiagnostics $vmComputerName = $this.Name switch ($this.Image.Type) { "Windows" { From 97137e9431ab09c0ef376611a5381a47c353d142 Mon Sep 17 00:00:00 2001 From: Sergey Shandar Date: Fri, 6 Oct 2017 18:23:38 -0700 Subject: [PATCH 27/29] -DisableBootDiagnostics --- .../Compute.Experiments/AzureRM.Compute.Experiments.psm1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psm1 b/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psm1 index 0ef33697707b..db478f510e38 100644 --- a/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psm1 +++ b/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psm1 @@ -565,8 +565,8 @@ class VirtualMachine: Resource1 { $vmConfig = New-AzureRmVMConfig ` -VMName $this.Name ` -VMSize $this.Size ` - -ErrorAction Stop ` - -DisableBootDiagnostics + -DisableBootDiagnostics ` + -ErrorAction Stop $vmComputerName = $this.Name switch ($this.Image.Type) { "Windows" { From b93dbd2e6065cf58c02e22199ed815e77ae24888 Mon Sep 17 00:00:00 2001 From: Sergey Shandar Date: Fri, 6 Oct 2017 18:35:12 -0700 Subject: [PATCH 28/29] Set-AzureRmVMBootDiagnostics --- .../Compute.Experiments/AzureRM.Compute.Experiments.psm1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psm1 b/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psm1 index db478f510e38..ecbb7a1bc550 100644 --- a/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psm1 +++ b/experiments/Compute.Experiments/AzureRM.Compute.Experiments.psm1 @@ -565,8 +565,8 @@ class VirtualMachine: Resource1 { $vmConfig = New-AzureRmVMConfig ` -VMName $this.Name ` -VMSize $this.Size ` - -DisableBootDiagnostics ` -ErrorAction Stop + $vmConfig = $vmConfig | Set-AzureRmVMBootDiagnostics -Disable -ErrorAction Stop $vmComputerName = $this.Name switch ($this.Image.Type) { "Windows" { From cfbd82445a85020ee7d66f90ceb78fea65a6102c Mon Sep 17 00:00:00 2001 From: Sergey Shandar Date: Mon, 9 Oct 2017 10:48:07 -0700 Subject: [PATCH 29/29] 1.0.30 --- comments.md | 171 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 171 insertions(+) create mode 100644 comments.md diff --git a/comments.md b/comments.md new file mode 100644 index 000000000000..be31b4b0f0d8 --- /dev/null +++ b/comments.md @@ -0,0 +1,171 @@ +# Comments + +- Local objects. +- Smart cmdlets for + - P2. Resource Group. + - P2. Virtual Network. + - P2. Security Group. +- P2. Resource Ids, a tree structure +- P1. Output for smart commands. In particular, information about (PS information stream ?) + - Resource Group!!! + - Virtual Network! + - Security Group! + - ...! +- Security Rules: + - DefaultSecurityRulesText - can/should we use it? +- P2. information stream +- P3. show progress +- P1. return PowerShell Job (async) + +## Tasks + +P0 is 09/05/2017 + +- [ ] P0 output +- [X] P0 create a package (PSM1, PSD1...) + - [X] P0 Manifest with dependencies +- image list + - [X] P0: json file or PSObject + - [ ] P1: json + - [ ] P2: source of image names. CDN, Azure... ??? +- names: + - P0: based on VM name specified by user (see also CLI, Portal). + - [X] P0: always fail if exist + - P1: can we reuse it? ??? + - P1: fallback: throw (suggests...) or reuse? + - P1: default shared name for Network (something else?!). CLI?? Portal?? +- P2 optional VM name. +- P1 Create Or Update scenario. +- P2 Rollback + +## Tasks + +- [X] P0: required modules +- [ ] replace Write-Host + - [X]: P0: remove Write-Host + - [ ]: P1: add progress +- [X] P0: parameter attributes +- [ ] P0: Linux image +- [ ] P0: more default parameters +- [X] P0: having a package. +- [ ] P1: Project build. + +## Graph + +1. `Location` +1. `ResourceGroup` + - depends on `Location` + - children + 1. `VirtualNetwork` + - depends on `Location` + - children + 1. `Subnet` + 1. `PublicIpAddress` + - depends on `Location` + 1. `SecurityGroup` + - depends on `Location` + - children + 1. `SecurityRule` + 1. `NetworkInterface` + - depends on `PublicIpAddress`, `Subnet`, `SecurityGroup`, `Location` + 1. `Vm` + - depends on `NetworkInterface`, `Location` + +## Levels + +1. Resources: + - `Location` (shared), + - `ResourceGroup` (shared) <- `Location` +1. Resources: + - `SecurityGroup` -> `SecurityRule` + - `Subnet` <- `VirtualNetwork` (shared?) + - `PublicIpAddress` +1. Resources: + - `NetworkInterface` (unique) ? +1. Resources: + - `VM` + +## Behavior + +a parameter value: + - undefined + - user's value + +if a resource exists + - then + - else + +resource name: +1. undefined + 1. resource exists - reuse|with validation (fail? or workaround or interactive) + 1. resource doesn't exist - create +1. user's value + 1. resource exist - reuse + 1. resource doesn't exist - fail (create?) + +smart location. Should it depends on a resource group location? + +default parameters - work backward + +## Resource Acquisition Matrix + +1. A resource name is + - undefined + - user's specified name + - user's specified id +1. A resource + - exists + - doesn't exist +1. A resource is + - shared + - unique + +## C# vs PowerShell + +### Proposal 1 + +- use C# to implement logic and type descriptions (no PowerShell dependencies, only .Net Standard and Azure SDK dependencies). +- use PowerShell to make a facade. + +### Proposal 2 + +- use C# to implement logic and type descriptions (with PowerShell dependencies) +- probably, no need for PSM1 files. + +### C# advantages + +- type/contract validations at compile time. +- much more feature to express logic, relations etc. +- testing is easier and, probably, faster. +- performance ?. +- customers may use the C# library for .Net programs (C#/VB/F#/...). +- C# type system is much more mature and well documented compare to PowerShell v5 classes. + +## Tasks + +- changelog +- remove warnings (-WarningAction=SilentContinue) +- help +- linux +- e2e manual test (Windows, Linux). +- feedback +- (-Auto) +- tab-completion +- VMSS +- rolling back +- output object + +## 9/15 + +- [X] [P-1] help (in doc, example) +- - signing (9/14) +- output format (Get-AzureRmVm) + - talk to Aaron + - how to use (connect to VM etc). +- output + - information stream (Write-Information) +- proper cmdlet + parameter attributes + struct + - [X] positional parameters (PR) (position 0 for name) +- [X] [P-1] shouldprocess (example) + +- [P0.5] validation (PSScript analyser)