From 5cf1b27e2ae797b7423a043cd10dea8143b6c843 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Mon, 30 Jan 2012 19:31:21 +0100 Subject: [PATCH 01/18] Feature #1095: Templates in one.*.allocate, one.*.update & one.vn.add/rmleases can be in XML --- include/Request.h | 7 ---- include/RequestManagerVirtualNetwork.h | 2 +- include/Template.h | 15 +++++++-- src/pool/PoolObjectSQL.cc | 14 +------- src/rm/Request.cc | 19 ----------- src/rm/RequestManagerAllocate.cc | 5 ++- src/rm/RequestManagerVirtualMachine.cc | 3 +- src/rm/RequestManagerVirtualNetwork.cc | 19 +++-------- src/template/Template.cc | 46 ++++++++++++++++++++++++++ 9 files changed, 68 insertions(+), 62 deletions(-) diff --git a/include/Request.h b/include/Request.h index f85e45f704..1078fd8898 100644 --- a/include/Request.h +++ b/include/Request.h @@ -219,13 +219,6 @@ protected: * @return string for logging */ string allocate_error (PoolObjectSQL::ObjectType obj, const string& error); - - /** - * Logs allocate errors - * @param message with the allocate error details (parsing) - * @return string for logging - */ - string allocate_error (char *error); }; /* -------------------------------------------------------------------------- */ diff --git a/include/RequestManagerVirtualNetwork.h b/include/RequestManagerVirtualNetwork.h index 46759ef899..de11553656 100644 --- a/include/RequestManagerVirtualNetwork.h +++ b/include/RequestManagerVirtualNetwork.h @@ -52,7 +52,7 @@ protected: string& error_str) = 0; /* -------------------------------------------------------------------- */ - string leases_error (char * error); + string leases_error (const string& error); }; /* ------------------------------------------------------------------------- */ diff --git a/include/Template.h b/include/Template.h index 1540c1e444..ab4ab441fd 100644 --- a/include/Template.h +++ b/include/Template.h @@ -70,7 +70,7 @@ public: * Parse a string representing the template, each attribute is inserted * in the template class. * @param parse_str string with template attributes - * @param error_msg error string, must be freed by the calling funtion. + * @param error_msg error string, must be freed by the calling function. * This string is null if no error occurred. * @return 0 on success. */ @@ -79,12 +79,23 @@ public: /** * Parse a template file. * @param filename of the template file - * @param error_msg error string, must be freed by the calling funtion. + * @param error_msg error string, must be freed by the calling function. * This string is null if no error occurred. * @return 0 on success. */ int parse(const char * filename, char **error_msg); + /** + * Parse a string representing the template, automatically detecting if + * it is the default syntax, or an XML template. Each attribute is inserted + * in the template class. + * @param parse_str string with template attributes, or XML template + * @param error_msg error string, must be freed by the calling function. + * This string is null if no error occurred. + * @return 0 on success. + */ + int parse_str_or_xml(const string &parse_str, string& error_msg); + /** * Marshall a template. This function generates a single string with the * template attributes ("VAR=VAL..."). diff --git a/src/pool/PoolObjectSQL.cc b/src/pool/PoolObjectSQL.cc index f10ba658ce..5ba64ced9d 100644 --- a/src/pool/PoolObjectSQL.cc +++ b/src/pool/PoolObjectSQL.cc @@ -166,7 +166,6 @@ void PoolObjectSQL::set_template_error_message(const string& message) int PoolObjectSQL::replace_template(const string& tmpl_str, string& error) { Template * new_tmpl = get_new_template(); - char * error_msg = 0; if ( new_tmpl == 0 ) { @@ -174,19 +173,8 @@ int PoolObjectSQL::replace_template(const string& tmpl_str, string& error) return -1; } - if ( new_tmpl->parse(tmpl_str, &error_msg) != 0 ) + if ( new_tmpl->parse_str_or_xml(tmpl_str, error) != 0 ) { - ostringstream oss; - - oss << "Parse error"; - - if (error_msg != 0) - { - oss << ": " << error_msg; - } - - error = oss.str(); - return -1; } diff --git a/src/rm/Request.cc b/src/rm/Request.cc index 4e44e59d9d..4b8b929b96 100644 --- a/src/rm/Request.cc +++ b/src/rm/Request.cc @@ -293,22 +293,3 @@ string Request::allocate_error (const string& error) /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ - -string Request::allocate_error (char *error) -{ - ostringstream oss; - - oss << "Parse error"; - - if ( error != 0 ) - { - oss << ": " << error; - free(error); - } - else - { - oss << "."; - } - - return allocate_error(oss.str()); -} diff --git a/src/rm/RequestManagerAllocate.cc b/src/rm/RequestManagerAllocate.cc index 35c8282c2b..051463f1dc 100644 --- a/src/rm/RequestManagerAllocate.cc +++ b/src/rm/RequestManagerAllocate.cc @@ -99,16 +99,15 @@ void RequestManagerAllocate::request_execute(xmlrpc_c::paramList const& params, if ( do_template == true ) { - char * error_msg = 0; string str_tmpl = xmlrpc_c::value_string(params.getString(1)); tmpl = get_object_template(); - rc = tmpl->parse(str_tmpl, &error_msg); + rc = tmpl->parse_str_or_xml(str_tmpl, error_str); if ( rc != 0 ) { - failure_response(INTERNAL, allocate_error(error_msg), att); + failure_response(INTERNAL, allocate_error(error_str), att); delete tmpl; return; diff --git a/src/rm/RequestManagerVirtualMachine.cc b/src/rm/RequestManagerVirtualMachine.cc index 175643446a..084b31c274 100644 --- a/src/rm/RequestManagerVirtualMachine.cc +++ b/src/rm/RequestManagerVirtualMachine.cc @@ -420,7 +420,6 @@ void VirtualMachineSaveDisk::request_execute(xmlrpc_c::paramList const& paramLis int rc; ostringstream oss; string error_str; - char * error_char; // ------------------ Template for the new image ------------------ @@ -437,7 +436,7 @@ void VirtualMachineSaveDisk::request_execute(xmlrpc_c::paramList const& paramLis itemplate = new ImageTemplate; - itemplate->parse(oss.str(), &error_char); + itemplate->parse_str_or_xml(oss.str(), error_str); // ------------------ Authorize the operation ------------------ diff --git a/src/rm/RequestManagerVirtualNetwork.cc b/src/rm/RequestManagerVirtualNetwork.cc index d6278ef4f7..33ce01e512 100644 --- a/src/rm/RequestManagerVirtualNetwork.cc +++ b/src/rm/RequestManagerVirtualNetwork.cc @@ -22,19 +22,9 @@ using namespace std; /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -string RequestManagerVirtualNetwork::leases_error (char *error) +string RequestManagerVirtualNetwork::leases_error (const string& error) { - ostringstream oss; - - oss << "Parse error."; - - if ( error != 0 ) - { - oss << " " << error; - free(error); - } - - return request_error("Error modifying network leases",oss.str()); + return request_error("Error modifying network leases",error); } /* ------------------------------------------------------------------------- */ @@ -50,7 +40,6 @@ void RequestManagerVirtualNetwork:: VirtualNetworkTemplate tmpl; VirtualNetwork * vn; - char * error_msg = 0; string error_str; int rc; @@ -59,11 +48,11 @@ void RequestManagerVirtualNetwork:: return; } - rc = tmpl.parse(str_tmpl, &error_msg); + rc = tmpl.parse_str_or_xml(str_tmpl, error_str); if ( rc != 0 ) { - failure_response(INTERNAL, leases_error(error_msg), att); + failure_response(INTERNAL, leases_error(error_str), att); return; } diff --git a/src/template/Template.cc b/src/template/Template.cc index 15a9842f03..d714182659 100644 --- a/src/template/Template.cc +++ b/src/template/Template.cc @@ -135,6 +135,52 @@ error_yy: /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ +int Template::parse_str_or_xml(const string &parse_str, string& error_msg) +{ + int rc; + + if ( parse_str[0] == '<' ) + { + rc = from_xml(parse_str); + + if ( rc != 0 ) + { + error_msg = "Parse error: XML Template malformed."; + } + } + else + { + char * error_char = 0; + + rc = parse(parse_str, &error_char); + + if ( rc != 0 ) + { + ostringstream oss; + + oss << "Parse error"; + + if (error_char != 0) + { + oss << ": " << error_char; + } + else + { + oss << "."; + } + + error_msg = oss.str(); + + free(error_char); + } + } + + return rc; +} + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + void Template::marshall(string &str, const char delim) { multimap::iterator it; From c03b78732f8af0f3d148afef091495cecec98cc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Wed, 8 Feb 2012 17:10:07 +0100 Subject: [PATCH 02/18] Better error message cleanup in Template::parse_str_or_xml --- src/template/Template.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/template/Template.cc b/src/template/Template.cc index d714182659..d41f248fce 100644 --- a/src/template/Template.cc +++ b/src/template/Template.cc @@ -163,6 +163,8 @@ int Template::parse_str_or_xml(const string &parse_str, string& error_msg) if (error_char != 0) { oss << ": " << error_char; + + free(error_char); } else { @@ -170,8 +172,6 @@ int Template::parse_str_or_xml(const string &parse_str, string& error_msg) } error_msg = oss.str(); - - free(error_char); } } From 03ddf136b7343dcad8cf0fde6ca36018eb143b94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Thu, 9 Feb 2012 03:22:11 -0800 Subject: [PATCH 03/18] Bug #1119: set right values for uid,gid columns in migrator 3.1.80_to_3.2.0 --- src/onedb/3.1.80_to_3.2.0.rb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/onedb/3.1.80_to_3.2.0.rb b/src/onedb/3.1.80_to_3.2.0.rb index 1693b4a44b..8be9d510e1 100644 --- a/src/onedb/3.1.80_to_3.2.0.rb +++ b/src/onedb/3.1.80_to_3.2.0.rb @@ -162,12 +162,19 @@ module Migrator @db.run "CREATE TABLE IF NOT EXISTS user_pool (oid INTEGER PRIMARY KEY, name VARCHAR(128), body TEXT, uid INTEGER, gid INTEGER, owner_u INTEGER, group_u INTEGER, other_u INTEGER, UNIQUE(name));" @db.fetch("SELECT * FROM old_user_pool") do |row| + doc = Document.new(row[:body]) + + gid = "1" + doc.root.each_element("GID") { |e| + gid = e.text + } + @db[:user_pool].insert( :oid => row[:oid], :name => row[:name], :body => row[:body], - :uid => "0", - :gid => row[:oid], + :uid => row[:oid], + :gid => gid, :owner_u => "1", :group_u => "0", :other_u => "0") From 68fe3f91cf686f24a4b8a7dbe50adf4789f211a1 Mon Sep 17 00:00:00 2001 From: Daniel Molina Date: Thu, 9 Feb 2012 17:40:21 +0100 Subject: [PATCH 04/18] bug #1114: econe client should set the default path '/' if not specified --- src/cloud/ec2/lib/EC2QueryClient.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cloud/ec2/lib/EC2QueryClient.rb b/src/cloud/ec2/lib/EC2QueryClient.rb index 96a0da7d6f..b80c44ecd8 100644 --- a/src/cloud/ec2/lib/EC2QueryClient.rb +++ b/src/cloud/ec2/lib/EC2QueryClient.rb @@ -70,6 +70,7 @@ module EC2QueryClient end @uri = URI.parse(endpoint) + path = @uri.path.empty? ? '/' : @uri.path @ec2_connection = AWS::EC2::Base.new( :access_key_id => @access_key_id, @@ -77,7 +78,7 @@ module EC2QueryClient :server => @uri.host, :port => @uri.port, :use_ssl => @uri.scheme == 'https', - :path => @uri.path) + :path => path) end From e5302cab2e35125d325d04b52c2bf00b1800e82b Mon Sep 17 00:00:00 2001 From: Daniel Molina Date: Thu, 9 Feb 2012 17:42:26 +0100 Subject: [PATCH 05/18] bug #1113: Default quota keys must be specified in uppecase --- src/authm_mad/remotes/quota/quota.conf | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/authm_mad/remotes/quota/quota.conf b/src/authm_mad/remotes/quota/quota.conf index fdcda4c08e..4d66cfb48b 100644 --- a/src/authm_mad/remotes/quota/quota.conf +++ b/src/authm_mad/remotes/quota/quota.conf @@ -22,8 +22,8 @@ # a given metric. #------------------------------------------------------------------------------- :defaults: - :cpu: - :memory: - :num_vms: - :storage: + :CPU: + :MEMORY: + :NUM_VMS: + :STORAGE: From aafefad6ab74a632e63485ce9344760e7b4f2961 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Thu, 9 Feb 2012 18:13:55 +0100 Subject: [PATCH 06/18] Add onedb migrator 3.2.1_to_3.3.0.rb --- install.sh | 1 + src/onedb/3.2.1_to_3.3.0.rb | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 src/onedb/3.2.1_to_3.3.0.rb diff --git a/install.sh b/install.sh index 4dcf332d88..a9dee20015 100755 --- a/install.sh +++ b/install.sh @@ -818,6 +818,7 @@ ONEDB_MIGRATOR_FILES="src/onedb/2.0_to_2.9.80.rb \ src/onedb/3.1.0_to_3.1.80.rb \ src/onedb/3.1.80_to_3.2.0.rb \ src/onedb/3.2.0_to_3.2.1.rb \ + src/onedb/3.2.1_to_3.3.0.rb \ src/onedb/onedb.rb \ src/onedb/onedb_backend.rb" diff --git a/src/onedb/3.2.1_to_3.3.0.rb b/src/onedb/3.2.1_to_3.3.0.rb new file mode 100644 index 0000000000..b2d439c2f7 --- /dev/null +++ b/src/onedb/3.2.1_to_3.3.0.rb @@ -0,0 +1,28 @@ +# -------------------------------------------------------------------------- * +# Copyright 2002-2011, 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 * +# a copy of the License at * +# * +# http://www.apache.org/licenses/LICENSE-2.0 * +# * +# Unless required by applicable law or agreed to in writing, software * +# distributed under the License is distributed on an "AS IS" BASIS, * +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * +# See the License for the specific language governing permissions and * +# limitations under the License. * +# -------------------------------------------------------------------------- * + +module Migrator + def db_version + "3.3.0" + end + + def one_version + "OpenNebula 3.3.0" + end + + def up + return true + end +end From 9cac009e8e5d7f76d41fd200e828043036e28a61 Mon Sep 17 00:00:00 2001 From: Daniel Molina Date: Thu, 9 Feb 2012 18:50:30 +0100 Subject: [PATCH 07/18] feature #1124: Improve EC2 describe_instances performance --- src/cloud/ec2/lib/EC2QueryServer.rb | 5 +++-- src/cloud/ec2/lib/views/describe_instances.erb | 1 - 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cloud/ec2/lib/EC2QueryServer.rb b/src/cloud/ec2/lib/EC2QueryServer.rb index cfcac7c538..4e2abd1072 100644 --- a/src/cloud/ec2/lib/EC2QueryServer.rb +++ b/src/cloud/ec2/lib/EC2QueryServer.rb @@ -54,8 +54,8 @@ class EC2QueryServer < CloudServer 'save' => :pending, 'epil' => :shutdown, 'shut' => :shutdown, + 'clea' => :shutdown, 'fail' => :terminated, - 'dele' => :terminated, 'unkn' => :terminated } @@ -211,7 +211,8 @@ class EC2QueryServer < CloudServer # Helper functions ########################################################################### def render_state(vm) - ec2_state = EC2_STATES[ONE_STATES[vm.status]] + one_state = ONE_STATES[vm.status] + ec2_state = EC2_STATES[one_state||:pending] return "#{ec2_state[:code]} #{ec2_state[:name]}" diff --git a/src/cloud/ec2/lib/views/describe_instances.erb b/src/cloud/ec2/lib/views/describe_instances.erb index e07e4e7179..09fae94ae5 100644 --- a/src/cloud/ec2/lib/views/describe_instances.erb +++ b/src/cloud/ec2/lib/views/describe_instances.erb @@ -12,7 +12,6 @@ <% vmpool.each do |vm| %> - <% vm.info %> i-<%= vm.id %> <%= vm['TEMPLATE/IMAGE_ID'] %> From c8f9e86b48161ba38ecfa03f79a231af169848dc Mon Sep 17 00:00:00 2001 From: Hector Sanjuan Date: Thu, 9 Feb 2012 18:57:47 +0100 Subject: [PATCH 08/18] Feature #1030: Fix onetemplate when no name is provided (cherry picked from commit 1cd6406dc587b9e2ffa1d82cd52e3e5bb76f8ef5) --- src/cli/onetemplate | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cli/onetemplate b/src/cli/onetemplate index 7a27e194fa..6016027f02 100755 --- a/src/cli/onetemplate +++ b/src/cli/onetemplate @@ -110,7 +110,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do number = options[:multiple] || 1 number.times do |i| exit_code=helper.perform_action(args[0],options,"instantiated") do |t| - name = options[:vm_name].gsub("%i",i.to_s) + name = options[:vm_name] + name = name.gsub("%i",i.to_s) if name res = t.instantiate(name) if !OpenNebula.is_error?(res) From 96c0c823e968a4b176301ef620156255b8e063a9 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Thu, 9 Feb 2012 22:06:54 +0100 Subject: [PATCH 09/18] Bug: Fix acct printing for network metrics --- src/cli/oneacct | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cli/oneacct b/src/cli/oneacct index ef32432d0a..91d0399eb6 100755 --- a/src/cli/oneacct +++ b/src/cli/oneacct @@ -66,13 +66,13 @@ class AcctHelper column :NETRX, "Group of the User", :right, :size=>10 do |d| OpenNebulaHelper.unit_to_str( - d[:network][:net_rx]/1024.0, + d[:network][:net_rx].to_i/1024.0, {}) end column :NETTX, "Group of the User", :right, :size=>10 do |d| OpenNebulaHelper.unit_to_str( - d[:network][:net_tx]/1024.0, + d[:network][:net_tx].to_i/1024.0, {}) end From 9c1e0db1ed93d1010496aaf19d5cbedda9030908 Mon Sep 17 00:00:00 2001 From: Daniel Molina Date: Fri, 10 Feb 2012 16:06:52 +0100 Subject: [PATCH 10/18] feature #1091: Refactor OCCICLient --- src/cloud/common/CloudClient.rb | 22 ++- src/cloud/occi/lib/OCCIClient.rb | 328 ++++++++----------------------- 2 files changed, 97 insertions(+), 253 deletions(-) diff --git a/src/cloud/common/CloudClient.rb b/src/cloud/common/CloudClient.rb index 19e2f90ea3..605b211323 100644 --- a/src/cloud/common/CloudClient.rb +++ b/src/cloud/common/CloudClient.rb @@ -61,7 +61,7 @@ module CloudClient # ######################################################################### def self.get_one_auth if ENV["ONE_AUTH"] and !ENV["ONE_AUTH"].empty? and - File.file?(ENV["ONE_AUTH"]) + File.file?(ENV["ONE_AUTH"]) one_auth=File.read(ENV["ONE_AUTH"]).strip.split(':') elsif File.file?(DEFAULT_AUTH_FILE) one_auth=File.read(DEFAULT_AUTH_FILE).strip.split(':') @@ -91,24 +91,30 @@ module CloudClient end begin - http.start do |connection| + res = http.start do |connection| block.call(connection) end rescue Errno::ECONNREFUSED => e str = "Error connecting to server (#{e.to_s}).\n" str << "Server: #{url.host}:#{url.port}" - return CloudClient::Error.new(str) + return CloudClient::Error.new(str,"503") rescue Errno::ETIMEDOUT => e str = "Error timeout connecting to server (#{e.to_s}).\n" str << "Server: #{url.host}:#{url.port}" - return CloudClient::Error.new(str) + return CloudClient::Error.new(str,"504") rescue Timeout::Error => e str = "Error timeout while connected to server (#{e.to_s}).\n" str << "Server: #{url.host}:#{url.port}" - return CloudClient::Error.new(str) + return CloudClient::Error.new(str,"504") + end + + if res.is_a?(Net::HTTPSuccess) + res + else + CloudClient::Error.new(res.body, res.code) end end @@ -118,10 +124,12 @@ module CloudClient # ######################################################################### class Error attr_reader :message + attr_reader :code # +message+ a description of the error - def initialize(message=nil) + def initialize(message=nil, code="500") @message=message + @code=code end def to_s() @@ -140,7 +148,7 @@ end # Command line help functions module CloudCLI - def print_xml(xml_text) + def print_xml(xml_text) begin doc = REXML::Document.new(xml_text) rescue REXML::ParseException => e diff --git a/src/cloud/occi/lib/OCCIClient.rb b/src/cloud/occi/lib/OCCIClient.rb index a5f2d7641d..0da2ec8c42 100755 --- a/src/cloud/occi/lib/OCCIClient.rb +++ b/src/cloud/occi/lib/OCCIClient.rb @@ -20,7 +20,7 @@ require 'rubygems' require 'rexml/document' require 'uri' -require 'CloudClient' +require 'deltacloud/drivers/opennebula/cloud_client' module OCCIClient @@ -30,11 +30,13 @@ module OCCIClient ##################################################################### class Client + attr_accessor :endpoint + ###################################################################### # Initialize client library ###################################################################### def initialize(endpoint_str=nil, user=nil, pass=nil, - timeout=nil, debug_flag=true) + timeout=nil, debug_flag=true) @debug = debug_flag @timeout = timeout @@ -65,50 +67,30 @@ module OCCIClient # Pool Resource Request Methods # ################################# + def get_root + get('/') + end + + ###################################################################### + # Retieves the available Instance types + ###################################################################### + def get_instance_types + get('/instance_type') + end + ###################################################################### # Post a new VM to the VM Pool - # :instance_type # :xmlfile ###################################################################### def post_vms(xmlfile) - xml=File.read(xmlfile) - - url = URI.parse(@endpoint+"/compute") - - req = Net::HTTP::Post.new(url.path) - req.body=xml - - req.basic_auth @occiauth[0], @occiauth[1] - - res = CloudClient::http_start(url, @timeout) do |http| - http.request(req) - end - - if CloudClient::is_error?(res) - return res - else - return res.body - end + post('/compute', xmlfile) end ###################################################################### # Retieves the pool of Virtual Machines ###################################################################### def get_vms - url = URI.parse(@endpoint+"/compute") - req = Net::HTTP::Get.new(url.path) - - req.basic_auth @occiauth[0], @occiauth[1] - - res = CloudClient::http_start(url, @timeout) {|http| - http.request(req) - } - - if CloudClient::is_error?(res) - return res - else - return res.body - end + get('/compute') end ###################################################################### @@ -116,44 +98,14 @@ module OCCIClient # :xmlfile xml description of the Virtual Network ###################################################################### def post_network(xmlfile) - xml=File.read(xmlfile) - - url = URI.parse(@endpoint+"/network") - - req = Net::HTTP::Post.new(url.path) - req.body=xml - - req.basic_auth @occiauth[0], @occiauth[1] - - res = CloudClient::http_start(url, @timeout) do |http| - http.request(req) - end - - if CloudClient::is_error?(res) - return res - else - return res.body - end + post('/network', xmlfile) end ###################################################################### # Retieves the pool of Virtual Networks ###################################################################### def get_networks - url = URI.parse(@endpoint+"/network") - req = Net::HTTP::Get.new(url.path) - - req.basic_auth @occiauth[0], @occiauth[1] - - res = CloudClient::http_start(url, @timeout) {|http| - http.request(req) - } - - if CloudClient::is_error?(res) - return res - else - return res.body - end + get('/network') end ###################################################################### @@ -251,22 +203,10 @@ module OCCIClient # Retieves the pool of Images owned by the user ###################################################################### def get_images - url = URI.parse(@endpoint+"/storage") - req = Net::HTTP::Get.new(url.path) - - req.basic_auth @occiauth[0], @occiauth[1] - - res = CloudClient::http_start(url, @timeout) {|http| - http.request(req) - } - - if CloudClient::is_error?(res) - return res - else - return res.body - end + get('/storage') end + #################################### # Entity Resource Request Methods # #################################### @@ -275,20 +215,7 @@ module OCCIClient # :id VM identifier ###################################################################### def get_vm(id) - url = URI.parse(@endpoint+"/compute/" + id.to_s) - req = Net::HTTP::Get.new(url.path) - - req.basic_auth @occiauth[0], @occiauth[1] - - res = CloudClient::http_start(url, @timeout) {|http| - http.request(req) - } - - if CloudClient::is_error?(res) - return res - else - return res.body - end + get('/compute/'+id.to_s) end ###################################################################### @@ -296,57 +223,14 @@ module OCCIClient # :xmlfile Compute OCCI xml representation ###################################################################### def put_vm(xmlfile) - xml = File.read(xmlfile) - - begin - vm_info = REXML::Document.new(xml).root - rescue Exception => e - error = CloudClient::Error.new(e.message) - return error - end - - if vm_info.elements['ID'] == nil - return CloudClient::Error.new("Can not find COMPUTE_ID") - end - - vm_id = vm_info.elements['ID'].text - - url = URI.parse(@endpoint+'/compute/' + vm_id) - - req = Net::HTTP::Put.new(url.path) - req.body = xml - - req.basic_auth @occiauth[0], @occiauth[1] - - res = CloudClient::http_start(url, @timeout) do |http| - http.request(req) - end - - if CloudClient::is_error?(res) - return res - else - return res.body - end + put('/compute/', xmlfile) end #################################################################### # :id Compute identifier #################################################################### def delete_vm(id) - url = URI.parse(@endpoint+"/compute/" + id.to_s) - req = Net::HTTP::Delete.new(url.path) - - req.basic_auth @occiauth[0], @occiauth[1] - - res = CloudClient::http_start(url, @timeout) {|http| - http.request(req) - } - - if CloudClient::is_error?(res) - return res - else - return res.body - end + delete('/compute/'+id.to_s) end ###################################################################### @@ -354,20 +238,7 @@ module OCCIClient # :id Virtual Network identifier ###################################################################### def get_network(id) - url = URI.parse(@endpoint+"/network/" + id.to_s) - req = Net::HTTP::Get.new(url.path) - - req.basic_auth @occiauth[0], @occiauth[1] - - res = CloudClient::http_start(url, @timeout) {|http| - http.request(req) - } - - if CloudClient::is_error?(res) - return res - else - return res.body - end + get('/network/'+id.to_s) end ###################################################################### @@ -375,78 +246,22 @@ module OCCIClient # :xmlfile Network OCCI xml representation ###################################################################### def put_network(xmlfile) - xml = File.read(xmlfile) - - begin - vnet_info = REXML::Document.new(xml).root - rescue Exception => e - error = CloudClient::Error.new(e.message) - return error - end - - if vnet_info.elements['ID'] == nil - return CloudClient::Error.new("Can not find NETWORK_ID") - end - - vnet_id = vnet_info.elements['ID'].text - - url = URI.parse(@endpoint+'/network/' + vnet_id) - - req = Net::HTTP::Put.new(url.path) - req.body = xml - - req.basic_auth @occiauth[0], @occiauth[1] - - res = CloudClient::http_start(url, @timeout) do |http| - http.request(req) - end - - if CloudClient::is_error?(res) - return res - else - return res.body - end + put('/network/', xmlfile) end ###################################################################### # :id VM identifier ###################################################################### def delete_network(id) - url = URI.parse(@endpoint+"/network/" + id.to_s) - req = Net::HTTP::Delete.new(url.path) - - req.basic_auth @occiauth[0], @occiauth[1] - - res = CloudClient::http_start(url, @timeout) {|http| - http.request(req) - } - - if CloudClient::is_error?(res) - return res - else - return res.body - end + delete('/network/'+id.to_s) end - ####################################################################### + ####################################################################### # Retieves an Image # :image_uuid Image identifier ###################################################################### - def get_image(image_uuid) - url = URI.parse(@endpoint+"/storage/"+image_uuid) - req = Net::HTTP::Get.new(url.path) - - req.basic_auth @occiauth[0], @occiauth[1] - - res = CloudClient::http_start(url, @timeout) {|http| - http.request(req) - } - - if CloudClient::is_error?(res) - return res - else - return res.body - end + def get_image(id) + get('/storage/'+id.to_s) end ###################################################################### @@ -454,26 +269,67 @@ module OCCIClient # :xmlfile Storage OCCI xml representation ###################################################################### def put_image(xmlfile) - xml = File.read(xmlfile) - + put('/storage/', xmlfile) + end + + ###################################################################### + # :id VM identifier + ###################################################################### + def delete_image(id) + delete('/storage/'+id.to_s) + end + + private + + def get(path) + url = URI.parse(@endpoint+path) + req = Net::HTTP::Get.new(url.path) + + do_request(url, req) + end + + def post(path, xmlfile) + url = URI.parse(@endpoint+path) + req = Net::HTTP::Post.new(url.path) + + req.body=File.read(xmlfile) + + do_request(url, req) + end + + def delete(path, xmlfile) + url = URI.parse(@endpoint+path) + req = Net::HTTP::Delete.new(url.path) + + do_request(url, req) + end + + def put(path, xmlfile) + xml = File.read(xmlfile) + + # Get ID from XML begin - image_info = REXML::Document.new(xml).root + info = REXML::Document.new(xml).root rescue Exception => e - error = OpenNebula::Error.new(e.message) + error = CloudClient::Error.new(e.message) return error end - - if image_info.elements['ID'] == nil - return CloudClient::Error.new("Can not find STORAGE_ID") + + if info.elements['ID'] == nil + return CloudClient::Error.new("Can not find RESOURCE ID") end - image_id = image_info.elements['ID'].text - - url = URI.parse(@endpoint+'/storage/' + image_id) + resource_id = info.elements['ID'].text + url = URI.parse(@endpoint+path + resource_id) req = Net::HTTP::Put.new(url.path) + req.body = xml + do_request(url, req) + end + + def do_request(url, req) req.basic_auth @occiauth[0], @occiauth[1] res = CloudClient::http_start(url, @timeout) do |http| @@ -486,25 +342,5 @@ module OCCIClient return res.body end end - - ###################################################################### - # :id VM identifier - ###################################################################### - def delete_image(id) - url = URI.parse(@endpoint+"/storage/" + id.to_s) - req = Net::HTTP::Delete.new(url.path) - - req.basic_auth @occiauth[0], @occiauth[1] - - res = CloudClient::http_start(url, @timeout) {|http| - http.request(req) - } - - if CloudClient::is_error?(res) - return res - else - return res.body - end - end end -end +end \ No newline at end of file From 59419f54df2be7cdaed1a6794dcd622e07e358f3 Mon Sep 17 00:00:00 2001 From: Daniel Molina Date: Fri, 10 Feb 2012 17:01:40 +0100 Subject: [PATCH 11/18] feature #1091: Fix require path --- src/cloud/occi/lib/OCCIClient.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cloud/occi/lib/OCCIClient.rb b/src/cloud/occi/lib/OCCIClient.rb index 0da2ec8c42..4b30b9fb2c 100755 --- a/src/cloud/occi/lib/OCCIClient.rb +++ b/src/cloud/occi/lib/OCCIClient.rb @@ -20,7 +20,7 @@ require 'rubygems' require 'rexml/document' require 'uri' -require 'deltacloud/drivers/opennebula/cloud_client' +require 'CloudClient' module OCCIClient From ab5db1ceb34084cb95ec314b4ffed53f3a22e6c2 Mon Sep 17 00:00:00 2001 From: Daniel Molina Date: Fri, 10 Feb 2012 18:20:12 +0100 Subject: [PATCH 12/18] feature #1091: Add extended information to the OCCI pools --- src/cloud/occi/lib/ImagePoolOCCI.rb | 13 +++++--- src/cloud/occi/lib/OCCIServer.rb | 34 ++++++++++---------- src/cloud/occi/lib/UserPoolOCCI.rb | 13 +++++--- src/cloud/occi/lib/VirtualMachinePoolOCCI.rb | 16 ++++++--- src/cloud/occi/lib/VirtualNetworkPoolOCCI.rb | 14 +++++--- 5 files changed, 56 insertions(+), 34 deletions(-) diff --git a/src/cloud/occi/lib/ImagePoolOCCI.rb b/src/cloud/occi/lib/ImagePoolOCCI.rb index 3bdfa8cf9d..ee38636867 100755 --- a/src/cloud/occi/lib/ImagePoolOCCI.rb +++ b/src/cloud/occi/lib/ImagePoolOCCI.rb @@ -14,20 +14,21 @@ # limitations under the License. # #--------------------------------------------------------------------------- # -require 'OpenNebula' - -include OpenNebula +require 'ImageOCCI' class ImagePoolOCCI < ImagePool OCCI_IMAGE_POOL = %q{ <% self.each{ |im| %> + <% if verbose %> + <%= im.to_occi(base_url) %> + <% else %> + <% end %> <% } %> } - # Creates the OCCI representation of a Virtual Machine Pool def to_occi(base_url) begin @@ -40,5 +41,9 @@ class ImagePoolOCCI < ImagePool return occi_text.gsub(/\n\s*/,'') end + + def factory(element_xml) + ImageOCCI.new(element_xml,@client) + end end diff --git a/src/cloud/occi/lib/OCCIServer.rb b/src/cloud/occi/lib/OCCIServer.rb index fbe3d210a9..8a4f66cf33 100755 --- a/src/cloud/occi/lib/OCCIServer.rb +++ b/src/cloud/occi/lib/OCCIServer.rb @@ -62,11 +62,11 @@ class OCCIServer < CloudServer # Prepare the OCCI XML Response # resource:: _Pool_ or _PoolElement_ that represents a OCCI resource # [return] _String_,_Integer_ Resource Representation or error, status code - def to_occi_xml(resource, code) - xml_response = resource.to_occi(@base_url) + def to_occi_xml(resource, opts) + xml_response = resource.to_occi(@base_url, opts[:verbose]) return xml_response, 500 if OpenNebula.is_error?(xml_response) - return xml_response, code + return xml_response, opts[:code] end ############################################################################ @@ -122,7 +122,7 @@ class OCCIServer < CloudServer return rc, CloudServer::HTTP_ERROR_CODE[rc.errno] end - return to_occi_xml(vmpool, 200) + return to_occi_xml(vmpool, :status=>200, :verbose=>request.params['verbose']) end @@ -142,7 +142,7 @@ class OCCIServer < CloudServer return rc, CloudServer::HTTP_ERROR_CODE[rc.errno] end - return to_occi_xml(network_pool, 200) + return to_occi_xml(network_pool, :status=>200, :verbose=>request.params['verbose']) end # Gets the pool representation of STORAGES @@ -161,7 +161,7 @@ class OCCIServer < CloudServer return rc, CloudServer::HTTP_ERROR_CODE[rc.errno] end - return to_occi_xml(image_pool, 200) + return to_occi_xml(image_pool, :status=>200, :verbose=>request.params['verbose']) end # Gets the pool representation of USERs @@ -178,7 +178,7 @@ class OCCIServer < CloudServer return rc, CloudServer::HTTP_ERROR_CODE[rc.errno] end - return to_occi_xml(user_pool, 200) + return to_occi_xml(user_pool, :status=>200, :verbose=>request.params['verbose']) end ############################################################################ @@ -214,7 +214,7 @@ class OCCIServer < CloudServer # --- Prepare XML Response --- vm.info - return to_occi_xml(vm, 201) + return to_occi_xml(vm, :status=>201) end # Get the representation of a COMPUTE resource @@ -233,7 +233,7 @@ class OCCIServer < CloudServer return rc, CloudServer::HTTP_ERROR_CODE[rc.errno] end - return to_occi_xml(vm, 200) + return to_occi_xml(vm, :status=>200) end @@ -277,7 +277,7 @@ class OCCIServer < CloudServer return result, code else vm.info - return to_occi_xml(vm, code) + return to_occi_xml(vm, :status=>code) end end @@ -307,7 +307,7 @@ class OCCIServer < CloudServer # --- Prepare XML Response --- network.info - return to_occi_xml(network, 201) + return to_occi_xml(network, :status=>201) end # Retrieves a NETWORK resource @@ -325,7 +325,7 @@ class OCCIServer < CloudServer return rc, CloudServer::HTTP_ERROR_CODE[rc.errno] end - return to_occi_xml(network, 200) + return to_occi_xml(network, :status=>200) end # Deletes a NETWORK resource @@ -371,7 +371,7 @@ class OCCIServer < CloudServer # --- Prepare XML Response --- vnet.info - return to_occi_xml(vnet, 202) + return to_occi_xml(vnet, :status=>202) end ############################################################################ @@ -411,7 +411,7 @@ class OCCIServer < CloudServer # --- Prepare XML Response --- image.info - return to_occi_xml(image, 201) + return to_occi_xml(image, :status=>201) end # Get a STORAGE resource @@ -430,7 +430,7 @@ class OCCIServer < CloudServer end # --- Prepare XML Response --- - return to_occi_xml(image, 200) + return to_occi_xml(image, :status=>200) end # Deletes a STORAGE resource (Not yet implemented) @@ -484,7 +484,7 @@ class OCCIServer < CloudServer # --- Prepare XML Response --- image.info - return to_occi_xml(image, 202) + return to_occi_xml(image, :status=>202) end # Get the representation of a USER @@ -503,6 +503,6 @@ class OCCIServer < CloudServer return rc, CloudServer::HTTP_ERROR_CODE[rc.errno] end - return to_occi_xml(user, 200) + return to_occi_xml(user, :status=>200) end end diff --git a/src/cloud/occi/lib/UserPoolOCCI.rb b/src/cloud/occi/lib/UserPoolOCCI.rb index bfad719c78..2745020dc7 100644 --- a/src/cloud/occi/lib/UserPoolOCCI.rb +++ b/src/cloud/occi/lib/UserPoolOCCI.rb @@ -14,20 +14,21 @@ # limitations under the License. # #--------------------------------------------------------------------------- # -require 'OpenNebula' - -include OpenNebula +require 'UserOCCI' class UserPoolOCCI < UserPool OCCI_USER_POOL = %q{ <% self.each{ |user| %> + <% if verbose %> + <%= user.to_occi(base_url) %> + <% else %> + <% end %> <% } %> } - # Creates the OCCI representation of a User Pool def to_occi(base_url) begin @@ -40,4 +41,8 @@ class UserPoolOCCI < UserPool return occi_text.gsub(/\n\s*/,'') end + + def factory(element_xml) + UserOCCI.new(element_xml,@client) + end end \ No newline at end of file diff --git a/src/cloud/occi/lib/VirtualMachinePoolOCCI.rb b/src/cloud/occi/lib/VirtualMachinePoolOCCI.rb index 55c9767c12..58a4eb6baa 100755 --- a/src/cloud/occi/lib/VirtualMachinePoolOCCI.rb +++ b/src/cloud/occi/lib/VirtualMachinePoolOCCI.rb @@ -14,22 +14,24 @@ # limitations under the License. # #--------------------------------------------------------------------------- # -require 'OpenNebula' - -include OpenNebula +require 'VirtualMachineOCCI' class VirtualMachinePoolOCCI < VirtualMachinePool OCCI_VM_POOL = %q{ - <% self.each{ |vm| %> + <% self.each{ |vm| %> + <% if verbose %> + <%= vm.to_occi(base_url) %> + <% else %> + <% end %> <% } %> } # Creates the OCCI representation of a Virtual Machine Pool - def to_occi(base_url) + def to_occi(base_url, verbose=false) begin occi = ERB.new(OCCI_VM_POOL) occi_text = occi.result(binding) @@ -40,5 +42,9 @@ class VirtualMachinePoolOCCI < VirtualMachinePool return occi_text.gsub(/\n\s*/,'') end + + def factory(element_xml) + VirtualMachineOCCI.new(element_xml,@client) + end end diff --git a/src/cloud/occi/lib/VirtualNetworkPoolOCCI.rb b/src/cloud/occi/lib/VirtualNetworkPoolOCCI.rb index 6772fefce9..3de2469ae9 100755 --- a/src/cloud/occi/lib/VirtualNetworkPoolOCCI.rb +++ b/src/cloud/occi/lib/VirtualNetworkPoolOCCI.rb @@ -14,15 +14,17 @@ # limitations under the License. # #--------------------------------------------------------------------------- # -require 'OpenNebula' - -include OpenNebula +require 'VirtualNetworkOCCI' class VirtualNetworkPoolOCCI < VirtualNetworkPool OCCI_NETWORK_POOL = %q{ - <% self.each{ |vn| %> + <% self.each{ |vn| %> + <% if verbose %> + <%= vn.to_occi(base_url) %> + <% else %> + <% end %> <% } %> } @@ -39,4 +41,8 @@ class VirtualNetworkPoolOCCI < VirtualNetworkPool return occi_text.gsub(/\n\s*/,'') end + + def factory(element_xml) + VirtualNetworkOCCI.new(element_xml,@client) + end end \ No newline at end of file From d907919f99fd747515cf74e527ab70243b43608e Mon Sep 17 00:00:00 2001 From: Daniel Molina Date: Mon, 13 Feb 2012 12:56:50 +0100 Subject: [PATCH 13/18] feature #1090: Add user and group information to OCCI resources --- src/cloud/occi/lib/ImageOCCI.rb | 2 ++ src/cloud/occi/lib/UserOCCI.rb | 1 + src/cloud/occi/lib/VirtualMachineOCCI.rb | 2 ++ src/cloud/occi/lib/VirtualNetworkOCCI.rb | 2 ++ 4 files changed, 7 insertions(+) diff --git a/src/cloud/occi/lib/ImageOCCI.rb b/src/cloud/occi/lib/ImageOCCI.rb index 7f3f1dec1a..777876fdcd 100755 --- a/src/cloud/occi/lib/ImageOCCI.rb +++ b/src/cloud/occi/lib/ImageOCCI.rb @@ -23,6 +23,8 @@ class ImageOCCI < Image <%= self.id.to_s %> <%= self.name %> + + <%= self['GNAME'] %> <%= self.state_str %> <% if self['TYPE'] != nil %> <%= self.type_str %> diff --git a/src/cloud/occi/lib/UserOCCI.rb b/src/cloud/occi/lib/UserOCCI.rb index 7c772c139f..fa8a960ef2 100644 --- a/src/cloud/occi/lib/UserOCCI.rb +++ b/src/cloud/occi/lib/UserOCCI.rb @@ -27,6 +27,7 @@ class UserOCCI < User <%= self.id.to_s %> <%= self.name %> + <%= self['GNAME'] %> <% user_quota.each { |key,value| key_s = key.to_s.upcase diff --git a/src/cloud/occi/lib/VirtualMachineOCCI.rb b/src/cloud/occi/lib/VirtualMachineOCCI.rb index c04c9cd1bf..4cb8754653 100755 --- a/src/cloud/occi/lib/VirtualMachineOCCI.rb +++ b/src/cloud/occi/lib/VirtualMachineOCCI.rb @@ -22,6 +22,8 @@ class VirtualMachineOCCI < VirtualMachine OCCI_VM = %q{ <%= self.id.to_s%> + + <%= self['GNAME'] %> <%= self['TEMPLATE/CPU'] %> <%= self['TEMPLATE/MEMORY'] %> <%= self.name%> diff --git a/src/cloud/occi/lib/VirtualNetworkOCCI.rb b/src/cloud/occi/lib/VirtualNetworkOCCI.rb index 22cb93901a..68edb59c7f 100755 --- a/src/cloud/occi/lib/VirtualNetworkOCCI.rb +++ b/src/cloud/occi/lib/VirtualNetworkOCCI.rb @@ -24,6 +24,8 @@ class VirtualNetworkOCCI < VirtualNetwork <%= self.id.to_s %> <%= self.name %> + + <%= self['GNAME'] %> <% if self['TEMPLATE/DESCRIPTION'] != nil %> <%= self['TEMPLATE/DESCRIPTION'] %> <% end %> From 3f901ac6f843f1183f891c780a0b4eacf5fe76c1 Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Mon, 13 Feb 2012 12:57:57 +0100 Subject: [PATCH 14/18] bug #1042: fix units for du size --- src/image_mad/remotes/fs/fsrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/image_mad/remotes/fs/fsrc b/src/image_mad/remotes/fs/fsrc index 4693bd1c75..a55682115b 100644 --- a/src/image_mad/remotes/fs/fsrc +++ b/src/image_mad/remotes/fs/fsrc @@ -65,7 +65,7 @@ echo "$IMAGE_REPOSITORY_PATH/`echo $CANONICAL_MD5 | cut -d ' ' -f1`" function fs_du { if [ -d "$1" ]; then - SIZE=`du -s "$1" | cut -f1` + SIZE=`du -sb "$1" | cut -f1` error=$? else SIZE=`stat -c %s "$1"` From 115091be5f3ef33d014982c1309f28f6acf6eca2 Mon Sep 17 00:00:00 2001 From: Daniel Molina Date: Mon, 13 Feb 2012 15:22:46 +0100 Subject: [PATCH 15/18] Fix typo in error message --- src/lcm/LifeCycleStates.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lcm/LifeCycleStates.cc b/src/lcm/LifeCycleStates.cc index 6eb61acbfe..391238680b 100644 --- a/src/lcm/LifeCycleStates.cc +++ b/src/lcm/LifeCycleStates.cc @@ -330,7 +330,7 @@ void LifeCycleManager::deploy_failure_action(int vid) vmpool->update_history(vm); - vm->log("LCM", Log::INFO, "Fail to life migrate VM." + vm->log("LCM", Log::INFO, "Fail to live migrate VM." " Assuming that the VM is still RUNNING (will poll VM)."); //---------------------------------------------------- From 6e718906bdf99947d49848b36bc4ed04a018a000 Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Mon, 13 Feb 2012 15:58:01 +0100 Subject: [PATCH 16/18] bug #1094: take out uneeded xmlparser requirement --- share/install_gems/install_gems | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/share/install_gems/install_gems b/share/install_gems/install_gems index 4d8e8844a7..b6e1403e91 100755 --- a/share/install_gems/install_gems +++ b/share/install_gems/install_gems @@ -7,19 +7,12 @@ DEFAULT=%w{optional sunstone quota cloud ozones_server acct auth_ldap} if defined?(RUBY_VERSION) && RUBY_VERSION>="1.8.7" SQLITE='sqlite3' - # xmlparser gem is not compatible with ruby 1.9 - OPTIONAL=%w{nokogiri} - - if RUBY_VERSION=='1.8.7' - OPTIONAL << 'xmlparser' - end else SQLITE='sqlite3-ruby --version 1.2.0' - OPTIONAL=%w{nokogiri xmlparser} end GROUPS={ - :optional => OPTIONAL, + :optional => ['nokogiri'], :quota => [SQLITE, 'sequel'], :sunstone => ['json', 'rack', 'sinatra', 'thin', 'sequel', SQLITE], :cloud => %w{amazon-ec2 rack sinatra thin uuidtools curb json}, From 407350bbb198826ffcb0dc1bf9cb1a822a415761 Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Mon, 13 Feb 2012 17:52:26 +0100 Subject: [PATCH 17/18] bug #1130: add period_to_str method This methods is used to create strings for time periods with this format: 80d 10:23:33 --- src/cli/one_helper.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/cli/one_helper.rb b/src/cli/one_helper.rb index e900a963bc..dc81700cb6 100644 --- a/src/cli/one_helper.rb +++ b/src/cli/one_helper.rb @@ -364,6 +364,15 @@ EOT end end + def OpenNebulaHelper.period_to_str(time) + seconds=time.to_i + minutes, seconds=seconds.divmod(60) + hours, minutes=minutes.divmod(60) + days, hours=hours.divmod(24) + + "%4dd %02d:%02d:%02d" % [days, hours, minutes, seconds] + end + BinarySufix = ["K", "M", "G", "T" ] def OpenNebulaHelper.unit_to_str(value, options, unit="K") From da82e97164306ac0b7ea81c1775903f18c428c5e Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Mon, 13 Feb 2012 17:54:22 +0100 Subject: [PATCH 18/18] bug #1130: use period_to_str in oneacct --- src/cli/oneacct | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cli/oneacct b/src/cli/oneacct index 91d0399eb6..4d623cd2d3 100755 --- a/src/cli/oneacct +++ b/src/cli/oneacct @@ -77,7 +77,7 @@ class AcctHelper end column :TIME, "Group of the User", :right, :size=>15 do |d| - OpenNebulaHelper.time_to_str(d[:time]) + OpenNebulaHelper.period_to_str(d[:time]) end default :VMID, :MEMORY, :CPU, :NETRX, :NETTX, :TIME