class OneTemplateHelper

Constants

EXTENDED
FLOAT_EXP
INT_EXP
MULTIPLE
PERSISTENT
RECURSIVE
USERDATA
VM_NAME

Public Class Methods

conf_file() click to toggle source
# File lib/one_helper/onetemplate_helper.rb, line 73
def self.conf_file
    "onetemplate.yaml"
end
get_user_inputs(template, keys = []) click to toggle source
# File lib/one_helper/onetemplate_helper.rb, line 143
def self.get_user_inputs(template, keys = [])
    user_inputs = template['VMTEMPLATE']['TEMPLATE']['USER_INPUTS']

    return '' unless user_inputs

    answers = OpenNebulaHelper.parse_user_inputs(user_inputs, keys)
    answers_s = ''
    answers.each do |key, val|
        next unless val

        # Do not replace values that are equal to the ones already in the
        # template. Useful for cpu, mem, vcpu
        if key != template['VMTEMPLATE']['TEMPLATE'][key]
            answers_s << "#{key} = \""
            answers_s << val.gsub('"', "\\\"") << "\"\n"
        end
    end

    answers_s
end
rname() click to toggle source
# File lib/one_helper/onetemplate_helper.rb, line 69
def self.rname
    "VMTEMPLATE"
end

Public Instance Methods

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

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

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

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

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

        column :REGTIME, "Registration time of the Template",
                :size=>15 do |d|
            OpenNebulaHelper.time_to_str(d["REGTIME"])
        end

        default :ID, :USER, :GROUP, :NAME, :REGTIME
    end

    table
end
show_resource(id, options) click to toggle source
# File lib/one_helper/onetemplate_helper.rb, line 78
def show_resource(id, options)
    resource = retrieve_resource(id)

    if !options[:extended].nil?
        rc = resource.info(options[:extended])
    else
        rc = resource.info
    end

    return -1, rc.message if OpenNebula.is_error?(rc)

    if options[:xml]
        return 0, resource.to_xml(true)
    elsif options[:json]
        # If body is set, the resource contains a JSON inside
        if options[:body]
            return 0, check_resource_xsd(resource)
        else
            return 0, ::JSON.pretty_generate(
                check_resource_xsd(resource)
            )
        end
    elsif options[:yaml]
        return 0, check_resource_xsd(resource).to_yaml(:indent => 4)
    else
        format_resource(resource, options)
        return 0
    end
end

Private Instance Methods

factory(id=nil) click to toggle source
# File lib/one_helper/onetemplate_helper.rb, line 166
def factory(id=nil)
    if id
        OpenNebula::Template.new_with_id(id, @client)
    else
        xml=OpenNebula::Template.build_xml
        OpenNebula::Template.new(xml, @client)
    end
end
factory_pool(user_flag=-2) click to toggle source
# File lib/one_helper/onetemplate_helper.rb, line 175
def factory_pool(user_flag=-2)
    OpenNebula::TemplatePool.new(@client, user_flag)
end
format_resource(template, options = {}) click to toggle source
# File lib/one_helper/onetemplate_helper.rb, line 179
def format_resource(template, options = {})
    str="%-15s: %-20s"
    str_h1="%-80s"

    CLIHelper.print_header(
        str_h1 % "TEMPLATE #{template['ID']} INFORMATION")
    puts str % ["ID", template.id.to_s]
    puts str % ["NAME", template.name]
    puts str % ["USER", template['UNAME']]
    puts str % ["GROUP", template['GNAME']]
    puts str % ["LOCK", OpenNebulaHelper.level_lock_to_str(template['LOCK/LOCKED'])]
    puts str % ["REGISTER TIME",
        OpenNebulaHelper.time_to_str(template['REGTIME'])]
    puts

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

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

        puts str % [e,  mask]
    }
    puts

    CLIHelper.print_header(str_h1 % "TEMPLATE CONTENTS",false)
    puts template.template_str
end