@@ -53,9 +53,18 @@ public class SetAzureVMDataDiskCommand : AzurePSCmdlet
53
53
[ ValidateNotNullOrEmpty ]
54
54
public string Name { get ; set ; }
55
55
56
+ [ Parameter (
57
+ Mandatory = true ,
58
+ Position = 1 ,
59
+ ParameterSetName = LunParameterSet ,
60
+ ValueFromPipelineByPropertyName = true ,
61
+ HelpMessage = HelpMessages . VMDataDiskLun ) ]
62
+ [ ValidateNotNullOrEmpty ]
63
+ public int ? Lun { get ; set ; }
64
+
56
65
[ Parameter (
57
66
Mandatory = false ,
58
- Position = 3 ,
67
+ Position = 2 ,
59
68
ValueFromPipelineByPropertyName = true ,
60
69
HelpMessage = HelpMessages . VMDataDiskCaching ) ]
61
70
[ ValidateNotNullOrEmpty ]
@@ -64,33 +73,19 @@ public class SetAzureVMDataDiskCommand : AzurePSCmdlet
64
73
65
74
[ Parameter (
66
75
Mandatory = false ,
67
- Position = 4 ,
76
+ Position = 3 ,
68
77
ValueFromPipelineByPropertyName = true ,
69
78
HelpMessage = HelpMessages . VMDataDiskSizeInGB ) ]
70
79
[ AllowNull ]
71
80
public int ? DiskSizeInGB { get ; set ; }
72
81
73
- [ Parameter (
74
- Mandatory = true ,
75
- Position = 5 ,
76
- ParameterSetName = LunParameterSet ,
77
- ValueFromPipelineByPropertyName = true ,
78
- HelpMessage = HelpMessages . VMDataDiskLun ) ]
79
- [ ValidateNotNullOrEmpty ]
80
- public int ? Lun { get ; set ; }
81
-
82
82
public override void ExecuteCmdlet ( )
83
83
{
84
84
var storageProfile = this . VM . StorageProfile ;
85
85
86
- if ( storageProfile == null )
86
+ if ( storageProfile == null || storageProfile . DataDisks == null )
87
87
{
88
- storageProfile = new StorageProfile ( ) ;
89
- }
90
-
91
- if ( storageProfile . DataDisks == null )
92
- {
93
- storageProfile . DataDisks = new List < DataDisk > ( ) ;
88
+ ThrowDataDiskNotExistError ( ) ;
94
89
}
95
90
96
91
var dataDisk = ( this . ParameterSetName . Equals ( LunParameterSet ) )
@@ -99,15 +94,7 @@ public override void ExecuteCmdlet()
99
94
100
95
if ( dataDisk == null )
101
96
{
102
- var missingDisk = ( this . ParameterSetName . Equals ( LunParameterSet ) )
103
- ? string . Format ( "LUN # {0}" , this . Lun )
104
- : "Name: " + this . Name ;
105
- ThrowTerminatingError (
106
- new ErrorRecord (
107
- new InvalidOperationException ( string . Format ( CultureInfo . InvariantCulture , Properties . Resources . DataDiskNotAssignedForVM , missingDisk ) ) ,
108
- string . Empty ,
109
- ErrorCategory . InvalidData ,
110
- null ) ) ;
97
+ ThrowDataDiskNotExistError ( ) ;
111
98
}
112
99
else
113
100
{
@@ -125,5 +112,20 @@ public override void ExecuteCmdlet()
125
112
126
113
WriteObject ( this . VM ) ;
127
114
}
115
+
116
+ private void ThrowDataDiskNotExistError ( )
117
+ {
118
+ var missingDisk = ( this . ParameterSetName . Equals ( LunParameterSet ) )
119
+ ? string . Format ( "LUN # {0}" , this . Lun )
120
+ : "Name: " + this . Name ;
121
+
122
+ ThrowTerminatingError
123
+ ( new ErrorRecord (
124
+ new InvalidOperationException ( string . Format ( CultureInfo . InvariantCulture ,
125
+ Properties . Resources . DataDiskNotAssignedForVM , missingDisk ) ) ,
126
+ string . Empty ,
127
+ ErrorCategory . InvalidData ,
128
+ null ) ) ;
129
+ }
128
130
}
129
131
}
0 commit comments