コード例 #1
0
 public void Should_Create_A_Network()
 {
     var provider = new CloudNetworksProvider(_testIdentity);
     var newNetwork = provider.CreateNetwork("192.0.2.0/24", "net-sdk-test-network");
     Assert.IsNotNull(newNetwork);
     _created_network_id = newNetwork.Id;
 }
コード例 #2
0
        public void TestBasicFunctionality()
        {
            INetworksProvider provider = new CloudNetworksProvider(Bootstrapper.Settings.TestIdentity);
            string networkName = UnitTestNetworkPrefix + Path.GetRandomFileName();
            string cidr = "192.0.2.0/24";

            CloudNetwork network;
            try
            {
                network = provider.CreateNetwork(cidr, networkName);
            }
            catch (BadServiceRequestException ex)
            {
                if (ex.Message == "Quota exceeded, too many networks.")
                    Assert.Inconclusive("The required test network could not be created due to a quota.");

                throw;
            }

            Assert.IsNotNull(network);

            CloudNetwork showNetwork = provider.ShowNetwork(network.Id);
            Assert.IsNotNull(showNetwork);
            Assert.AreEqual(network.Id, showNetwork.Id);
            Assert.AreEqual(network.Label, showNetwork.Label);
            Assert.AreEqual(network.Cidr, showNetwork.Cidr);
        }
コード例 #3
0
 public void Should_Show_Newly_Created_Network()
 {
     var provider = new CloudNetworksProvider(_testIdentity);
     var network = provider.ShowNetwork(_created_network_id);
     Assert.IsNotNull(network);
     Assert.AreEqual(network.Label, "net-sdk-test-network");
     Assert.AreEqual(network.Cidr, "192.0.2.0/24");
 }
コード例 #4
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"));
        }
コード例 #5
0
        public static CloudNetworksProvider networksProvider()
        {
            string CloudIdentityUserName = (string)(HttpContext.Current.Session["CloudIdentityUserName"]);;
            string CloudIdentityApiKey   = (string)(HttpContext.Current.Session["CloudIdentityApiKey"]);

            RackspaceCloudIdentity identity = new RackspaceCloudIdentity()
            {
                Username = CloudIdentityUserName, APIKey = CloudIdentityApiKey
            };

            CloudNetworksProvider CloudNetworksProvider = new net.openstack.Providers.Rackspace.CloudNetworksProvider(identity);

            return(CloudNetworksProvider);
        }
コード例 #6
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);
            }
        }
コード例 #7
0
ファイル: Program.cs プロジェクト: ravikamachi/openstack.net
        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();
        }
コード例 #8
0
        public void Should_Not_Find_Just_Deleted_Network()
        {
            var provider = new CloudNetworksProvider(_testIdentity);

            try
            {
                var network = provider.ShowNetwork(_created_network_id);
                Assert.Fail("Deleted network was still found in ShowNetwork");
            }
            catch (Exception ex)
            {
                Assert.AreEqual(ex.GetType(), typeof(net.openstack.Core.Exceptions.Response.ItemNotFoundException), "Expected ItemNotFoundException was not thrown");
            }
        }
コード例 #9
0
 public void Should_Delete_Newly_Created_Network()
 {
     var provider = new CloudNetworksProvider(_testIdentity);
     Assert.IsTrue(provider.DeleteNetwork(_created_network_id));
 }
コード例 #10
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);
        }
コード例 #11
0
 public void Should_Have_Networks()
 {
     var provider = new CloudNetworksProvider(_testIdentity);
     var networks = provider.ListNetworks();
     Assert.IsNotNull(networks);
 }
コード例 #12
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);
        }
コード例 #13
0
 public void Should_Delete_Network_After_Server_Deleted()
 {
     var provider = new CloudNetworksProvider(_testIdentity);
     Assert.IsTrue(provider.DeleteNetwork(_created_network_id2));
 }
コード例 #14
0
        public void Should_Fail_Deleting_Network_When_Server_Is_Attached()
        {
            var provider = new CloudNetworksProvider(_testIdentity);

            try
            {
                provider.DeleteNetwork(_created_network_id2);
                Assert.Fail("Network should not be deletable if a server exists in it");
            }
            catch (Exception ex)
            {
                Assert.AreEqual(ex.GetType(), typeof(net.openstack.Core.Exceptions.UserAuthorizationException), "Expected UserAuthorizationException was not thrown when deleting network");
            }
        }
コード例 #15
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);
            }
        }
コード例 #16
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"));
 }
コード例 #17
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.");
        }