@@ -35,53 +35,21 @@ function New-AzVm {
35
35
}
36
36
37
37
$resourceGroup = $rgi.GetOrCreate ($Name + " ResourceGroup" , $locationi.Value , $null );
38
- $virtualNetwork = $vni.GetOrCreate (
39
- $Name + " VirtualNetwork" ,
40
- $locationi.Value ,
41
- $resourceGroup.ResourceGroupName );
42
- $publicIpAddress = $piai.GetOrCreate (
43
- $Name + " PublicIpAddress" ,
44
- $locationi.Value ,
45
- $resourceGroup.ResourceGroupName );
46
- $securityGroup = $sgi.GetOrCreate (
47
- $Name + " SecurityGroup" ,
48
- $locationi.Value ,
49
- $resourceGroup.ResourceGroupName )
38
+ $networkInterface = $nii.GetOrCreate ($Name , $locationi.Value , $resourceGroup.ResourceGroupName );
50
39
51
40
if (-not $Credential ) {
52
41
$Credential = Get-Credential
53
42
}
54
43
if (-not $ResourceGroupName ) {
55
44
$ResourceGroupName = $Name + " ResourceGroup" ;
56
45
}
57
- if (-not $VirtualNetworkName ) {
58
- $VirtualNetworkName = $Name + " VirtualNetwork" ;
59
- }
60
- if (-not $PublicIpAddressName ) {
61
- $PublicIpAddressName = $Name + " PublicIpAddress" ;
62
- }
63
- if (-not $SecurityGroupName ) {
64
- $SecurityGroupName = $Name + " SecurityGroup" ;
65
- }
66
- if (-not $NetworkInterfaceName ) {
67
- $NetworkInterfaceName = $Name + " NetworkInterface"
68
- }
69
46
70
47
# Find VM Image
71
48
$vmImage = $images | Where-Object { $_.Name -eq $ImageName } | Select-Object - First 1
72
49
if (-not $vmImage ) {
73
50
throw " Unknown image: " + $ImageName
74
51
}
75
52
76
- # Network Interface
77
- $networkInterface = New-AzureRmNetworkInterface `
78
- - ResourceGroupName $ResourceGroupName `
79
- - Location $Location `
80
- - Name $NetworkInterfaceName `
81
- - PublicIpAddressId $publicIpAddress.Id `
82
- - SubnetId $virtualNetwork.Subnets [0 ].Id `
83
- - NetworkSecurityGroupId $securityGroup.Id
84
-
85
53
# VM
86
54
$vmSize = " Standard_DS2"
87
55
$vmConfig = New-AzureRmVMConfig - VMName $Name - VMSize $vmSize
@@ -295,17 +263,37 @@ class SecurityGroup: Resource1 {
295
263
}
296
264
297
265
class NetworkInterface : AzureObject {
266
+ [VirtualNetwork ] $VirtualNetwork ;
267
+ [PublicIpAddress ] $PublicIpAddress ;
268
+ [SecurityGroup ] $SecurityGroup ;
269
+
298
270
NetworkInterface(
299
271
[string ] $name ,
300
272
[VirtualNetwork ] $virtualNetwork ,
301
273
[PublicIpAddress ] $publicIpAddress ,
302
274
[SecurityGroup ] $securityGroup
303
275
): base($name , @ ($virtualNetwork , $publicIpAddress , $securityGroup )) {
276
+ $this.VirtualNetwork = $virtualNetwork ;
277
+ $this.PublicIpAddress = $publicIpAddress ;
278
+ $this.SecurityGroup = $securityGroup ;
304
279
}
305
280
306
281
[object ] GetInfo() {
307
282
return Get-AzureRMNetworkInterface - Name $this.Name ;
308
283
}
284
+
285
+ [object ] Create([string ] $name , [string ] $location , [string ] $resourceGroupName ) {
286
+ $xpublicIpAddress = $this.PublicIpAddress.GetOrCreate ($name , $location , $resourceGroupName );
287
+ $xvirtualNetwork = $this.VirtualNetwork.GetOrCreate ($name , $location , $resourceGroupName );
288
+ $xsecurityGroup = $this.SecurityGroup.GetOrCreate ($name , $location , $resourceGroupName );
289
+ return New-AzureRmNetworkInterface `
290
+ - ResourceGroupName $resourceGroupName `
291
+ - Location $location `
292
+ - Name $name `
293
+ - PublicIpAddressId $xpublicIpAddress.Id `
294
+ - SubnetId $xvirtualNetwork.Subnets [0 ].Id `
295
+ - NetworkSecurityGroupId $xsecurityGroup.Id
296
+ }
309
297
}
310
298
311
299
class VirtualMachine : AzureObject {
0 commit comments