/*   /// <inheritdoc cref="NetworkingApiBuilder.ListPortsAsync" />
         * public async Task<IPage<Port>> ListPortsAsync(Identifier startPortId = null, int? pageSize = null, CancellationToken cancellationToken = default(CancellationToken))
         * {
         *     //IEnumerable<IServiceResource>
         *     PortCollection request = await _networkingApiBuilder.ListPortsAsync<PortCollection>(null, cancellationToken);
         *
         *     request.Url.SetQueryParams(new
         *     {
         *         marker = startPortId,
         *         limit = pageSize
         *     });
         *
         *     return await request.SendAsync()
         *         .ReceiveJson<PortCollection>();
         * }*/

        /// <inheritdoc cref="NetworkingApiBuilder.CreatePortAsync" />
        public Task <Port> CreatePortAsync(PortCreateDefinition port, CancellationToken cancellationToken = default(CancellationToken))
        {
            return(_networkingApiBuilder
                   .CreatePortAsync(port, cancellationToken)
                   .SendAsync()
                   .ReceiveJson <Port>());
        }
        public async void CreatePortTests()
        {
            var network = await _testData.CreateNetwork();

            var subnet = await _testData.CreateSubnet(network);

            var portIdAddress = subnet.CIDR.Replace("0/24", "2");
            var definition    = new PortCreateDefinition(network.Id)
            {
                Name     = TestData.GenerateName(),
                FixedIPs =
                {
                    new IPAddressAssociation(subnet.Id, portIdAddress)
                }
            };

            Trace.WriteLine(string.Format("Creating port named: {0}", definition.Name));
            var port = await _testData.CreatePort(definition);

            Trace.WriteLine("Verifying port matches requested definition...");
            Assert.NotNull(port);
            Assert.NotNull(port.Id);
            Assert.Equal(definition.Name, port.Name);
            Assert.Equal(definition.NetworkId, port.NetworkId);
            Assert.Equal(subnet.Id, port.FixedIPs.Single().SubnetId);
            Assert.Equal(portIdAddress, port.FixedIPs.Single().IPAddress);
        }
    public async Task Run(string username, string apiKey, string region)
    {
        // Configure authentication
        var identity = new CloudIdentity
        {
            Username = username,
            APIKey = apiKey
        };
        var identityService = new CloudIdentityProvider(identity);
        var networkService = new CloudNetworkService(identityService, region);

        Console.WriteLine("Creating Sample Network... ");
        var networkDefinition = new NetworkDefinition {Name = "Sample"};
        var sampleNetwork = await networkService.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 networkService.CreateSubnetAsync(subnetDefinition);

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

        Console.WriteLine("Listing Networks...");
        var networks = await networkService.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 networkService.DeletePortAsync(samplePort.Id);
        await networkService.DeleteNetworkAsync(sampleNetwork.Id);
    }
Esempio n. 4
0
        public async Task <Port> CreatePort(PortCreateDefinition definition)
        {
            var port = await _cloudNetworkService.CreatePortAsync(definition);

            Register(port);
            await Task.Delay(TimeSpan.FromMilliseconds(500));

            return(port);
        }
Esempio n. 5
0
        public void CreatePort()
        {
            using (var httpTest = new HttpTest())
            {
                Identifier networkId = Guid.NewGuid();
                Identifier portId = Guid.NewGuid();
                httpTest.RespondWithJson(new Port { Id = portId });

                var definition = new PortCreateDefinition(networkId);
                var port = _cloudNetworkService.CreatePort(definition);

                httpTest.ShouldHaveCalled("*/ports");
                Assert.NotNull(port);
                Assert.Equal(portId, port.Id);
            }
        }
Esempio n. 6
0
        public void CreatePort()
        {
            using (var httpTest = new HttpTest())
            {
                Identifier networkId = Guid.NewGuid();
                Identifier portId    = Guid.NewGuid();
                httpTest.RespondWithJson(new Port {
                    Id = portId
                });

                var definition = new PortCreateDefinition(networkId);
                var port       = _cloudNetworkService.CreatePort(definition);

                httpTest.ShouldHaveCalled("*/ports");
                Assert.NotNull(port);
                Assert.Equal(portId, port.Id);
            }
        }
 /// <inheritdoc cref="NetworkingApiBuilder.CreatePortAsync" />
 public Task<Port> CreatePortAsync(PortCreateDefinition port, CancellationToken cancellationToken = default(CancellationToken))
 {
     return _networkingApiBuilder
         .CreatePortAsync(port, cancellationToken)
         .SendAsync()
         .ReceiveJson<Port>();
 }
        public async void CreatePortTests()
        {
            var network = await _testData.CreateNetwork();
            var subnet = await _testData.CreateSubnet(network);

            var portIdAddress = subnet.CIDR.Replace("0/24", "2");
            var definition = new PortCreateDefinition(network.Id)
            {
                Name = TestData.GenerateName(),
                FixedIPs =
                {
                    new IPAddressAssociation(subnet.Id, portIdAddress)
                }
            };

            Trace.WriteLine(string.Format("Creating port named: {0}", definition.Name));
            var port = await _testData.CreatePort(definition);

            Trace.WriteLine("Verifying port matches requested definition...");
            Assert.NotNull(port);
            Assert.NotNull(port.Id);
            Assert.Equal(definition.Name, port.Name);
            Assert.Equal(definition.NetworkId, port.NetworkId);
            Assert.Equal(subnet.Id, port.FixedIPs.Single().SubnetId);
            Assert.Equal(portIdAddress, port.FixedIPs.Single().IPAddress);
        }
 /// <inheritdoc cref="OpenStack.Synchronous.NetworkingServiceExtensions.CreatePort"/>
 public static Port CreatePort(this CloudNetworkService cloudNetworkService, PortCreateDefinition port)
 {
     return cloudNetworkService.CreatePortAsync(port).ForceSynchronous();
 }
 public async Task<Port> CreatePort(PortCreateDefinition definition)
 {
     var port = await _cloudNetworkService.CreatePortAsync(definition);
     Register(port);
     await Task.Delay(TimeSpan.FromMilliseconds(500));
     return port;
 }