-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommon.Aci.Control.cs
More file actions
45 lines (37 loc) · 1.25 KB
/
Common.Aci.Control.cs
File metadata and controls
45 lines (37 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
using System.Threading.Tasks;
using Microsoft.Azure.Management.Fluent;
using Microsoft.Azure.Management.ResourceManager.Fluent;
using Microsoft.Azure.Management.ResourceManager.Fluent.Authentication;
namespace X5ff.Aci.Control.Common
{
public class ContainerInstanceControl
{
private readonly IAzure azure;
public ContainerInstanceControl()
{
var credentials = SdkContext.AzureCredentialsFactory.FromSystemAssignedManagedServiceIdentity(MSIResourceType.AppService, AzureEnvironment.AzureGlobalCloud);
this.azure = Azure.Configure().Authenticate(credentials).WithDefaultSubscription();
}
public async Task Start(string name, string resourceGroup)
{
await this.azure.ContainerGroups.StartAsync(resourceGroup, name);
}
public async Task Stop(string name, string resourceGroup)
{
var group = await this.azure.ContainerGroups.GetByResourceGroupAsync(resourceGroup, name);
await group?.StopAsync();
}
public async Task<string?> GetStatus(string name, string resourceGroup)
{
var group = await this.azure.ContainerGroups.GetByResourceGroupAsync(resourceGroup, name);
if (group == null)
{
return null;
}
else
{
return group.State;
}
}
}
}