Skip to content

Commit eaeb84a

Browse files
committed
overload to enable vnets to be returned by location
1 parent ecf9dec commit eaeb84a

File tree

6 files changed

+40
-18
lines changed

6 files changed

+40
-18
lines changed

Elastacloud.AzureManagement.Fluent/Clients/Interfaces/IVirtualNetworkingClient.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ interface IVirtualNetworkingClient
2424
/// </summary>
2525
IEnumerable<VirtualNetworkingUtils.VirtualNetwork> GetAvailableVirtualNetworks();
2626
/// <summary>
27+
/// Gets the virtual networks available in the current subscription
28+
/// </summary>
29+
/// <param name="location">Location of the vnet e.g. North Europe</param>
30+
IEnumerable<VirtualNetworkingUtils.VirtualNetwork> GetAvailableVirtualNetworks(string location);
31+
/// <summary>
2732
/// Creates an empty VNET to add address ranges and subnets to
2833
/// </summary>
2934
string AddSubnetToAddressRange(string networkName, string addressRange, string subnetName);

Elastacloud.AzureManagement.Fluent/Clients/LinuxVirtualMachineClient.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ private void CheckVmDeploymentIsRunning(List<LinuxVirtualMachineProperties> prop
9595
{
9696
// 1. Get the number of vms in the role and create a binary list
9797
var linuxProperties = new Dictionary<string, RoleInstanceStatus>();
98-
properties.ForEach(property => linuxProperties.Add(property.HostName, RoleInstanceStatus.Unknown));
98+
properties.ForEach(property => linuxProperties.Add(property.HostName, RoleInstanceStatus.RoleStateUnknown));
9999
var vmProperties = new LinuxVirtualMachineProperties() {CloudServiceName = properties[0].CloudServiceName};
100100
// 2. Set the value to if the vm is running or not
101101
int index = 0;
@@ -123,10 +123,11 @@ private void CheckVmDeploymentIsRunning(List<LinuxVirtualMachineProperties> prop
123123
linuxProperties[vm.RoleName] = vm.Status;
124124
});
125125
index++;
126-
Task.Delay(TimeSpan.FromSeconds(10)).RunSynchronously();
126+
// TODO: advice from Zak on the best way to use task.delay instead
127+
Thread.Sleep(TimeSpan.FromSeconds(10));
127128
}
128129

129-
if (index == 100)
130+
if (index == 360)
130131
{
131132
throw new FluentManagementException("timed out listening for status changes - check vms are running correctly", "LinuxVirtualMachineClient");
132133
}

