Feature #1141

add url support to quota.rb for images

Added by Chris Johnston over 9 years ago. Updated over 9 years ago.

Status:ClosedStart date:02/24/2012
Priority:NormalDue date:
Assignee:Daniel Molina% Done:

100%

Category:-
Target version:Release 3.4
Resolution:fixed Pull request:

Description

The existing quota.rb only supports file based paths. The following patch against 3.0 adds support for url based paths. Looks simple to integrate into >= 3.2 but don't have an environment to verify.

--- quota.rb.old    2012-02-21 18:07:55.975870102 +0000
+++ quota.rb    2012-02-21 18:09:20.211865780 +0000
@@ -78,7 +78,13 @@

     IMAGE_USAGE = {
         :storage => {
-            :proc_info  => lambda {|template| File.size(template['PATH']) },
+            :proc_info  => lambda {|template|
+                if template['PATH']
+                    (image_size(template['PATH']).to_f / 2**20).round()
+                else
+                    0
+                end
+            },
             :xpath => 'SIZE'
         }
     }
@@ -86,6 +92,24 @@
     RESOURCES = ["VM", "IMAGE"]

     ###########################################################################
+    # Image helper
+    ###########################################################################
+    def self.image_size(path)
+        require 'uri'
+        require 'net/http'
+        uri = URI.parse(path)
+        if uri.scheme == nil
+            File.size(path)
+        else
+            response = nil
+            Net::HTTP.start(uri.host,uri.port) do |http|
+                response = http.head(uri.path)
+            end
+            response.content_length
+        end
+    end
+
+    ###########################################################################
     # DB handling
     ###########################################################################
     def initialize

Associated revisions

Revision 64476abb
Added by Daniel Molina over 9 years ago

feature #1141: Add url support to quota.rb

History

#1 Updated by Daniel Molina over 9 years ago

  • Status changed from New to Closed
  • Assignee set to Daniel Molina
  • Target version set to Release 3.4
  • % Done changed from 0 to 100
  • Resolution set to fixed

Hi Chris,

This feature has been included in master and will be distributed with the next release.

Thank you for your contribution.

Also available in: Atom PDF