mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-30 22:50:10 +03:00
parent
9ed1d12dbb
commit
6855d38460
@ -798,6 +798,29 @@ EOT
|
||||
return 0
|
||||
end
|
||||
|
||||
# Check if a resource defined by attributes is referenced in pool
|
||||
#
|
||||
# @param pool pool to search in
|
||||
# @param xpath xpath to search in pool
|
||||
# @param resource_name name of the resource to search (e.g IMAGE)
|
||||
# @attributes hash with resource attributes, must contains :id, :name
|
||||
# and :uname
|
||||
#
|
||||
# atributes {uname => ..., name => ..., id => ...}
|
||||
def check_orphan(pool, xpath, resource_name, attributes)
|
||||
return false if attributes.empty?
|
||||
|
||||
return false unless pool["#{xpath}[#{resource_name}_ID = "\
|
||||
"#{attributes[:id]}]"].nil?
|
||||
|
||||
return false unless pool["#{xpath}[#{resource_name} = "\
|
||||
"'#{attributes[:name]}' and "\
|
||||
"#{resource_name}_UNAME = "\
|
||||
"'#{attributes[:uname]}']"].nil?
|
||||
|
||||
true
|
||||
end
|
||||
|
||||
def show_resource(id, options)
|
||||
resource = retrieve_resource(id)
|
||||
|
||||
|
@ -249,6 +249,29 @@ class OneImageHelper < OpenNebulaHelper::OneHelper
|
||||
table
|
||||
end
|
||||
|
||||
def check_orphans
|
||||
orphans = []
|
||||
xpath = '/VMTEMPLATE_POOL/VMTEMPLATE/TEMPLATE/DISK'
|
||||
|
||||
pool = factory_pool
|
||||
tmpl_pool = OpenNebula::TemplatePool.new(@client, -2)
|
||||
|
||||
pool.info
|
||||
tmpl_pool.info
|
||||
|
||||
pool.each do |img|
|
||||
attrs = { :id => img['ID'],
|
||||
:name => img['NAME'],
|
||||
:uname => img['UNAME'] }
|
||||
|
||||
orphans << img['ID'] if check_orphan(tmpl_pool,
|
||||
xpath,
|
||||
'IMAGE', attrs)
|
||||
end
|
||||
|
||||
orphans
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def factory(id=nil)
|
||||
|
@ -438,4 +438,14 @@ CommandParser::CmdParser.new(ARGV) do
|
||||
i.unlock
|
||||
end
|
||||
end
|
||||
|
||||
show_desc = <<-EOT.unindent
|
||||
Shows orphans images (i.e images not referenced in any template).
|
||||
EOT
|
||||
|
||||
command :orphans, show_desc do
|
||||
puts helper.check_orphans
|
||||
|
||||
return 0
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user