Skip to content

Commit 305df46

Browse files
committed
Merge pull request #202 from nupurkot/dev
Fixing ExpressRoute commandlets + new Set-AzureDedicatedCircuitBandwidth commandlet
2 parents 1852cb9 + 5a2e6a2 commit 305df46

File tree

11 files changed

+213
-123
lines changed

11 files changed

+213
-123
lines changed

src/ServiceManagement/ExpressRoute/Commands.ExpressRoute/Commands.ExpressRoute.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
</Reference>
8484
<Reference Include="Microsoft.WindowsAzure.Management.ExpressRoute, Version=0.9.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
8585
<SpecificVersion>False</SpecificVersion>
86-
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Management.ExpressRoute.0.18.0-preview\lib\net40\Microsoft.WindowsAzure.Management.ExpressRoute.dll</HintPath>
86+
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Management.ExpressRoute.0.18.2-preview\lib\net40\Microsoft.WindowsAzure.Management.ExpressRoute.dll</HintPath>
8787
</Reference>
8888
<Reference Include="Newtonsoft.Json">
8989
<HintPath>..\..\..\packages\Newtonsoft.Json.6.0.4\lib\net45\Newtonsoft.Json.dll</HintPath>
@@ -135,6 +135,7 @@
135135
<Compile Include="DedicatedCircuits\GetAzureDedicatedCircuit.cs" />
136136
<Compile Include="DedicatedCircuits\NewAzureDedicatedCircuit.cs" />
137137
<Compile Include="DedicatedCircuits\RemoveAzureDedicatedCircuit.cs" />
138+
<Compile Include="DedicatedCircuitBandwidths\SetAzureDedicatedCircuitBandwidth.cs" />
138139
<Compile Include="ExpressRouteBaseCmdlet.cs" />
139140
<Compile Include="ExpressRouteClient.cs" />
140141
<Compile Include="Properties\AssemblyInfo.cs" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using System;
16+
using System.Management.Automation;
17+
using Microsoft.WindowsAzure.Commands.ExpressRoute.Properties;
18+
19+
namespace Microsoft.WindowsAzure.Commands.ExpressRoute
20+
{
21+
using Management.ExpressRoute.Models;
22+
23+
[Cmdlet(VerbsCommon.Set, "AzureDedicatedCircuitBandwidth"), OutputType(typeof(AzureDedicatedCircuit))]
24+
public class SetAzureDedicatedCircuitBandwidthCommand : ExpressRouteBaseCmdlet
25+
{
26+
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true,
27+
HelpMessage = "Service Key of Azure Dedicated Circuit to be removed")]
28+
[ValidateGuid]
29+
[ValidateNotNullOrEmpty]
30+
public string ServiceKey { get; set; }
31+
32+
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Circuit Bandwidth")]
33+
[ValidateNotNullOrEmpty]
34+
public UInt32 Bandwidth { get; set; }
35+
36+
[Parameter(HelpMessage = "Do not confirm Azure Dedicated Circuit Update")]
37+
public SwitchParameter Force { get; set; }
38+
39+
public override void ExecuteCmdlet()
40+
{
41+
ConfirmAction(
42+
Force.IsPresent,
43+
string.Format(Resources.SetAzureDedicatedCircuitBandwidthWarning, ServiceKey, Bandwidth),
44+
Resources.SetAzureDedicatedCircuitBandwidthMessage,
45+
ServiceKey,
46+
() =>
47+
{
48+
var circuit = ExpressRouteClient.SetAzureDedicatedCircuitBandwidth(ServiceKey, Bandwidth);
49+
50+
WriteObject(circuit);
51+
52+
});
53+
}
54+
}
55+
}
56+

src/ServiceManagement/ExpressRoute/Commands.ExpressRoute/ExpressRouteClient.cs

Lines changed: 79 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ namespace Microsoft.WindowsAzure.Commands.ExpressRoute
2323
using Microsoft.WindowsAzure.Management.ExpressRoute.Models;
2424
using System;
2525
using System.Collections.Generic;
26+
using System.ComponentModel;
2627
using System.Net;
2728
using Utilities.Common;
2829
using Microsoft.Azure.Common.Authentication.Models;
@@ -61,14 +62,23 @@ public AzureBgpPeering GetAzureBGPPeering(string serviceKey, BgpPeeringAccessTyp
6162
public AzureBgpPeering NewAzureBGPPeering(string serviceKey, UInt32 peerAsn, string primaryPeerSubnet,
6263
string secondaryPeerSubnet, UInt32 vlanId, BgpPeeringAccessType accessType, string sharedKey = null)
6364
{
64-
return Client.BorderGatewayProtocolPeerings.New(serviceKey, accessType, new BorderGatewayProtocolPeeringNewParameters()
65+
var result = Client.BorderGatewayProtocolPeerings.New(serviceKey, accessType, new BorderGatewayProtocolPeeringNewParameters()
6566
{
6667
PeerAutonomousSystemNumber = peerAsn,
6768
PrimaryPeerSubnet = primaryPeerSubnet,
6869
SecondaryPeerSubnet = secondaryPeerSubnet,
6970
SharedKey = sharedKey,
7071
VirtualLanId = vlanId
71-
}).BgpPeering;
72+
});
73+
74+
if (result.HttpStatusCode.Equals(HttpStatusCode.OK))
75+
{
76+
return GetAzureBGPPeering(serviceKey, accessType);
77+
}
78+
else
79+
{
80+
throw new Exception(result.Error.ToString());
81+
}
7282
}
7383

