Пример #1
0
        public void TestVirtualInterfaces()
        {
            IComputeProvider  provider         = new CloudServersProvider(Bootstrapper.Settings.TestIdentity);
            INetworksProvider networksProvider = new CloudNetworksProvider(Bootstrapper.Settings.TestIdentity);
            CloudNetwork      publicNetwork    = networksProvider.ListNetworks().Single(i => i.Label.Equals("public", StringComparison.OrdinalIgnoreCase));
            CloudNetwork      privateNetwork   = networksProvider.ListNetworks().Single(i => i.Label.Equals("private", StringComparison.OrdinalIgnoreCase));

            VirtualInterface publicVirtualInterface = provider.CreateVirtualInterface(_server.Id, publicNetwork.Id);

            Assert.IsNotNull(publicVirtualInterface);
            Assert.IsFalse(string.IsNullOrEmpty(publicVirtualInterface.Id));
            Assert.IsNotNull(publicVirtualInterface.MACAddress);

            VirtualInterface privateVirtualInterface = provider.CreateVirtualInterface(_server.Id, privateNetwork.Id);

            Assert.IsNotNull(privateVirtualInterface);
            Assert.IsFalse(string.IsNullOrEmpty(privateVirtualInterface.Id));
            Assert.IsNotNull(privateVirtualInterface.MACAddress);

            IEnumerable <VirtualInterface> virtualInterfaces = provider.ListVirtualInterfaces(_server.Id);

            Assert.IsNotNull(virtualInterfaces);
            Assert.IsTrue(virtualInterfaces.Where(i => i.Id.Equals(publicVirtualInterface.Id, StringComparison.OrdinalIgnoreCase)).Any());
            Assert.IsTrue(virtualInterfaces.Where(i => i.Id.Equals(privateVirtualInterface.Id, StringComparison.OrdinalIgnoreCase)).Any());

            bool deleted;

            deleted = provider.DeleteVirtualInterface(_server.Id, publicVirtualInterface.Id);
            Assert.IsTrue(deleted);

            deleted = provider.DeleteVirtualInterface(_server.Id, privateVirtualInterface.Id);
            Assert.IsTrue(deleted);
        }
Пример #2
0
        public void Should_Have_Public_Network()
        {
            var provider = new CloudNetworksProvider(_testIdentity);
            var networks = provider.ListNetworks();

            Assert.IsNotNull(networks.SingleOrDefault(n => n.Id == "00000000-0000-0000-0000-000000000000" && n.Label == "public"));
        }
Пример #3
0
        public void TestListNetworks()
        {
            INetworksProvider          provider = new CloudNetworksProvider(Bootstrapper.Settings.TestIdentity);
            IEnumerable <CloudNetwork> networks = provider.ListNetworks();

            Assert.IsNotNull(networks);
            if (!networks.Any())
            {
                Assert.Inconclusive("The test could not proceed because the specified account and/or region does not appear to contain any configured networks.");
            }

            Console.WriteLine("Networks");
            foreach (CloudNetwork network in networks)
            {
                Assert.IsNotNull(network);

                Console.WriteLine("    {0}: {1} ({2})", network.Id, network.Label, network.Cidr);

                Assert.IsFalse(string.IsNullOrEmpty(network.Id));
                Assert.IsFalse(string.IsNullOrEmpty(network.Label));

                if (!string.IsNullOrEmpty(network.Cidr))
                {
                    CloudNetworksValidator.Default.ValidateCidr(network.Cidr);
                }
            }
        }
Пример #4
0
        public void Should_Have_Networks()
        {
            var provider = new CloudNetworksProvider(_testIdentity);
            var networks = provider.ListNetworks();

            Assert.IsNotNull(networks);
        }
Пример #5
0
        static void Main(string[] args)
        {
            const string region = "RegionOne";

            // Configure OpenStack.NET
            OpenStackNet.Configure(options => options.DefaultTimeout = TimeSpan.FromSeconds(5));

            // Authenticate
            var identityUrl = new Uri("http://example.com");
            var user        = new CloudIdentityWithProject();
            var identity    = new OpenStackIdentityProvider(identityUrl, user);

            identity.Authenticate();

            // Use legacy and new providers
            var legacyNetworking = new CloudNetworksProvider(null, identity);

            legacyNetworking.ListNetworks();
            var networks = new NetworkingService(identity, region);

            networks.ListNetworks();

            var legacyCompute = new CloudServersProvider(null, identity);

            legacyCompute.ListServers();
            var compute = new ComputeService(identity, region);

            compute.ListServers();
        }
Пример #6
0
        public static void Init(TestContext context)
        {
            _testIdentity = new RackspaceCloudIdentity(Bootstrapper.Settings.TestIdentity);

            var provider = new CloudServersProvider(_testIdentity);

            _initImage  = provider.ListImages(imageName: "CentOS 6.3").First();
            _initFlavor = provider.ListFlavors().OrderBy(f => f.Id).First();

            var netProvider = new CloudNetworksProvider(_testIdentity);
            var networks    = netProvider.ListNetworks();

            _testNetwork = networks.FirstOrDefault(n => !n.Label.Equals("public") && !n.Label.Equals("private"));
        }
Пример #7
0
        public void CleanupTestNetworks()
        {
            INetworksProvider          provider = new CloudNetworksProvider(Bootstrapper.Settings.TestIdentity);
            IEnumerable <CloudNetwork> networks = provider.ListNetworks();

            Assert.IsNotNull(networks);

            foreach (CloudNetwork network in networks)
            {
                Assert.IsNotNull(network);
                if (!network.Label.StartsWith(UnitTestNetworkPrefix))
                {
                    continue;
                }

                Console.WriteLine("Removing network... {0}: {1}", network.Id, network.Label);
                provider.DeleteNetwork(network.Id);
            }
        }
Пример #8
0
        public void CleanupServers()
        {
            var provider = new CloudServersProvider(_testIdentity);
            var srvs     = provider.ListServers();

            foreach (var svr in srvs.Where(s => s.Name == "net-sdk-test-server"))
            {
                provider.DeleteServer(svr.Id);
            }


            var networkProvider = new CloudNetworksProvider(_testIdentity);
            var networks        = networkProvider.ListNetworks();

            foreach (var network in networks.Where(n => n.Label == "net-sdk-test-network" || n.Label == "net-sdk-test-network-for-server"))
            {
                networkProvider.DeleteNetwork(network.Id);
            }
        }
Пример #9
0
        public void TestListAddressesByNetwork()
        {
            IComputeProvider           provider         = new CloudServersProvider(Bootstrapper.Settings.TestIdentity);
            INetworksProvider          networksProvider = new CloudNetworksProvider(Bootstrapper.Settings.TestIdentity);
            IEnumerable <CloudNetwork> networks         = networksProvider.ListNetworks();

            bool foundAddress = false;

            foreach (CloudNetwork network in networks)
            {
                Console.WriteLine("Network: {0}", network.Label);
                IEnumerable <IPAddress> addresses = provider.ListAddressesByNetwork(_server.Id, network.Label);
                foreach (IPAddress address in addresses)
                {
                    foundAddress = true;
                    Console.WriteLine("  {0}", address);
                }
            }

            if (!foundAddress)
            {
                Assert.Inconclusive("Couldn't find addresses on any network for the server.");
            }
        }