/
Program.cs
86 lines (76 loc) · 3.68 KB
/
Program.cs
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
// 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.Fluent;
using Microsoft.Azure.Management.ResourceManager.Fluent;
using Microsoft.Azure.Management.ResourceManager.Fluent.Core;
using Microsoft.Azure.Management.Samples.Common;
using System;
namespace ListVirtualMachineExtensionImages
{
public class Program
{
/**
* List all virtual machine extension image publishers and
* list all virtual machine extension images published by Microsoft.OSTCExtensions, Microsoft.Azure.Extensions
* by browsing through extension image publishers, types, and versions.
*/
public static void RunSample(IAzure azure)
{
//=================================================================
// List all virtual machine extension image publishers and
// list all virtual machine extension images
// published by Microsoft.OSTCExtensions and Microsoft.Azure.Extensions
// y browsing through extension image publishers, types, and versions
var publishers = azure
.VirtualMachineImages
.Publishers
.ListByRegion(Region.USEast);
Utilities.Log("US East data center: printing list of \n"
+ "a) Publishers and\n"
+ "b) virtual machine images published by Microsoft.OSTCExtensions and Microsoft.Azure.Extensions");
Utilities.Log("=======================================================");
Utilities.Log("\n");
foreach (var publisher in publishers)
{
Utilities.Log("Publisher - " + publisher.Name);
if (StringComparer.OrdinalIgnoreCase.Equals(publisher.Name, "Microsoft.OSTCExtensions") ||
StringComparer.OrdinalIgnoreCase.Equals(publisher.Name, "Microsoft.Azure.Extensions"))
{
Utilities.Log("\n\n");
Utilities.Log("=======================================================");
Utilities.Log("Located " + publisher.Name);
Utilities.Log("=======================================================");
Utilities.Log("Printing entries as publisher/type/version");
foreach (var imageType in publisher.ExtensionTypes.List())
{
foreach (var version in imageType.Versions.List())
{
var image = version.GetImage();
Utilities.Log($"Image - {publisher.Name}/{image.TypeName}/{image.VersionName}");
}
}
Utilities.Log("\n\n");
}
}
}
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();
RunSample(azure);
}
catch (Exception ex)
{
Utilities.Log(ex);
}
}
}
}