Example #1
0
        public async Task <Network> CreateNetwork(NetworkDefinition definition)
        {
            var network = await _networkingService.CreateNetworkAsync(definition);

            Register(network);
            return(network);
        }
 /// <inheritdoc cref="NetworkingApiBuilder.UpdateNetworkAsync" />
 public Task<Network> UpdateNetworkAsync(Identifier networkId, NetworkDefinition network, CancellationToken cancellationToken = default(CancellationToken))
 {
     return _networkingApiBuilder
         .UpdateNetworkAsync(networkId, network, cancellationToken)
         .SendAsync()
         .ReceiveJson<Network>();
 }
 /// <inheritdoc cref="NetworkingApiBuilder.UpdateNetworkAsync" />
 public Task <Network> UpdateNetworkAsync(Identifier networkId, NetworkDefinition network, CancellationToken cancellationToken = default(CancellationToken))
 {
     return(_networkingApiBuilder
            .UpdateNetworkAsync(networkId, network, cancellationToken)
            .SendAsync()
            .ReceiveJson <Network>());
 }
 /// <inheritdoc cref="NetworkingApiBuilder.CreateNetworkAsync" />
 public Task<Network> CreateNetworkAsync(NetworkDefinition network, CancellationToken cancellationToken = default(CancellationToken))
 {
     return _networkingApiBuilder
         .CreateNetworkAsync(network, cancellationToken)
         .SendAsync()
         .ReceiveJson<Network>();
 }
 /// <inheritdoc cref="NetworkingApiBuilder.CreateNetworkAsync" />
 public Task <Network> CreateNetworkAsync(NetworkDefinition network, CancellationToken cancellationToken = default(CancellationToken))
 {
     return(_networkingApiBuilder
            .CreateNetworkAsync(network, cancellationToken)
            .SendAsync()
            .ReceiveJson <Network>());
 }
    public async Task Run(string identityEndpoint, string username, string password, string project, string region)
    {
        // Configure authentication
        var user = new CloudIdentityWithProject
        {
            Username = username,
            Password = password,
            ProjectName = project
        };
        var identity = new OpenStackIdentityProvider(new Uri(identityEndpoint), user);
        var networking = new NetworkingService(identity, region);

        Console.WriteLine("Creating Sample Network... ");
        var networkDefinition = new NetworkDefinition {Name = "Sample"};
        var sampleNetwork = await networking.CreateNetworkAsync(networkDefinition);

        Console.WriteLine("Adding a subnet to Sample Network...");
        var subnetDefinition = new SubnetCreateDefinition(sampleNetwork.Id, IPVersion.IPv4, "192.0.2.0/24")
        {
            Name = "Sample"
        };
        var sampleSubnet = await networking.CreateSubnetAsync(subnetDefinition);

        Console.WriteLine("Attaching a port to Sample Network...");
        var portDefinition = new PortCreateDefinition(sampleNetwork.Id)
        {
            Name = "Sample"
        };
        var samplePort = await networking.CreatePortAsync(portDefinition);

        Console.WriteLine("Listing Networks...");
        var networks = await networking.ListNetworksAsync();
        foreach (Network network in networks)
        {
            Console.WriteLine($"{network.Id}\t\t\t{network.Name}");
        }

        Console.WriteLine();
        Console.WriteLine("Sample Network Information:");
        Console.WriteLine();
        Console.WriteLine($"Network Id: {sampleNetwork.Id}");
        Console.WriteLine($"Network Name: {sampleNetwork.Name}");
        Console.WriteLine($"Network Status: {sampleNetwork.Status}");
        Console.WriteLine();
        Console.WriteLine($"Subnet Id: {sampleSubnet.Id}");
        Console.WriteLine($"Subnet Name: {sampleSubnet.Name}");
        Console.WriteLine($"Subnet IPs: {sampleSubnet.AllocationPools.First().Start} - {sampleSubnet.AllocationPools.First().End}");
        Console.WriteLine();
        Console.WriteLine($"Port Id: {samplePort.Id}");
        Console.WriteLine($"Port Name: {samplePort.Name}");
        Console.WriteLine($"Port Address: {samplePort.MACAddress}");
        Console.WriteLine($"Port Status: {samplePort.Status}");
        Console.WriteLine();

        Console.WriteLine("Deleting Sample Network...");
        await networking.DeletePortAsync(samplePort.Id);
        await networking.DeleteNetworkAsync(sampleNetwork.Id);
    }
        public void CreateNetwork()
        {
            using (var httpTest = new HttpTest())
            {
                Identifier networkId = Guid.NewGuid();
                httpTest.RespondWithJson(new Network{Id = networkId});

                var definition = new NetworkDefinition();
                var network = _networkingService.CreateNetwork(definition);

                httpTest.ShouldHaveCalled("*/networks");
                Assert.NotNull(network);
                Assert.Equal(networkId, network.Id);
            }
        }
        public async Task UpdateNetworkTest()
        {
            Network network = await _testData.CreateNetwork();

            var networkUpdate = new NetworkDefinition
            {
                Name = string.Format("{0}-updated", network.Name)
            };

            Trace.WriteLine("Updating the network...");
            network = await _networkingService.UpdateNetworkAsync(network.Id, networkUpdate);

            Trace.WriteLine("Verifying network was updated as requested...");
            Assert.NotNull(network);
            Assert.Equal(networkUpdate.Name, network.Name);
        }
        public async Task UpdateNetworkTest()
        {
            Network network = await _testData.CreateNetwork();

            var networkUpdate = new NetworkDefinition
            {
                Name = string.Format("{0}-updated", network.Name)
            };

            Trace.WriteLine("Updating the network...");
            network = await _networkingService.UpdateNetworkAsync(network.Id, networkUpdate);

            Trace.WriteLine("Verifying network was updated as requested...");
            Assert.NotNull(network);
            Assert.Equal(networkUpdate.Name, network.Name);
        }
Example #10
0
        public void CreateNetwork()
        {
            using (var httpTest = new HttpTest())
            {
                Identifier networkId = Guid.NewGuid();
                httpTest.RespondWithJson(new Network {
                    Id = networkId
                });

                var definition = new NetworkDefinition();
                var network    = _networkingService.CreateNetwork(definition);

                httpTest.ShouldHaveCalled("*/networks");
                Assert.NotNull(network);
                Assert.Equal(networkId, network.Id);
            }
        }
 public async Task<Network> CreateNetwork(NetworkDefinition definition)
 {
     var network = await _networkingService.CreateNetworkAsync(definition);
     Register(network);
     return network;
 }
 /// <summary>
 /// Updates the specified network.
 /// </summary>
 /// <param name="networkingService">The networking service.</param>
 /// <param name="networkId">The network identifier.</param>
 /// <param name="network">The updated network definition.</param>
 /// <returns>
 /// The updated network.
 /// </returns>
 public static Network UpdateNetwork(this NetworkingService networkingService, Identifier networkId, NetworkDefinition network)
 {
     return networkingService.UpdateNetworkAsync(networkId, network).ForceSynchronous();
 }
 /// <summary>
 /// Creates a network.
 /// </summary>
 /// <param name="networkingService">The networking service.</param>
 /// <param name="network">The network definition.</param>
 /// <returns>
 /// The created network.
 /// </returns>
 public static Network CreateNetwork(this NetworkingService networkingService, NetworkDefinition network)
 {
     return networkingService.CreateNetworkAsync(network).ForceSynchronous();
 }