diff --git a/include/VirtualMachineTemplate.h b/include/VirtualMachineTemplate.h index c19fbdf171..7dec7279d4 100644 --- a/include/VirtualMachineTemplate.h +++ b/include/VirtualMachineTemplate.h @@ -34,9 +34,28 @@ public: ~VirtualMachineTemplate(){}; - VirtualMachineTemplate(VirtualMachineTemplate& vmt):Template(vmt){}; + VirtualMachineTemplate(VirtualMachineTemplate& vmt):Template(vmt){}; + + /** + * Checks the template for RESTRICTED ATTRIBUTES + * @param rs_attr the first restricted attribute found if any + * @return true if a restricted attribute is found in the template + */ + bool check(string& rs_attr); private: + /** + * Number of restricted attributes + */ + const static int RS_ATTRS_LENGTH; + + /** + * Restricted template attributes in the form + * 'SINGLE' or 'VECTOR/ATTR'. Restricted attributes are only + * allowed for ONE_ADMIN Group. + */ + const static string RESTRICTED_ATTRIBUTES[]; + friend class VirtualMachine; }; diff --git a/install.sh b/install.sh index 1f836c13fb..0ef1d692af 100755 --- a/install.sh +++ b/install.sh @@ -198,6 +198,7 @@ ETC_DIRS="$ETC_LOCATION/im_kvm \ LIB_DIRS="$LIB_LOCATION/ruby \ $LIB_LOCATION/ruby/OpenNebula \ + $LIB_LOCATION/ruby/zona \ $LIB_LOCATION/ruby/cloud/ \ $LIB_LOCATION/ruby/cloud/econe \ $LIB_LOCATION/ruby/cloud/econe/views \ @@ -273,7 +274,8 @@ OZONES_DIRS="$OZONES_LOCATION/lib \ OZONES_CLIENT_DIRS="$LIB_LOCATION/ruby \ $LIB_LOCATION/ruby/OpenNebula \ $LIB_LOCATION/ruby/cli \ - $LIB_LOCATION/ruby/cli/ozones_helper" + $LIB_LOCATION/ruby/cli/ozones_helper \ + $LIB_LOCATION/ruby/zona" LIB_ECO_CLIENT_DIRS="$LIB_LOCATION/ruby \ $LIB_LOCATION/ruby/OpenNebula \ @@ -372,10 +374,11 @@ INSTALL_CLIENT_FILES=( CLI_LIB_FILES:$LIB_LOCATION/ruby/cli ONE_CLI_LIB_FILES:$LIB_LOCATION/ruby/cli/one_helper ETC_CLIENT_FILES:$ETC_LOCATION - OZONES_LIB_CLIENT_FILES:$LIB_LOCATION/ruby OZONES_BIN_CLIENT_FILES:$BIN_LOCATION OZONES_LIB_CLIENT_CLI_FILES:$LIB_LOCATION/ruby/cli OZONES_LIB_CLIENT_CLI_HELPER_FILES:$LIB_LOCATION/ruby/cli/ozones_helper + OZONES_LIB_API_FILES:$LIB_LOCATION/ruby + OZONES_LIB_API_ZONA_FILES:$LIB_LOCATION/ruby/zona CLI_CONF_FILES:$ETC_LOCATION/cli OCA_LIB_FILES:$LIB_LOCATION/ruby RUBY_OPENNEBULA_LIB_FILES:$LIB_LOCATION/ruby/OpenNebula @@ -430,10 +433,11 @@ INSTALL_OZONES_FILES=( OZONES_PUBLIC_IMAGES_FILES:$OZONES_LOCATION/public/images OZONES_PUBLIC_CSS_FILES:$OZONES_LOCATION/public/css OZONES_PUBLIC_JS_PLUGINS_FILES:$OZONES_LOCATION/public/js/plugins - OZONES_LIB_CLIENT_FILES:$LIB_LOCATION/ruby OZONES_BIN_CLIENT_FILES:$BIN_LOCATION OZONES_LIB_CLIENT_CLI_FILES:$LIB_LOCATION/ruby/cli OZONES_LIB_CLIENT_CLI_HELPER_FILES:$LIB_LOCATION/ruby/cli/ozones_helper + OZONES_LIB_API_FILES:$LIB_LOCATION/ruby + OZONES_LIB_API_ZONA_FILES:$LIB_LOCATION/ruby/zona ) INSTALL_OZONES_ETC_FILES=( @@ -1061,6 +1065,16 @@ OZONES_LIB_ZONE_FILES="src/ozones/Server/lib/OZones/Zones.rb \ src/ozones/Server/lib/OZones/AggregatedImages.rb \ src/ozones/Server/lib/OZones/AggregatedTemplates.rb" +OZONES_LIB_API_FILES="src/ozones/Client/lib/zona.rb" + +OZONES_LIB_API_ZONA_FILES="src/ozones/Client/lib/zona/ZoneElement.rb \ + src/ozones/Client/lib/zona/OZonesPool.rb \ + src/ozones/Client/lib/zona/OZonesJSON.rb \ + src/ozones/Client/lib/zona/VDCPool.rb \ + src/ozones/Client/lib/zona/VDCElement.rb \ + src/ozones/Client/lib/zona/OZonesElement.rb \ + src/ozones/Client/lib/zona/ZonePool.rb" + OZONES_PUBLIC_VENDOR_JQUERY=$SUNSTONE_PUBLIC_VENDOR_JQUERY OZONES_PUBLIC_VENDOR_DATATABLES=$SUNSTONE_PUBLIC_VENDOR_DATATABLES @@ -1096,8 +1110,6 @@ OZONES_PUBLIC_JS_PLUGINS_FILES="src/ozones/Server/public/js/plugins/zones-tab.js src/ozones/Server/public/js/plugins/aggregated-tab.js \ src/ozones/Server/public/js/plugins/dashboard-tab.js" -OZONES_LIB_CLIENT_FILES="src/ozones/Client/lib/OZonesClient.rb" - OZONES_LIB_CLIENT_CLI_FILES="src/ozones/Client/lib/cli/ozones_helper.rb" OZONES_LIB_CLIENT_CLI_HELPER_FILES="\ diff --git a/src/authm_mad/remotes/quota/onequota b/src/authm_mad/remotes/quota/onequota index a6fd24e669..0638a299c5 100755 --- a/src/authm_mad/remotes/quota/onequota +++ b/src/authm_mad/remotes/quota/onequota @@ -99,7 +99,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do arg_list.map! {|a| a.to_i } [0, arg_list] end - + set :format, :userid, OpenNebulaHelper.rname_to_id_desc("USER") do |arg| OpenNebulaHelper.rname_to_id(arg, "USER") end @@ -130,6 +130,26 @@ cmd=CommandParser::CmdParser.new(ARGV) do exit_with_code 0 end + ######################################################################## + unset_desc = <<-EOT.unindent + Unset a quota for a given user. + Examples: + onequota unset 3 cpu + onequota unset 4 cpu,memory,storage + EOT + + command :unset, unset_desc, :userid, :quota_list do + user_id, keys = args + + values_hash = Hash.new + keys.each_with_index { |k,i| + values_hash[k.to_sym] = 0 + } + + quota.set_quota(user_id, values_hash) + exit_with_code 0 + end + ######################################################################## delete_desc = "Delete the defined quotas for the given user" @@ -140,7 +160,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do ######################################################################## show_desc = "Show the user's quota and usage. (usage/quota)" - + FORCE={ :name => "force", :short => "-f", diff --git a/src/authm_mad/remotes/quota/quota.rb b/src/authm_mad/remotes/quota/quota.rb index 1f13234e45..805eff1d6e 100644 --- a/src/authm_mad/remotes/quota/quota.rb +++ b/src/authm_mad/remotes/quota/quota.rb @@ -154,6 +154,19 @@ class Quota set(QUOTA_TABLE, uid, quota) end + # Retrieves quota information for a given user + # + # @param [Integer, nil] uid the user id from which get the quota + # information, if nil will retrieve the quotas for all users. + # @return [Hash] Hash containing the quota information and the user id + # + # { + # :uid => 4, + # :cpu => 8, + # :memory => 8064, + # :num_vms => 4, + # :storage => 1240019 + # } def get_quota(uid=nil) limit = get(QUOTA_TABLE, uid) limit ? limit : @conf[:defaults].merge!(:uid => uid) @@ -192,14 +205,16 @@ class Quota msg = "" separator = "" info.each { |qname, quota_requested| - unless quota[qname] + unless quota[qname] || quota[qname]==0 next end - used = send(DB_QUOTA_SCHEMA[qname].name.to_sym, total[qname]) - request = send(DB_QUOTA_SCHEMA[qname].name.to_sym, quota_requested) - limit = send(DB_QUOTA_SCHEMA[qname].name.to_sym, quota[qname]) - spent = used + request + type = DB_QUOTA_SCHEMA[qname].name.to_sym + + used = send(type, total[qname]) + request = send(type, quota_requested) + limit = send(type, quota[qname]) + spent = used + request if spent > limit msg << separator @@ -228,6 +243,22 @@ class Quota ########################################################################### # Usage ########################################################################### + # Retrieves usage information for a given user + # + # @param [Integer] uid the user id from which get the usage information. + # @param ["VM", "IMAGE"] resource kind of resource. If nil will return + # the usage for all kinds of resources + # @param [true, false] force If true will force the usage calculation + # instead of retrieving it from the cache + # @return [Hash] Hash containing the usage information and the user id + # + # { + # :uid => 4, + # :cpu => 8, + # :memory => 8064, + # :num_vms => 4, + # :storage => 1240019 + # } def get_usage(user_id, resource=nil, force=false) if force if RESOURCES.include?(resource) @@ -242,9 +273,9 @@ class Quota pool = get_pool(res, user_id) base_xpath = "/#{res}_POOL/#{resource}" Quota.const_get("#{res}_USAGE".to_sym).each { |key, params| + usage[key] ||= 0 pool.each_xpath("#{base_xpath}/#{params[:xpath]}") { |elem| if elem - usage[key] ||= 0 if params[:count] usage[key] += 1 else diff --git a/src/authm_mad/remotes/quota/test/quota_spec.rb b/src/authm_mad/remotes/quota/test/quota_spec.rb index ff80f0c6c8..cf58842847 100644 --- a/src/authm_mad/remotes/quota/test/quota_spec.rb +++ b/src/authm_mad/remotes/quota/test/quota_spec.rb @@ -31,7 +31,7 @@ describe "Quota testing" do