#!/usr/bin/env ruby # -------------------------------------------------------------------------- # # Copyright 2002-2010, 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. # #--------------------------------------------------------------------------- # ONE_LOCATION=ENV["ONE_LOCATION"] if !ONE_LOCATION RUBY_LIB_LOCATION="/usr/lib/one/ruby" else RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby" end $: << RUBY_LIB_LOCATION require 'OpenNebula' require 'CommandManager' require 'client_utilities' require 'command_parse' ShowTableImage={ :id => { :name => "ID", :desc => "ONE identifier for the Image", :size => 4, :proc => lambda {|d,e| d.id } }, :user=> { :name => "USER", :desc => "Name of the owner", :size => 8, :proc => lambda {|d,e| d["USERNAME"] } }, :name => { :name => "NAME", :desc => "Name of the Image", :size => 20, :proc => lambda {|d,e| d.name } }, :type => { :name => "TYPE", :desc => "Type of the Image", :size => 4, :proc => lambda {|d,e| d.short_type_str } }, :regtime => { :name => "REGTIME", :desc => "Registration time of the Image", :size => 20, :proc => lambda {|d,e| str_register_time(d) } }, :public => { :name => "PUBLIC", :desc => "Whether the Image is public or not", :size => 3, :proc => lambda {|d,e| if d["PUBLIC"].to_i == 1 then "Yes" else "No" end} }, :persistent => { :name => "PERSISTENT", :desc => "Whether the Image is persistent or not", :size => 3, :proc => lambda {|d,e| if d["PERSISTENT"].to_i == 1 then "Yes" else "No" end} }, :state => { :name => "STAT", :desc => "State of the Image", :size => 4, :proc => lambda {|d,e| d.short_state_str } }, :runningvms => { :name => "#VMS", :desc => "Number of VMs currently running from this Image", :size => 5, :proc => lambda {|d,e| d['RUNNING_VMS'] } }, :default => [:id, :user, :name, :type, :regtime, :public, :persistent, :state, :runningvms] } class ImageShow def initialize(client, filter_flag="-2") @imagepool=OpenNebula::ImagePool.new(client, filter_flag.to_i) @table=ShowTable.new(ShowTableImage) end def header_image_small scr_bold scr_underline print @table.header_str scr_restore puts "" end def top(options=nil) delay=1 delay=options[:delay] if options && options[:delay] result=nil begin while true scr_cls scr_move(0,0) result=list_short(options) sleep delay end rescue Exception end result end def list_short(options=nil) res=@imagepool.info() if options @table.columns=options[:columns] if options[:columns] end if OpenNebula.is_error?(res) result=res puts res.message exit -1 else if options[:filter_flag] vms=@imagepool.select{|element| element['USERNAME']==options[:filter_flag] } else vms=@imagepool end result=[true, ""] header_image_small if options puts @table.data_str(vms, options) else puts @table.data_str(vms) end result end end def top(options=nil) delay=1 delay=options[:delay] if options && options[:delay] result=nil begin while true scr_cls scr_move(0,0) result=list_short(options) sleep delay end rescue Exception end result end end ########################## ## COMMAND LINE PARSING ## ########################## class OneImageParse < CommandParse COMMANDS_HELP=<<-EOT Commands: * register (Registers an image, copying it to the repository if it applies) oneimage register