Skip to content

Commit 02d848b

Browse files
updated validation
1 parent 0139426 commit 02d848b

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

src/Compute/Compute/VirtualMachine/Operation/NewAzureVMCommand.cs

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1138,26 +1138,31 @@ private void cleanUp()
11381138

11391139
private void validate()
11401140
{
1141-
if (this.GenerateSshKey.IsPresent && !this.IsParameterBound(c => c.SshKeyName))
1141+
if (this.IsParameterBound(c => c.SshKeyName))
11421142
{
1143-
throw new Exception("Please provide parameter '-SshKeyName' to be used with '-GenerateSshKey'");
1144-
}
1143+
if (this.ParameterSetName == "DefaultParameterSet" && !IsLinuxOs())
1144+
{
1145+
throw new Exception("Parameters '-SshKeyName' and '-GenerateSshKey' are only allowed with Linux VMs");
1146+
}
11451147

1146-
if (this.ParameterSetName == "DefaultParameterSet" && !IsLinuxOs())
1147-
{
1148-
throw new Exception("Parameters '-SshKeyName' and '-GenerateSshKey' are only allowed with Linux VMs");
1148+
if (this.ParameterSetName == "SimpleParameterSet")
1149+
{
1150+
var client = new Client(DefaultProfile.DefaultContext);
1151+
ImageAndOsType ImageAndOsType = client.UpdateImageAndOsTypeAsync(
1152+
null, this.ResourceGroupName, this.Image, "").Result;
1153+
if (ImageAndOsType?.OsType != OperatingSystemTypes.Linux)
1154+
{
1155+
throw new Exception("Parameters '-SshKeyName' and '-GenerateSshKey' are only allowed with Linux VMs");
1156+
}
1157+
}
11491158
}
1150-
1151-
if (this.ParameterSetName == "SimpleParameterSet")
1159+
else
11521160
{
1153-
var client = new Client(DefaultProfile.DefaultContext);
1154-
ImageAndOsType ImageAndOsType = client.UpdateImageAndOsTypeAsync(
1155-
null, this.ResourceGroupName, this.Image, "").Result;
1156-
if (ImageAndOsType?.OsType != OperatingSystemTypes.Linux)
1161+
if (this.GenerateSshKey.IsPresent)
11571162
{
1158-
throw new Exception("Parameters '-SshKeyName' and '-GenerateSshKey' are only allowed with Linux VMs");
1163+
throw new Exception("Please provide parameter '-SshKeyName' to be used with '-GenerateSshKey'");
11591164
}
1160-
}
1165+
}
11611166
}
11621167
}
11631168
}

0 commit comments

Comments
 (0)