class OneDatastoreHelper

Constants

DATASTORE
FILE_DATASTORE

Public Class Methods

conf_file() click to toggle source
# File lib/one_helper/onedatastore_helper.rb, line 45
def self.conf_file
    "onedatastore.yaml"
end
rname() click to toggle source
# File lib/one_helper/onedatastore_helper.rb, line 41
def self.rname
    "DATASTORE"
end

Public Instance Methods

format_pool(options) click to toggle source
# File lib/one_helper/onedatastore_helper.rb, line 49
def format_pool(options)
    config_file = self.class.table_conf

    table = CLIHelper::ShowTable.new(config_file, self) do
        column :ID, "ONE identifier for the Datastore", :size=>4 do |d|
            d["ID"]
        end

        column :USER, "Username of the Datastore owner", :left,
                :size=>10 do |d|
            helper.user_name(d, options)
        end

        column :GROUP, "Group of the Datastore", :left,
                :size=>10 do |d|
            helper.group_name(d, options)
        end

        column :NAME, "Name of the Datastore", :left, :size=>13 do |d|
            d["NAME"]
        end

        column :SIZE, "Datastore total size", :size =>10 do |d|
            shared = d['TEMPLATE']['SHARED']
            if shared != nil && shared.upcase == 'NO'
                "-"
            else
                OpenNebulaHelper.unit_to_str(d['TOTAL_MB'].to_i, {}, 'M')
            end
        end

        column :AVAIL, "Datastore free size", :left, :size =>5 do |d|
            if d['TOTAL_MB'].to_i == 0
                "-"
            else
                "#{((d['FREE_MB'].to_f/d['TOTAL_MB'].to_f) * 100).round()}%"
            end
        end

        column :CLUSTERS, "Cluster IDs", :left, :size=>12 do |d|
            OpenNebulaHelper.clusters_str(d["CLUSTERS"]["ID"])
        end

        column :IMAGES, "Number of Images", :size=>6 do |d|
            if d["IMAGES"]["ID"].nil?
                "0"
            else
                [d["IMAGES"]["ID"]].flatten.size
            end
        end

        column :TYPE, "Datastore type", :left, :size=>4 do |d|
            type = OpenNebula::Datastore::DATASTORE_TYPES[d["TYPE"].to_i]
            OpenNebula::Datastore::SHORT_DATASTORE_TYPES[type]
        end

        column :DS, "Datastore driver", :left, :size=>7 do |d|
            d["DS_MAD"]
        end

        column :TM, "Transfer driver", :left, :size=>7 do |d|
            d["TM_MAD"]
        end

        column :STAT, "State of the Datastore", :left, :size=>3 do |d|
            state = OpenNebula::Datastore::DATASTORE_STATES[d["STATE"].to_i]
            OpenNebula::Datastore::SHORT_DATASTORE_STATES[state]
        end

        default :ID, :USER, :GROUP, :NAME, :SIZE, :AVAIL, :CLUSTERS, :IMAGES,
                :TYPE, :DS, :TM, :STAT
    end

    table
end

Private Instance Methods

factory(id=nil) click to toggle source
# File lib/one_helper/onedatastore_helper.rb, line 127
def factory(id=nil)
    if id
        OpenNebula::Datastore.new_with_id(id, @client)
    else
        xml=OpenNebula::Datastore.build_xml
        OpenNebula::Datastore.new(xml, @client)
    end
end
factory_pool(user_flag=-2) click to toggle source
# File lib/one_helper/onedatastore_helper.rb, line 136
def factory_pool(user_flag=-2)
    OpenNebula::DatastorePool.new(@client)
end
format_resource(datastore, options = {}) click to toggle source
# File lib/one_helper/onedatastore_helper.rb, line 140
def format_resource(datastore, options = {})
    str="%-15s: %-20s"
    str_h1="%-80s"

    CLIHelper.print_header(str_h1 % "DATASTORE #{datastore['ID']} INFORMATION")
    puts str % ["ID",       datastore.id.to_s]
    puts str % ["NAME",     datastore.name]
    puts str % ["USER",     datastore['UNAME']]
    puts str % ["GROUP",    datastore['GNAME']]
    puts str % ["CLUSTERS",
        OpenNebulaHelper.clusters_str(datastore.retrieve_elements("CLUSTERS/ID"))]

    puts str % ["TYPE",     datastore.type_str]
    puts str % ["DS_MAD",   datastore['DS_MAD']]
    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)

    shared = datastore['TEMPLATE/SHARED']
    local = shared != nil && shared.upcase == 'NO'
    limit_mb = datastore['TEMPLATE/LIMIT_MB']

    puts str % ["TOTAL:", local ? '-' : OpenNebulaHelper.unit_to_str(datastore['TOTAL_MB'].to_i, {},'M')]
    puts str % ["FREE:",  local ? '-' : OpenNebulaHelper.unit_to_str(datastore['FREE_MB'].to_i, {},'M')]
    puts str % ["USED: ", local ? '-' : OpenNebulaHelper.unit_to_str(datastore['USED_MB'].to_i, {},'M')]
    puts str % ["LIMIT:",  local || limit_mb.nil? ? '-' : OpenNebulaHelper.unit_to_str(limit_mb.to_i, {},'M')]
    puts

    CLIHelper.print_header(str_h1 % "PERMISSIONS",false)

    ["OWNER", "GROUP", "OTHER"].each { |e|
        mask = "---"
        mask[0] = "u" if datastore["PERMISSIONS/#{e}_U"] == "1"
        mask[1] = "m" if datastore["PERMISSIONS/#{e}_M"] == "1"
        mask[2] = "a" if datastore["PERMISSIONS/#{e}_A"] == "1"

        puts str % [e,  mask]
    }
    puts

    CLIHelper.print_header(str_h1 % "DATASTORE TEMPLATE", false)
    puts datastore.template_str

    puts

    CLIHelper.print_header("%-15s" % "IMAGES")
    datastore.img_ids.each do |id|
        puts "%-15s" % [id]
    end
end