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

Several group OCA and JSON related improvments

Remove file template group creation
(cherry picked from commit 900adef61466469edf2f7bdf61c8c29b2d50b4eb)
This commit is contained in:
Tino Vazquez 2014-03-06 15:18:25 +01:00
parent 7783017148
commit bb8c30895b
4 changed files with 20 additions and 33 deletions

View File

@ -154,8 +154,8 @@ EOT
:format => String
},
{
:name => 'admin_passwd',
:large => '--admin_passwd password',
:name => 'admin_password',
:large => '--admin_password password',
:short => "-p",
:description =>
'Password for the admin user of the group',

View File

@ -94,39 +94,31 @@ cmd=CommandParser::CmdParser.new(ARGV) do
EOT
command :create, create_desc, [:file, :group_name, nil], :options =>
command :create, create_desc, [:group_name, nil], :options =>
OpenNebulaHelper::GROUP_OPTIONS do
if args[0] && !options.empty?
STDERR.puts "You can not use both template file and template"<<
" creation options."
next -1
end
if !args[0] && options.empty?
STDERR.puts "Please use either a template, just a group name or command arguments"
STDERR.puts "Please use either a group name or command arguments"
next -1
end
if options && options[:admin_user]
if !options[:admin_passwd]
if !options[:admin_password]
STDERR.puts "Admin user needs password"
next -1
end
admin_user=Hash.new
admin_user[:name] = options[:admin_user]
admin_user[:password] = options[:admin_passwd]
admin_user[:password] = options[:admin_password]
if options[:admin_driver]
admin_user[:auth_driver] = options[:admin_driver]
end
options[:user] = admin_user
end
if args[0] && File.exists?(args[0])
hashed_template = helper.parse_template(File.open(args[0]).read)
helper.create_complete_resource(hashed_template)
elsif !options.empty?
if !options.empty?
helper.create_complete_resource(options)
elsif args[0]
helper.create_resource(options) do |group|

View File

@ -75,14 +75,8 @@ module OpenNebula
alias_method :info!, :info
def create(group_hash)
group_hash=Hash[group_hash.map{|(k,v)| [k.to_sym,v]}]
if group_hash[:user]
group_hash[:user]=Hash[group_hash[:user].map{|(k,v)|
[k.to_sym,v]}]
end
if !group_hash[:name]
return -1,
return -1,
"Group Name not defined, aborting group create operation"
end
@ -109,13 +103,12 @@ module OpenNebula
if group_hash[:resource_providers]
for rp in group_hash[:resource_providers]
# If we have resource providers, add them
if rp["zone_id"] and rp["cluster_id"]
if rp["cluster_id"].class!=Fixnum and
rp["cluster_id"].upcase=="ALL"
add_provider({"zone_id"=>rp["zone_id"],
"cluster_id"=>ALL_CLUSTERS_IN_ZONE})
if rp[:zone_id] and rp[:cluster_id]
if rp[:cluster_id].class!=Fixnum and
rp[:cluster_id].upcase=="ALL"
add_provider(rp[:zone_id],ALL_CLUSTERS_IN_ZONE)
else
add_provider(rp)
add_provider(rp[:zone_id],rp[:cluster_id])
end
end
end

View File

@ -21,7 +21,7 @@ module OpenNebulaJSON
include JSONUtils
def create(template_json)
group_hash = parse_json(template_json,'group')
group_hash = parse_json_sym(template_json,:group)
if OpenNebula.is_error?(group_hash)
return group_hash
end
@ -39,8 +39,10 @@ module OpenNebulaJSON
when "chown" then self.chown(action_hash['params'])
when "update" then self.update(action_hash['params'])
when "set_quota" then self.set_quota(action_hash['params'])
when "add_provider" then self.add_provider(action_hash['params'])
when "del_provider" then self.del_provider(action_hash['params'])
when "add_provider" then
self.add_provider_json(action_hash['params'])
when "del_provider" then
self.del_provider_json(action_hash['params'])
else
error_msg = "#{action_hash['perform']} action not " <<
" available for this resource"
@ -62,11 +64,11 @@ module OpenNebulaJSON
super(quota_template)
end
def add_provider(params=Hash.new)
def add_provider_json(params=Hash.new)
super(params['zone_id'].to_i, params['cluster_id'].to_i)
end
def del_provider(params=Hash.new)
def del_provider_json(params=Hash.new)
super(params['zone_id'].to_i, params['cluster_id'].to_i)
end
end