@@ -35,53 +35,21 @@ function New-AzVm {
3535 }
3636
3737 $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 );
5039
5140 if (-not $Credential ) {
5241 $Credential = Get-Credential
5342 }
5443 if (-not $ResourceGroupName ) {
5544 $ResourceGroupName = $Name + " ResourceGroup" ;
5645 }
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- }
6946
7047 # Find VM Image
7148 $vmImage = $images | Where-Object { $_.Name -eq $ImageName } | Select-Object - First 1
7249 if (-not $vmImage ) {
7350 throw " Unknown image: " + $ImageName
7451 }
7552
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-
8553 # VM
8654 $vmSize = " Standard_DS2"
8755 $vmConfig = New-AzureRmVMConfig - VMName $Name - VMSize $vmSize
@@ -295,17 +263,37 @@ class SecurityGroup: Resource1 {
295263}
296264
297265class NetworkInterface : AzureObject {
266+ [VirtualNetwork ] $VirtualNetwork ;
267+ [PublicIpAddress ] $PublicIpAddress ;
268+ [SecurityGroup ] $SecurityGroup ;
269+
298270 NetworkInterface(
299271 [string ] $name ,
300272 [VirtualNetwork ] $virtualNetwork ,
301273 [PublicIpAddress ] $publicIpAddress ,
302274 [SecurityGroup ] $securityGroup
303275 ): base($name , @ ($virtualNetwork , $publicIpAddress , $securityGroup )) {
276+ $this.VirtualNetwork = $virtualNetwork ;
277+ $this.PublicIpAddress = $publicIpAddress ;
278+ $this.SecurityGroup = $securityGroup ;
304279 }
305280
306281 [object ] GetInfo() {
307282 return Get-AzureRMNetworkInterface - Name $this.Name ;
308283 }
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+ }
309297}
310298
311299class VirtualMachine : AzureObject {
0 commit comments