public OpenstackImage GetImage(OpenstackImage image, Identity identity)
        {
            //TODO: get the image from glance without listing all of them, using filtered request by name
            var image2 = ListImages().Where((x) => x.Name.Equals(image.Name)).ToList().FirstOrDefault();

            return(GetImage(image2.Id));
        }
        public OpenstackImage GetImage(string imageId, Identity identity)
        {
            OpenstackImage image;
            RequestManager requestManager = new RequestManager(identity);
            var            uri            = string.Format("/v2/images/{0}", imageId);
            JObject        response       = requestManager.Get(uri, "glance");
            var            tempinstance   = response;

            if (response != null)
            {
                image = new OpenstackImage()
                {
                    Id     = tempinstance["id"].ToString(),
                    Name   = tempinstance["name"].ToString(),
                    Status = tempinstance["status"].ToString(),
                };
                if (tempinstance["container_format"] != null)
                {
                    image.ContainerFormat = tempinstance["container_format"].ToString();
                }
                if (tempinstance["disk_format"] != null)
                {
                    image.DiskFormat = tempinstance["disk_format"].ToString();
                }
                return(image);
            }
            return(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;
                    }
                }
            }
        }
        public IList <OpenstackImage> ListImages(Identity identity)
        {
            IList <OpenstackImage> list           = new List <OpenstackImage>();
            RequestManager         requestManager = new RequestManager(identity);
            var     uri           = "/images/detail";
            JObject response      = requestManager.Get(uri, "nova");
            var     tempinstances = response["images"];

            foreach (var tempinstance in tempinstances)
            {
                var instance = new OpenstackImage()
                {
                    Id     = tempinstance["id"].ToString(),
                    Name   = tempinstance["name"].ToString(),
                    Status = tempinstance["status"].ToString(),
                };
                list.Add(instance);
            }
            return(list);
        }
        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);
        }
 public OpenstackImage GetImage(string imageId, Identity identity)
 {
     OpenstackImage image;
     RequestManager requestManager = new RequestManager(identity);
     var uri = string.Format("/v2/images/{0}", imageId);
     JObject response = requestManager.Get(uri, "glance");
     var tempinstance = response;
     if (response != null)
     {
         image = new OpenstackImage()
         {
             Id = tempinstance["id"].ToString(),
             Name = tempinstance["name"].ToString(),
             Status = tempinstance["status"].ToString(),
         };
         if (tempinstance["container_format"] != null)
             image.ContainerFormat = tempinstance["container_format"].ToString();
         if (tempinstance["disk_format"] != null)
             image.DiskFormat = tempinstance["disk_format"].ToString();
         return image;
     }
     return null;
 }
 public IList<OpenstackImage> ListImages(Identity identity)
 {
     IList<OpenstackImage> list = new List<OpenstackImage>();
     RequestManager requestManager = new RequestManager(identity);
     var uri = "/images/detail";
     JObject response = requestManager.Get(uri, "nova");
     var tempinstances = response["images"];
     foreach (var tempinstance in tempinstances)
     {
         var instance = new OpenstackImage()
         {
             Id = tempinstance["id"].ToString(),
             Name = tempinstance["name"].ToString(),
             Status = tempinstance["status"].ToString(),
         };
         list.Add(instance);
     }
     return list;
 }
 public OpenstackImage GetImage(OpenstackImage image, Identity identity)
 {
     //TODO: get the image from glance without listing all of them, using filtered request by name
     var image2 = ListImages().Where((x) => x.Name.Equals(image.Name)).ToList().FirstOrDefault();
     return GetImage(image2.Id);
 }
 public OpenstackImage GetImage(OpenstackImage imageId)
 {
     return GetImage(imageId, _identity);
 }
 public OpenstackImage GetImage(OpenstackImage imageId)
 {
     return(GetImage(imageId, _identity));
 }