Esempio n. 1
0
        protected SimpleServer GetServerByNameOrCreate(string serverName, bool forceCreateServer = true)
        {
            var os      = new OpenStackMember(UserName, Password, TenantName); // with tenant
            var servers = os.ListServersDetails().Where <Server>(x =>
            {
                var metadata = x.GetMetadata();
                if (!metadata.ContainsKey("loginname"))
                {
                    return(false);
                }
                return(metadata["loginname"] == serverName);
            });

            if (servers != null && servers.Count() > 0)
            {
                return(servers.First <Server>());
            }
            else
            {
                if (!forceCreateServer)
                {
                    throw new ArgumentException("no item found");
                }

                // create server
                var       image   = os.ListImages().First();
                var       network = os.ListNetworks().Where <Network>(x => x.Name.Contains("ext_")).First <Network>();
                NewServer server  = os.CreateServer(serverName, image.Id, GetFlavorByName("g-1gb").Id, "YKJkd2-GF%x1O", keyname: null, nametag: "test nametag", networks: (new String[] { network.Id }));
                Trace.WriteLine(String.Format("server creation transferred : {0}", DateTime.Now));
                Assert.IsNotNull(server);
                Assert.IsNotNull(server.AdminPassword);
                Trace.WriteLine(string.Format("ServerName : {0}", serverName));
                Trace.WriteLine(string.Format("AdminPassword : {0}", server.AdminPassword));

                // wait for activate
                os.ServersProvider.WaitForServerActive(server.Id);
                Trace.WriteLine(String.Format("server activated : {0}", DateTime.Now));

                servers = os.ListServersDetails().Where <Server>(x =>
                {
                    var metadata = x.GetMetadata();
                    if (!metadata.ContainsKey("loginname"))
                    {
                        return(false);
                    }
                    return(metadata["loginname"] == serverName);
                });
                if (servers != null && servers.Count() > 0)
                {
                    return(servers.First <SimpleServer>());
                }
                else
                {
                    throw new ArgumentException("server creation faild");
                }
            }
        }
        public void GetImageTest()
        {
            var os    = new OpenStackMember(UserName, Password, TenantName);
            var image = os.ListImages().First();
            var i     = os.GetImage(image.Id);

            Assert.IsNotNull(i);
            Trace.WriteLine(String.Format("imageid : {0}", i.Id));
            Assert.IsTrue(image.Id == i.Id);
            Assert.IsTrue(image.Name == i.Name);
        }
 public void ListImagesTest()
 {
     foreach (var m in TestEnvMembers.Members)
     {
         var os     = new OpenStackMember(m.UserName, m.Password, m.TenantName);
         var images = os.ListImages();
         Assert.IsNotNull(images);
         foreach (var i in images)
         {
             Assert.IsNotNull(i.Id);
             Assert.IsNotNull(i.Name);
             Assert.IsNotNull(i.Links);
             Trace.WriteLine(String.Format("imageid : {0}, name : {1}, links : {2}", i.Id, i.Name, i.Links));
             Assert.IsNotNull(i.ExtensionData);
         }
     }
 }
        public void CreateServerTest_5times()
        {
            OpenStackMember os        = null;
            NewServer       server    = null;
            var             serverIds = new List <string>();

            try
            {
                os = new OpenStackMember(UserName, Password, TenantName, TenantId);
                var image = os.ListImages().First();
                for (int cnt = 1; cnt <= 15; cnt++)
                {
                    IEnumerable <SimpleServer> servers = os.ListServers();
                    var      names      = servers.GroupBy(s => s.Name, (key, g) => key);
                    string[] data       = Enumerable.Range(1, 100).Select(i => string.Format("{0}_{1}", TesterName, i)).ToArray <string>();
                    string   serverName = (from b in data where !names.Contains <string>(b) select b).First();
                    server = os.CreateServer(serverName, image.Id, GetFlavorByName("g-1gb").Id, "D$fjhg5422mnM-");
                    serverIds.Add(server.Id);
                    Trace.WriteLine(String.Format("server creation transferred : {0}", DateTime.Now));
                    Assert.IsNotNull(server);
                    Assert.IsNotNull(server.AdminPassword);
                    Trace.WriteLine(string.Format("ServerName : {0}", serverName));
                    Trace.WriteLine(string.Format("AdminPassword : {0}", server.AdminPassword));
                }
            }
            finally
            {
                foreach (var serverId in serverIds)
                {
                    bool bDelete = os.DeleteServer(serverId);
                    Assert.IsTrue(bDelete);
                    Trace.WriteLine(String.Format("server deletion transferred : {0}", DateTime.Now));
                    os.ServersProvider.WaitForServerDeleted(serverId);
                    Trace.WriteLine(String.Format("server deleted : {0}", DateTime.Now));
                }
            }
        }
        public void CreateServerTest()
        {
            var os = new OpenStackMember(UserName, Password, TenantName, TenantId);

            var image = os.ListImages().First();

            // decide server name which is not duplicated.
            IEnumerable <SimpleServer> servers = os.ListServers();
            var names = servers.GroupBy(s => s.Name, (key, g) => key);

            string[] data       = Enumerable.Range(1, 100).Select(i => string.Format("{0}_{1}", TesterName, i)).ToArray <string>();
            string   serverName = (from b in data where !names.Contains <string>(b) select b).First();

            // create server
            // the name tag must not contain space
            NewServer server = os.CreateServer(serverName, image.Id, GetFlavorByName("g-1gb").Id, "S5df!Afdas%'Zt", keyname: null, nametag: "test_nametag", networks: null);

            Trace.WriteLine(String.Format("server creation transferred : {0}", DateTime.Now));
            Assert.IsNotNull(server);
            Assert.IsNotNull(server.AdminPassword);
            Trace.WriteLine(string.Format("ServerName : {0}", serverName));
            Trace.WriteLine(string.Format("AdminPassword : {0}", server.AdminPassword));

            // wait for activate
            os.ServersProvider.WaitForServerActive(server.Id);
            Trace.WriteLine(String.Format("server activated : {0}", DateTime.Now));

            bool bDelete = os.DeleteServer(server.Id);

            Assert.IsTrue(bDelete);
            Trace.WriteLine(String.Format("server deletion transferred : {0}", DateTime.Now));

            // wait for delete
            os.ServersProvider.WaitForServerDeleted(server.Id);
            Trace.WriteLine(String.Format("server deleted : {0}", DateTime.Now));
        }