Exemplo n.º 1
0
    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);
    }
Exemplo n.º 2
0
        public void CreateSubnet()
        {
            using (var httpTest = new HttpTest())
            {
                Identifier networkId = Guid.NewGuid();
                Identifier subnetId = Guid.NewGuid();
                httpTest.RespondWithJson(new Subnet { Id = subnetId });

                var definition = new SubnetCreateDefinition(networkId, IPVersion.IPv4, "10.0.0.0/24");
                var subnet = _networkingService.CreateSubnet(definition);
                
                httpTest.ShouldHaveCalled("*/subnets");
                Assert.NotNull(subnet);
                Assert.Equal(subnetId, subnet.Id);
            }
        }
 public async Task<Subnet> CreateSubnet(SubnetCreateDefinition definition)
 {
     var subnet = await _networkingService.CreateSubnetAsync(definition);
     Register(subnet);
     return subnet;
 }
        public async Task CreateSubnetTest()
        {
            var network = await _testData.CreateNetwork();
            var definition = new SubnetCreateDefinition(network.Id, IPVersion.IPv4, "192.168.3.0/24")
            {
                Name = TestData.GenerateName(),
                IsDHCPEnabled = true,
                GatewayIP = "192.168.3.1",
                AllocationPools =
                {
                    new AllocationPool("192.168.3.10", "192.168.3.50")
                },
                Nameservers =
                {
                    "8.8.8.8"
                },
                HostRoutes =
                {
                    new HostRoute("1.2.3.4/24", "10.0.0.1")
                }
            };

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

            Trace.WriteLine("Verifying subnet matches requested definition...");
            Assert.NotNull(subnet);
            Assert.Equal(definition.NetworkId, subnet.NetworkId);
            Assert.Equal(definition.Name, subnet.Name);
            Assert.Equal(definition.CIDR, subnet.CIDR);
            Assert.Equal(definition.IPVersion, subnet.IPVersion);
            Assert.Equal(definition.IsDHCPEnabled, subnet.IsDHCPEnabled);
            Assert.Equal(definition.GatewayIP, subnet.GatewayIP);
            Assert.Equal(definition.AllocationPools, subnet.AllocationPools);
            Assert.Equal(definition.Nameservers, subnet.Nameservers);
            Assert.Equal(definition.HostRoutes, subnet.HostRoutes);
        }
 /// <inheritdoc cref="NetworkingApiBuilder.CreateSubnetAsync" />
 public Task<Subnet> CreateSubnetAsync(SubnetCreateDefinition subnet, CancellationToken cancellationToken = default(CancellationToken))
 {
     return _networkingApiBuilder
         .CreateSubnetAsync(subnet, cancellationToken)
         .SendAsync()
         .ReceiveJson<Subnet>();
 }
 /// <summary>
 /// Creates a subnet.
 /// </summary>
 /// <param name="networkingService">The networking service.</param>
 /// <param name="subnet">The subnet definition.</param>
 /// <returns>
 /// The created subnet.
 /// </returns>
 public static Subnet CreateSubnet(this NetworkingService networkingService, SubnetCreateDefinition subnet)
 {
     return networkingService.CreateSubnetAsync(subnet).ForceSynchronous();
 }