Skip to content

Commit e1e3da1

Browse files
author
Ed Munoz
committed
Add GetDeploymentBySlot for networking cmdlets
1 parent 2e9241d commit e1e3da1

File tree

2 files changed

+54
-10
lines changed

2 files changed

+54
-10
lines changed

src/ServiceManagement/Network/Commands.Network/Commands.Network.csproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<PropertyGroup>
44
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -199,6 +199,8 @@
199199
<Compile Include="NetworkSecurityGroup\Utilities\NetworkSecurityGroupConfigurationBaseCmdlet.cs" />
200200
<Compile Include="..\..\Compute\Commands.ServiceManagement\Model\IPersistentVM.cs" />
201201
<Compile Include="..\..\Compute\Commands.ServiceManagement\Model\PersistentVM.cs" />
202+
<Compile Include="..\..\Compute\Commands.ServiceManagement\Model\PersistentVMRoleContext.cs" />
203+
<Compile Include="..\..\Compute\Commands.ServiceManagement\Model\ServiceOperationContext.cs" />
202204
<Compile Include="Properties\Resources.Designer.cs">
203205
<AutoGen>True</AutoGen>
204206
<DesignTime>True</DesignTime>

src/ServiceManagement/Network/Commands.Network/NetworkClient.cs

Lines changed: 51 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,27 @@
1414

1515
namespace Microsoft.Azure.Commands.Network
1616
{
17+
using Gateway.Model;
18+
using Hyak.Common;
19+
using Microsoft.Azure.Common.Authentication;
20+
using Microsoft.Azure.Common.Authentication.Models;
21+
using Microsoft.WindowsAzure.Commands.ServiceManagement.Model;
22+
using Microsoft.WindowsAzure.Management.Compute;
23+
using NetworkSecurityGroup.Model;
24+
using Routes.Model;
1725
using System;
1826
using System.Collections.Generic;
1927
using System.Linq;
2028
using System.Management.Automation;
21-
using Gateway.Model;
22-
using NetworkSecurityGroup.Model;
23-
using Routes.Model;
29+
using System.Security.Cryptography.X509Certificates;
2430
using WindowsAzure.Commands.Common.Storage;
2531
using WindowsAzure.Commands.Utilities.Common;
2632
using WindowsAzure.Management;
2733
using WindowsAzure.Management.Network;
2834
using WindowsAzure.Management.Network.Models;
2935
using WindowsAzure.Storage.Auth;
30-
using Microsoft.Azure.Common.Authentication.Models;
31-
using Microsoft.Azure.Common.Authentication;
32-
using Hyak.Common;
33-
using System.Security.Cryptography.X509Certificates;
34-
using PowerShellAppGwModel = ApplicationGateway.Model;
35-
using Microsoft.WindowsAzure.Management.Compute;
3636
using ComputeModels = Microsoft.WindowsAzure.Management.Compute.Models;
37+
using PowerShellAppGwModel = ApplicationGateway.Model;
3738

3839
public class NetworkClient
3940
{
@@ -836,5 +837,46 @@ public void SetNetworkSecurityGroupForSubnet(string networkSecurityGroupName, st
836837

837838
client.NetworkSecurityGroups.AddToSubnet(virtualNetworkName, subnetName, parameters);
838839
}
840+
841+
public string GetDeploymentBySlot(string serviceName, string slot)
842+
{
843+
if (string.IsNullOrEmpty(serviceName))
844+
{
845+
throw new ArgumentNullException(serviceName);
846+
}
847+
848+
if (string.IsNullOrEmpty(slot))
849+
{
850+
throw new ArgumentNullException(slot);
851+
}
852+
853+
var slotType = (ComputeModels.DeploymentSlot)Enum.Parse(typeof(ComputeModels.DeploymentSlot), slot, true);
854+
855+
return this.computeClient.Deployments.GetBySlot(
856+
serviceName,
857+
slotType).Name;
858+
}
859+
860+
public string GetDeploymentName(IPersistentVM vm, string slot, string serviceName)
861+
{
862+
string deploymentName = null;
863+
var vmRoleContext = vm as PersistentVMRoleContext;
864+
if (vmRoleContext != null)
865+
{
866+
deploymentName = vmRoleContext.DeploymentName;
867+
}
868+
869+
if (string.IsNullOrEmpty(slot) && string.IsNullOrEmpty(deploymentName))
870+
{
871+
slot = DeploymentSlotType.Production;
872+
}
873+
874+
if (string.IsNullOrEmpty(deploymentName))
875+
{
876+
deploymentName = this.GetDeploymentBySlot(serviceName, slot);
877+
}
878+
879+
return deploymentName;
880+
}
839881
}
840882
}

0 commit comments

Comments
 (0)