Elastacloud.AzureManagement.Fluent/Clients/VirtualNetworkClient.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,28 @@ public VirtualNetworkClient(string subscriptionId, X509Certificate2 managementCe
4141
/// <summary>
4242
/// Gets the available virtual networks in the correct order binding the address ranges to the subnets
4343
/// </summary>
44-
public IEnumerable<VirtualNetworkingUtils.VirtualNetwork> GetAvailableVirtualNetworks()
44+
public IEnumerable<VirtualNetworkingUtils.VirtualNetwork> GetAvailableVirtualNetworks(string location)
4545
{
4646
var command = new ListVirtualNetworksCommand()
4747
{
4848
SubscriptionId = SubscriptionId,
4949
Certificate = ManagementCertificate
5050
};
5151
command.Execute();
52-
return VirtualNetworkingUtils.ConvertVNetToHierarchicalModel(command.VirtualNetworks);
52+
List<VirtualNetworkSite> virtualNetworks = command.VirtualNetworks;
53+
if (location != null)
54+
{
55+
virtualNetworks = command.VirtualNetworks.Where(network => network.Location == location).ToList();
56+
}
57+
58+
return VirtualNetworkingUtils.ConvertVNetToHierarchicalModel(virtualNetworks);
59+
}
60+
/// <summary>
61+
/// Used if all the locations should be returned instead of a single location
62+
/// </summary>
63+
public IEnumerable<VirtualNetworkingUtils.VirtualNetwork> GetAvailableVirtualNetworks()
64+
{
65+
return GetAvailableVirtualNetworks(null);
5366
}
5467

5568
/// <summary>

Elastacloud.AzureManagement.Fluent/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,5 @@
4949

5050
// Make internal interfaces visible to Moq and the testing library
5151
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2"), InternalsVisibleTo("Elastacloud.AzureManagement.Fluent.Tests")]
52-
[assembly: AssemblyVersion("0.5.0.96")]
53-
[assembly: AssemblyFileVersion("0.5.0.96")]
52+
[assembly: AssemblyVersion("0.5.0.97")]
53+
[assembly: AssemblyFileVersion("0.5.0.97")]

Elastacloud.AzureManagement.Fluent/Types/RoleInstanceStatus.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ namespace Elastacloud.AzureManagement.Fluent.Types
1111
public enum RoleInstanceStatus
1212
{
1313
Unknown,
14+
RoleStateUnknown,
1415
CreatingVM,
1516
StartingVM,
1617
CreatingRole,

Elastacloud.FluentManagement.FSTest/VirtualMachines.fsx

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,24 +43,26 @@ let properties = new LinuxVirtualMachineProperties(
4343
AdministratorPassword = "P@ssword761",
4444
HostName = "briskit",
4545
RoleName = "briskit",
46-
CloudServiceName = "briskit1000",
46+
CloudServiceName = "briskit1003",
4747
PublicEndpoints = List<InputEndpoint>([|sshEndpoint|]),
48-
CustomTemplateName = "b39f27a8b8c64d52b05eac6a62ebad85__Ubuntu_DAILY_BUILD-trusty-14_04_1-LTS-amd64-server-20141202.1-en-us-30GB",
49-
DeploymentName = "briskit1000",
50-
StorageAccountName = "clustered",
51-
AvailabilitySet = "clustered",
52-
VirtualNetwork = VirtualNetworkDescriptor(
53-
VirtualNetworkName = "fsnet",
54-
SubnetName = "fred"))
48+
CustomTemplateName = "b39f27a8b8c64d52b05eac6a62ebad85__Ubuntu-14_10-amd64-server-20141204-en-us-30GB",
49+
DeploymentName = "briskit1003",
50+
StorageAccountName = "clustered")//,
51+
//VirtualNetwork = VirtualNetworkDescriptor(
52+
// VirtualNetworkName = "fsnet",
53+
// SubnetName = "fred"))
5554

55+
vmClient.LinuxVirtualMachineStatusEvent.Subscribe(fun vmstatus -> printfn "from %s to %s" (vmstatus.OldStatus.ToString()) (vmstatus.NewStatus.ToString()))
5656
vmClient.CreateNewVirtualMachineDeploymentFromTemplateGallery(
5757
List<LinuxVirtualMachineProperties>([|properties|]),
58-
"briskit1000")
58+
"briskit1003")
5959
// test 1: Ensure that above contains no subnets when it's created and returns the address range + 1 ip
6060
// test 2: Receive events on state changes and ensure readyrole
61-
vmClient.LinuxVirtualMachineStatusEvent.Subscribe(fun vmstatus -> printfn "from %s to %s" (vmstatus.OldStatus.ToString()) (vmstatus.NewStatus.ToString()))
6261
// test 3: When created delete the subnet from the vnet - should generate a subnet busy exception of some sort
6362
let vnClient = VirtualNetworkClient(subscriptionId, (getFromBizsparkPlus subscriptionId))
63+
let all = vnClient.GetAvailableVirtualNetworks()
64+
let we = vnClient.GetAvailableVirtualNetworks("West Europe")
65+
let ne = vnClient.GetAvailableVirtualNetworks("North Europe")
6466
vnClient.AddSubnetToAddressRange("bigbadbeetleborgs", "10.0.0.0/20", "max-1")
65-
vnClient.RemoveSubnet("bigbadbeetleborgs", "max-1")
67+
vnClient.RemoveSubnet("skynet", "cluster")
6668
let images = vmClient.GetCurrentUbuntuImage()

0 commit comments

Comments
 (0)