7484
public bool RemoveAzureBGPPeering(string serviceKey, BgpPeeringAccessType accessType)
@@ -81,15 +91,22 @@ public AzureBgpPeering UpdateAzureBGPPeering(string serviceKey,
8191
BgpPeeringAccessType accessType, UInt32 peerAsn, string primaryPeerSubnet,
8292
string secondaryPeerSubnet, UInt32 vlanId, string sharedKey)
8393
{
84-
return
85-
(Client.BorderGatewayProtocolPeerings.Update(serviceKey, accessType, new BorderGatewayProtocolPeeringUpdateParameters()
94+
var result = Client.BorderGatewayProtocolPeerings.Update(serviceKey, accessType, new BorderGatewayProtocolPeeringUpdateParameters()
8695
{
8796
PeerAutonomousSystemNumber = peerAsn,
8897
PrimaryPeerSubnet = primaryPeerSubnet,
8998
SecondaryPeerSubnet = secondaryPeerSubnet,
9099
SharedKey = sharedKey,
91100
VirtualLanId = vlanId,
92-
})).BgpPeering;
101+
});
102+
if (result.HttpStatusCode.Equals(HttpStatusCode.OK))
103+
{
104+
return GetAzureBGPPeering(serviceKey, accessType);
105+
}
106+
else
107+
{
108+
throw new Exception(result.Error.ToString());
109+
}
93110
}
94111

95112
public AzureDedicatedCircuit GetAzureDedicatedCircuit(string serviceKey)
@@ -100,20 +117,46 @@ public AzureDedicatedCircuit GetAzureDedicatedCircuit(string serviceKey)
100117
public AzureDedicatedCircuit NewAzureDedicatedCircuit(string circuitName,
101118
UInt32 bandwidth, string location, string serviceProviderName)
102119
{
103-
return (Client.DedicatedCircuits.New(new DedicatedCircuitNewParameters()
120+
var result = Client.DedicatedCircuits.New(new DedicatedCircuitNewParameters()
104121
{
105122
Bandwidth = bandwidth,
106123
CircuitName = circuitName,
107124
Location = location,
108125
ServiceProviderName = serviceProviderName
109-
})).DedicatedCircuit;
126+
});
127+
128+
if (result.HttpStatusCode.Equals(HttpStatusCode.OK))
129+
{
130+
return GetAzureDedicatedCircuit(result.Data);
131+
}
132+
else
133+
{
134+
throw new Exception(result.Error.ToString());
135+
}
110136
}
111137

112138
public IEnumerable<AzureDedicatedCircuit> ListAzureDedicatedCircuit()
113139
{
114140
return (Client.DedicatedCircuits.List().DedicatedCircuits);
115141
}
116142

