@@ -45,6 +45,45 @@ public static async Task<ImageAndOsType> UpdateImageAndOsTypeAsync(
45
45
return imageAndOsType ;
46
46
}
47
47
48
+ var compute = client . GetClient < ComputeManagementClient > ( ) ;
49
+
50
+ if ( imageName . Contains ( ':' ) )
51
+ {
52
+ if ( location == null )
53
+ {
54
+ return null ;
55
+ }
56
+
57
+ var imageArray = imageName . Split ( ':' ) ;
58
+ if ( imageArray . Length != 4 )
59
+ {
60
+ throw new InvalidOperationException (
61
+ string . Format ( Resources . InvalidImageName , imageName ) ) ;
62
+ }
63
+ var image = new ImageReference
64
+ {
65
+ Publisher = imageArray [ 0 ] ,
66
+ Offer = imageArray [ 1 ] ,
67
+ Sku = imageArray [ 2 ] ,
68
+ Version = imageArray [ 3 ] ,
69
+ } ;
70
+
71
+ if ( image . Version . ToLower ( ) == "latest" )
72
+ {
73
+ var images = await compute . VirtualMachineImages . ListAsync (
74
+ location , image . Publisher , image . Offer , image . Sku ) ;
75
+ // According to Compute API:
76
+ // "The allowed formats are Major.Minor.Build or 'latest'.
77
+ // Major, Minor, and Build are decimal numbers."
78
+ image . Version = images
79
+ . Select ( i => ImageVersion . Parse ( i . Name ) )
80
+ . Aggregate ( ( a , b ) => a . CompareTo ( b ) < 0 ? b : a )
81
+ . ToString ( ) ;
82
+ }
83
+ var imageModel = await compute . VirtualMachineImages . GetAsync (
84
+ location , image . Publisher , image . Offer , image . Sku , image . Version ) ;
85
+ return new ImageAndOsType ( imageModel . OsDiskImage . OperatingSystem , image ) ;
86
+ }
48
87
if ( imageName . Contains ( "/" ) )
49
88
{
50
89
var imageArray = imageName . Split ( '/' ) ;
@@ -69,16 +108,15 @@ public static async Task<ImageAndOsType> UpdateImageAndOsTypeAsync(
69
108
var resourceName = imageArray [ 8 ] ;
70
109
71
110
if ( empty != string . Empty
72
- || subscriptions != SdkEngine . Subscriptions
111
+ || subscriptions != SdkEngine . Subscriptions
73
112
|| resourceGroups != ResourceType . ResourceGroups
74
113
|| providers != EntityConfigExtensions . Providers
75
114
|| providerNamespace != ComputeStrategy . Namespace
76
115
|| provider != "images" )
77
116
{
78
- throw new ArgumentException ( "Invalid image resource id '" + imageName + "'." ) ;
117
+ throw new ArgumentException ( "Invalid image resource id '" + imageName + "'." ) ;
79
118
}
80
119
81
- var compute = client . GetClient < ComputeManagementClient > ( ) ;
82
120
if ( compute . SubscriptionId != subscriptionId )
83
121
{
84
122
throw new ArgumentException ( "The image subscription doesn't match the current subscription." ) ;
@@ -90,47 +128,8 @@ public static async Task<ImageAndOsType> UpdateImageAndOsTypeAsync(
90
128
localImage . StorageProfile . OsDisk . OsType ,
91
129
new ImageReference { Id = localImage . Id } ) ;
92
130
}
93
- else if ( imageName . Contains ( ':' ) )
94
- {
95
- if ( location == null )
96
- {
97
- return null ;
98
- }
99
-
100
- var imageArray = imageName . Split ( ':' ) ;
101
- if ( imageArray . Length != 4 )
102
- {
103
- throw new InvalidOperationException (
104
- string . Format ( Resources . InvalidImageName , imageName ) ) ;
105
- }
106
- var image = new ImageReference
107
- {
108
- Publisher = imageArray [ 0 ] ,
109
- Offer = imageArray [ 1 ] ,
110
- Sku = imageArray [ 2 ] ,
111
- Version = imageArray [ 3 ] ,
112
- } ;
113
- var compute = client . GetClient < ComputeManagementClient > ( ) ;
114
- if ( image . Version . ToLower ( ) == "latest" )
115
- {
116
- var images = await compute . VirtualMachineImages . ListAsync (
117
- location , image . Publisher , image . Offer , image . Sku ) ;
118
- // According to Compute API:
119
- // "The allowed formats are Major.Minor.Build or 'latest'.
120
- // Major, Minor, and Build are decimal numbers."
121
- image . Version = images
122
- . Select ( i => ImageVersion . Parse ( i . Name ) )
123
- . Aggregate ( ( a , b ) => a . CompareTo ( b ) < 0 ? b : a )
124
- . ToString ( ) ;
125
- }
126
- var imageModel = await compute . VirtualMachineImages . GetAsync (
127
- location , image . Publisher , image . Offer , image . Sku , image . Version ) ;
128
- return new ImageAndOsType ( imageModel . OsDiskImage . OperatingSystem , image ) ;
129
- }
130
131
else
131
132
{
132
- var compute = client . GetClient < ComputeManagementClient > ( ) ;
133
-
134
133
try
135
134
{
136
135
var localImage = await compute . Images . GetAsync ( resourceGroupName , imageName ) ;
0 commit comments