1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-21 14:50:08 +03:00

feature #661: Add block to the create method

This commit is contained in:
Daniel Molina 2011-06-10 18:24:40 +02:00
parent 149200536d
commit 47260a3072
9 changed files with 18 additions and 34 deletions

View File

@ -67,10 +67,10 @@ EOT
@translation_hash = nil
end
def create_resource(template, options)
def create_resource(options, &block)
resource = factory
rc = resource.allocate(template)
rc = block.call(resource)
if OpenNebula.is_error?(rc)
return -1, rc.message
else
@ -114,7 +114,7 @@ EOT
if OpenNebula.is_error?(rc)
return -1, rc.message
else
puts "#{self.rname} #{id}: #{verbose}" if options[:verbose]
puts "#{self.class.rname} #{id}: #{verbose}" if options[:verbose]
return 0
end
end

View File

@ -19,18 +19,6 @@ require 'one_helper'
class OneHostHelper < OpenNebulaHelper::OneHelper
TABLE_CONF_FILE="#{OpenNebulaHelper::TABLE_CONF_PATH}/onehost.yaml"
def create_resource(args, options)
resource = factory
rc = resource.allocate(args[0], args[1], args[2], args[3])
if OpenNebula.is_error?(rc)
return -1, rc.message
else
puts "ID: #{resource.id.to_s}" if options[:verbose]
return 0
end
end
def self.rname
"HOST"
end

View File

@ -19,11 +19,6 @@ require 'one_helper'
class OneImageHelper < OpenNebulaHelper::OneHelper
TABLE_CONF_FILE="#{OpenNebulaHelper::TABLE_CONF_PATH}/oneimage.yaml"
def create_resource(template_file, options)
template=File.read(template_file)
super(template, options)
end
def self.rname
"IMAGE"
end

View File

@ -19,11 +19,6 @@ require 'one_helper'
class OneVMHelper < OpenNebulaHelper::OneHelper
TABLE_CONF_FILE="#{OpenNebulaHelper::TABLE_CONF_PATH}/onevm.yaml"
def create_resource(template_file, options)
template=File.read(template_file)
super(template, options)
end
def self.rname
"VM"
end

View File

@ -19,11 +19,6 @@ require 'one_helper'
class OneVNetHelper < OpenNebulaHelper::OneHelper
TABLE_CONF_FILE="#{OpenNebulaHelper::TABLE_CONF_PATH}/onevnet.yaml"
def create_resource(template_file, options)
template=File.read(template_file)
super(template, options)
end
def self.rname
"VNET"
end

View File

@ -60,7 +60,9 @@ cmd=CommandParser::CmdParser.new(ARGV) do
# Commands
########################################################################
command :create, 'Create a new Virtual Network', :text, :text, :text, :text do
helper.create_resource(args, options)
helper.create_resource(options) do |host|
host.allocate(args[0], args[1], args[2], args[3])
end
end
command :delete, 'Removes a Virtual Network', [:range, :vnetid_list] do

View File

@ -64,7 +64,10 @@ cmd=CommandParser::CmdParser.new(ARGV) do
# Commands
########################################################################
command :create, 'Registers an Image', :file do
helper.create_resource(args[0], options)
helper.create_resource(options) do |image|
template=File.read(args[0])
image.allocate(template)
end
end
command :show, 'Gets info from an Image', :imageid, :options=>OpenNebulaHelper::XML do

View File

@ -66,7 +66,10 @@ cmd=CommandParser::CmdParser.new(ARGV) do
end
command :create, 'Create a new Virtual Machine', :file do
helper.create_resource(args.shift, options)
helper.create_resource(options) do |vm|
template=File.read(args[0])
vm.allocate(template)
end
end
command :delete, 'Removes a Virtual Machine', [:range, :vmid_list] do

View File

@ -60,7 +60,10 @@ cmd=CommandParser::CmdParser.new(ARGV) do
# Commands
########################################################################
command :create, 'Create a new Virtual Network', :file do
helper.create_resource(args[0], options)
helper.create_resource(options) do |vn|
template=File.read(args[0])
vn.allocate(template)
end
end
command :show, 'Gets info from a Virtual Network', :vnetid,