143+
public AzureDedicatedCircuit SetAzureDedicatedCircuitBandwidth(string serviceKey, UInt32 bandwidth)
144+
{
145+
var result = Client.DedicatedCircuits.Update(serviceKey, (new DedicatedCircuitUpdateParameters()
146+
{
147+
Bandwidth = bandwidth
148+
}));
149+
150+
if (result.HttpStatusCode.Equals(HttpStatusCode.OK))
151+
{
152+
return GetAzureDedicatedCircuit(serviceKey);
153+
}
154+
else
155+
{
156+
throw new Exception(result.Error.ToString());
157+
}
158+
}
159+
117160
public bool RemoveAzureDedicatedCircuit(string serviceKey)
118161
{
119162
var result = Client.DedicatedCircuits.Remove(serviceKey);
@@ -127,7 +170,15 @@ public AzureDedicatedCircuitLink GetAzureDedicatedCircuitLink(string serviceKey,
127170

128171
public AzureDedicatedCircuitLink NewAzureDedicatedCircuitLink(string serviceKey, string vNetName)
129172
{
130-
return (Client.DedicatedCircuitLinks.New(serviceKey, vNetName)).DedicatedCircuitLink;
173+
var result = Client.DedicatedCircuitLinks.New(serviceKey, vNetName);
174+
if (result.HttpStatusCode.Equals(HttpStatusCode.OK))
175+
{
176+
return GetAzureDedicatedCircuitLink(serviceKey, vNetName);
177+
}
178+
else
179+
{
180+
throw new Exception(result.Error.ToString());
181+
}
131182
}
132183

133184
public IEnumerable<AzureDedicatedCircuitLink> ListAzureDedicatedCircuitLink(string serviceKey)
@@ -153,13 +204,31 @@ public AzureCrossConnection GetAzureCrossConnection(string serviceKey)
153204

154205
public AzureCrossConnection NewAzureCrossConnection(string serviceKey)
155206
{
156-
return (Client.CrossConnections.New(serviceKey)).CrossConnection;
207+
var result = Client.CrossConnections.New(serviceKey);
208+
209+
if (result.HttpStatusCode.Equals(HttpStatusCode.OK))
210+
{
211+
return GetAzureCrossConnection(serviceKey);
212+
}
213+
else
214+
{
215+
throw new Exception(result.Error.ToString());
216+
}
157217
}
158218

159219
public AzureCrossConnection SetAzureCrossConnection(string serviceKey,
160220
CrossConnectionUpdateParameters parameters)
161221
{
162-
return (Client.CrossConnections.Update(serviceKey, parameters)).CrossConnection;
222+
var result = Client.CrossConnections.Update(serviceKey, parameters);
223+
224+
if (result.HttpStatusCode.Equals(HttpStatusCode.OK))
225+
{
226+
return GetAzureCrossConnection(serviceKey);
227+
}
228+
else
229+
{
230+
throw new Exception(result.Error.ToString());
231+
}
163232
}
164233

165234
public IEnumerable<AzureCrossConnection> ListAzureCrossConnections()

src/ServiceManagement/ExpressRoute/Commands.ExpressRoute/Properties/Resources.Designer.cs

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ServiceManagement/ExpressRoute/Commands.ExpressRoute/Properties/Resources.resx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@
150150
<data name="RemoveAzureDedicatdCircuitWarning" xml:space="preserve">
151151
<value>Are you sure you want to remove the Dedicated Circuit with service key '{0}'?</value>
152152
</data>
153+
<data name="SetAzureDedicatedCircuitBandwidthWarning" xml:space="preserve">
154+
<value>Are you sure you want to update the bandwidth of the Dedicated Circuit with service key '{0}' to '{1}'?</value>
155+
</data>
153156
<data name="RemoveAzureDedicatedCircuitFailed" xml:space="preserve">
154157
<value>Remove-AzureDedicatedCircuit Operation failed.</value>
155158
</data>
@@ -180,6 +183,9 @@
180183
<data name="RemoveAzureDedicatedCircuitMessage" xml:space="preserve">
181184
<value>Removing Dedicated Circuit</value>
182185
</data>
186+
<data name="SetAzureDedicatedCircuitBandwidthMessage" xml:space="preserve">
187+
<value>Updating Dedicated Circuit Bandwidth</value>
188+
</data>
183189
<data name="RemoveAzureDedicatedCircuitSucceeded" xml:space="preserve">
184190
<value>Successfully removed Azure Dedicated Circuit with Service Key {0}.</value>
185191
</data>

src/ServiceManagement/ExpressRoute/Commands.ExpressRoute/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111
<package id="Microsoft.IdentityModel.Clients.ActiveDirectory" version="2.12.111071459" targetFramework="net45" />
1212
<package id="Microsoft.Net.Http" version="2.2.28" targetFramework="net45" />
1313
<package id="Microsoft.WindowsAzure.Management" version="4.0.1" targetFramework="net45" />
14-
<package id="Microsoft.WindowsAzure.Management.ExpressRoute" version="0.18.0-preview" targetFramework="net45" />
14+
<package id="Microsoft.WindowsAzure.Management.ExpressRoute" version="0.18.2-preview" targetFramework="net45" />
1515
<package id="Newtonsoft.Json" version="6.0.4" targetFramework="net45" />
1616
</packages>

src/ServiceManagement/Services/Commands.Test/Commands.Test.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@
118118
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Management.Compute.9.0.0\lib\net40\Microsoft.WindowsAzure.Management.Compute.dll</HintPath>
119119
</Reference>
120120
<Reference Include="Microsoft.WindowsAzure.Management.ExpressRoute">
121-
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Management.ExpressRoute.0.18.0-preview\lib\net40\Microsoft.WindowsAzure.Management.ExpressRoute.dll</HintPath>
121+
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Management.ExpressRoute.0.18.2-preview\lib\net40\Microsoft.WindowsAzure.Management.ExpressRoute.dll</HintPath>
122122
</Reference>
123123
<Reference Include="Microsoft.WindowsAzure.Management.MediaServices">
124124
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Management.MediaServices.4.0.0\lib\net40\Microsoft.WindowsAzure.Management.MediaServices.dll</HintPath>

0 commit comments

Comments
 (0)