public FileInfo DownloadImage(string imageId, string outputPath, Identity identity)
 {
     RequestManager requestManager = new RequestManager(identity);
     var uri = string.Format("/v2/images/{0}/file", imageId);
     FileInfo result = requestManager.Download(imageId, outputPath, "glance");
     return result;
 }
        public void UploadImage()
        {
            string path = @"E:\AtlasVHDS\Snapshot-8e2f.ami";
            FileInfo image = new FileInfo(path);
            Identity identity = new Identity()
            {
                AuthEndpoint = "http://192.168.1.149:5000/v2.0",
                Password = "******",
                TenantName = "admin",
                Username = "******",
            };
            ImageManager imageManager = new ImageManager(identity);
            OpenstackImage img = new OpenstackImage()
            {
                Name = "Test" + Guid.NewGuid().ToString().Substring(0, 4),
                DiskFormat = image.Extension,
                Size = image.Length,

            };
               OpenstackImage obj= imageManager.UploadImage(image);
        }
 public RequestManager(Identity identity)
 {
     this._identity = identity;
 }
 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 ImageManager(Identity identity)
 {
     this._identity = identity;
 }
        public OpenstackImage UploadImage(FileInfo image, Identity identity)
        {
            RequestManager requestManager = new RequestManager(_identity);
            var uri = string.Format("/v1/images");
            JObject result = requestManager.Upload(image, uri, "glance");
            var jImage = result["image"];
            OpenstackImage returnedImage = new OpenstackImage()
            {
                CheckSum = jImage["checksum"].ToString(),
                ContainerFormat = jImage["container_format"].ToString(),
                DiskFormat = jImage["disk_format"].ToString(),
                Id = jImage["id"].ToString(),
                IsPublic = jImage["is_public"].ToString() == "true" ? true : false,
                Name = jImage["name"].ToString(),
                Size = long.Parse(jImage["size"].ToString()),
                Status = jImage["status"].ToString(),
            };

            return returnedImage;
        }
 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);
 }