Пример #1
0
 public void CreateSnapshot()
 {
     Identity identity = new Identity()
     {
         AuthEndpoint = "http://192.168.1.149:5000/v2.0",
         Password = "******",
         TenantName = "admin",
         Username = "******",
     };
     InstanceManager instanceManager = new InstanceManager(identity);
     var firstInstaceId = instanceManager.ListInstances(identity)[0].Id;
     var snapshotName = instanceManager.CreateSnapshot(firstInstaceId, (x) => { return true; });
     ImageManager imageManager = new ImageManager(identity);
     OpenstackImage image = imageManager.GetImage(new OpenstackImage() { Name = snapshotName });
     Assert.AreNotSame(image, null);
 }
Пример #2
0
 public void DeleteSnapshot()
 {
     Identity identity = new Identity()
     {
         AuthEndpoint = "http://192.168.1.149:5000/v2.0",
         Password = "******",
         TenantName = "admin",
         Username = "******",
     };
     InstanceManager instanceManager = new InstanceManager(identity);
     var firstInstaceId = "a9a8ba2c-fc26-4ecc-8419-ca9b7cf326a2";
     var snapshotName = instanceManager.CreateSnapshot(firstInstaceId, (x) => { return true; });
     ImageManager imageManager = new ImageManager(identity);
     OpenstackImage image = imageManager.GetImage(new OpenstackImage() { Name = snapshotName });
     Assert.AreNotSame(image, null);
     imageManager.Delete(image.Id);
     image = imageManager.GetImage(new OpenstackImage() { Name = snapshotName });
     Assert.AreEqual(image, null);
 }
Пример #3
0
 public void DownloadSnapshot()
 {
     Identity identity = new Identity()
     {
         AuthEndpoint = "http://192.168.1.118:5000/v2.0",
         Password = "******",
         TenantName = "admin",
         Username = "******",
     };
     InstanceManager instanceManager = new InstanceManager(identity);
     var firstInstaceId = "f71e50ab-cf33-4491-b6f4-8887b29b2c22";
     var snapshotName = instanceManager.CreateSnapshot(firstInstaceId, (x) => { return true; });
     ImageManager imageManager = new ImageManager(identity);
     OpenstackImage image = imageManager.GetImage(new OpenstackImage() { Name = snapshotName });
     Assert.AreNotSame(image, null);
     image = imageManager.GetImage(image.Id);
     imageManager.DownloadImage(image.Id, @"E:\\AtlasVHDS\\" + image.Name + "." + image.DiskFormat);
     imageManager.Delete(image.Id);
     image = imageManager.GetImage(new OpenstackImage() { Name = snapshotName });
     Assert.AreEqual(image, null);
 }
 public void Delete(string imageId)
 {
     RequestManager requestManager = new RequestManager(_identity);
     var uri = string.Format("/v2/images/{0}", imageId);
     requestManager.Delete(uri, "glance");
     ImageManager imageManager = new ImageManager(_identity);
     var deleteFinished = false;
     if (imageId != null)
     {
         while (!deleteFinished)
         {
             OpenstackImage image = imageManager.GetImage(imageId);
             if (image != null)
             {
                 Thread.Sleep(10000);
             }
             else
             {
                 deleteFinished = true;
             }
         }
     }
 }
Пример #5
0
        public void ListImages()
        {
            Identity identity = new Identity()
            {
                AuthEndpoint = "http://192.168.1.149:5000/v2.0",
                Password = "******",
                TenantName = "admin",
                Username = "******",

            };

            ImageManager imageManager = new ImageManager(identity);
            IList<OpenstackImage> instances = imageManager.ListImages();
            Assert.IsTrue(instances.Count != 0);
        }
 public string CreateSnapshot(string instanceId, Func<decimal, bool> progressCallback)
 {
     string snapshotName = CreateSnapshot(instanceId, _identity);
     bool snapshotFinished = false;
     var progress = 0;
     var progressStep = 5;
     ImageManager imageManager = new ImageManager(_identity);
     if (snapshotName != null)
     {
         OpenstackImage imageParent = imageManager.GetImage(new OpenstackImage() { Name = snapshotName });
         while (!snapshotFinished)
         {
             OpenstackImage image = imageManager.GetImage(imageParent.Id);
             if (image.Status.ToLower() == "active")
             {
                 snapshotFinished = true;
                 progress = 100;
             }
             if (image.Status.ToLower() == "error")
             {
                 throw new Exception("Snapshot failed to create!");
             }
             if (progress != 100)
             {
                 if (!snapshotFinished && progress + progressStep < 99)
                     progress += progressStep;
             }
             progressCallback(progress);
             Thread.Sleep(10000);
         }
     }
     return snapshotName;
 }