Skip to content

Commit

Permalink
updated swagger to allow setting the commissioned state property, cor…
Browse files Browse the repository at this point in the history
…responding powershell updates
  • Loading branch information
dexiang-ms committed Aug 19, 2020
1 parent c25cdcc commit cac5f46
Show file tree
Hide file tree
Showing 10 changed files with 207 additions and 28 deletions.
37 changes: 37 additions & 0 deletions src/Network/Network.Test/ScenarioTests/CustomIpPrefixTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

using Microsoft.Azure.Commands.Network.Test.ScenarioTests;
using Microsoft.WindowsAzure.Commands.ScenarioTest;
using Xunit;

namespace Commands.Network.Test.ScenarioTests
{

public class CustomIpPrefixTests : NetworkTestRunner
{
public CustomIpPrefixTests(Xunit.Abstractions.ITestOutputHelper output)
: base(output)
{
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
[Trait(Category.Owner, NrpTeamAlias.billingandtelemetry)]
public void TestCustomIpPrefixCRUD()
{
TestRunner.RunTestScript("Test-CustomIpPrefixCRUD");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
// ----------------------------------------------------------------------------------

using Microsoft.Azure.Commands.Network.Test.ScenarioTests;
using Microsoft.Rest.ClientRuntime.Azure.TestFramework;
using Microsoft.WindowsAzure.Commands.ScenarioTest;
using System;
using Xunit;

namespace Commands.Network.Test.ScenarioTests
Expand All @@ -29,7 +31,7 @@ public MasterCustomIpPrefixTests(Xunit.Abstractions.ITestOutputHelper output)
[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
[Trait(Category.Owner, NrpTeamAlias.billingandtelemetry)]
public void TestPublicIpPrefixCRUD()
public void TestMasterCustomIpPrefixCRUD()
{
TestRunner.RunTestScript("Test-MasterCustomIpPrefixCRUD");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ public PSCustomIpPrefix GetCustomIpPrefix(string resourceGroupName, string name,
return psModel;
}

public PSCustomIpPrefix ToPsCustomIpPrefix(CustomIpPrefix publicIpPrefix)
public PSCustomIpPrefix ToPsCustomIpPrefix(CustomIpPrefix customIpPrefix)
{
var psModel = NetworkResourceManagerProfile.Mapper.Map<PSCustomIpPrefix>(publicIpPrefix);
var psModel = NetworkResourceManagerProfile.Mapper.Map<PSCustomIpPrefix>(customIpPrefix);

psModel.Tag = TagsConversionHelper.CreateTagHashtable(publicIpPrefix.Tags);
psModel.Tag = TagsConversionHelper.CreateTagHashtable(customIpPrefix.Tags);

return psModel;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ public class SetAzureCustomIpPrefixCommand : CustomIpPrefixBaseCmdlet
public SwitchParameter Decomission { get; set; }

[Parameter(
Mandatory = true,
Mandatory = false,
ValueFromPipelineByPropertyName = true,
HelpMessage = "A hashtable which represents resource tags.",
ParameterSetName = SetByNameParameterSet)]
[Parameter(Mandatory = true, ParameterSetName = SetByResourceIdParameterSet)]
[Parameter(Mandatory = false, ParameterSetName = SetByResourceIdParameterSet)]
[Parameter(Mandatory = false, ParameterSetName = SetByInputObjectParameterSet)]
public Hashtable Tag { get; set; }

Expand Down Expand Up @@ -108,17 +108,19 @@ public override void Execute()
throw new ArgumentException(Microsoft.Azure.Commands.Network.Properties.Resources.CommissioningStateConflict);
}

var psModel = new PSCustomIpPrefix()
PSCustomIpPrefix customIpPrefixToUpdate = this.GetCustomIpPrefix(this.ResourceGroupName, this.Name);

if (customIpPrefixToUpdate == null)
{
Name = InputObject.Name,
ResourceGroupName = InputObject.ResourceGroupName
};
throw new PSArgumentException(Properties.Resources.ResourceNotFound, this.Name);
}

if (Commission || Decomission)
{
psModel.CommissionedState = Commission ? "Commissioning" : "Decomissioning";
customIpPrefixToUpdate.CommissionedState = Commission ? "Commissioning" : "Decomissioning";
}

var sdkModel = NetworkResourceManagerProfile.Mapper.Map<MNM.CustomIpPrefix>(psModel);
var sdkModel = NetworkResourceManagerProfile.Mapper.Map<MNM.CustomIpPrefix>(customIpPrefixToUpdate);

if (this.IsParameterBound(c => c.InputObject))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,6 @@ public class NewAzureMasterCustomIpPrefixCommand : MasterCustomIpPrefixBaseCmdle
[ValidateNotNullOrEmpty]
public string Location { get; set; }

[Parameter(
Mandatory = true,
ValueFromPipelineByPropertyName = true,
HelpMessage = "The geography of edge routers this prefix range will be advertised on.")]
[ValidateNotNullOrEmpty]
[ValidateSet(
MNM.RIR.NorthAmerica,
MNM.RIR.Europe,
MNM.RIR.Asia,
MNM.RIR.SouthAmerica,
MNM.RIR.Africa,
MNM.RIR.Global,
IgnoreCase = true)]
public string Geography { get; set; }

[Parameter(
Mandatory = true,
ValueFromPipelineByPropertyName = true,
Expand Down Expand Up @@ -121,7 +106,6 @@ private PSMasterCustomIpPrefix CreateMasterCustomIpPrefix()
Name = this.Name,
ResourceGroupName = this.ResourceGroupName,
Location = this.Location,
Geography = this.Geography,
Cidr = this.Cidr,
OriginalValidationMessage = this.ValidationMessage,
SignedValidationMessage = this.SignedValidationMessage
Expand Down
6 changes: 6 additions & 0 deletions src/Network/Network/Models/BYOIP/PSCustomIpPrefix.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,11 @@ public class PSCustomIpPrefix : PSTopLevelResource
public List<string> Zones { get; set; }

public string ProvisioningState { get; set; }

[JsonIgnore]
public string MasterCustomIpPrefixText
{
get { return JsonConvert.SerializeObject(MasterCustomIpPrefix, Formatting.Indented, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }); }
}
}
}
6 changes: 6 additions & 0 deletions src/Network/Network/Models/BYOIP/PSMasterCustomIpPrefix.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,11 @@ public class PSMasterCustomIpPrefix : PSTopLevelResource
public List<PSResourceId> CustomIpPrefixes { get; set; }

public string ValidationState { get; set; }

[JsonIgnore]
public string CustomIpPrefixesText
{
get { return JsonConvert.SerializeObject(CustomIpPrefixes, Formatting.Indented, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }); }
}
}
}
2 changes: 2 additions & 0 deletions src/Network/Network/Models/PSPublicIpPrefix.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public class PSPublicIpPrefix : PSTopLevelResource

public List<PSPublicIpAddress> PublicIpAddresses { get; set; }

public PSResourceId CustomIpPrefix { get; set; }

[JsonIgnore]
public string PublicIpAddressesText
{
Expand Down
132 changes: 132 additions & 0 deletions src/Network/Network/Network.format.ps1xml
Original file line number Diff line number Diff line change
Expand Up @@ -1492,6 +1492,138 @@
</ListEntry>
</ListEntries>
</ListControl>
</View>
<View>
<Name>Microsoft.Azure.Commands.Network.Models.PSMasterCustomIpPrefix</Name>
<ViewSelectedBy>
<TypeName>Microsoft.Azure.Commands.Network.Models.PSMasterCustomIpPrefix</TypeName>
</ViewSelectedBy>
<ListControl>
<ListEntries>
<ListEntry>
<ListItems>
<ListItem>
<Label>Name</Label>
<PropertyName>Name</PropertyName>
</ListItem>
<ListItem>
<Label>ResourceGroupName</Label>
<PropertyName>ResourceGroupName</PropertyName>
</ListItem>
<ListItem>
<Label>Location</Label>
<PropertyName>Location</PropertyName>
</ListItem>
<ListItem>
<Label>Id</Label>
<PropertyName>Id</PropertyName>
</ListItem>
<ListItem>
<Label>Etag</Label>
<PropertyName>Etag</PropertyName>
</ListItem>
<ListItem>
<Label>ResourceGuid</Label>
<PropertyName>ResourceGuid</PropertyName>
</ListItem>
<ListItem>
<Label>ProvisioningState</Label>
<PropertyName>ProvisioningState</PropertyName>
</ListItem>
<ListItem>
<Label>Tags</Label>
<PropertyName>TagsTable</PropertyName>
</ListItem>
<ListItem>
<Label>Cidr</Label>
<PropertyName>Cidr</PropertyName>
</ListItem>
<ListItem>
<Label>ValidationState</Label>
<PropertyName>ValidationState</PropertyName>
</ListItem>
<ListItem>
<Label>OriginalValidationMessage</Label>
<PropertyName>OriginalValidationMessage</PropertyName>
</ListItem>
<ListItem>
<Label>SignedValidationMessage</Label>
<PropertyName>SignedValidationMessage</PropertyName>
</ListItem>
<ListItem>
<Label>CustomIpPrefixes</Label>
<PropertyName>CustomIpPrefixesText</PropertyName>
</ListItem>
<ListItem>
<Label>Zones</Label>
<PropertyName>Zones</PropertyName>
</ListItem>
</ListItems>
</ListEntry>
</ListEntries>
</ListControl>
</View>
<View>
<Name>Microsoft.Azure.Commands.Network.Models.PSCustomIpPrefix</Name>
<ViewSelectedBy>
<TypeName>Microsoft.Azure.Commands.Network.Models.PSCustomIpPrefix</TypeName>
</ViewSelectedBy>
<ListControl>
<ListEntries>
<ListEntry>
<ListItems>
<ListItem>
<Label>Name</Label>
<PropertyName>Name</PropertyName>
</ListItem>
<ListItem>
<Label>ResourceGroupName</Label>
<PropertyName>ResourceGroupName</PropertyName>
</ListItem>
<ListItem>
<Label>Location</Label>
<PropertyName>Location</PropertyName>
</ListItem>
<ListItem>
<Label>Id</Label>
<PropertyName>Id</PropertyName>
</ListItem>
<ListItem>
<Label>Etag</Label>
<PropertyName>Etag</PropertyName>
</ListItem>
<ListItem>
<Label>ResourceGuid</Label>
<PropertyName>ResourceGuid</PropertyName>
</ListItem>
<ListItem>
<Label>ProvisioningState</Label>
<PropertyName>ProvisioningState</PropertyName>
</ListItem>
<ListItem>
<Label>Tags</Label>
<PropertyName>TagsTable</PropertyName>
</ListItem>
<ListItem>
<Label>Cidr</Label>
<PropertyName>Cidr</PropertyName>
</ListItem>
<ListItem>
<Label>CommissionedState</Label>
<PropertyName>CommissionedState</PropertyName>
</ListItem>
<ListItem>
<Label>MasterCustomIpPrefix</Label>
<PropertyName>MasterCustomIpPrefixText</PropertyName>
</ListItem>
<ListItem>
<Label>Zones</Label>
<PropertyName>Zones</PropertyName>
</ListItem>
</ListItems>
</ListEntry>
</ListEntries>
</ListControl>
</View>
<View>
<Name>Microsoft.Azure.Commands.Network.Models.PSPublicIpPrefix</Name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ public class NewAzurePublicIpPrefixCommand : PublicIpPrefixBaseCmdlet
ValueFromPipelineByPropertyName = true)]
public string[] Zone { get; set; }

[Parameter(
Mandatory = false,
ValueFromPipelineByPropertyName = true,
HelpMessage = "The CustomIpPrefix that this PublicIpPrefix will be associated with")]
public PSCustomIpPrefix CustomIpPrefix { get; set; }

[Parameter(
Mandatory = false,
ValueFromPipelineByPropertyName = true,
Expand Down Expand Up @@ -165,6 +171,8 @@ private PSPublicIpPrefix CreatePublicIpPrefix()
publicIpPrefix.IpTags = this.IpTag?.ToList();
}

publicIpPrefix.CustomIpPrefix = this.CustomIpPrefix;

var theModel = NetworkResourceManagerProfile.Mapper.Map<MNM.PublicIPPrefix>(publicIpPrefix);

theModel.Tags = TagsConversionHelper.CreateTagDictionary(this.Tag, validate: true);
Expand Down

0 comments on commit cac5f46

Please sign in to comment.