From e90f0693c1d5e51ee71e206fdabb4dc9361797be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Fri, 13 Feb 2015 16:41:29 +0100 Subject: [PATCH] Feature #3456: DS enable/disable in ruby oca and cli --- src/cli/etc/onedatastore.yaml | 10 +++- src/cli/one_helper/onedatastore_helper.rb | 13 +++-- src/cli/onedatastore | 20 +++++++ src/oca/ruby/opennebula/datastore.rb | 64 +++++++++++++++++------ 4 files changed, 87 insertions(+), 20 deletions(-) diff --git a/src/cli/etc/onedatastore.yaml b/src/cli/etc/onedatastore.yaml index f3feb939aa..c8f77e6183 100644 --- a/src/cli/etc/onedatastore.yaml +++ b/src/cli/etc/onedatastore.yaml @@ -33,12 +33,17 @@ :DS: :desc: Datastore driver - :size: 8 + :size: 6 :left: true :TM: :desc: Transfer driver - :size: 8 + :size: 7 + :left: true + +:STAT: + :desc: State of the Datastore + :size: 4 :left: true :default: @@ -51,4 +56,5 @@ - :TYPE - :DS - :TM +- :STAT diff --git a/src/cli/one_helper/onedatastore_helper.rb b/src/cli/one_helper/onedatastore_helper.rb index 7bbee9e5c1..4baebed233 100644 --- a/src/cli/one_helper/onedatastore_helper.rb +++ b/src/cli/one_helper/onedatastore_helper.rb @@ -82,15 +82,21 @@ class OneDatastoreHelper < OpenNebulaHelper::OneHelper Datastore::SHORT_DATASTORE_TYPES[type] end - column :DS, "Datastore driver", :left, :size=>8 do |d| + column :DS, "Datastore driver", :left, :size=>6 do |d| d["DS_MAD"] end - column :TM, "Transfer driver", :left, :size=>8 do |d| + column :TM, "Transfer driver", :left, :size=>7 do |d| d["TM_MAD"] end - default :ID, :NAME, :SIZE, :AVAIL, :CLUSTER, :IMAGES, :TYPE, :DS, :TM + column :STAT, "State of the Datastore", :left, :size=>4 do |d| + state = Datastore::DATASTORE_STATES[d["STATE"].to_i] + Datastore::SHORT_DATASTORE_STATES[state] + end + + default :ID, :NAME, :SIZE, :AVAIL, :CLUSTER, :IMAGES, + :TYPE, :DS, :TM, :STAT end table @@ -128,6 +134,7 @@ class OneDatastoreHelper < OpenNebulaHelper::OneHelper puts str % ["TM_MAD", datastore['TM_MAD']] puts str % ["BASE PATH",datastore['BASE_PATH']] puts str % ["DISK_TYPE",Image::DISK_TYPES[datastore['DISK_TYPE'].to_i]] + puts str % ["STATE", datastore.state_str] puts CLIHelper.print_header(str_h1 % "DATASTORE CAPACITY", false) diff --git a/src/cli/onedatastore b/src/cli/onedatastore index a06ecb613f..2394fdd88e 100755 --- a/src/cli/onedatastore +++ b/src/cli/onedatastore @@ -184,4 +184,24 @@ cmd=CommandParser::CmdParser.new(ARGV) do o.rename(args[1]) end end + + enable_desc = <<-EOT.unindent + Enables the given Datastore. Only available for System Datastores + EOT + + command :enable, enable_desc, [:range,:datastoreid_list] do + helper.perform_actions(args[0],options,"enabled") do |obj| + obj.enable + end + end + + disable_desc = <<-EOT.unindent + Disables the given Datastore. Only available for System Datastores + EOT + + command :disable, disable_desc, [:range,:datastoreid_list] do + helper.perform_actions(args[0],options,"disabled") do |obj| + obj.disable + end + end end diff --git a/src/oca/ruby/opennebula/datastore.rb b/src/oca/ruby/opennebula/datastore.rb index 31424cd30d..56531521fd 100644 --- a/src/oca/ruby/opennebula/datastore.rb +++ b/src/oca/ruby/opennebula/datastore.rb @@ -30,7 +30,8 @@ module OpenNebula :update => "datastore.update", :chown => "datastore.chown", :chmod => "datastore.chmod", - :rename => "datastore.rename" + :rename => "datastore.rename", + :enable => "datastore.enable" } DATASTORE_TYPES=%w{IMAGE SYSTEM FILE} @@ -41,6 +42,13 @@ module OpenNebula "FILE" => "fil" } + DATASTORE_STATES=%w{READY DISABLED} + + SHORT_DATASTORE_STATES={ + "READY" => "rdy", + "DISABLED" => "disa" + } + # Creates a Datastore description with just its identifier # this method should be used to create plain Datastore objects. # +id+ the id of the user @@ -66,20 +74,6 @@ module OpenNebula ####################################################################### # XML-RPC Methods for the Datastore Object ####################################################################### - # Returns the datastore type - def type - self['TYPE'].to_i - end - - # Returns the datastore type (string value) - def type_str - DATASTORE_TYPES[type] - end - - # Returns the datastore type (string value) - def short_type_str - SHORT_DATASTORE_TYPES[type_str] - end # Retrieves the information of the given Datastore. def info() @@ -157,10 +151,50 @@ module OpenNebula return call(DATASTORE_METHODS[:rename], @pe_id, name) end + # Enables a Datastore + def enable + return call(DATASTORE_METHODS[:enable], @pe_id, true) + end + + # Disables a Datastore + def disable + return call(DATASTORE_METHODS[:enable], @pe_id, false) + end + # --------------------------------------------------------------------- # Helpers to get information # --------------------------------------------------------------------- + # Returns the datastore type + def type + self['TYPE'].to_i + end + + # Returns the datastore type (string value) + def type_str + DATASTORE_TYPES[type] + end + + # Returns the datastore type (string value) + def short_type_str + SHORT_DATASTORE_TYPES[type_str] + end + + # Returns the state of the datastore (numeric value) + def state + self['STATE'].to_i + end + + # Returns the state of the datastore (string value) + def state_str + DATASTORE_STATES[state] + end + + # Returns the state of the datastore (string value) + def short_state_str + SHORT_DATASTORE_STATES[state_str] + end + # Returns whether or not the image with id 'id' is part of this datastore def contains(id) #This doesn't work in ruby 1.8.5