public void TestRevertServerResize()
        {
            IComputeProvider provider = Bootstrapper.CreateComputeProvider();

            string serverName = UserComputeTests.UnitTestServerPrefix + Path.GetRandomFileName();

            Flavor flavor = UserComputeTests.ListAllFlavorsWithDetails(provider).OrderBy(i => i.RAMInMB).ThenBy(i => i.DiskSizeInGB).FirstOrDefault(i => !i.Id.Equals(_server.Flavor.Id, StringComparison.OrdinalIgnoreCase));

            if (flavor == null)
            {
                Assert.Inconclusive("Couldn't find a flavor to use for the test server.");
            }

            bool resized = provider.ResizeServer(_server.Id, serverName, flavor.Id);

            Assert.IsTrue(resized);
            Server resizedServer = provider.WaitForServerState(_server.Id, ServerState.VerifyResize, new[] { ServerState.Active, ServerState.Error, ServerState.Unknown, ServerState.Suspended });

            Assert.AreEqual(ServerState.VerifyResize, resizedServer.Status);
            _server = resizedServer;

            bool reverted = provider.RevertServerResize(resizedServer.Id);

            Assert.IsTrue(reverted);
            Server revertedServer = provider.WaitForServerActive(_server.Id);

            Assert.AreEqual(ServerState.Active, revertedServer.Status);
            _server = revertedServer;
        }
        public void TestRebuildServer()
        {
            IComputeProvider provider = Bootstrapper.CreateComputeProvider();

            Flavor flavor = UserComputeTests.ListAllFlavorsWithDetails(provider).OrderBy(i => i.RAMInMB).ThenBy(i => i.DiskSizeInGB).FirstOrDefault();

            if (flavor == null)
            {
                Assert.Inconclusive("Couldn't find a flavor to use for the test server.");
            }

            SimpleServerImage[] images = UserComputeTests.ListAllImages(provider).ToArray();
            SimpleServerImage   image  = images.FirstOrDefault(i => i.Name.IndexOf(TestImageNameSubstring, StringComparison.OrdinalIgnoreCase) >= 0);

            if (image == null)
            {
                Assert.Inconclusive(string.Format("Couldn't find the {0} image to use for the test server.", TestImageNameSubstring));
            }

            Server rebuilt = provider.RebuildServer(_server.Id, null, image.Id, flavor.Id, _password);

            Assert.IsNotNull(rebuilt);
            Server rebuiltServer = provider.WaitForServerActive(rebuilt.Id);

            Assert.AreEqual(ServerState.Active, rebuiltServer.Status);
            _server = rebuiltServer;
        }
        public void TestSoftRebootServer()
        {
            IComputeProvider provider     = Bootstrapper.CreateComputeProvider();
            bool             rebootResult = provider.RebootServer(_server.Id, RebootType.Soft);

            Assert.IsTrue(rebootResult);
            Server rebootServer = provider.WaitForServerActive(_server.Id);

            Assert.AreEqual(ServerState.Active, rebootServer.Status);
        }
        public void TestAttachServerVolume()
        {
            IComputeProvider provider = Bootstrapper.CreateComputeProvider();

            IBlockStorageProvider blockStorageProvider = Bootstrapper.CreateBlockStorageProvider();
            VolumeType            volumeType           = UserBlockStorageTests.GetSsdVolumeTypeOrDefault(blockStorageProvider);
            string volumeName = UserBlockStorageTests.UnitTestVolumePrefix + Path.GetRandomFileName();
            Volume volume     = blockStorageProvider.CreateVolume(UserBlockStorageTests.MinimumVolumeSize, displayName: volumeName, volumeType: volumeType != null ? volumeType.Id : null);

            Assert.AreEqual(VolumeState.Available, blockStorageProvider.WaitForVolumeAvailable(volume.Id).Status);

            /* AttachServerVolume
             */
            ServerVolume serverVolume = provider.AttachServerVolume(_server.Id, volume.Id);

            Assert.IsNotNull(serverVolume);
            Assert.IsFalse(string.IsNullOrEmpty(serverVolume.Id));
            Assert.AreEqual(_server.Id, serverVolume.ServerId);
            Assert.AreEqual(volume.Id, serverVolume.VolumeId);

            Assert.AreEqual(VolumeState.InUse, blockStorageProvider.WaitForVolumeState(volume.Id, VolumeState.InUse, new[] { VolumeState.Available, VolumeState.Error }).Status);

            /* ListServerVolumes
             */
            ServerVolume[] serverVolumes = provider.ListServerVolumes(_server.Id).ToArray();
            Assert.IsNotNull(serverVolumes);
            Assert.AreEqual(1, serverVolumes.Length);
            Assert.AreEqual(serverVolume.Id, serverVolumes[0].Id);
            Assert.AreEqual(serverVolume.ServerId, serverVolumes[0].ServerId);
            Assert.AreEqual(serverVolume.VolumeId, serverVolumes[0].VolumeId);

            /* GetServerVolumeDetails
             */
            ServerVolume volumeDetails = provider.GetServerVolumeDetails(_server.Id, volume.Id);

            Assert.IsNotNull(volumeDetails);
            Assert.AreEqual(serverVolume.Id, volumeDetails.Id);
            Assert.AreEqual(serverVolume.ServerId, volumeDetails.ServerId);
            Assert.AreEqual(serverVolume.VolumeId, volumeDetails.VolumeId);

            bool detach = provider.DetachServerVolume(_server.Id, volume.Id);

            Assert.IsTrue(detach);
            provider.WaitForServerActive(_server.Id);
            ServerVolume[] remainingVolumes = provider.ListServerVolumes(_server.Id).ToArray();
            Assert.AreEqual(0, remainingVolumes.Length);

            Assert.AreEqual(VolumeState.Available, blockStorageProvider.WaitForVolumeAvailable(volume.Id).Status);
            bool deleted = blockStorageProvider.DeleteVolume(volume.Id);

            Assert.IsTrue(blockStorageProvider.WaitForVolumeDeleted(volume.Id));
        }
        public void TestChangeAdministratorPassword()
        {
            IComputeProvider provider = Bootstrapper.CreateComputeProvider();

            string password             = Path.GetTempPath();
            bool   changePasswordResult = provider.ChangeAdministratorPassword(_server.Id, password);

            Assert.IsTrue(changePasswordResult);
            _password = password;
            Server changePasswordServer = provider.WaitForServerActive(_server.Id);

            Assert.AreEqual(ServerState.Active, changePasswordServer.Status);
        }
        public void TestRescueServer()
        {
            IComputeProvider provider = Bootstrapper.CreateComputeProvider();

            string rescueResult = provider.RescueServer(_server.Id);

            Assert.IsFalse(string.IsNullOrEmpty(rescueResult));
            Server rescueServer = provider.WaitForServerState(_server.Id, ServerState.Rescue, new[] { ServerState.Active, ServerState.Error, ServerState.Unknown, ServerState.Suspended });

            Assert.AreEqual(ServerState.Rescue, rescueServer.Status);

            bool unrescueResult = provider.UnRescueServer(_server.Id);

            Assert.IsTrue(unrescueResult);
            Server unrescueServer = provider.WaitForServerActive(_server.Id);

            Assert.AreEqual(ServerState.Active, unrescueServer.Status);
        }
        public static void ClassInitialize(TestContext testContext)
        {
            IComputeProvider provider   = Bootstrapper.CreateComputeProvider();
            string           serverName = UserComputeTests.UnitTestServerPrefix + Path.GetRandomFileName();

            Flavor flavor = UserComputeTests.ListAllFlavorsWithDetails(provider).OrderBy(i => i.RAMInMB).ThenBy(i => i.DiskSizeInGB).FirstOrDefault();

            if (flavor == null)
            {
                Assert.Inconclusive("Couldn't find a flavor to use for the test server.");
            }

            SimpleServerImage[] images = UserComputeTests.ListAllImages(provider).ToArray();
            SimpleServerImage   image  = images.FirstOrDefault(i => i.Name.IndexOf(TestImageNameSubstring, StringComparison.OrdinalIgnoreCase) >= 0);

            if (image == null)
            {
                Assert.Inconclusive(string.Format("Couldn't find the {0} image to use for the test server.", TestImageNameSubstring));
            }

            Stopwatch timer = Stopwatch.StartNew();

            Console.Write("Creating server for image {0}...", image.Name);
            NewServer server = provider.CreateServer(serverName, image.Id, flavor.Id, attachToServiceNetwork: true);

            Assert.IsNotNull(server);
            Assert.IsFalse(string.IsNullOrEmpty(server.Id));

            _password = server.AdminPassword;

            _server = provider.WaitForServerActive(server.Id);
            Assert.IsNotNull(_server);
            Assert.AreEqual(server.Id, _server.Id);
            Assert.AreEqual(ServerState.Active, _server.Status);

            Console.WriteLine("done. {0} seconds", timer.Elapsed.TotalSeconds);
        }