From bd5151dcba94f4a1f8b61ba16794575e50ca10e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Fri, 9 Mar 2012 15:05:27 +0100 Subject: [PATCH 01/14] Feature #1112: Migrator to 3.3.80 returns error if it finds active VMs --- src/onedb/3.3.0_to_3.3.80.rb | 41 ++++++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/src/onedb/3.3.0_to_3.3.80.rb b/src/onedb/3.3.0_to_3.3.80.rb index 7194edc1e5..884d9bceae 100644 --- a/src/onedb/3.3.0_to_3.3.80.rb +++ b/src/onedb/3.3.0_to_3.3.80.rb @@ -25,7 +25,38 @@ module Migrator "OpenNebula 3.3.80" end + SHORT_VM_STATES=%w{init pend hold actv stop susp done fail} + + SHORT_LCM_STATES=%w{prol boot runn migr save save save migr prol, + epil epil shut shut fail clea unkn} + def up + + header_done = false + + @db.fetch("SELECT oid,name,state,lcm_state FROM vm_pool WHERE ( state <> 1 AND state <> 6 )") do |row| + if ( !header_done ) + puts "You can't have active VMs. Please shutdown or delete the following VMs:" + puts + puts " ID STAT NAME" + + header_done = true + end + + if row[:state] != 3 + state_str = SHORT_VM_STATES[row[:state]] + else + state_str = SHORT_LCM_STATES[row[:lcm_state]] + end + + puts "#{'%6.6s' % row[:oid].to_s} #{state_str} #{row[:name]}" + end + + if ( header_done ) + puts + return false + end + one_location = ENV["ONE_LOCATION"] if !one_location @@ -208,9 +239,7 @@ module Migrator if ( hash.length == 32 && hash =~ /^[0-9A-F]+$/i ) e.text = "#{var_location}/datastores/1/#{hash}" - # TODO: create link, or mv image file? `ln -s #{previous_source} #{e.text}` - # `mv #{e.text} #{previous_source}` end } @@ -250,15 +279,15 @@ module Migrator " 0" << " 0" << " " << - " fs" << # TODO - " shared" << # TODO + " fs" << + " shared" << " #{var_location}/datastores/1" << " -1" << " none" << images_element << " " << "" From 3e9af3242ce65199f2b05d67f594c7360a6dd9fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Fri, 9 Mar 2012 15:11:00 +0100 Subject: [PATCH 02/14] Feature #1112: Set DS_MAD as '-' for the system datastore --- src/datastore/DatastorePool.cc | 2 +- src/onedb/3.3.0_to_3.3.80.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/datastore/DatastorePool.cc b/src/datastore/DatastorePool.cc index 7dfd9fe096..1557659a39 100644 --- a/src/datastore/DatastorePool.cc +++ b/src/datastore/DatastorePool.cc @@ -52,7 +52,7 @@ DatastorePool::DatastorePool(SqlDB * db): // --------------------------------------------------------------------- oss << "NAME = " << SYSTEM_DS_NAME << endl - << "DS_MAD = fs" << endl + << "DS_MAD = -" << endl << "TM_MAD = shared"; ds_tmpl = new DatastoreTemplate; diff --git a/src/onedb/3.3.0_to_3.3.80.rb b/src/onedb/3.3.0_to_3.3.80.rb index 884d9bceae..3dff69249c 100644 --- a/src/onedb/3.3.0_to_3.3.80.rb +++ b/src/onedb/3.3.0_to_3.3.80.rb @@ -122,14 +122,14 @@ module Migrator " 0" << " 0" << " " << - " fs" << + " -" << " shared" << " #{var_location}/datastores/0" << " -1" << " none" << " " << " " << "" From f2e6303c3ee887af7564b998b583f2ab5d2f7324 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Fri, 9 Mar 2012 15:49:45 +0100 Subject: [PATCH 03/14] Feature #1112: Add new cluster_id parameter to one.vn.allocate --- include/RequestManagerAllocate.h | 14 ++++++++++++-- src/cli/onehost | 4 ++++ src/cli/onevnet | 13 +++++++++++-- src/oca/ruby/OpenNebula/VirtualNetwork.rb | 10 +++++++--- 4 files changed, 34 insertions(+), 7 deletions(-) diff --git a/include/RequestManagerAllocate.h b/include/RequestManagerAllocate.h index 9522314868..8b3497b418 100644 --- a/include/RequestManagerAllocate.h +++ b/include/RequestManagerAllocate.h @@ -146,7 +146,7 @@ public: VirtualNetworkAllocate(): RequestManagerAllocate("VirtualNetworkAllocate", "Allocates a new virtual network", - "A:ss", + "A:ssi", true) { Nebula& nd = Nebula::instance(); @@ -170,6 +170,16 @@ public: RequestAttributes& att, int cluster_id, const string& cluster_name); + + int get_cluster_id(xmlrpc_c::paramList const& paramList) + { + return xmlrpc_c::value_int(paramList.getInt(2)); + }; + + int add_to_cluster(Cluster* cluster, int id, string& error_msg) + { + return cluster->add_datastore(id, error_msg); + }; }; /* ------------------------------------------------------------------------- */ @@ -181,7 +191,7 @@ public: ImageAllocate(): RequestManagerAllocate("ImageAllocate", "Allocates a new image", - "A:ss", + "A:ssi", true) { Nebula& nd = Nebula::instance(); diff --git a/src/cli/onehost b/src/cli/onehost index 9f72204b66..4c60cc1673 100755 --- a/src/cli/onehost +++ b/src/cli/onehost @@ -52,6 +52,10 @@ cmd=CommandParser::CmdParser.new(ARGV) do helper.list_to_id(arg) end + set :format, :clusterid, OpenNebulaHelper.rname_to_id_desc("CLUSTER") do |arg| + OpenNebulaHelper.rname_to_id(arg, "CLUSTER") + end + ######################################################################## # Commands ######################################################################## diff --git a/src/cli/onevnet b/src/cli/onevnet index 720673db27..6f8a7084ff 100755 --- a/src/cli/onevnet +++ b/src/cli/onevnet @@ -52,6 +52,10 @@ cmd=CommandParser::CmdParser.new(ARGV) do OpenNebulaHelper.rname_to_id(arg, "USER") end + set :format, :clusterid, OpenNebulaHelper.rname_to_id_desc("CLUSTER") do |arg| + OpenNebulaHelper.rname_to_id(arg, "CLUSTER") + end + set :format, :vnetid, OneVNetHelper.to_id_desc do |arg| helper.to_id(arg) end @@ -72,10 +76,15 @@ cmd=CommandParser::CmdParser.new(ARGV) do Creates a new Virtual Network from the given template file EOT - command :create, create_desc, :file do + command :create, create_desc, :file, [:clusterid, nil] do helper.create_resource(options) do |vn| template=File.read(args[0]) - vn.allocate(template) + + if args.size == 1 + vn.allocate(template) + else + vn.allocate(template, args[1].to_i) + end end end diff --git a/src/oca/ruby/OpenNebula/VirtualNetwork.rb b/src/oca/ruby/OpenNebula/VirtualNetwork.rb index 1c24e0ad95..2b82cc1622 100644 --- a/src/oca/ruby/OpenNebula/VirtualNetwork.rb +++ b/src/oca/ruby/OpenNebula/VirtualNetwork.rb @@ -78,9 +78,13 @@ module OpenNebula # Allocates a new VirtualNetwork in OpenNebula # - # +description+ A string containing the template of the VirtualNetwork. - def allocate(description) - super(VN_METHODS[:allocate],description) + # @param description [String] The template of the VirtualNetwork. + # @param cluster_id [Integer] Id of the cluster + # + # @return [Integer, OpenNebula::Error] the new ID in case of + # success, error otherwise + def allocate(description,cluster_id=ClusterPool::NONE_CLUSTER_ID) + super(VN_METHODS[:allocate], description, cluster_id) end # Replaces the template contents From d265f670585d7c5eed5f00c54f3c38542be9e84b Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Fri, 9 Mar 2012 17:04:33 +0100 Subject: [PATCH 04/14] feature #1112: new onehost command. Better arguments --- src/cli/command_parser.rb | 2 +- src/cli/etc/onehost.yaml | 10 ++++- src/cli/one_helper/onecluster_helper.rb | 14 +++++++ src/cli/one_helper/onedatastore_helper.rb | 13 ++++++ src/cli/one_helper/onehost_helper.rb | 14 +++++-- src/cli/onehost | 49 +++++++++++++++++++---- src/oca/ruby/OpenNebula/Host.rb | 2 +- 7 files changed, 90 insertions(+), 14 deletions(-) diff --git a/src/cli/command_parser.rb b/src/cli/command_parser.rb index efe463d962..fe3fc911ac 100755 --- a/src/cli/command_parser.rb +++ b/src/cli/command_parser.rb @@ -311,7 +311,7 @@ EOT opts.on(*args) do |o| if e[:proc] - e[:proc].call(o, @options) + @options[e[:name].to_sym]=e[:proc].call(o, @options) elsif e[:name]=="help" help exit diff --git a/src/cli/etc/onehost.yaml b/src/cli/etc/onehost.yaml index 8a8c781f9b..dcb95c9cda 100644 --- a/src/cli/etc/onehost.yaml +++ b/src/cli/etc/onehost.yaml @@ -5,7 +5,12 @@ :NAME: :desc: Name of the Host - :size: 15 + :size: 12 + :left: true + +:CLUSTER: + :desc: Name of the Cluster + :size: 8 :left: true :RVM: @@ -38,11 +43,12 @@ :STAT: :desc: Host status - :size: 6 + :size: 4 :default: - :ID - :NAME +- :CLUSTER - :RVM - :TCPU - :FCPU diff --git a/src/cli/one_helper/onecluster_helper.rb b/src/cli/one_helper/onecluster_helper.rb index d709b4808c..fbf82b0a8a 100644 --- a/src/cli/one_helper/onecluster_helper.rb +++ b/src/cli/one_helper/onecluster_helper.rb @@ -17,6 +17,20 @@ require 'one_helper' class OneClusterHelper < OpenNebulaHelper::OneHelper + + CLUSTER = { + :name => "cluster", + :short => "-c id|name", + :large => "--cluster id|name" , + :description => "Selects the cluster", + :format => String, + :proc => lambda { |o, options| + ch = OneClusterHelper.new + rc, cid = ch.to_id(o) + cid + } + } + def self.rname "CLUSTER" end diff --git a/src/cli/one_helper/onedatastore_helper.rb b/src/cli/one_helper/onedatastore_helper.rb index 33f812c1a0..85f2cde4d7 100644 --- a/src/cli/one_helper/onedatastore_helper.rb +++ b/src/cli/one_helper/onedatastore_helper.rb @@ -17,6 +17,19 @@ require 'one_helper' class OneDatastoreHelper < OpenNebulaHelper::OneHelper + DATASTORE = { + :name => "datastore", + :short => "-d id|name", + :large => "--datastore id|name" , + :description => "Selects the datastore", + :format => String, + :proc => lambda { |o, options| + ch = OneDatastoreHelper.new + rc, dsid = ch.to_id(o) + dsid + } + } + def self.rname "DATASTORE" end diff --git a/src/cli/one_helper/onehost_helper.rb b/src/cli/one_helper/onehost_helper.rb index 74628bb18f..63434231ba 100644 --- a/src/cli/one_helper/onehost_helper.rb +++ b/src/cli/one_helper/onehost_helper.rb @@ -39,10 +39,18 @@ class OneHostHelper < OpenNebulaHelper::OneHelper d["ID"] end - column :NAME, "Name of the Host", :left, :size=>15 do |d| + column :NAME, "Name of the Host", :left, :size=>12 do |d| d["NAME"] end + column :CLUSTER, "Name of the Cluster", :left, :size=>8 do |d| + if d["CLUSTER"] == "none" + "-" + else + d["CLUSTER"] + end + end + column :RVM, "Number of Virtual Machines running", :size=>6 do |d| d["HOST_SHARE"]["RUNNING_VMS"] end @@ -82,11 +90,11 @@ class OneHostHelper < OpenNebulaHelper::OneHelper OpenNebulaHelper.unit_to_str(acpu,options) end - column :STAT, "Host status", :size=>6 do |d| + column :STAT, "Host status", :size=>4 do |d| OneHostHelper.state_to_str(d["STATE"]) end - default :ID, :NAME, :RVM, :TCPU, :FCPU, :ACPU, :TMEM, :FMEM, + default :ID, :NAME, :CLUSTER, :RVM, :TCPU, :FCPU, :ACPU, :TMEM, :FMEM, :AMEM, :STAT end diff --git a/src/cli/onehost b/src/cli/onehost index 9f72204b66..a56a49792c 100755 --- a/src/cli/onehost +++ b/src/cli/onehost @@ -29,6 +29,7 @@ $: << RUBY_LIB_LOCATION+"/cli" require 'command_parser' require 'one_helper/onehost_helper' +require 'one_helper/onecluster_helper' cmd=CommandParser::CmdParser.new(ARGV) do usage "`onehost` [] []" @@ -41,6 +42,31 @@ cmd=CommandParser::CmdParser.new(ARGV) do ######################################################################## set :option, CommandParser::OPTIONS + IM = { + :name => "im", + :short => "-i im_mad", + :large => "--im im_mad" , + :description => "Set the information driver for the host", + :format => String + } + + VMM = { + :name => "vmm", + :short => "-v vmm_mad", + :large => "--vm vmm_mad" , + :description => "Set the virtualization driver for the host", + :format => String + } + + VNET = { + :name => "vnm", + :short => "-n vnet_mad", + :large => "--net vnet_mad" , + :description => "Set the network driver for the host", + :format => String + } + + CREAT_OPTIONS = [ IM, VMM, VNET, OneClusterHelper::CLUSTER ] ######################################################################## # Formatters for arguments ######################################################################## @@ -60,14 +86,23 @@ cmd=CommandParser::CmdParser.new(ARGV) do Creates a new Host EOT - command :create, create_desc, :hostname, :im_mad, :vmm_mad, - :vnm_mad, [:clusterid, nil] do + command :create, create_desc, :hostname, :options=>CREAT_OPTIONS do + if options[:im].nil? or options[:vmm].nil? or options[:vnm].nil? + STDERR.puts "Drivers are mandatory to create a host:" + STDERR.puts "\t -i information driver" + STDERR.puts "\t -v hypervisor driver" + STDERR.puts "\t -n network driver" + exit -1 + end + + cid = options[:cluster] || ClusterPool::NONE_CLUSTER_ID + helper.create_resource(options) do |host| - if args.size == 4 - host.allocate(args[0], args[1], args[2], args[3]) - else - host.allocate(args[0], args[1], args[2], args[3], args[4].to_i) - end + host.allocate(args[0], + options[:im], + options[:vmm], + options[:vnm], + cid) end end diff --git a/src/oca/ruby/OpenNebula/Host.rb b/src/oca/ruby/OpenNebula/Host.rb index c8274532ec..f0c6286939 100644 --- a/src/oca/ruby/OpenNebula/Host.rb +++ b/src/oca/ruby/OpenNebula/Host.rb @@ -82,7 +82,7 @@ module OpenNebula # @param im [String] Name of the im_driver (information/monitoring) # @param vmm [String] Name of the vmm_driver (hypervisor) # @param tm [String] Name of the vnm_driver (networking) - # @param cluster_id [Integer] Id of the cluster + # @param cluster_id [String] Id of the cluster # # @return [Integer, OpenNebula::Error] the new ID in case of # success, error otherwise From 6861fa660ebd8fe3ca4c71f760ebbf72307ef304 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Fri, 9 Mar 2012 17:13:24 +0100 Subject: [PATCH 05/14] feature #1112: Removed formatter --- src/cli/onehost | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/cli/onehost b/src/cli/onehost index 354c3c284e..3b7d89fa63 100755 --- a/src/cli/onehost +++ b/src/cli/onehost @@ -67,9 +67,11 @@ cmd=CommandParser::CmdParser.new(ARGV) do } CREAT_OPTIONS = [ IM, VMM, VNET, OneClusterHelper::CLUSTER ] + ######################################################################## # Formatters for arguments ######################################################################## + set :format, :hostid, OneHostHelper.to_id_desc do |arg| helper.to_id(arg) end @@ -78,10 +80,6 @@ cmd=CommandParser::CmdParser.new(ARGV) do helper.list_to_id(arg) end - set :format, :clusterid, OpenNebulaHelper.rname_to_id_desc("CLUSTER") do |arg| - OpenNebulaHelper.rname_to_id(arg, "CLUSTER") - end - ######################################################################## # Commands ######################################################################## From 961e368116aa02301916eb58bded4d3dbeb770ea Mon Sep 17 00:00:00 2001 From: Tino Vazquez Date: Fri, 9 Mar 2012 17:13:42 +0100 Subject: [PATCH 06/14] TM shared drivers compatibility with VMware --- src/mad/sh/scripts_common.sh | 1 + src/tm_mad/common/context | 3 ++ src/tm_mad/shared/ln | 39 +++++++++++++++++---- src/tm_mad/tm_common.sh | 15 ++++++++ src/vmm/LibVirtDriverVMware.cc | 6 ++-- src/vmm_mad/exec/vmm_exec_vmware.conf | 9 ++--- src/vmm_mad/remotes/vmware/vmware_driver.rb | 3 +- 7 files changed, 61 insertions(+), 15 deletions(-) diff --git a/src/mad/sh/scripts_common.sh b/src/mad/sh/scripts_common.sh index 1296f3c65a..7e6bb04ce8 100755 --- a/src/mad/sh/scripts_common.sh +++ b/src/mad/sh/scripts_common.sh @@ -27,6 +27,7 @@ ISCSIADM=iscsiadm LVCREATE=lvcreate LVREMOVE=lvremove LVS=lvs +LN=ln MD5SUM=md5sum MKFS=mkfs MKISOFS=mkisofs diff --git a/src/tm_mad/common/context b/src/tm_mad/common/context index a36c2e5699..d519110140 100755 --- a/src/tm_mad/common/context +++ b/src/tm_mad/common/context @@ -73,6 +73,9 @@ exec_and_log "$MKISOFS -o $ISO_FILE -J -R $ISO_DIR" "Error creating iso fs" exec_and_log "$SCP $ISO_FILE $DST" "Error copying context ISO to $DST" +# Creates symbolic link to add a .iso suffix, needed for VMware CDROMs +ssh_exec_and_log $DST_HOST "$LN -s $DST_PATH $DST_PATH.iso" "Error creating ISO symbolic link" + rm -rf $ISO_DIR > /dev/null 2>&1 exit 0 diff --git a/src/tm_mad/shared/ln b/src/tm_mad/shared/ln index 4ecb76e42b..2a9395d484 100755 --- a/src/tm_mad/shared/ln +++ b/src/tm_mad/shared/ln @@ -16,7 +16,7 @@ # limitations under the License. # #--------------------------------------------------------------------------- # -# ln fe:SOURCE host:remote_system_ds/disk.i size +# ln fe:SOURCE host:remote_system_ds/disk.i # - fe is the front-end hostname # - SOURCE is the path of the disk image in the form DS_BASE_PATH/disk # - host is the target host to deploy the VM @@ -43,16 +43,41 @@ DST_PATH=`arg_path $DST` DST_HOST=`arg_host $DST` DST_DIR=`dirname $DST_PATH` -ssh_make_path $DST_HOST $DST_DIR - #------------------------------------------------------------------------------- # Link (ln) SRC into DST #------------------------------------------------------------------------------- -log "Linking $SRC_PATH in $DST" +# Is it a file or a folder (VMware)? +if [ -d `arg_path $SRC` ]; then + ssh_make_path $DST_HOST $DST_PATH + + # It's a folder, make links for all elements + SRC_FOLDER_NAME=`basename $SRC_PATH` + SRC_WITH_NO_FOLDER=`dirname $SRC_PATH` + SRC_DS_NAME=`basename $SRC_WITH_NO_FOLDER` + REL_SRC_PATH="../../../$SRC_DS_NAME/$SRC_FOLDER_NAME" + + log "Link all files in $SRC_PATH to $DST_PATH" + +LINK_SCRIPT=$(cat <" << endl; file << "\t\t\tget_oid() - << "/images/disk." << i << "'/>" << endl; + << "/disk." << i << "'/>" << endl; } else if ( type == "CDROM" ) { file << "\t\t" << endl; file << "\t\t\tget_oid() - << "/images/disk." << i << ".iso'/>" << endl; + << "/disk." << i << ".iso'/>" << endl; } else { file << "\t\t" << endl << "\t\t\t" << endl; + << "/disk." << i << "/disk.vmdk'/>" << endl; } file << "\t\t\t e OpenNebula.log_error("Cannot open checkpoint #{e.message}") exit -1 From a9d7a9b072367cf64bd8566d77020662b8c7a7d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Fri, 9 Mar 2012 17:32:54 +0100 Subject: [PATCH 07/14] Bug #1159: Move restricted attribute checks to RM. Do not check restricted attributes when a template owned by oneadmin is instantiated --- include/RequestManagerAllocate.h | 4 +++ src/image/Image.cc | 20 ------------ src/rm/RequestManagerAllocate.cc | 52 ++++++++++++++++++++++++++++++ src/rm/RequestManagerVMTemplate.cc | 21 ++++++++++++ src/vm/VirtualMachine.cc | 28 ++-------------- 5 files changed, 80 insertions(+), 45 deletions(-) diff --git a/include/RequestManagerAllocate.h b/include/RequestManagerAllocate.h index 8b3497b418..faceccd4db 100644 --- a/include/RequestManagerAllocate.h +++ b/include/RequestManagerAllocate.h @@ -205,6 +205,10 @@ public: void request_execute(xmlrpc_c::paramList const& _paramList, RequestAttributes& att); + + bool allocate_authorization(Template * obj_template, + RequestAttributes& att, + PoolObjectAuth * cluster_perms); }; /* ------------------------------------------------------------------------- */ diff --git a/src/image/Image.cc b/src/image/Image.cc index dfa867ee24..e05c4b8ffd 100644 --- a/src/image/Image.cc +++ b/src/image/Image.cc @@ -95,25 +95,10 @@ int Image::insert(SqlDB *db, string& error_str) string persistent_attr; string dev_prefix; string source_attr; - string aname; string saved_id; ostringstream oss; - // ------------------------------------------------------------------------ - // Check template for restricted attributes - // ------------------------------------------------------------------------ - - if ( uid != 0 && gid != GroupPool::ONEADMIN_ID ) - { - ImageTemplate *img_template = static_cast(obj_template); - - if (img_template->check(aname)) - { - goto error_restricted; - } - } - // --------------------------------------------------------------------- // Check default image attributes // --------------------------------------------------------------------- @@ -242,11 +227,6 @@ error_path_and_source: error_str = "Template malformed, PATH and SOURCE are mutually exclusive."; goto error_common; -error_restricted: - oss << "Template includes a restricted attribute " << aname << "."; - error_str = oss.str(); - goto error_common; - error_common: NebulaLog::log("IMG", Log::ERROR, error_str); return -1; diff --git a/src/rm/RequestManagerAllocate.cc b/src/rm/RequestManagerAllocate.cc index 5342d9efd8..e5c70bda4a 100644 --- a/src/rm/RequestManagerAllocate.cc +++ b/src/rm/RequestManagerAllocate.cc @@ -76,9 +76,28 @@ bool VirtualMachineAllocate::allocate_authorization( AuthRequest ar(att.uid, att.gid); string t64; + string aname; VirtualMachineTemplate * ttmpl = static_cast(tmpl); + // Check template for restricted attributes + + if ( att.uid != 0 && att.gid != GroupPool::ONEADMIN_ID ) + { + if (ttmpl->check(aname)) + { + ostringstream oss; + + oss << "VM Template includes a restricted attribute " << aname; + + failure_response(AUTHORIZATION, + authorization_error(oss.str(), att), + att); + + return false; + } + } + ar.add_create_auth(auth_object, tmpl->to_xml(t64)); VirtualMachine::set_auth_request(att.uid, ar, ttmpl); @@ -98,6 +117,39 @@ bool VirtualMachineAllocate::allocate_authorization( /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ +bool ImageAllocate::allocate_authorization( + Template * tmpl, + RequestAttributes& att, + PoolObjectAuth * cluster_perms) +{ + string aname; + + ImageTemplate * itmpl = static_cast(tmpl); + + // Check template for restricted attributes + + if ( att.uid != 0 && att.gid != GroupPool::ONEADMIN_ID ) + { + if (itmpl->check(aname)) + { + ostringstream oss; + + oss << "Template includes a restricted attribute " << aname; + + failure_response(AUTHORIZATION, + authorization_error(oss.str(), att), + att); + + return false; + } + } + + return RequestManagerAllocate::allocate_authorization(tmpl, att, cluster_perms); +} + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + void RequestManagerAllocate::request_execute(xmlrpc_c::paramList const& params, RequestAttributes& att) { diff --git a/src/rm/RequestManagerVMTemplate.cc b/src/rm/RequestManagerVMTemplate.cc index a62aa2f56d..d354d5a037 100644 --- a/src/rm/RequestManagerVMTemplate.cc +++ b/src/rm/RequestManagerVMTemplate.cc @@ -39,6 +39,7 @@ void VMTemplateInstantiate::request_execute(xmlrpc_c::paramList const& paramList VMTemplate * rtmpl; string error_str; + string aname; rtmpl = tpool->get(id,true); @@ -57,6 +58,26 @@ void VMTemplateInstantiate::request_execute(xmlrpc_c::paramList const& paramList rtmpl->unlock(); + // Check template for restricted attributes, but only if the Template owner + // is not oneadmin + + if ( perms.uid != 0 && perms.gid != GroupPool::ONEADMIN_ID ) + { + if (tmpl->check(aname)) + { + ostringstream oss; + + oss << "VM Template includes a restricted attribute " << aname; + + failure_response(AUTHORIZATION, + authorization_error(oss.str(), att), + att); + + delete tmpl; + return; + } + } + tmpl->erase("NAME"); tmpl->set(new SingleAttribute("NAME",name)); diff --git a/src/vm/VirtualMachine.cc b/src/vm/VirtualMachine.cc index 38fd4100f0..f11f91ac70 100644 --- a/src/vm/VirtualMachine.cc +++ b/src/vm/VirtualMachine.cc @@ -198,26 +198,9 @@ int VirtualMachine::insert(SqlDB * db, string& error_str) int rc; string name; - SingleAttribute * attr; - string aname; - string value; - - ostringstream oss; - - // ------------------------------------------------------------------------ - // Check template for restricted attributes - // ------------------------------------------------------------------------ - - if ( uid != 0 && gid != GroupPool::ONEADMIN_ID ) - { - VirtualMachineTemplate *vt = - static_cast(obj_template); - - if (vt->check(aname)) - { - goto error_restricted; - } - } + SingleAttribute * attr; + string value; + ostringstream oss; // ------------------------------------------------------------------------ // Set a name if the VM has not got one and VM_ID @@ -327,11 +310,6 @@ error_leases_rollback: release_network_leases(); goto error_common; -error_restricted: - oss << "VM Template includes a restricted attribute " << aname << "."; - error_str = oss.str(); - goto error_common; - error_name_length: oss << "NAME is too long; max length is 128 chars."; error_str = oss.str(); From c88fdb617afbc2d6118e8c3f0870d48871b5424a Mon Sep 17 00:00:00 2001 From: Tino Vazquez Date: Fri, 9 Mar 2012 18:11:53 +0100 Subject: [PATCH 08/14] SSH TM drivers compatibility with VMware --- src/tm_mad/ssh/clone | 2 +- src/tm_mad/ssh/mvds | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tm_mad/ssh/clone b/src/tm_mad/ssh/clone index 87a95357fb..8a81d9b95d 100755 --- a/src/tm_mad/ssh/clone +++ b/src/tm_mad/ssh/clone @@ -58,6 +58,6 @@ http://*) *) log "Cloning $SRC in $DST_PATH" - exec_and_log "$SCP $SRC $DST" "Error copying $SRC to $DST" + exec_and_log "$SCP -r $SRC $DST" "Error copying $SRC to $DST" ;; esac diff --git a/src/tm_mad/ssh/mvds b/src/tm_mad/ssh/mvds index 74bb8cc8cf..47c66b6b41 100755 --- a/src/tm_mad/ssh/mvds +++ b/src/tm_mad/ssh/mvds @@ -49,6 +49,6 @@ SRC_HOST=`arg_host $SRC` # Move the image back to the datastore #------------------------------------------------------------------------------- log "Moving $SRC_PATH to datastore as $DST_PATH" -exec_and_log "$SCP $SRC $DST" "Error copying $SRC to $DST" +exec_and_log "$SCP -r $SRC $DST" "Error copying $SRC to $DST" exit 0 From 94088ad0797e3f57d6d98cccf25feef148432a97 Mon Sep 17 00:00:00 2001 From: Tino Vazquez Date: Fri, 9 Mar 2012 18:15:53 +0100 Subject: [PATCH 09/14] change bash ssh wrapper to sh to ensure vSphere 5.x compatibility --- src/mad/sh/scripts_common.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mad/sh/scripts_common.sh b/src/mad/sh/scripts_common.sh index 7e6bb04ce8..204b87eb38 100755 --- a/src/mad/sh/scripts_common.sh +++ b/src/mad/sh/scripts_common.sh @@ -212,7 +212,7 @@ function mkfs_command { #This function executes $2 at $1 host and report error $3 function ssh_exec_and_log { - SSH_EXEC_ERR=`$SSH $1 bash -s 2>&1 1>/dev/null <&1 1>/dev/null <&1 1>/dev/null <&1 1>/dev/null < Date: Fri, 9 Mar 2012 18:24:20 +0100 Subject: [PATCH 10/14] Feature #1112: onedb restores the original DB if the upgrade process fails --- src/onedb/onedb.rb | 74 +++++++++++++++++++++++++++------------------- 1 file changed, 44 insertions(+), 30 deletions(-) diff --git a/src/onedb/onedb.rb b/src/onedb/onedb.rb index a6a041ad38..967b27962b 100644 --- a/src/onedb/onedb.rb +++ b/src/onedb/onedb.rb @@ -107,43 +107,57 @@ class OneDB backup(ops[:backup], ops) end - result = nil - i = 0 + begin + result = nil + i = 0 - while ( matches.size > 0 ) - if ( matches.size > 1 ) - raise "There are more than one file that match \ - \"#{RUBY_LIB_LOCATION}/onedb/#{version}_to_*.rb\"" + while ( matches.size > 0 ) + if ( matches.size > 1 ) + raise "There are more than one file that match \ + \"#{RUBY_LIB_LOCATION}/onedb/#{version}_to_*.rb\"" + end + + file = matches[0] + + puts " > Running migrator #{file}" if ops[:verbose] + + load(file) + @backend.extend Migrator + result = @backend.up + + if !result + raise "Error while upgrading from #{version} to " << + " #{@backend.db_version}" + end + + puts " > Done" if ops[:verbose] + puts "" if ops[:verbose] + + matches = Dir.glob( + "#{RUBY_LIB_LOCATION}/onedb/#{@backend.db_version}_to_*.rb") end - file = matches[0] - - puts " > Running migrator #{file}" if ops[:verbose] - - load(file) - @backend.extend Migrator - result = @backend.up - - if !result - raise "Error while upgrading from #{version} to " << - " #{@backend.db_version}" + # Modify db_versioning table + if result != nil + @backend.update_db_version(version) + else + puts "Database already uses version #{version}" end - puts " > Done" if ops[:verbose] - puts "" if ops[:verbose] + return 0 - matches = Dir.glob( - "#{RUBY_LIB_LOCATION}/onedb/#{@backend.db_version}_to_*.rb") + rescue Exception => e + puts e.message + + puts + puts "The database will be restored" + + ops[:force] = true + + restore(ops[:backup], ops) + + return -1 end - - # Modify db_versioning table - if result != nil - @backend.update_db_version(version) - else - puts "Database already uses version #{version}" - end - - return 0 end private From 0e8ecf97f76302eab9a90e6f2d2e98e038e500b2 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Fri, 9 Mar 2012 18:28:11 +0100 Subject: [PATCH 11/14] feature #1112: Datastore Command --- src/cli/etc/onedatastore.yaml | 24 ++++++++++++++ src/cli/one_helper/onedatastore_helper.rb | 39 +++++++++++++++++------ src/cli/onedatastore | 18 +++++++---- 3 files changed, 65 insertions(+), 16 deletions(-) diff --git a/src/cli/etc/onedatastore.yaml b/src/cli/etc/onedatastore.yaml index a012998163..7b9ffe5237 100644 --- a/src/cli/etc/onedatastore.yaml +++ b/src/cli/etc/onedatastore.yaml @@ -8,7 +8,31 @@ :size: 15 :left: true +:CLUSTER: + :desc: Name of the Cluster + :size: 8 + :left: true + +:IMAGES: + :desc: Number of Images + :size: 6 + :left: true + +:TYPE: + :desc: Datastore driver + :size: 6 + :left: true + +:TM: + :desc: Transfer driver + :size: 6 + :left: true + :default: - :ID - :NAME +- :CLUSTER +- :IMAGES +- :TYPE +- :TM diff --git a/src/cli/one_helper/onedatastore_helper.rb b/src/cli/one_helper/onedatastore_helper.rb index 85f2cde4d7..a143379d24 100644 --- a/src/cli/one_helper/onedatastore_helper.rb +++ b/src/cli/one_helper/onedatastore_helper.rb @@ -29,7 +29,7 @@ class OneDatastoreHelper < OpenNebulaHelper::OneHelper dsid } } - + def self.rname "DATASTORE" end @@ -46,11 +46,31 @@ class OneDatastoreHelper < OpenNebulaHelper::OneHelper d["ID"] end - column :NAME, "Name of the Datastore", :left, :size=>15 do |d| + column :NAME, "Name of the Datastore", :left, :size=>12 do |d| d["NAME"] end - default :ID, :NAME + column :CLUSTER, "Name of the Cluster", :left, :size=>8 do |d| + if d["CLUSTER"] == "none" + "-" + else + d["CLUSTER"] + end + end + + column :IMAGES, "Number of Images", :left, :size=>6 do |d| + d["IMAGES"].size + end + + column :TYPE, "Datastore driver", :left, :size=>6 do |d| + d["DS_MAD"] + end + + column :TM, "Transfer driver", :left, :size=>6 do |d| + d["TM_MAD"] + end + + default :ID, :CLUSTER, :NAME, :IMAGES, :TYPE, :TM_MAD end table @@ -82,6 +102,7 @@ class OneDatastoreHelper < OpenNebulaHelper::OneHelper puts str % ["USER", datastore['UNAME']] puts str % ["GROUP", datastore['GNAME']] puts str % ["CLUSTER", datastore['CLUSTER']] + puts str % ["CLUSTER_ID", datastore['CLUSTER_ID']] puts str % ["DS_MAD", datastore['DS_MAD']] puts str % ["TM_MAD", datastore['TM_MAD']] @@ -100,14 +121,14 @@ class OneDatastoreHelper < OpenNebulaHelper::OneHelper } puts - CLIHelper.print_header(str_h1 % "IMAGES", false) - CLIHelper.print_header("%-15s" % ["ID"]) + CLIHelper.print_header(str_h1 % "DATASTORE TEMPLATE",false) + puts datastore.template_str + + puts + + CLIHelper.print_header(str_h1 % "REGISTERED IMAGES", false) datastore.img_ids.each do |id| puts "%-15s" % [id] end - - puts - CLIHelper.print_header(str_h1 % "DATASTORE TEMPLATE",false) - puts datastore.template_str end end diff --git a/src/cli/onedatastore b/src/cli/onedatastore index 514b5c2249..02dbab9189 100755 --- a/src/cli/onedatastore +++ b/src/cli/onedatastore @@ -29,6 +29,7 @@ $: << RUBY_LIB_LOCATION+"/cli" require 'command_parser' require 'one_helper/onedatastore_helper' +require 'one_helper/onecluster_helper' cmd=CommandParser::CmdParser.new(ARGV) do usage "`onedatastore` [] []" @@ -76,14 +77,17 @@ cmd=CommandParser::CmdParser.new(ARGV) do Creates a new Datastore from the given template file EOT - command :create, create_desc, :file, [:clusterid, nil] do - helper.create_resource(options) do |datastore| - template=File.read(args[0]) + command :create, create_desc, :file, :options=>[OneClusterHelper::CLUSTER] do - if args.size == 1 - datastore.allocate(template) - else - datastore.allocate(template, args[1].to_i) + cid = options[:cluster] || ClusterPool::NONE_CLUSTER_ID + + helper.create_resource(options) do |datastore| + begin + template=File.read(args[0]) + datastore.allocate(template, cid) + rescue =>e + STDERR.puts e.message + exit -1 end end end From 5c9dcf90337a692d41a8c4ddb517a895f4be0830 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Fri, 9 Mar 2012 21:25:05 +0100 Subject: [PATCH 12/14] feature #1112: Work on onecluster command --- src/cli/etc/onecluster.yaml | 19 ++++++++++++++++- src/cli/one_helper/onecluster_helper.rb | 26 +++++++++++++++++------ src/cli/one_helper/onedatastore_helper.rb | 4 ++-- 3 files changed, 39 insertions(+), 10 deletions(-) diff --git a/src/cli/etc/onecluster.yaml b/src/cli/etc/onecluster.yaml index b69de015c6..f3d4949e85 100644 --- a/src/cli/etc/onecluster.yaml +++ b/src/cli/etc/onecluster.yaml @@ -8,7 +8,24 @@ :size: 15 :left: true +:HOSTS: + :desc: Number of Hosts + :size: 5 + :left: true + +:NETS: + :desc: Number of Networks + :size: 5 + :left: true + +:DATASTORES: + :desc: Number of Datastores + :size: 10 + :left: true + :default: - :ID - :NAME - +- :HOSTS +- :NETS +- :DATASTORES diff --git a/src/cli/one_helper/onecluster_helper.rb b/src/cli/one_helper/onecluster_helper.rb index fbf82b0a8a..4e837f9a29 100644 --- a/src/cli/one_helper/onecluster_helper.rb +++ b/src/cli/one_helper/onecluster_helper.rb @@ -51,7 +51,19 @@ class OneClusterHelper < OpenNebulaHelper::OneHelper d["NAME"] end - default :ID, :NAME + column :HOSTS, "Number of Hosts", :left, :size=>5 do |d| + d["HOSTS"].size + end + + column :NETS, "Number of Networks", :left, :size=>5 do |d| + d["HOSTS"].size + end + + column :DATASTORES, "Number of Datastores", :left, :size=>10 do |d| + d["DATASTORES"].size + end + + default :ID, :NAME, :HOSTS, :NETS, :DATASTORES end table @@ -86,16 +98,16 @@ class OneClusterHelper < OpenNebulaHelper::OneHelper puts "%-15s" % [id] end - puts - CLIHelper.print_header("%-15s" % ["DATASTORES"]) - cluster.datastore_ids.each do |id| - puts "%-15s" % [id] - end - puts CLIHelper.print_header("%-15s" % ["VNETS"]) cluster.vnet_ids.each do |id| puts "%-15s" % [id] end + + puts + CLIHelper.print_header("%-15s" % ["DATASTORES"]) + cluster.datastore_ids.each do |id| + puts "%-15s" % [id] + end end end diff --git a/src/cli/one_helper/onedatastore_helper.rb b/src/cli/one_helper/onedatastore_helper.rb index a143379d24..16f68d6e6b 100644 --- a/src/cli/one_helper/onedatastore_helper.rb +++ b/src/cli/one_helper/onedatastore_helper.rb @@ -121,12 +121,12 @@ class OneDatastoreHelper < OpenNebulaHelper::OneHelper } puts - CLIHelper.print_header(str_h1 % "DATASTORE TEMPLATE",false) + CLIHelper.print_header(str_h1 % "DATASTORE TEMPLATE", false) puts datastore.template_str puts - CLIHelper.print_header(str_h1 % "REGISTERED IMAGES", false) + CLIHelper.print_header("%-15s" % "IMAGES") datastore.img_ids.each do |id| puts "%-15s" % [id] end From 9ae062e39ea873f3f18f7616d0ed43fcde8c69de Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Fri, 9 Mar 2012 21:45:02 +0100 Subject: [PATCH 13/14] feature #1112: Update onevnet command --- src/cli/etc/onevnet.yaml | 16 +++++++++++----- src/cli/one_helper/onevnet_helper.rb | 22 +++++++++++++++------- src/cli/onevnet | 23 ++++++++++++----------- 3 files changed, 38 insertions(+), 23 deletions(-) diff --git a/src/cli/etc/onevnet.yaml b/src/cli/etc/onevnet.yaml index 12820657ad..36d07930ca 100644 --- a/src/cli/etc/onevnet.yaml +++ b/src/cli/etc/onevnet.yaml @@ -3,11 +3,6 @@ :desc: ONE identifier for Virtual Network :size: 4 -:NAME: - :desc: Name of the Virtual Network - :size: 15 - :left: true - :USER: :desc: Username of the Virtual Network owner :size: 8 @@ -18,6 +13,16 @@ :size: 8 :left: true +:NAME: + :desc: Name of the Virtual Network + :size: 15 + :left: true + +:CLUSTER: + :desc: Name of the Cluster + :size: 8 + :left: true + :TYPE: :desc: Type of Virtual Network :size: 6 @@ -39,6 +44,7 @@ - :USER - :GROUP - :NAME +- :CLUSTER - :TYPE - :BRIDGE - :LEASES diff --git a/src/cli/one_helper/onevnet_helper.rb b/src/cli/one_helper/onevnet_helper.rb index 6b2b439c5a..8281f51eff 100644 --- a/src/cli/one_helper/onevnet_helper.rb +++ b/src/cli/one_helper/onevnet_helper.rb @@ -39,11 +39,6 @@ class OneVNetHelper < OpenNebulaHelper::OneHelper 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) @@ -54,11 +49,24 @@ class OneVNetHelper < OpenNebulaHelper::OneHelper helper.group_name(d, options) end + column :NAME, "Name of the Virtual Network", :left, + :size=>15 do |d| + d["NAME"] + end + + column :CLUSTER, "Name of the Cluster", :left, :size=>8 do |d| + if d["CLUSTER"] == "none" + "-" + else + d["CLUSTER"] + end + 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| + column :SIZE, "Size of the Virtual Network", :size=>5 do |d| d["SIZE"] end @@ -68,7 +76,7 @@ class OneVNetHelper < OpenNebulaHelper::OneHelper end column :LEASES, "Number of this Virtual Network's given leases", - :size=>7 do |d| + :size=>6 do |d| d["TOTAL_LEASES"] end diff --git a/src/cli/onevnet b/src/cli/onevnet index 6f8a7084ff..e76da4b48d 100755 --- a/src/cli/onevnet +++ b/src/cli/onevnet @@ -29,6 +29,7 @@ $: << RUBY_LIB_LOCATION+"/cli" require 'command_parser' require 'one_helper/onevnet_helper' +require 'one_helper/onecluster_helper' cmd=CommandParser::CmdParser.new(ARGV) do usage "`onevnet` [] []" @@ -41,6 +42,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do ######################################################################## set :option, CommandParser::OPTIONS + CREATE_OPTIONS = [OneClusterHelper::CLUSTER] + ######################################################################## # Formatters for arguments ######################################################################## @@ -52,10 +55,6 @@ cmd=CommandParser::CmdParser.new(ARGV) do OpenNebulaHelper.rname_to_id(arg, "USER") end - set :format, :clusterid, OpenNebulaHelper.rname_to_id_desc("CLUSTER") do |arg| - OpenNebulaHelper.rname_to_id(arg, "CLUSTER") - end - set :format, :vnetid, OneVNetHelper.to_id_desc do |arg| helper.to_id(arg) end @@ -76,14 +75,16 @@ cmd=CommandParser::CmdParser.new(ARGV) do Creates a new Virtual Network from the given template file EOT - command :create, create_desc, :file, [:clusterid, nil] do - helper.create_resource(options) do |vn| - template=File.read(args[0]) + command :create, create_desc, :file, options=>CREATE_OPTIONS do + cid = options[:cluster] || ClusterPool::NONE_CLUSTER_ID - if args.size == 1 - vn.allocate(template) - else - vn.allocate(template, args[1].to_i) + helper.create_resource(options) do |vn| + begin + template=File.read(args[0]) + vn.allocate(template, cid) + rescue => e + STDERR.puts e.message + exit -1 end end end From fbbf10950ac9dbcdc9b3452309336f741c8fca96 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Fri, 9 Mar 2012 22:43:44 +0100 Subject: [PATCH 14/14] feature #1112: Image command includes datastore information --- src/cli/etc/oneimage.yaml | 17 +++++++++++------ src/cli/one_helper/onedatastore_helper.rb | 6 +++++- src/cli/one_helper/oneimage_helper.rb | 19 +++++++++---------- src/cli/oneimage | 23 ++++++++++++++++------- 4 files changed, 41 insertions(+), 24 deletions(-) diff --git a/src/cli/etc/oneimage.yaml b/src/cli/etc/oneimage.yaml index c8ddff7956..235d7e8ca9 100644 --- a/src/cli/etc/oneimage.yaml +++ b/src/cli/etc/oneimage.yaml @@ -3,11 +3,6 @@ :desc: ONE identifier for the Image :size: 4 -:NAME: - :desc: Name of the Image - :size: 12 - :left: true - :USER: :desc: Username of the Virtual Machine owner :size: 8 @@ -18,6 +13,16 @@ :size: 8 :left: true +:NAME: + :desc: Name of the Image + :size: 12 + :left: true + +:DATASTORE: + :desc: Name of the Datastore + :size: 10 + :left: true + :SIZE: :desc: Size of the Image :size: 7 @@ -47,9 +52,9 @@ - :USER - :GROUP - :NAME +- :DATASTORE - :SIZE - :TYPE -- :REGTIME - :PERSISTENT - :STAT - :RVMS diff --git a/src/cli/one_helper/onedatastore_helper.rb b/src/cli/one_helper/onedatastore_helper.rb index 16f68d6e6b..4f524bbd71 100644 --- a/src/cli/one_helper/onedatastore_helper.rb +++ b/src/cli/one_helper/onedatastore_helper.rb @@ -59,7 +59,11 @@ class OneDatastoreHelper < OpenNebulaHelper::OneHelper end column :IMAGES, "Number of Images", :left, :size=>6 do |d| - d["IMAGES"].size + if d["IMAGES"]["ID"].nil? + "0" + else + d["IMAGES"]["ID"].size + end end column :TYPE, "Datastore driver", :left, :size=>6 do |d| diff --git a/src/cli/one_helper/oneimage_helper.rb b/src/cli/one_helper/oneimage_helper.rb index 4d13ae95dc..b02ea356d9 100644 --- a/src/cli/one_helper/oneimage_helper.rb +++ b/src/cli/one_helper/oneimage_helper.rb @@ -45,10 +45,6 @@ class OneImageHelper < OpenNebulaHelper::OneHelper d["ID"] end - column :NAME, "Name of the Image", :left, :size=>12 do |d| - d["NAME"] - end - column :USER, "Username of the Virtual Machine owner", :left, :size=>8 do |d| helper.user_name(d, options) @@ -59,13 +55,16 @@ class OneImageHelper < OpenNebulaHelper::OneHelper helper.group_name(d, options) end - column :TYPE, "Type of the Image", :size=>4 do |d,e| - OneImageHelper.type_to_str(d["TYPE"]) + column :NAME, "Name of the Image", :left, :size=>12 do |d| + d["NAME"] end - column :REGTIME, "Registration time of the Image", - :size=>20 do |d| - OpenNebulaHelper.time_to_str(d["REGTIME"]) + column :DATASTORE, "Name of the Image", :left, :size=>10 do |d| + d["DATASTORE"] + end + + column :TYPE, "Type of the Image", :size=>4 do |d,e| + OneImageHelper.type_to_str(d["TYPE"]) end column :PERSISTENT, "Whether the Image is persistent or not", @@ -87,7 +86,7 @@ class OneImageHelper < OpenNebulaHelper::OneHelper OpenNebulaHelper.unit_to_str(d['SIZE'].to_i,options,"M") end - default :ID, :USER, :GROUP, :NAME, :SIZE, :TYPE, :REGTIME, + default :ID, :USER, :GROUP, :NAME, :DATASTORE, :SIZE, :TYPE, :PERSISTENT , :STAT, :RVMS end diff --git a/src/cli/oneimage b/src/cli/oneimage index bb8635f5db..fca548c8ce 100755 --- a/src/cli/oneimage +++ b/src/cli/oneimage @@ -29,6 +29,7 @@ $: << RUBY_LIB_LOCATION+"/cli" require 'command_parser' require 'one_helper/oneimage_helper' +require 'one_helper/onedatastore_helper' cmd=CommandParser::CmdParser.new(ARGV) do usage "`oneimage` [] []" @@ -45,6 +46,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do list_options << OpenNebulaHelper::XML list_options << OpenNebulaHelper::NUMERIC + CREATE_OPTIONS = [OneDatastoreHelper::DATASTORE] + ######################################################################## # Formatters for arguments ######################################################################## @@ -56,10 +59,6 @@ cmd=CommandParser::CmdParser.new(ARGV) do OpenNebulaHelper.rname_to_id(arg, "USER") end - set :format, :datastoreid, OpenNebulaHelper.rname_to_id_desc("DATASTORE") do |arg| - OpenNebulaHelper.rname_to_id(arg, "DATASTORE") - end - set :format, :imageid, OneImageHelper.to_id_desc do |arg| helper.to_id(arg) end @@ -80,10 +79,20 @@ cmd=CommandParser::CmdParser.new(ARGV) do Creates a new Image from the given template file EOT - command :create, create_desc, :file, :datastoreid do + command :create, create_desc, :file, :options=>CREATE_OPTIONS do + if options[:datastore].nil? + STDERR.puts "Datastore to save the image is mandatory: " + STDERR.puts "\t -d datastore_id" + exit -1 + end helper.create_resource(options) do |image| - template=File.read(args[0]) - image.allocate(template, args[1]) + begin + template=File.read(args[0]) + image.allocate(template, options[:datastore] ) + rescue => e + STDERR.puts e.messsage + exit -1 + end end end