Skip to content

Commit eac6277

Browse files
OutputType
1 parent 315747d commit eac6277

File tree

2 files changed

+41
-18
lines changed

2 files changed

+41
-18
lines changed

experiments/Compute.Experiments/AzureRM.Compute.Experiments.Tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ $vm = New-AzVm -Name MyVM -Credential $vmCredential
2424
$vm
2525

2626
# clean-up
27-
Remove-AzureRmResourceGroup -ResourceId $vm.resourceId
27+
Remove-AzureRmResourceGroup -ResourceId $vm.ResourceGroupId

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

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,17 @@ function New-AzVm {
55
[CmdletBinding(SupportsShouldProcess = $true)]
66
param (
77
[Parameter(Mandatory=$true, Position=0)][string] $Name = "VM",
8-
[Parameter()][PSCredential] $Credential,
9-
[Parameter()][string] $ImageName = "Win2012R2Datacenter",
8+
109
[Parameter()][string] $ResourceGroupName,
1110
[Parameter()][string] $Location,
11+
1212
[Parameter()][string] $VirtualNetworkName,
1313
[Parameter()][string] $PublicIpAddressName,
14-
[Parameter()][string] $SecurityGroupName
14+
[Parameter()][string] $SecurityGroupName,
15+
16+
[Parameter()][PSCredential] $Credential,
17+
[Parameter()][string] $ImageName = "Win2012R2Datacenter",
18+
[Parameter()][string] $Size = "Standard_DS1_v2"
1519
)
1620

1721
PROCESS {
@@ -29,7 +33,14 @@ function New-AzVm {
2933
$sgi);
3034

3135
# the purpouse of the New-AzVm cmdlet is to create (not get) a VM so $name is $null.
32-
$vmi = [VirtualMachine]::new($null, $nii, $rgi, $Credential, $ImageName, $images);
36+
$vmi = [VirtualMachine]::new(
37+
$null,
38+
$nii,
39+
$rgi,
40+
$Credential,
41+
$ImageName,
42+
$images,
43+
$Size);
3344

3445
# infer a location
3546
$locationi = [Location]::new();
@@ -48,14 +59,24 @@ function New-AzVm {
4859
$resourceGroup = $rgi.GetOrCreate($createParams);
4960
$vmResponse = $vmi.Create($createParams);
5061

51-
New-PsObject @{
52-
ResourceId = $resourceGroup.ResourceId;
53-
Response = $vmResponse;
54-
}
62+
return [PSAzureVm]::new(
63+
$resourceGroup.ResourceId,
64+
$Name
65+
);
5566
}
5667
}
5768
}
5869

70+
class PSAzureVm {
71+
[string] $ResourceGroupId;
72+
[string] $Name;
73+
74+
PSAzureVm([string] $resourceGroupId, [string] $name) {
75+
$this.ResourceGroupId = $resourceGroupId;
76+
$this.Name = $name;
77+
}
78+
}
79+
5980
class Location {
6081
[int] $Priority;
6182
[string] $Value;
@@ -258,20 +279,23 @@ class VirtualMachine: AzureObject {
258279
[pscredential] $Credential;
259280
[string] $ImageName;
260281
[object] $Images;
282+
[string] $Size;
261283

262284
VirtualMachine(
263285
[string] $name,
264286
[NetworkInterface] $networkInterface,
265287
[ResourceGroup] $resourceGroup,
266288
[PSCredential] $credential,
267289
[string] $imageName,
268-
[object] $images):
290+
[object] $images,
291+
[string] $size):
269292
base($name, @($networkInterface, $resourceGroup)) {
270293

271294
$this.Credential = $credential;
272295
$this.ImageName = $imageName;
273296
$this.NetworkInterface = $networkInterface;
274297
$this.Images = $images;
298+
$this.Size = $size;
275299
}
276300

277301
[object] GetInfo() {
@@ -282,29 +306,28 @@ class VirtualMachine: AzureObject {
282306
$networkInterfaceInstance = $this.NetworkInterface.GetOrCreate($p);
283307

284308
if (-not $this.Credential) {
285-
$this.Credential = Get-Credential
309+
$this.Credential = Get-Credential;
286310
}
287311

288-
$vmImage = $this.Images | Where-Object { $_.Name -eq $this.ImageName } | Select-Object -First 1
312+
$vmImage = $this.Images | Where-Object { $_.Name -eq $this.ImageName } | Select-Object -First 1;
289313
if (-not $vmImage) {
290-
throw "Unknown image: " + $this.ImageName
314+
throw "Unknown image: " + $this.ImageName;
291315
}
292316

293-
$vmSize = "Standard_DS2"
294-
$vmConfig = New-AzureRmVMConfig -VMName $p.Name -VMSize $vmSize
295-
$vmComputerName = $p.Name + "Computer"
317+
$vmConfig = New-AzureRmVMConfig -VMName $p.Name -VMSize $this.Size;
318+
$vmComputerName = $p.Name + "Computer";
296319
switch ($vmImage.Type) {
297320
"Windows" {
298321
$vmConfig = $vmConfig | Set-AzureRmVMOperatingSystem `
299322
-Windows `
300323
-ComputerName $vmComputerName `
301-
-Credential $this.Credential
324+
-Credential $this.Credential;
302325
}
303326
"Linux" {
304327
$vmConfig = $vmConfig | Set-AzureRmVMOperatingSystem `
305328
-Linux `
306329
-ComputerName $vmComputerName `
307-
-Credential $this.Credential
330+
-Credential $this.Credential;
308331
}
309332
}
310333

0 commit comments

Comments
 (0)