28
28
29
29
namespace Microsoft . Azure . Commands . Network
30
30
{
31
- [ Cmdlet ( VerbsCommon . New , ResourceManager . Common . AzureRMConstants . AzureRMPrefix + "VirtualRouter" , SupportsShouldProcess = true , DefaultParameterSetName = VirtualRouterParameterSetNames . ByVirtualWanObject ) , OutputType ( typeof ( PSVirtualRouter ) ) ]
31
+ [ Cmdlet ( VerbsCommon . New , ResourceManager . Common . AzureRMConstants . AzureRMPrefix + "VirtualRouter" , SupportsShouldProcess = true , DefaultParameterSetName = VirtualRouterParameterSetNames . ByHostedGateway ) , OutputType ( typeof ( PSVirtualRouter ) ) ]
32
32
public partial class NewAzureRmVirtualRouter : VirtualRouterBaseCmdlet
33
33
{
34
34
[ Parameter (
@@ -47,32 +47,20 @@ public partial class NewAzureRmVirtualRouter : VirtualRouterBaseCmdlet
47
47
[ ValidateNotNullOrEmpty ]
48
48
public string Name { get ; set ; }
49
49
50
- [ Parameter (
51
- Mandatory = true ,
52
- ValueFromPipeline = true ,
53
- ParameterSetName = CortexParameterSetNames . ByVirtualWanObject ,
54
- HelpMessage = "The virtual wan object this hub is linked to." ) ]
55
- public PSVirtualWan VirtualWan { get ; set ; }
56
-
57
50
[ Parameter (
58
51
Mandatory = true ,
59
52
ValueFromPipelineByPropertyName = true ,
60
- ParameterSetName = CortexParameterSetNames . ByVirtualWanResourceId ,
61
- HelpMessage = "The id of virtual wan object this hub is linked to." ) ]
62
- [ ResourceIdCompleter ( "Microsoft.Network/virtualWans" ) ]
63
- public string VirtualWanId { get ; set ; }
53
+ ParameterSetName = VirtualRouterParameterSetNames . ByHostedGateway ,
54
+ HelpMessage = "The gateway where Virtual Router needs to be hosted." ) ]
55
+ public PSVirtualNetworkGateway HostedGateway { get ; set ; }
64
56
65
57
[ Parameter (
66
58
Mandatory = true ,
67
- HelpMessage = "The subnet where the virtual hub is hosted." ) ]
68
- [ ValidateNotNullOrEmpty ]
69
- public string HostedSubnet { get ; set ; }
70
-
71
- [ Parameter (
72
- Mandatory = true ,
73
- HelpMessage = "The address space string." ) ]
74
- [ ValidateNotNullOrEmpty ]
75
- public string AddressPrefix { get ; set ; }
59
+ ValueFromPipelineByPropertyName = true ,
60
+ ParameterSetName = VirtualRouterParameterSetNames . ByHostedGatewayId ,
61
+ HelpMessage = "The id of gateway where Virtual Router needs to be hosted." ) ]
62
+ [ ResourceIdCompleter ( "Microsoft.Network/virtualNetworkGateways" ) ]
63
+ public string HostedGatewayId { get ; set ; }
76
64
77
65
[ Parameter (
78
66
Mandatory = true ,
@@ -102,7 +90,7 @@ public override void Execute()
102
90
var present = true ;
103
91
try
104
92
{
105
- this . NetworkClient . NetworkManagementClient . VirtualHubs . Get ( this . ResourceGroupName , this . Name ) ;
93
+ this . NetworkClient . NetworkManagementClient . VirtualRouters . Get ( this . ResourceGroupName , this . Name ) ;
106
94
}
107
95
catch ( Exception ex )
108
96
{
@@ -122,55 +110,47 @@ public override void Execute()
122
110
throw new PSArgumentException ( string . Format ( Properties . Resources . ResourceAlreadyPresentInResourceGroup , this . Name , this . ResourceGroupName ) ) ;
123
111
}
124
112
125
- string virtualWanRGName = null ;
126
- string virtualWanName = null ;
113
+ string hostedGatewayId = null ;
127
114
128
115
//// Resolve the virtual wan
129
- if ( ParameterSetName . Equals ( CortexParameterSetNames . ByVirtualWanObject , StringComparison . OrdinalIgnoreCase ) )
116
+ if ( ParameterSetName . Equals ( VirtualRouterParameterSetNames . ByHostedGateway , StringComparison . OrdinalIgnoreCase ) )
130
117
{
131
- virtualWanRGName = this . VirtualWan . ResourceGroupName ;
132
- virtualWanName = this . VirtualWan . Name ;
118
+ hostedGatewayId = this . HostedGateway . Id ;
133
119
}
134
- else if ( ParameterSetName . Equals ( CortexParameterSetNames . ByVirtualWanResourceId , StringComparison . OrdinalIgnoreCase ) )
120
+ else if ( ParameterSetName . Equals ( VirtualRouterParameterSetNames . ByHostedGatewayId , StringComparison . OrdinalIgnoreCase ) )
135
121
{
136
- var parsedWanResourceId = new ResourceIdentifier ( this . VirtualWanId ) ;
137
- virtualWanName = parsedWanResourceId . ResourceName ;
138
- virtualWanRGName = parsedWanResourceId . ResourceGroupName ;
122
+ hostedGatewayId = this . HostedGatewayId ;
139
123
}
140
124
141
- if ( string . IsNullOrWhiteSpace ( virtualWanRGName ) || string . IsNullOrWhiteSpace ( virtualWanName ) )
125
+ if ( string . IsNullOrWhiteSpace ( hostedGatewayId ) )
142
126
{
143
- throw new PSArgumentException ( Properties . Resources . VirtualWanReferenceNeededForVirtualHub ) ;
127
+ throw new PSArgumentException ( Properties . Resources . VirtualGatewayRequiredForVirtualRouter ) ;
144
128
}
145
129
146
- PSVirtualWan resolvedVirtualWan = new VirtualWanBaseCmdlet ( ) . GetVirtualWan ( virtualWanRGName , virtualWanName ) ;
147
-
148
130
149
131
ConfirmAction (
150
132
Properties . Resources . CreatingResourceMessage ,
151
133
Name ,
152
134
( ) =>
153
135
{
154
136
WriteVerbose ( String . Format ( Properties . Resources . CreatingLongRunningOperationMessage , this . ResourceGroupName , this . Name ) ) ;
155
- PSVirtualHub virtualHub = new PSVirtualHub
137
+ PSVirtualRouter virtualRouter = new PSVirtualRouter
156
138
{
157
139
ResourceGroupName = this . ResourceGroupName ,
158
140
Name = this . Name ,
159
- VirtualWan = new PSResourceId ( ) { Id = resolvedVirtualWan . Id } ,
160
- AddressPrefix = this . AddressPrefix ,
161
- Location = this . Location
141
+ HostedGateway = new PSResourceId ( ) { Id = hostedGatewayId } ,
142
+ Location = this . Location ,
143
+ VirtualRouterAsn = GatewayAsn
162
144
} ;
163
145
164
- virtualHub . IpConfigurations . Add ( ( PSSubnet ) new PSResourceId ( ) { Id = this . HostedSubnet } ) ;
165
-
166
- var vVirtualHubModel = NetworkResourceManagerProfile . Mapper . Map < MNM . VirtualHub > ( virtualHub ) ;
167
- vVirtualHubModel . Tags = TagsConversionHelper . CreateTagDictionary ( this . Tag , validate : true ) ;
146
+ var vVirtualRouterModel = NetworkResourceManagerProfile . Mapper . Map < MNM . VirtualRouter > ( virtualRouter ) ;
147
+ vVirtualRouterModel . Tags = TagsConversionHelper . CreateTagDictionary ( this . Tag , validate : true ) ;
168
148
169
- this . NetworkClient . NetworkManagementClient . VirtualHubs . CreateOrUpdate ( this . ResourceGroupName , this . Name , vVirtualHubModel ) ;
170
- var getVirtualHub = this . NetworkClient . NetworkManagementClient . VirtualHubs . Get ( this . ResourceGroupName , this . Name ) ;
171
- var psVirtualRouter = NetworkResourceManagerProfile . Mapper . Map < PSVirtualRouter > ( getVirtualHub ) ;
149
+ this . NetworkClient . NetworkManagementClient . VirtualRouters . CreateOrUpdate ( this . ResourceGroupName , this . Name , vVirtualRouterModel ) ;
150
+ var getVirtualRouter = this . NetworkClient . NetworkManagementClient . VirtualRouters . Get ( this . ResourceGroupName , this . Name ) ;
151
+ var psVirtualRouter = NetworkResourceManagerProfile . Mapper . Map < PSVirtualRouter > ( getVirtualRouter ) ;
172
152
psVirtualRouter . ResourceGroupName = this . ResourceGroupName ;
173
- psVirtualRouter . Tag = TagsConversionHelper . CreateTagHashtable ( getVirtualHub . Tags ) ;
153
+ psVirtualRouter . Tag = TagsConversionHelper . CreateTagHashtable ( getVirtualRouter . Tags ) ;
174
154
WriteObject ( psVirtualRouter , true ) ;
175
155
} ) ;
176
156
0 commit comments