コード例 #1
0
        public async Task <Port> CreatePort(PortCreateDefinition definition)
        {
            var port = await _networkingService.CreatePortAsync(definition);

            Register(port);
            return(port);
        }
コード例 #2
0
 /// <inheritdoc cref="NetworkingApiBuilder.CreatePortAsync" />
 public Task <Port> CreatePortAsync(PortCreateDefinition port, CancellationToken cancellationToken = default(CancellationToken))
 {
     return(_networkingApiBuilder
            .CreatePortAsync(port, cancellationToken)
            .SendAsync()
            .ReceiveJson <Port>());
 }
コード例 #3
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);
    }
コード例 #4
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 = _networkingService.CreatePort(definition);

                httpTest.ShouldHaveCalled("*/ports");
                Assert.NotNull(port);
                Assert.Equal(portId, port.Id);
            }
        }
コード例 #5
0
        public void Serialize()
        {
            var input = new PortCreateDefinition(null)
            {
                DHCPOptions =
                {
                    {"a", "stuff"},
                    {"b", "things"}
                }
            };

            string result = OpenStackNet.Serialize(input);

            string expectedJson = JObject.Parse("{'port':{'extra_dhcp_opts':[{'opt_name':'a','opt_value':'stuff'},{'opt_name':'b','opt_value':'things'}]}}").ToString(Formatting.None);
            Assert.Equal(expectedJson, result);
        }
コード例 #6
0
        public void Serialize()
        {
            var input = new PortCreateDefinition(null)
            {
                DHCPOptions =
                {
                    { "a", "stuff"  },
                    { "b", "things" }
                }
            };

            string result = OpenStackNet.Configuration.FlurlHttpSettings.JsonSerializer.Serialize(input);

            string expectedJson = JObject.Parse("{'port':{'extra_dhcp_opts':[{'opt_name':'a','opt_value':'stuff'},{'opt_name':'b','opt_value':'things'}]}}").ToString(Formatting.None);

            Assert.Equal(expectedJson, result);
        }
コード例 #7
0
ファイル: PortTests.cs プロジェクト: szdree/openstack.net
        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       = _networkingService.CreatePort(definition);

                httpTest.ShouldHaveCalled("*/ports");
                Assert.NotNull(port);
                Assert.Equal(portId, port.Id);
            }
        }
コード例 #8
0
        public async Task CreatePortTest()
        {
            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(),
                DHCPOptions =
                {
                    { "server-ip-address", "192.168.1.1" }
                },
                AllowedAddresses =
                {
                    new AllowedAddress("10.0.0.1")
                    {
                        MACAddress = "24:a0:74:f0:1c:66"
                    }
                },
                MACAddress = "24:a0:74:f0:1c:66",
                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(definition.DHCPOptions, port.DHCPOptions);
            Assert.Equal(definition.AllowedAddresses, port.AllowedAddresses);
            Assert.Equal(subnet.Id, port.FixedIPs.Single().SubnetId);
            Assert.Equal(portIdAddress, port.FixedIPs.Single().IPAddress);
        }
コード例 #9
0
 public async Task<Port> CreatePort(PortCreateDefinition definition)
 {
     var port = await _networkingService.CreatePortAsync(definition);
     Register(port);
     return port;
 }
コード例 #10
0
        public async Task CreatePortTest()
        {
            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(),
                DHCPOptions =
                {
                    {"server-ip-address", "192.168.1.1"}
                },
                AllowedAddresses =
                {
                    new AllowedAddress("10.0.0.1") { MACAddress = "24:a0:74:f0:1c:66" }
                },
                MACAddress = "24:a0:74:f0:1c:66",
                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(definition.DHCPOptions, port.DHCPOptions);
            Assert.Equal(definition.AllowedAddresses, port.AllowedAddresses);
            Assert.Equal(subnet.Id, port.FixedIPs.Single().SubnetId);
            Assert.Equal(portIdAddress, port.FixedIPs.Single().IPAddress);
        }
コード例 #11
0
 /// <inheritdoc cref="NetworkingApiBuilder.CreatePortAsync" />
 public Task<Port> CreatePortAsync(PortCreateDefinition port, CancellationToken cancellationToken = default(CancellationToken))
 {
     return _networkingApiBuilder
         .CreatePortAsync(port, cancellationToken)
         .SendAsync()
         .ReceiveJson<Port>();
 }
コード例 #12
0
 /// <summary>
 /// Creates a port.
 /// </summary>
 /// <param name="networkingService">The networking service.</param>
 /// <param name="port">The port definition.</param>
 /// <returns>
 /// The created port.
 /// </returns>
 public static Port CreatePort(this NetworkingService networkingService, PortCreateDefinition port)
 {
     return networkingService.CreatePortAsync(port).ForceSynchronous();
 }