Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,14 @@ function Test-VirtualMachineProfile

# Network
$ipname = 'hpfip' + ((Get-Random) % 10000);
$ipRefUri1 = "https://test.foo.bar/$ipname";
$ipRefUri = "https://test.foo.bar/$ipname";
$nicName = $ipname + 'nic1';
$publicIPName = $ipname + 'name1';

$p = Add-AzureVMNetworkInterface -VM $p -Id $ipRefUri1;

$ipname = 'hpfip' + ((Get-Random) % 10000);
$ipRefUri2 = "https://test.foo.bar/$ipname";
$p = Add-AzureVMNetworkInterface -VM $p -Id $ipRefUri2;

# Remove all NICs
$p = $p | Remove-AzureVMNetworkInterface
Assert-AreEqual $p.NetworkProfile.NetworkInterfaces.Count 0;

$p = Add-AzureVMNetworkInterface -VM $p -Id $ipRefUri1;
$p = Add-AzureVMNetworkInterface -VM $p -Id $ipRefUri2;
$p = Remove-AzureVMNetworkInterface -VM $p -Id $ipRefUri2;
$p = Add-AzureVMNetworkInterface -VM $p -Id $ipRefUri;

Assert-AreEqual $p.NetworkProfile.NetworkInterfaces.Count 1;
Assert-AreEqual $p.NetworkProfile.NetworkInterfaces[0].ReferenceUri $ipRefUri1;
Assert-AreEqual $p.NetworkProfile.NetworkInterfaces[0].ReferenceUri $ipRefUri;

# Storage
$stoname = 'hpfteststo' + ((Get-Random) % 10000);
Expand Down Expand Up @@ -78,23 +66,6 @@ function Test-VirtualMachineProfile
Assert-AreEqual $p.StorageProfile.DataDisks[1].Lun 1;
Assert-AreEqual $p.StorageProfile.DataDisks[1].VirtualHardDisk.Uri $dataDiskVhdUri2;

# Remove all data disks
$p = $p | Remove-AzureVMDataDisk;
Assert-AreEqual $p.StorageProfile.DataDisks.Count 0;

$p = Add-AzureVMDataDisk -VM $p -Name 'testDataDisk1' -Caching 'ReadOnly' -DiskSizeInGB 10 -Lun 0 -VhdUri $dataDiskVhdUri1 -CreateOption Empty;
$p = Add-AzureVMDataDisk -VM $p -Name 'testDataDisk2' -Caching 'ReadOnly' -DiskSizeInGB 11 -Lun 1 -VhdUri $dataDiskVhdUri2 -CreateOption Empty;

Assert-AreEqual $p.StorageProfile.DataDisks.Count 2;
Assert-AreEqual $p.StorageProfile.DataDisks[0].Caching 'ReadOnly';
Assert-AreEqual $p.StorageProfile.DataDisks[0].DiskSizeGB 10;
Assert-AreEqual $p.StorageProfile.DataDisks[0].Lun 0;
Assert-AreEqual $p.StorageProfile.DataDisks[0].VirtualHardDisk.Uri $dataDiskVhdUri1;
Assert-AreEqual $p.StorageProfile.DataDisks[1].Caching 'ReadOnly';
Assert-AreEqual $p.StorageProfile.DataDisks[1].DiskSizeGB 11;
Assert-AreEqual $p.StorageProfile.DataDisks[1].Lun 1;
Assert-AreEqual $p.StorageProfile.DataDisks[1].VirtualHardDisk.Uri $dataDiskVhdUri2;

