13
13
// ----------------------------------------------------------------------------------
14
14
15
15
using Microsoft . Azure . Management . Compute . Models ;
16
- using System ;
17
16
using System . Collections . Generic ;
18
17
using System . Linq ;
18
+ using System . Text . RegularExpressions ;
19
19
20
20
namespace Microsoft . Azure . Commands . Compute . Models
21
21
{
@@ -41,7 +41,9 @@ public string VMSize
41
41
}
42
42
43
43
public IDictionary < string , string > Tags { get ; set ; }
44
+
44
45
public string AvailabilitySetId { get ; set ; }
46
+
45
47
public string ProvisioningState { get ; set ; }
46
48
47
49
public string OSConfiguration
@@ -70,16 +72,29 @@ public string SourceImageId
70
72
}
71
73
}
72
74
73
- public string OSDisk
75
+ public ImageReference ImageReference
74
76
{
75
77
get
76
78
{
77
- if ( this . StorageProfile != null && this . StorageProfile . OSDisk != null )
79
+ if ( this . StorageProfile != null )
80
+ {
81
+ return this . StorageProfile . ImageReference ;
82
+ }
83
+
84
+ return null ;
85
+ }
86
+ }
87
+
88
+ public OSDisk OSDisk
89
+ {
90
+ get
91
+ {
92
+ if ( this . StorageProfile != null )
78
93
{
79
- return this . StorageProfile . OSDisk . Name ;
94
+ return this . StorageProfile . OSDisk ;
80
95
}
81
96
82
- return string . Empty ;
97
+ return null ;
83
98
}
84
99
}
85
100
@@ -111,15 +126,19 @@ public IList<string> NetworkInterfaces
111
126
112
127
public IList < VirtualMachineExtension > Extensions { get ; set ; }
113
128
114
- public VirtualMachineInstanceView Status { get ; set ; }
115
-
116
129
public HardwareProfile HardwareProfile { get ; set ; }
117
130
118
131
public NetworkProfile NetworkProfile { get ; set ; }
119
132
120
133
public OSProfile OSProfile { get ; set ; }
121
134
122
135
public StorageProfile StorageProfile { get ; set ; }
136
+
137
+ public VirtualMachineInstanceView InstanceView { get ; set ; }
138
+
139
+ public Plan Plan { get ; set ; }
140
+
141
+ public string Id { get ; set ; }
123
142
}
124
143
125
144
public static class PSVirtualMachineConversions
@@ -136,28 +155,33 @@ public static PSVirtualMachine ToPSVirtualMachine(this VirtualMachineGetResponse
136
155
137
156
public static PSVirtualMachine ToPSVirtualMachine ( this VirtualMachine virtualMachine , string rgName = null )
138
157
{
158
+ if ( string . IsNullOrEmpty ( rgName ) )
159
+ {
160
+ bool parsed = TryParseResourceGroupName ( virtualMachine . Id , out rgName ) ;
161
+ }
162
+
139
163
PSVirtualMachine result = new PSVirtualMachine
140
164
{
141
165
ResourceGroupName = rgName ,
142
- Name = virtualMachine == null ? null : virtualMachine . Name ,
143
- Location = virtualMachine == null ? null : virtualMachine . Location ,
166
+ Id = virtualMachine . Id ,
167
+ Name = virtualMachine . Name ,
168
+ Location = virtualMachine . Location ,
144
169
ProvisioningState = virtualMachine . ProvisioningState ,
145
- Tags = virtualMachine . Tags ,
146
- Extensions = virtualMachine . Extensions ,
147
- Status = null , // TODO: VM response does not return Status info yet
170
+ Tags = virtualMachine . Tags ,
171
+ Extensions = virtualMachine . Extensions ,
172
+ InstanceView = virtualMachine . InstanceView ,
173
+ Plan = virtualMachine . Plan ,
174
+ OSProfile = virtualMachine . OSProfile ,
175
+ HardwareProfile = virtualMachine . HardwareProfile ,
176
+ StorageProfile = virtualMachine . StorageProfile ,
177
+ NetworkProfile = virtualMachine . NetworkProfile ,
148
178
} ;
149
179
150
- var asetRef = virtualMachine . AvailabilitySetReference ;
151
- if ( asetRef != null )
180
+ if ( virtualMachine . AvailabilitySetReference != null )
152
181
{
153
182
result . AvailabilitySetId = virtualMachine . AvailabilitySetReference . ReferenceUri ;
154
183
}
155
184
156
- result . OSProfile = virtualMachine . OSProfile ;
157
- result . HardwareProfile = virtualMachine . HardwareProfile ;
158
- result . StorageProfile = virtualMachine . StorageProfile ;
159
- result . NetworkProfile = virtualMachine . NetworkProfile ;
160
-
161
185
return result ;
162
186
}
163
187
@@ -176,5 +200,25 @@ public static List<PSVirtualMachine> ToPSVirtualMachineList(this VirtualMachineL
176
200
177
201
return results ;
178
202
}
203
+
204
+ private static bool TryParseResourceGroupName ( string virtualMachineId , out string rgName )
205
+ {
206
+ const string group = "rgname" ;
207
+ const string pattern = @"(.*?)/resourcegroups/(?<" + group + @">\S+)/providers/Microsoft.Compute/virtualMachines/(.*?)" ;
208
+
209
+ Regex r = new Regex ( pattern , RegexOptions . IgnoreCase ) ;
210
+ Match m = r . Match ( virtualMachineId ) ;
211
+
212
+ if ( m . Success )
213
+ {
214
+ rgName = m . Groups [ group ] . Value ;
215
+ return true ;
216
+ }
217
+ else
218
+ {
219
+ rgName = null ;
220
+ return false ;
221
+ }
222
+ }
179
223
}
180
224
}
0 commit comments