This repository was archived by the owner on Dec 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
116 lines (102 loc) · 5.17 KB
/
Program.cs
File metadata and controls
116 lines (102 loc) · 5.17 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
using Microsoft.Azure.Management.ContainerService.Fluent;
using Microsoft.Azure.Management.ContainerService.Fluent.Models;
using Microsoft.Azure.Management.Fluent;
using Microsoft.Azure.Management.ResourceManager.Fluent;
using Microsoft.Azure.Management.ResourceManager.Fluent.Core;
using Microsoft.Azure.Management.Samples.Common;
using System;
namespace ManageContainerServiceWithDockerSwarmOrchestrator
{
public class Program
{
/**
* An Azure Container Services sample for managing a container service with Docker Swarm orchestration.
* - Create an Azure Container Service with Docker Swarm orchestrator
* - Update the number of agent virtual machines in an Azure Container Service
*/
public static void RunSample(IAzure azure)
{
string rgName = SdkContext.RandomResourceName("rgACS", 15);
string acsName = SdkContext.RandomResourceName("acssample", 30);
Region region = Region.USEast;
string rootUserName = "acsuser";
string sshPublicKey = // replace with a real SSH public key
"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCyhPdNuJUmTeLsaZL83vARuSVlN5qbKs7j"
+ "Cm723fqH85rIRQHgwEUXJbENEgZT0cXEgz4h36bQLMYT3/30fRnxYl8U6gRn27zFiMwaDstOjc9EofStODbiHx9A"
+ "Y1XYStjegdf+LNa5tmRv8dZEdj47XDxosSG3JKHpSuf0fXr4u7NjgAxdYOxyMSPAEcfXQctA+ybHkGDLdjLHT7q5C"
+ "4RXlQT7S9v5z532C3KuUSQW7n3QBP3xw/bC8aKcJafwZUYjYnw7owkBnv4TsZVva2le7maYkrtLH6w+XbhfHY4WwK"
+ "Y2Xxl1TxSGkb8tDsa6XgTmGfAKcDpnIe0DASJD8wFF dotnet.sample@azure.com";
try
{
//=============================================================
// Create an Azure Container Service with Docker Swarm orchestration
Utilities.Log("Creating an Azure Container Service with Docker Swarm ochestration and one agent (virtual machine)");
IContainerService azureContainerService = azure.ContainerServices.Define(acsName)
.WithRegion(region)
.WithNewResourceGroup(rgName)
.WithSwarmOrchestration()
.WithLinux()
.WithRootUsername(rootUserName)
.WithSshKey(sshPublicKey)
.WithMasterNodeCount(ContainerServiceMasterProfileCount.MIN)
.DefineAgentPool("agentpool")
.WithVirtualMachineCount(1)
.WithVirtualMachineSize(ContainerServiceVMSizeTypes.StandardD1V2)
.WithDnsPrefix("dns-ap-" + acsName)
.Attach()
.WithMasterDnsPrefix("dns-" + acsName)
.Create();
Utilities.Log("Created Azure Container Service: " + azureContainerService.Id);
Utilities.Print(azureContainerService);
//=============================================================
// Update a Docker Swarm Azure Container Service with two agents (virtual machines)
Utilities.Log("Updating a Docker Swarm Azure Container Service with two agents (virtual machines)");
azureContainerService.Update()
.WithAgentVirtualMachineCount(2)
.Apply();
Utilities.Log("Updated Azure Container Service: " + azureContainerService.Id);
Utilities.Print(azureContainerService);
}
finally
{
try
{
Utilities.Log("Deleting Resource Group: " + rgName);
azure.ResourceGroups.BeginDeleteByName(rgName);
Utilities.Log("Deleted Resource Group: " + rgName);
}
catch (NullReferenceException)
{
Utilities.Log("Did not create any resources in Azure. No clean up is necessary");
}
catch (Exception g)
{
Utilities.Log(g);
}
}
}
public static void Main(string[] args)
{
try
{
//=============================================================
// Authenticate
var credentials = SdkContext.AzureCredentialsFactory.FromFile(Environment.GetEnvironmentVariable("AZURE_AUTH_LOCATION"));
var azure = Azure
.Configure()
.WithLogLevel(HttpLoggingDelegatingHandler.Level.Basic)
.Authenticate(credentials)
.WithDefaultSubscription();
// Print selected subscription
Utilities.Log("Selected subscription: " + azure.SubscriptionId);
RunSample(azure);
}
catch (Exception ex)
{
Utilities.Log(ex);
}
}
}
}