Skip to content

Commit

Permalink
Implementation of azure container instance management APIs (Azure#8)
Browse files Browse the repository at this point in the history
* Add implementation for azure container instance management APIs

(cherry picked from commit cf05917bb7621b0a12fa1c6c2c00340148d9c9a2)

* Updates based on review feedback
  • Loading branch information
milismsft authored and Hovsep committed Sep 20, 2017
1 parent 86d99ca commit 64ca428
Show file tree
Hide file tree
Showing 52 changed files with 7,347 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Fluent.SDK.sln
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Azure.Management.
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Azure.Management.Scheduler.Fluent", "src\ResourceManagement\Scheduler\Microsoft.Azure.Management.Scheduler.Fluent.csproj", "{A49A03EA-43F2-418C-A261-CA72EFE16B31}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Azure.Management.ContainerInstance.Fluent", "src\ResourceManagement\ContainerInstance\Microsoft.Azure.Management.ContainerInstance.Fluent.csproj", "{0F35F73F-C8FD-4F2B-8089-C7205D641EE2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -213,6 +215,10 @@ Global
{A49A03EA-43F2-418C-A261-CA72EFE16B31}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A49A03EA-43F2-418C-A261-CA72EFE16B31}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A49A03EA-43F2-418C-A261-CA72EFE16B31}.Release|Any CPU.Build.0 = Release|Any CPU
{0F35F73F-C8FD-4F2B-8089-C7205D641EE2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0F35F73F-C8FD-4F2B-8089-C7205D641EE2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0F35F73F-C8FD-4F2B-8089-C7205D641EE2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0F35F73F-C8FD-4F2B-8089-C7205D641EE2}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
7 changes: 7 additions & 0 deletions Fluent.Tests.sln
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Azure.Management.
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Azure.Management.Search.Fluent", "src\ResourceManagement\Search\Microsoft.Azure.Management.Search.Fluent.csproj", "{7501A087-BACB-47B8-93C4-0951995D96D6}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Azure.Management.ContainerInstance.Fluent", "src\ResourceManagement\ContainerInstance\Microsoft.Azure.Management.ContainerInstance.Fluent.csproj", "{DB2C0D40-8DC4-4A84-AF40-4946DE7031F8}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -139,6 +141,10 @@ Global
{7501A087-BACB-47B8-93C4-0951995D96D6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7501A087-BACB-47B8-93C4-0951995D96D6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7501A087-BACB-47B8-93C4-0951995D96D6}.Release|Any CPU.Build.0 = Release|Any CPU
{DB2C0D40-8DC4-4A84-AF40-4946DE7031F8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DB2C0D40-8DC4-4A84-AF40-4946DE7031F8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DB2C0D40-8DC4-4A84-AF40-4946DE7031F8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DB2C0D40-8DC4-4A84-AF40-4946DE7031F8}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -163,5 +169,6 @@ Global
{7E31864C-5BB0-4AEB-85E1-C5354898870D} = {6861600A-FFF3-49C3-8A91-7174F754EAED}
{62350028-496C-4668-A877-8B27274DD28C} = {6861600A-FFF3-49C3-8A91-7174F754EAED}
{7501A087-BACB-47B8-93C4-0951995D96D6} = {6861600A-FFF3-49C3-8A91-7174F754EAED}
{DB2C0D40-8DC4-4A84-AF40-4946DE7031F8} = {6861600A-FFF3-49C3-8A91-7174F754EAED}
EndGlobalSection
EndGlobal
10 changes: 10 additions & 0 deletions Tests/Fluent.Tests/Common/TestHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Microsoft.Azure.Management.Batch.Fluent;
using Microsoft.Azure.Management.Cdn.Fluent;
using Microsoft.Azure.Management.Compute.Fluent;
using Microsoft.Azure.Management.ContainerInstance.Fluent;
using Microsoft.Azure.Management.ContainerRegistry.Fluent;
using Microsoft.Azure.Management.CosmosDB.Fluent;
using Microsoft.Azure.Management.Fluent;
Expand Down Expand Up @@ -220,6 +221,15 @@ public static IServiceBusManager CreateServiceBusManager()
.Authenticate(c, c.DefaultSubscriptionId));
}

public static IContainerInstanceManager CreateContainerInstanceManager()
{
return CreateMockedManager(c => ContainerInstanceManager
.Configure()
.WithDelegatingHandlers(GetHandlers())
.WithLogLevel(HttpLoggingDelegatingHandler.Level.BodyAndHeaders)
.Authenticate(c, c.DefaultSubscriptionId));
}

