diff --git a/include/GroupPool.h b/include/GroupPool.h index 28afe2eba8..335a52c245 100644 --- a/include/GroupPool.h +++ b/include/GroupPool.h @@ -93,9 +93,23 @@ public: */ Group * get(const string& name, bool lock) { + // The owner is set to -1, because it is not used in the key() method return static_cast(PoolSQL::get(name,-1,lock)); }; + /** + * Generate an index key for the object + * @param name of the object + * @param uid owner of the object, only used if needed + * + * @return the key, a string + */ + string key(const string& name, int uid) + { + // Name is enough key because Groups can't repeat names. + return name; + }; + /** Update a particular Group * @param user pointer to Group * @return 0 on success diff --git a/include/HostPool.h b/include/HostPool.h index 700344ff1a..7bdc0bfc23 100644 --- a/include/HostPool.h +++ b/include/HostPool.h @@ -79,9 +79,23 @@ public: */ Host * get(string name, bool lock) { + // The owner is set to -1, because it is not used in the key() method return static_cast(PoolSQL::get(name,-1,lock)); }; + /** + * Generate an index key for the object + * @param name of the object + * @param uid owner of the object, only used if needed + * + * @return the key, a string + */ + string key(const string& name, int uid) + { + // Name is enough key because Hosts can't repeat names. + return name; + }; + /** * Bootstraps the database table(s) associated to the Host pool * @return 0 on success diff --git a/include/ImageTemplate.h b/include/ImageTemplate.h index 243e9f3f45..21dd0eec64 100644 --- a/include/ImageTemplate.h +++ b/include/ImageTemplate.h @@ -46,7 +46,15 @@ private: static vector restricted_attributes; - static void set_restricted_attributes(vector& rattrs); + /** + * Stores the attributes as restricted, these attributes will be used in + * ImageTemplate::check + * @param rattrs Attributes to restrict + */ + static void set_restricted_attributes(vector& rattrs) + { + Template::set_restricted_attributes(rattrs, restricted_attributes); + }; }; /* -------------------------------------------------------------------------- */ diff --git a/include/PoolSQL.h b/include/PoolSQL.h index 822a5559b3..86641daaa7 100644 --- a/include/PoolSQL.h +++ b/include/PoolSQL.h @@ -82,6 +82,20 @@ public: */ PoolObjectSQL * get(const string& name, int uid, bool lock); + /** + * Updates the cache name index. Must be called when the owner of an object + * is changed + * + * @param old_name Object's name before the change + * @param old_uid Object's owner ID before the change + * @param new_name Object's name after the change + * @param new_uid Object's owner ID after the change + */ + void update_cache_index(string& old_name, + int old_uid, + string& new_name, + int new_uid); + /** * Finds a set objects that satisfies a given condition * @param oids a vector with the oids of the objects. @@ -273,7 +287,7 @@ private: * * @return the key, a string */ - string key(const string& name, int uid) + virtual string key(const string& name, int uid) { ostringstream key; diff --git a/include/Template.h b/include/Template.h index 8a1dbe8b9a..1540c1e444 100644 --- a/include/Template.h +++ b/include/Template.h @@ -221,6 +221,16 @@ protected: */ Attribute* vector_xml_att(const xmlNode * node); + /** + * Stores the attributes as restricted, these attributes will be used in + * Template::check + * @param rattrs Attributes to restrict + * @param restricted_attributes The attributes will be stored here + */ + static void set_restricted_attributes( + vector& rattrs, + vector& restricted_attributes); + /** * Checks the template for RESTRICTED ATTRIBUTES * @param rs_attr the first restricted attribute found if any diff --git a/include/UserPool.h b/include/UserPool.h index 20120b4c62..3926c71613 100644 --- a/include/UserPool.h +++ b/include/UserPool.h @@ -80,9 +80,23 @@ public: */ User * get(string name, bool lock) { + // The owner is set to -1, because it is not used in the key() method return static_cast(PoolSQL::get(name,-1,lock)); }; + /** + * Generate an index key for the object + * @param name of the object + * @param uid owner of the object, only used if needed + * + * @return the key, a string + */ + string key(const string& name, int uid) + { + // Name is enough key because Users can't repeat names. + return name; + }; + /** Update a particular User * @param user pointer to User * @return 0 on success diff --git a/include/VirtualMachineTemplate.h b/include/VirtualMachineTemplate.h index 422a73cfa4..5e36fbbb8c 100644 --- a/include/VirtualMachineTemplate.h +++ b/include/VirtualMachineTemplate.h @@ -52,7 +52,15 @@ private: static vector restricted_attributes; - static void set_restricted_attributes(vector& rattrs); + /** + * Stores the attributes as restricted, these attributes will be used in + * VirtualMachineTemplate::check + * @param rattrs Attributes to restrict + */ + static void set_restricted_attributes(vector& rattrs) + { + Template::set_restricted_attributes(rattrs, restricted_attributes); + }; }; /* -------------------------------------------------------------------------- */ diff --git a/share/install_gems/install_gems b/share/install_gems/install_gems index 2d37390604..4d8e8844a7 100755 --- a/share/install_gems/install_gems +++ b/share/install_gems/install_gems @@ -112,7 +112,7 @@ EOT `gem install rubygems-update --version '= 1.3.6'` - if $?.ecxitstatus!=0 + if $?.exitstatus!=0 puts "Error updating rubygems" exit(-1) end diff --git a/src/cli/one_helper.rb b/src/cli/one_helper.rb index 3bfda3e948..e900a963bc 100644 --- a/src/cli/one_helper.rb +++ b/src/cli/one_helper.rb @@ -287,7 +287,12 @@ EOT end def pool_to_array(pool) - phash = pool.to_hash + if !pool.instance_of?(Hash) + phash = pool.to_hash + else + phash = pool + end + rname = self.class.rname if phash["#{rname}_POOL"] && diff --git a/src/cli/one_helper/onegroup_helper.rb b/src/cli/one_helper/onegroup_helper.rb index 22da321f67..a949d29978 100644 --- a/src/cli/one_helper/onegroup_helper.rb +++ b/src/cli/one_helper/onegroup_helper.rb @@ -44,6 +44,24 @@ class OneGroupHelper < OpenNebulaHelper::OneHelper exit_code end + def format_pool(options) + config_file = self.class.table_conf + + table = CLIHelper::ShowTable.new(config_file, self) do + column :ID, "ONE identifier for the Group", :size=>4 do |d| + d["ID"] + end + + column :NAME, "Name of the Group", :left, :size=>15 do |d| + d["NAME"] + end + + default :ID, :NAME + end + + table + end + private def factory(id=nil) @@ -75,22 +93,4 @@ class OneGroupHelper < OpenNebulaHelper::OneHelper puts "%-15s" % [uid] end end - - def format_pool(options) - config_file = self.class.table_conf - - table = CLIHelper::ShowTable.new(config_file, self) do - column :ID, "ONE identifier for the Group", :size=>4 do |d| - d["ID"] - end - - column :NAME, "Name of the Group", :left, :size=>15 do |d| - d["NAME"] - end - - default :ID, :NAME - end - - table - end end diff --git a/src/cli/one_helper/onehost_helper.rb b/src/cli/one_helper/onehost_helper.rb index 5951f13abc..b50a02c617 100644 --- a/src/cli/one_helper/onehost_helper.rb +++ b/src/cli/one_helper/onehost_helper.rb @@ -31,58 +31,6 @@ class OneHostHelper < OpenNebulaHelper::OneHelper return Host::SHORT_HOST_STATES[state_str] end - private - - def factory(id=nil) - if id - OpenNebula::Host.new_with_id(id, @client) - else - xml=OpenNebula::Host.build_xml - OpenNebula::Host.new(xml, @client) - end - end - - def factory_pool(user_flag=-2) - #TBD OpenNebula::HostPool.new(@client, user_flag) - OpenNebula::HostPool.new(@client) - end - - def format_resource(host) - str = "%-22s: %-20s" - str_h1 = "%-80s" - - CLIHelper.print_header( - str_h1 % "HOST #{host.id.to_s} INFORMATION", true) - - puts str % ["ID", host.id.to_s] - puts str % ["NAME", host.name] - puts str % ["STATE", host.state_str] - puts str % ["IM_MAD", host['IM_MAD']] - puts str % ["VM_MAD", host['VM_MAD']] - puts str % ["VN_MAD", host['VN_MAD']] - puts str % ["TM_MAD", host['TM_MAD']] - puts str % ["LAST MONITORING TIME", host['LAST_MON_TIME']] - puts - - CLIHelper.print_header(str_h1 % "HOST SHARES", false) - - puts str % ["MAX MEM", host['HOST_SHARE/MAX_MEM']] - puts str % ["USED MEM (REAL)", host['HOST_SHARE/USED_MEM']] - puts str % ["USED MEM (ALLOCATED)", host['HOST_SHARE/MEM_USAGE']] - puts str % ["MAX CPU", host['HOST_SHARE/MAX_CPU']] - puts str % ["USED CPU (REAL)", host['HOST_SHARE/USED_CPU']] - puts str % ["USED CPU (ALLOCATED)", host['HOST_SHARE/CPU_USAGE']] - puts str % ["MAX DISK", host['HOST_SHARE/MAX_DISK']] - puts str % ["USED DISK (REAL)", host['HOST_SHARE/USED_DISK']] - puts str % ["USED DISK (ALLOCATED)", host['HOST_SHARE/DISK_USAGE']] - puts str % ["RUNNING VMS", host['HOST_SHARE/RUNNING_VMS']] - puts - - CLIHelper.print_header(str_h1 % "MONITORING INFORMATION", false) - - puts host.template_str - end - def format_pool(options) config_file = self.class.table_conf @@ -144,4 +92,56 @@ class OneHostHelper < OpenNebulaHelper::OneHelper table end + + private + + def factory(id=nil) + if id + OpenNebula::Host.new_with_id(id, @client) + else + xml=OpenNebula::Host.build_xml + OpenNebula::Host.new(xml, @client) + end + end + + def factory_pool(user_flag=-2) + #TBD OpenNebula::HostPool.new(@client, user_flag) + OpenNebula::HostPool.new(@client) + end + + def format_resource(host) + str = "%-22s: %-20s" + str_h1 = "%-80s" + + CLIHelper.print_header( + str_h1 % "HOST #{host.id.to_s} INFORMATION", true) + + puts str % ["ID", host.id.to_s] + puts str % ["NAME", host.name] + puts str % ["STATE", host.state_str] + puts str % ["IM_MAD", host['IM_MAD']] + puts str % ["VM_MAD", host['VM_MAD']] + puts str % ["VN_MAD", host['VN_MAD']] + puts str % ["TM_MAD", host['TM_MAD']] + puts str % ["LAST MONITORING TIME", host['LAST_MON_TIME']] + puts + + CLIHelper.print_header(str_h1 % "HOST SHARES", false) + + puts str % ["MAX MEM", host['HOST_SHARE/MAX_MEM']] + puts str % ["USED MEM (REAL)", host['HOST_SHARE/USED_MEM']] + puts str % ["USED MEM (ALLOCATED)", host['HOST_SHARE/MEM_USAGE']] + puts str % ["MAX CPU", host['HOST_SHARE/MAX_CPU']] + puts str % ["USED CPU (REAL)", host['HOST_SHARE/USED_CPU']] + puts str % ["USED CPU (ALLOCATED)", host['HOST_SHARE/CPU_USAGE']] + puts str % ["MAX DISK", host['HOST_SHARE/MAX_DISK']] + puts str % ["USED DISK (REAL)", host['HOST_SHARE/USED_DISK']] + puts str % ["USED DISK (ALLOCATED)", host['HOST_SHARE/DISK_USAGE']] + puts str % ["RUNNING VMS", host['HOST_SHARE/RUNNING_VMS']] + puts + + CLIHelper.print_header(str_h1 % "MONITORING INFORMATION", false) + + puts host.template_str + end end diff --git a/src/cli/one_helper/oneimage_helper.rb b/src/cli/one_helper/oneimage_helper.rb index 0387ed3a71..27a4910ec1 100644 --- a/src/cli/one_helper/oneimage_helper.rb +++ b/src/cli/one_helper/oneimage_helper.rb @@ -36,60 +36,7 @@ class OneImageHelper < OpenNebulaHelper::OneHelper type_str = Image::IMAGE_TYPES[id] return Image::SHORT_IMAGE_TYPES[type_str] end - - private - - def factory(id=nil) - if id - OpenNebula::Image.new_with_id(id, @client) - else - xml=OpenNebula::Image.build_xml - OpenNebula::Image.new(xml, @client) - end - end - - def factory_pool(user_flag=-2) - OpenNebula::ImagePool.new(@client, user_flag) - end - - def format_resource(image) - str="%-15s: %-20s" - str_h1="%-80s" - - CLIHelper.print_header(str_h1 % "IMAGE #{image['ID']} INFORMATION") - puts str % ["ID", image.id.to_s] - puts str % ["NAME", image.name] - puts str % ["USER", image['UNAME']] - puts str % ["GROUP",image['GNAME']] - puts str % ["TYPE", image.type_str] - puts str % ["REGISTER TIME", - OpenNebulaHelper.time_to_str(image['REGTIME'])] - puts str % ["PERSISTENT", - OpenNebulaHelper.boolean_to_str(image["PERSISTENT"])] - puts str % ["SOURCE",image['SOURCE']] - puts str % ["PATH",image['PATH']] if image['PATH'] && !image['PATH'].empty? - puts str % ["FSTYPE",image['FSTYPE']] if image['FSTYPE'] && !image['FSTYPE'].empty? - puts str % ["SIZE", image['SIZE']] - puts str % ["STATE", image.short_state_str] - puts str % ["RUNNING_VMS", image['RUNNING_VMS']] - puts - - CLIHelper.print_header(str_h1 % "PERMISSIONS",false) - - ["OWNER", "GROUP", "OTHER"].each { |e| - mask = "---" - mask[0] = "u" if image["PERMISSIONS/#{e}_U"] == "1" - mask[1] = "m" if image["PERMISSIONS/#{e}_M"] == "1" - mask[2] = "a" if image["PERMISSIONS/#{e}_A"] == "1" - - puts str % [e, mask] - } - puts - - CLIHelper.print_header(str_h1 % "IMAGE TEMPLATE",false) - puts image.template_str - end - + def format_pool(options) config_file = self.class.table_conf @@ -146,4 +93,57 @@ class OneImageHelper < OpenNebulaHelper::OneHelper table end + + private + + def factory(id=nil) + if id + OpenNebula::Image.new_with_id(id, @client) + else + xml=OpenNebula::Image.build_xml + OpenNebula::Image.new(xml, @client) + end + end + + def factory_pool(user_flag=-2) + OpenNebula::ImagePool.new(@client, user_flag) + end + + def format_resource(image) + str="%-15s: %-20s" + str_h1="%-80s" + + CLIHelper.print_header(str_h1 % "IMAGE #{image['ID']} INFORMATION") + puts str % ["ID", image.id.to_s] + puts str % ["NAME", image.name] + puts str % ["USER", image['UNAME']] + puts str % ["GROUP",image['GNAME']] + puts str % ["TYPE", image.type_str] + puts str % ["REGISTER TIME", + OpenNebulaHelper.time_to_str(image['REGTIME'])] + puts str % ["PERSISTENT", + OpenNebulaHelper.boolean_to_str(image["PERSISTENT"])] + puts str % ["SOURCE",image['SOURCE']] + puts str % ["PATH",image['PATH']] if image['PATH'] && !image['PATH'].empty? + puts str % ["FSTYPE",image['FSTYPE']] if image['FSTYPE'] && !image['FSTYPE'].empty? + puts str % ["SIZE", image['SIZE']] + puts str % ["STATE", image.short_state_str] + puts str % ["RUNNING_VMS", image['RUNNING_VMS']] + puts + + CLIHelper.print_header(str_h1 % "PERMISSIONS",false) + + ["OWNER", "GROUP", "OTHER"].each { |e| + mask = "---" + mask[0] = "u" if image["PERMISSIONS/#{e}_U"] == "1" + mask[1] = "m" if image["PERMISSIONS/#{e}_M"] == "1" + mask[2] = "a" if image["PERMISSIONS/#{e}_A"] == "1" + + puts str % [e, mask] + } + puts + + CLIHelper.print_header(str_h1 % "IMAGE TEMPLATE",false) + puts image.template_str + end end diff --git a/src/cli/one_helper/onetemplate_helper.rb b/src/cli/one_helper/onetemplate_helper.rb index 268e9c83eb..8b56fbe2c4 100644 --- a/src/cli/one_helper/onetemplate_helper.rb +++ b/src/cli/one_helper/onetemplate_helper.rb @@ -41,6 +41,38 @@ class OneTemplateHelper < OpenNebulaHelper::OneHelper "onetemplate.yaml" end + def format_pool(options) + config_file = self.class.table_conf + + table = CLIHelper::ShowTable.new(config_file, self) do + column :ID, "ONE identifier for the Template", :size=>4 do |d| + d["ID"] + end + + column :NAME, "Name of the Template", :left, :size=>15 do |d| + d["NAME"] + end + + column :USER, "Username of the Template owner", :left, + :size=>8 do |d| + helper.user_name(d, options) + end + + column :GROUP, "Group of the Template", :left, :size=>8 do |d| + helper.group_name(d, options) + end + + column :REGTIME, "Registration time of the Template", + :size=>20 do |d| + OpenNebulaHelper.time_to_str(d["REGTIME"]) + end + + default :ID, :USER, :GROUP, :NAME, :REGTIME + end + + table + end + private def factory(id=nil) @@ -85,36 +117,4 @@ class OneTemplateHelper < OpenNebulaHelper::OneHelper CLIHelper.print_header(str_h1 % "TEMPLATE CONTENTS",false) puts template.template_str end - - def format_pool(options) - config_file = self.class.table_conf - - table = CLIHelper::ShowTable.new(config_file, self) do - column :ID, "ONE identifier for the Template", :size=>4 do |d| - d["ID"] - end - - column :NAME, "Name of the Template", :left, :size=>15 do |d| - d["NAME"] - end - - column :USER, "Username of the Template owner", :left, - :size=>8 do |d| - helper.user_name(d, options) - end - - column :GROUP, "Group of the Template", :left, :size=>8 do |d| - helper.group_name(d, options) - end - - column :REGTIME, "Registration time of the Template", - :size=>20 do |d| - OpenNebulaHelper.time_to_str(d["REGTIME"]) - end - - default :ID, :USER, :GROUP, :NAME, :REGTIME - end - - table - end end diff --git a/src/cli/one_helper/oneuser_helper.rb b/src/cli/one_helper/oneuser_helper.rb index 11480b9f44..82a060b44e 100644 --- a/src/cli/one_helper/oneuser_helper.rb +++ b/src/cli/one_helper/oneuser_helper.rb @@ -143,6 +143,36 @@ class OneUserHelper < OpenNebulaHelper::OneHelper return 0, 'export ONE_AUTH=' << auth.class::LOGIN_PATH end + def format_pool(options) + config_file = self.class.table_conf + + table = CLIHelper::ShowTable.new(config_file, self) do + column :ID, "ONE identifier for the User", :size=>4 do |d| + d["ID"] + end + + column :NAME, "Name of the User", :left, :size=>15 do |d| + d["NAME"] + end + + column :GROUP, "Group of the User", :left, :size=>8 do |d| + helper.group_name(d, options) + end + + column :AUTH, "Auth driver of the User", :left, :size=>8 do |d| + d["AUTH_DRIVER"] + end + + column :PASSWORD, "Password of the User", :size=>50 do |d| + d['PASSWORD'] + end + + default :ID, :GROUP, :NAME, :AUTH, :PASSWORD + end + + table + end + private def factory(id=nil) @@ -178,34 +208,4 @@ class OneUserHelper < OpenNebulaHelper::OneHelper CLIHelper.print_header(str_h1 % "USER TEMPLATE",false) puts user.template_str end - - def format_pool(options) - config_file = self.class.table_conf - - table = CLIHelper::ShowTable.new(config_file, self) do - column :ID, "ONE identifier for the User", :size=>4 do |d| - d["ID"] - end - - column :NAME, "Name of the User", :left, :size=>15 do |d| - d["NAME"] - end - - column :GROUP, "Group of the User", :left, :size=>8 do |d| - helper.group_name(d, options) - end - - column :AUTH, "Auth driver of the User", :left, :size=>8 do |d| - d["AUTH_DRIVER"] - end - - column :PASSWORD, "Password of the User", :size=>50 do |d| - d['PASSWORD'] - end - - default :ID, :GROUP, :NAME, :AUTH, :PASSWORD - end - - table - end end diff --git a/src/cli/one_helper/onevm_helper.rb b/src/cli/one_helper/onevm_helper.rb index 066be63a13..10b7c75c3d 100644 --- a/src/cli/one_helper/onevm_helper.rb +++ b/src/cli/one_helper/onevm_helper.rb @@ -47,6 +47,68 @@ class OneVMHelper < OpenNebulaHelper::OneHelper return short_state_str end + def format_pool(options) + config_file = self.class.table_conf + + table = CLIHelper::ShowTable.new(config_file, self) do + column :ID, "ONE identifier for Virtual Machine", :size=>6 do |d| + d["ID"] + end + + column :NAME, "Name of the Virtual Machine", :left, + :size=>15 do |d| + d["NAME"] + end + + column :USER, "Username of the Virtual Machine owner", :left, + :size=>8 do |d| + helper.user_name(d, options) + end + + column :GROUP, "Group of the Virtual Machine", :left, + :size=>8 do |d| + helper.group_name(d, options) + end + + column :STAT, "Actual status", :size=>4 do |d,e| + OneVMHelper.state_to_str(d["STATE"], d["LCM_STATE"]) + end + + column :CPU, "CPU percentage used by the VM", :size=>3 do |d| + d["CPU"] + end + + column :MEM, "Memory used by the VM", :size=>7 do |d| + OpenNebulaHelper.unit_to_str(d["MEMORY"].to_i, options) + end + + column :HOSTNAME, "Host where the VM is running", :size=>15 do |d| + if d['HISTORY_RECORDS'] && d['HISTORY_RECORDS']['HISTORY'] + state_str = VirtualMachine::VM_STATE[d['STATE'].to_i] + if %w{ACTIVE SUSPENDED}.include? state_str + d['HISTORY_RECORDS']['HISTORY']['HOSTNAME'] + end + end + end + + column :TIME, "Time since the VM was submitted", :size=>11 do |d| + stime = Time.at(d["STIME"].to_i) + etime = d["ETIME"]=="0" ? Time.now : Time.at(d["ETIME"].to_i) + dtime = Time.at(etime-stime).getgm + "%02d %02d:%02d:%02d" % [ + dtime.yday-1, + dtime.hour, + dtime.min, + dtime.sec] + end + + default :ID, :USER, :GROUP, :NAME, :STAT, :CPU, :MEM, :HOSTNAME, + :TIME + end + + table + end + private def factory(id=nil) @@ -120,68 +182,6 @@ class OneVMHelper < OpenNebulaHelper::OneHelper end end - def format_pool(options) - config_file = self.class.table_conf - - table = CLIHelper::ShowTable.new(config_file, self) do - column :ID, "ONE identifier for Virtual Machine", :size=>6 do |d| - d["ID"] - end - - column :NAME, "Name of the Virtual Machine", :left, - :size=>15 do |d| - d["NAME"] - end - - column :USER, "Username of the Virtual Machine owner", :left, - :size=>8 do |d| - helper.user_name(d, options) - end - - column :GROUP, "Group of the Virtual Machine", :left, - :size=>8 do |d| - helper.group_name(d, options) - end - - column :STAT, "Actual status", :size=>4 do |d,e| - OneVMHelper.state_to_str(d["STATE"], d["LCM_STATE"]) - end - - column :CPU, "CPU percentage used by the VM", :size=>3 do |d| - d["CPU"] - end - - column :MEM, "Memory used by the VM", :size=>7 do |d| - OpenNebulaHelper.unit_to_str(d["MEMORY"].to_i, options) - end - - column :HOSTNAME, "Host where the VM is running", :size=>15 do |d| - if d['HISTORY_RECORDS'] && d['HISTORY_RECORDS']['HISTORY'] - state_str = VirtualMachine::VM_STATE[d['STATE'].to_i] - if %w{ACTIVE SUSPENDED}.include? state_str - d['HISTORY_RECORDS']['HISTORY']['HOSTNAME'] - end - end - end - - column :TIME, "Time since the VM was submitted", :size=>11 do |d| - stime = Time.at(d["STIME"].to_i) - etime = d["ETIME"]=="0" ? Time.now : Time.at(d["ETIME"].to_i) - dtime = Time.at(etime-stime).getgm - "%02d %02d:%02d:%02d" % [ - dtime.yday-1, - dtime.hour, - dtime.min, - dtime.sec] - end - - default :ID, :USER, :GROUP, :NAME, :STAT, :CPU, :MEM, :HOSTNAME, - :TIME - end - - table - end - def format_history(vm) table=CLIHelper::ShowTable.new(nil, self) do column :SEQ, "Sequence number", :size=>4 do |d| diff --git a/src/cli/one_helper/onevnet_helper.rb b/src/cli/one_helper/onevnet_helper.rb index afc9d77291..72fb32346c 100644 --- a/src/cli/one_helper/onevnet_helper.rb +++ b/src/cli/one_helper/onevnet_helper.rb @@ -31,6 +31,53 @@ class OneVNetHelper < OpenNebulaHelper::OneHelper return VirtualNetwork::SHORT_VN_TYPES[type_str] end + def format_pool(options) + config_file = self.class.table_conf + + table = CLIHelper::ShowTable.new(config_file, self) do + column :ID, "ONE identifier for Virtual Network", :size=>4 do |d| + d["ID"] + end + + column :NAME, "Name of the Virtual Network", :left, + :size=>15 do |d| + d["NAME"] + end + + column :USER, "Username of the Virtual Network owner", :left, + :size=>8 do |d| + helper.user_name(d, options) + end + + column :GROUP, "Group of the Virtual Network", :left, + :size=>8 do |d| + helper.group_name(d, options) + end + + column :TYPE, "Type of Virtual Network", :size=>6 do |d| + OneVNetHelper.type_to_str(d["TYPE"]) + end + + column :SIZE, "Size of the Virtual Network", :size=>6 do |d| + d["SIZE"] + end + + column :BRIDGE, "Bridge associated to the Virtual Network", + :size=>6 do |d| + d["BRIDGE"] + end + + column :LEASES, "Number of this Virtual Network's given leases", + :size=>7 do |d| + d["TOTAL_LEASES"] + end + + default :ID, :USER, :GROUP, :NAME, :TYPE, :BRIDGE, :LEASES + end + + table + end + private def factory(id=nil) @@ -101,51 +148,4 @@ class OneVNetHelper < OpenNebulaHelper::OneHelper end } end - - def format_pool(options) - config_file = self.class.table_conf - - table = CLIHelper::ShowTable.new(config_file, self) do - column :ID, "ONE identifier for Virtual Network", :size=>4 do |d| - d["ID"] - end - - column :NAME, "Name of the Virtual Network", :left, - :size=>15 do |d| - d["NAME"] - end - - column :USER, "Username of the Virtual Network owner", :left, - :size=>8 do |d| - helper.user_name(d, options) - end - - column :GROUP, "Group of the Virtual Network", :left, - :size=>8 do |d| - helper.group_name(d, options) - end - - column :TYPE, "Type of Virtual Network", :size=>6 do |d| - OneVNetHelper.type_to_str(d["TYPE"]) - end - - column :SIZE, "Size of the Virtual Network", :size=>6 do |d| - d["SIZE"] - end - - column :BRIDGE, "Bridge associated to the Virtual Network", - :size=>6 do |d| - d["BRIDGE"] - end - - column :LEASES, "Number of this Virtual Network's given leases", - :size=>7 do |d| - d["TOTAL_LEASES"] - end - - default :ID, :USER, :GROUP, :NAME, :TYPE, :BRIDGE, :LEASES - end - - table - end end diff --git a/src/cloud/occi/lib/ImageOCCI.rb b/src/cloud/occi/lib/ImageOCCI.rb index c15cd97c0e..7f3f1dec1a 100755 --- a/src/cloud/occi/lib/ImageOCCI.rb +++ b/src/cloud/occi/lib/ImageOCCI.rb @@ -22,7 +22,7 @@ class ImageOCCI < Image OCCI_IMAGE = %q{ <%= self.id.to_s %> - <%= self.name %><%= self.name %> <%= self.state_str %> <% if self['TYPE'] != nil %> <%= self.type_str %> diff --git a/src/cloud/occi/lib/ui/public/js/plugins/storage.js b/src/cloud/occi/lib/ui/public/js/plugins/storage.js index f505615b1e..6e7b99d7fd 100644 --- a/src/cloud/occi/lib/ui/public/js/plugins/storage.js +++ b/src/cloud/occi/lib/ui/public/js/plugins/storage.js @@ -1,5 +1,5 @@ /* -------------------------------------------------------------------------- */ -/* Copyright 2002-2012, OpenNebula Project Leads (OCCI.org) */ +/* Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) */ /* */ /* Licensed under the Apache License, Version 2.0 (the "License"); you may */ /* not use this file except in compliance with the License. You may obtain */ diff --git a/src/image/ImageManagerDriver.cc b/src/image/ImageManagerDriver.cc index c565209491..7c1862fb65 100644 --- a/src/image/ImageManagerDriver.cc +++ b/src/image/ImageManagerDriver.cc @@ -228,13 +228,12 @@ void ImageManagerDriver::protocol( if ( rc < 0 ) { - image->unlock(); NebulaLog::log("ImM",Log::ERROR,"Image could not be removed from DB"); } if ( result == "SUCCESS" ) { - NebulaLog::log("ImM",Log::ERROR,"Image successfully removed."); + NebulaLog::log("ImM",Log::INFO,"Image successfully removed."); } else { @@ -267,10 +266,23 @@ error_mkfs: goto error_common; error_rm: + image->unlock(); + os.str(""); os << "Error removing image from repository. Remove file " << source << " to completely delete image."; + getline(is,info); + + if (!info.empty() && (info[0] != '-')) + { + os << ": " << info; + } + + NebulaLog::log("ImM", Log::ERROR, os); + + return; + error_common: getline(is,info); diff --git a/src/image/ImageTemplate.cc b/src/image/ImageTemplate.cc index 6df1942c3d..60c1fb623a 100644 --- a/src/image/ImageTemplate.cc +++ b/src/image/ImageTemplate.cc @@ -23,22 +23,3 @@ vector ImageTemplate::restricted_attributes; /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ - -void ImageTemplate::set_restricted_attributes(vector& rattrs) -{ - const SingleAttribute * sattr; - string attr; - - for (unsigned int i = 0 ; i < rattrs.size() ; i++ ) - { - sattr = static_cast(rattrs[i]); - - attr = sattr->value(); - transform (attr.begin(),attr.end(),attr.begin(),(int(*)(int))toupper); - - restricted_attributes.push_back(attr); - } -} - -/* -------------------------------------------------------------------------- */ -/* -------------------------------------------------------------------------- */ diff --git a/src/oca/ruby/OpenNebula.rb b/src/oca/ruby/OpenNebula.rb index 0d0b2ac4a2..6bb4a4916c 100644 --- a/src/oca/ruby/OpenNebula.rb +++ b/src/oca/ruby/OpenNebula.rb @@ -79,6 +79,30 @@ module OpenNebula value.class==OpenNebula::Error end + + if OpenNebula::NOKOGIRI + class NokogiriStreamParser < XMLRPC::XMLParser::AbstractStreamParser + def initialize + @parser_class = NokogiriParser + end + + class NokogiriParser < Nokogiri::XML::SAX::Document + include XMLRPC::XMLParser::StreamParserMixin + + alias :cdata_block :character + alias :characters :character + alias :end_element :endElement + alias :start_element :startElement + + def parse(str) + parser = Nokogiri::XML::SAX::Parser.new(self) + parser.parse(str) + end + end + end + end + + # The client class, represents the connection with the core and handles the # xml-rpc calls. class Client @@ -113,14 +137,15 @@ module OpenNebula end @server = XMLRPC::Client.new2(@one_endpoint) + + if OpenNebula::NOKOGIRI + @server.set_parser(NokogiriStreamParser.new) + elsif XMLPARSER + @server.set_parser(XMLRPC::XMLParser::XMLStreamParser.new) + end end def call(action, *args) - - if XMLPARSER - @server.set_parser(XMLRPC::XMLParser::XMLStreamParser.new) - end - begin response = @server.call_async("one."+action, @one_auth, *args) diff --git a/src/ozones/Client/bin/onezone b/src/ozones/Client/bin/onezone index c23ff75dfe..af922e7bcb 100755 --- a/src/ozones/Client/bin/onezone +++ b/src/ozones/Client/bin/onezone @@ -30,6 +30,15 @@ $: << RUBY_LIB_LOCATION+"/cli" require 'command_parser' require 'ozones_helper/zones_helper.rb' + +class Hash + def self.transform_keys_to_strings(value) + return value if not value.is_a?(Hash) + hash = value.inject({}){|memo,(k,v)| memo[k.to_s] = Hash.transform_keys_to_strings(v); memo} + return hash + end +end + cmd=CommandParser::CmdParser.new(ARGV) do usage "`onezone` [] []" version OpenNebulaHelper::ONE_VERSION @@ -56,7 +65,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do show_desc = <<-EOT.unindent Show information of a particular Zone - Available resources: host, vm, image, vn, template, user + Available resources: host, vm, image, vnet, vmtemplate, user Examples: onezone show 4 onezone show 4 host @@ -67,50 +76,42 @@ cmd=CommandParser::CmdParser.new(ARGV) do case args[1] when "host" - aux_helper = OneHostHelper.new( - zone[:ONENAME] + ":" + zone[:ONEPASS], - zone[:ENDPOINT], - false) - - aux_helper.list_pool(options) + aux_helper = OneHostHelper.new when "vm" - aux_helper = OneVMHelper.new( - zone[:ONENAME] + ":" + zone[:ONEPASS], - zone[:ENDPOINT], - false) - - aux_helper.list_pool(options) + aux_helper = OneVMHelper.new when "image" - aux_helper = OneImageHelper.new( - zone[:ONENAME] + ":" + zone[:ONEPASS], - zone[:ENDPOINT], - false) - - aux_helper.list_pool(options) - when "vn" - aux_helper = OneVNetHelper.new( - zone[:ONENAME] + ":" + zone[:ONEPASS], - zone[:ENDPOINT], - false) - - aux_helper.list_pool(options) - - when "template" - aux_helper = OneTemplateHelper.new( - zone[:ONENAME] + ":" + zone[:ONEPASS], - zone[:ENDPOINT], - false) - - aux_helper.list_pool(options) - + aux_helper = OneImageHelper.new + when "vnet" + aux_helper = OneVNetHelper.new + when "vmtemplate" + aux_helper = OneTemplateHelper.new when "user" - aux_helper = OneUserHelper.new( - zone[:ONENAME] + ":" + zone[:ONEPASS], - zone[:ENDPOINT], - false) - - aux_helper.list_pool(options) + aux_helper = OneUserHelper.new + else + puts "\n:!: Pool #{args[1]} doesn't exist or is not supported\n\n" + next 0 end + + pool_hash_data = helper.get_resource_pool("zone", zone[:ID], args[1]) + + if pool_hash_data[0] != 0 + puts "\nError retrieving information for pool #{args[1]}. Reason: " + pool_hash_data[1] + "\n\n" + next 0 + end + + if !pool_hash_data[1] + next 0 + end + + if pool_hash_data[1].is_a?(Hash) + pool_hash_data[1]=[Hash.transform_keys_to_strings(pool_hash_data[1])] + else + pool_hash_data[1].each{|hash| hash.replace(Hash.transform_keys_to_strings(hash))} + end + + table = aux_helper.format_pool(options) + table.show(pool_hash_data[1]) + 0 end diff --git a/src/ozones/Client/lib/cli/ozones_helper.rb b/src/ozones/Client/lib/cli/ozones_helper.rb index dffe8c704d..6ce320b5e8 100644 --- a/src/ozones/Client/lib/cli/ozones_helper.rb +++ b/src/ozones/Client/lib/cli/ozones_helper.rb @@ -61,6 +61,16 @@ module OZonesHelper end end + def get_resource_pool(kind, id, pool) + rc = @client.get_resource_pool(kind, id, pool) + + if Zona::is_error?(rc) + [-1, rc.message] + else + [0 , Zona::OZonesJSON.parse_json(rc.body, pool.upcase+"_POOL")[pool.upcase.to_sym]] + end + end + def delete_resource(kind, id, options) rc = @client.delete_resource(kind, id) diff --git a/src/ozones/Client/lib/zona.rb b/src/ozones/Client/lib/zona.rb index 7a2433453a..d22a8270c4 100644 --- a/src/ozones/Client/lib/zona.rb +++ b/src/ozones/Client/lib/zona.rb @@ -190,6 +190,23 @@ EOT return Client.parse_error(res, kind) end + # Retrieves a pool belonging to a specific resource + # @param [String] Kind resource kind: vdc, zone... + # @param [#to_i] id resource id + # @param [String] Kind of pool: image, vm, host, etc + # @return [String, Zona::Error] Response string or Error + def get_resource_pool(kind, id, pool) + url = URI.parse("#{@endpoint}/#{kind}/#{id}/#{pool}") + req = Net::HTTP::Get.new(url.path) + + req.basic_auth @ozonesauth[0], @ozonesauth[1] + + res = Client.http_start(url, @timeout) {|http| + http.request(req) + } + return Client.parse_error(res, kind) + end + # Deletes a resource # @param [String] kind resource kind: vdc, zone... # @param [#to_i] id resource id diff --git a/src/pool/PoolSQL.cc b/src/pool/PoolSQL.cc index e8f749e8a3..f763dd2b38 100644 --- a/src/pool/PoolSQL.cc +++ b/src/pool/PoolSQL.cc @@ -339,6 +339,32 @@ PoolObjectSQL * PoolSQL::get(const string& name, int ouid, bool olock) /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ +void PoolSQL::update_cache_index(string& old_name, + int old_uid, + string& new_name, + int new_uid) +{ + map::iterator index; + + lock(); + + string old_key = key(old_name, old_uid); + string new_key = key(new_name, new_uid); + + index = name_pool.find(old_key); + + if ( index != name_pool.end() ) + { + name_pool.erase(old_key); + name_pool.insert(make_pair(new_key, index->second)); + } + + unlock(); +} + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + void PoolSQL::replace() { bool removed = false; diff --git a/src/rm/RequestManagerChown.cc b/src/rm/RequestManagerChown.cc index f458cbbcf1..e1563dfd83 100644 --- a/src/rm/RequestManagerChown.cc +++ b/src/rm/RequestManagerChown.cc @@ -134,11 +134,16 @@ void RequestManagerChown::request_execute(xmlrpc_c::paramList const& paramList, { failure_response(NO_EXISTS,get_error(object_name(auth_object),oid),att); return; - } + } if ( noid != -1 ) { + string obj_name = object->get_name(); + int old_uid = object->get_uid(); + object->set_user(noid,nuname); + + pool->update_cache_index(obj_name, old_uid, obj_name, noid); } if ( ngid != -1 ) @@ -273,4 +278,3 @@ void UserChown::request_execute(xmlrpc_c::paramList const& paramList, return; } - \ No newline at end of file diff --git a/src/template/Template.cc b/src/template/Template.cc index 73e4f829d8..15a9842f03 100644 --- a/src/template/Template.cc +++ b/src/template/Template.cc @@ -533,6 +533,26 @@ void Template::rebuild_attributes(const xmlNode * root_element) /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ +void Template::set_restricted_attributes( vector& rattrs, + vector& restricted_attributes) +{ + const SingleAttribute * sattr; + string attr; + + for (unsigned int i = 0 ; i < rattrs.size() ; i++ ) + { + sattr = static_cast(rattrs[i]); + + attr = sattr->value(); + transform (attr.begin(),attr.end(),attr.begin(),(int(*)(int))toupper); + + restricted_attributes.push_back(attr); + } +} + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + bool Template::check(string& rs_attr, const vector &restricted_attributes) { size_t pos; diff --git a/src/vm/VirtualMachineTemplate.cc b/src/vm/VirtualMachineTemplate.cc index 4a199ac7e7..6b6bc73ca3 100644 --- a/src/vm/VirtualMachineTemplate.cc +++ b/src/vm/VirtualMachineTemplate.cc @@ -23,23 +23,3 @@ vector VirtualMachineTemplate::restricted_attributes; /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ - -void VirtualMachineTemplate::set_restricted_attributes( - vector& rattrs) -{ - const SingleAttribute * sattr; - string attr; - - for (unsigned int i = 0 ; i < rattrs.size() ; i++ ) - { - sattr = static_cast(rattrs[i]); - - attr = sattr->value(); - transform (attr.begin(),attr.end(),attr.begin(),(int(*)(int))toupper); - - restricted_attributes.push_back(attr); - } -} - -/* -------------------------------------------------------------------------- */ -/* -------------------------------------------------------------------------- */