# Windows OS
$user = "Foo12";
$password = 'BaR@000' + ((Get-Random) % 10000);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,14 +214,6 @@
<Label>StorageProfile</Label>
<PropertyName>StorageProfileText</PropertyName>
</ListItem>
<ListItem>
<Label>DataDiskNames</Label>
<PropertyName>DataDiskNames</PropertyName>
</ListItem>
<ListItem>
<Label>NetworkInterfaceIds</Label>
<PropertyName>NetworkInterfaceIds</PropertyName>
</ListItem>
</ListItems>
</ListEntry>
</ListEntries>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public string ResourceGroupName
{
get
{
if (string.IsNullOrEmpty(Id)) return null;
Regex r = new Regex(@"(.*?)/resourcegroups/(?<rgname>\S+)/providers/(.*?)", RegexOptions.IgnoreCase);
Match m = r.Match(Id);
return m.Success ? m.Groups["rgname"].Value : null;
Expand Down Expand Up @@ -135,37 +134,5 @@ public string StorageProfileText
{
get { return JsonConvert.SerializeObject(StorageProfile, Formatting.Indented); }
}

[JsonIgnore]
public string [] DataDiskNames
{
get
{
if (this.StorageProfile == null) return null;

var dataDiskNames = new List<string>();
foreach (var disk in StorageProfile.DataDisks)
{
dataDiskNames.Add(disk.Name);
}
return dataDiskNames.ToArray();
}
}

[JsonIgnore]
public string[] NetworkInterfaceIds
{
get
{
if (this.NetworkProfile == null) return null;

var nicIds = new List<string>();
foreach (var nic in NetworkProfile.NetworkInterfaces)
{
nicIds.Add(nic.ReferenceUri);
}
return nicIds.ToArray();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,13 @@ public class RemoveAzureVMDataDiskCommand : AzurePSCmdlet
[ValidateNotNullOrEmpty]
public PSVirtualMachine VM { get; set; }

[Alias("Name")]
[Parameter(
Mandatory = true,
Position = 1,
ValueFromPipelineByPropertyName = true,
HelpMessage = HelpMessages.VMDataDiskName)]
[ValidateNotNullOrEmpty]
public string [] DataDiskNames { get; set; }
public string Name { get; set; }

public override void ExecuteCmdlet()
{
Expand All @@ -55,10 +54,7 @@ public override void ExecuteCmdlet()
{
var disks = storageProfile.DataDisks.ToList();
var comp = StringComparison.OrdinalIgnoreCase;
foreach (var diskName in DataDiskNames)
{
disks.RemoveAll(d => string.Equals(d.Name, diskName, comp));
}
disks.RemoveAll(d => string.Equals(d.Name, this.Name, comp));
storageProfile.DataDisks = disks;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,35 +41,30 @@ public class RemoveAzureVMNetworkInterfaceCommand : AzurePSCmdlet
[ValidateNotNullOrEmpty]
public PSVirtualMachine VM { get; set; }

[Alias("Id", "NicIds")]
[Alias("NicId", "NetworkInterfaceId")]
[Parameter(
Mandatory = true,
Position = 1,
ValueFromPipelineByPropertyName = true,
HelpMessage = HelpMessages.VMNetworkInterfaceID)]
[ValidateNotNullOrEmpty]
public string[] NetworkInterfaceIds { get; set; }
public string Id { get; set; }

public override void ExecuteCmdlet()
{
var networkProfile = this.VM.NetworkProfile;

foreach (var id in this.NetworkInterfaceIds)
if (networkProfile != null && networkProfile.NetworkInterfaces != null && networkProfile.NetworkInterfaces.Any(nic => string.Equals(nic.ReferenceUri, this.Id, StringComparison.OrdinalIgnoreCase)))
{
if (networkProfile != null &&
networkProfile.NetworkInterfaces != null &&
networkProfile.NetworkInterfaces.Any(nic =>
string.Equals(nic.ReferenceUri, id, StringComparison.OrdinalIgnoreCase)))
var nicReference = networkProfile.NetworkInterfaces.First(nic => string.Equals(nic.ReferenceUri, this.Id, StringComparison.OrdinalIgnoreCase));
networkProfile.NetworkInterfaces.Remove(nicReference);

if (!networkProfile.NetworkInterfaces.Any())
{
var nicReference = networkProfile.NetworkInterfaces.First(nic => string.Equals(nic.ReferenceUri, id, StringComparison.OrdinalIgnoreCase));
networkProfile.NetworkInterfaces.Remove(nicReference);
networkProfile = null;
}
}

if (!networkProfile.NetworkInterfaces.Any())
{
networkProfile = null;
}
this.VM.NetworkProfile = networkProfile;

WriteObject(this.VM);
Expand Down