public static IRegistryManager CreateRegistryManager()
{
return CreateMockedManager(c => RegistryManager
Expand Down
107 changes: 107 additions & 0 deletions Tests/Fluent.Tests/ContainerInstance/ContainerInstanceTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

using Azure.Tests;
using Fluent.Tests.Common;
using Microsoft.Azure.Management.ContainerInstance.Fluent;
using Microsoft.Azure.Management.ContainerInstance.Fluent.Models;
using Microsoft.Azure.Management.ResourceManager.Fluent.Core;
using Microsoft.Rest.ClientRuntime.Azure.TestFramework;
using Xunit;

namespace Fluent.Tests
{
public class ContainerInstanceTest
{
[Fact]
public void ContainerRegistryCRD()
{
using (var context = FluentMockContext.Start(GetType().FullName))
{
var rgName = TestUtilities.GenerateName("rgaci");
var cgName = TestUtilities.GenerateName("aci");
var containerInstanceManager = TestHelper.CreateContainerInstanceManager();
var resourceManager = TestHelper.CreateResourceManager();
IContainerGroup containerGroup = null;

try
{
var temp = containerInstanceManager.ContainerGroups.Define(cgName);

containerGroup = containerInstanceManager.ContainerGroups.Define(cgName)
.WithRegion(Region.USEast)
.WithNewResourceGroup(rgName)
.WithLinux()
.WithPublicImageRegistryOnly()
.WithoutVolume()
.DefineContainerInstance("tomcat")
.WithImage("tomcat")
.WithExternalTcpPort(8080)
.WithCpuCoreCount(1)
.Attach()
.DefineContainerInstance("nginx")
.WithImage("nginx")
.WithExternalTcpPort(80)
.Attach()
.WithTag("tag1", "value1")
.Create();

Assert.Equal(cgName, containerGroup.Name);
Assert.Equal("Linux", containerGroup.OSType.Value);
Assert.Equal(0, containerGroup.ImageRegistryServers.Count);
Assert.Equal(0, containerGroup.Volumes.Count);
Assert.NotNull(containerGroup.IPAddress);
Assert.True(containerGroup.IsIPAddressPublic);
Assert.Equal(2, containerGroup.ExternalTcpPorts.Length);
Assert.Equal(2, containerGroup.ExternalPorts.Count);
Assert.Empty(containerGroup.ExternalUdpPorts);
Assert.Equal(8080, containerGroup.ExternalTcpPorts[0]);
Assert.Equal(80, containerGroup.ExternalTcpPorts[1]);
Assert.Equal(2, containerGroup.Containers.Count);
Container tomcatContainer = containerGroup.Containers["tomcat"];
Assert.NotNull(tomcatContainer);
Container nginxContainer = containerGroup.Containers["nginx"];
Assert.NotNull(nginxContainer);
Assert.Equal("tomcat", tomcatContainer.Name);
Assert.Equal("tomcat", tomcatContainer.Image);
Assert.Equal(1.0, tomcatContainer.Resources.Requests.Cpu);
Assert.Equal(1.5, tomcatContainer.Resources.Requests.MemoryInGB);
Assert.Equal(1, tomcatContainer.Ports.Count);
Assert.Equal(8080, tomcatContainer.Ports[0].Port);
Assert.Null(tomcatContainer.VolumeMounts);
Assert.Null(tomcatContainer.Command);
Assert.NotNull(tomcatContainer.EnvironmentVariables);
Assert.Empty(tomcatContainer.EnvironmentVariables);
Assert.Equal("nginx", nginxContainer.Name);
Assert.Equal("nginx", nginxContainer.Image);
Assert.Equal(1.0, nginxContainer.Resources.Requests.Cpu);
Assert.Equal(1.5, nginxContainer.Resources.Requests.MemoryInGB);
Assert.Equal(1, nginxContainer.Ports.Count);
Assert.Equal(80, nginxContainer.Ports[0].Port);
Assert.Null(nginxContainer.VolumeMounts);
Assert.Null(nginxContainer.Command);
Assert.NotNull(nginxContainer.EnvironmentVariables);
Assert.Empty(nginxContainer.EnvironmentVariables);
Assert.True(containerGroup.Tags.ContainsKey("tag1"));

IContainerGroup containerGroup2 = containerInstanceManager.ContainerGroups.GetByResourceGroup(rgName, cgName);

var containerGroupList = containerInstanceManager.ContainerGroups.ListByResourceGroup(rgName);

containerGroup.Refresh();

containerInstanceManager.ContainerGroups.DeleteById(containerGroup.Id);
}
finally
{
try
{
resourceManager.ResourceGroups.BeginDeleteByName(rgName);
}
catch { }
}

}
}
}
}
Loading

0 comments on commit 64ca428

Please sign in to comment.