1
0
mirror of https://github.com/OpenNebula/one.git synced 2024-12-22 13:33:52 +03:00

F #2347: Allocate, delete and info API calls for the VMGroup

This commit is contained in:
Ruben S. Montero 2017-01-03 01:22:10 +01:00
parent 7381aa4030
commit 17749cb5e7
19 changed files with 827 additions and 8 deletions

View File

@ -37,6 +37,7 @@
#include "VirtualRouterPool.h"
#include "MarketPlacePool.h"
#include "MarketPlaceAppPool.h"
#include "VMGroupPool.h"
#include "VirtualMachineManager.h"
#include "LifeCycleManager.h"
@ -156,6 +157,11 @@ public:
return apppool;
};
VMGroupPool * get_vmgrouppool()
{
return vmgrouppool;
};
// --------------------------------------------------------------
// Manager Accessors
// --------------------------------------------------------------
@ -580,10 +586,10 @@ private:
"/DEFAULT_GROUP_QUOTAS/VM_QUOTA"),
system_db(0), db(0),
vmpool(0), hpool(0), vnpool(0), upool(0), ipool(0), gpool(0), tpool(0),
dspool(0), clpool(0), docpool(0), zonepool(0),
secgrouppool(0), vdcpool(0), vrouterpool(0), marketpool(0), apppool(0),
lcm(0), vmm(0), im(0), tm(0), dm(0), rm(0), hm(0), authm(0),
aclm(0), imagem(0), marketm(0), ipamm(0)
dspool(0), clpool(0), docpool(0), zonepool(0), secgrouppool(0),
vdcpool(0), vrouterpool(0), marketpool(0), apppool(0), vmgrouppool(0),
lcm(0), vmm(0), im(0), tm(0), dm(0), rm(0), hm(0), authm(0), aclm(0),
imagem(0), marketm(0), ipamm(0)
{
const char * nl = getenv("ONE_LOCATION");
@ -634,6 +640,7 @@ private:
delete vrouterpool;
delete marketpool;
delete apppool;
delete vmgrouppool;
delete vmm;
delete lcm;
delete im;
@ -718,6 +725,7 @@ private:
VirtualRouterPool * vrouterpool;
MarketPlacePool * marketpool;
MarketPlaceAppPool * apppool;
VMGroupPool * vmgrouppool;
// ---------------------------------------------------------------
// Nebula Managers

View File

@ -679,4 +679,33 @@ private:
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
class VMGroupAllocate : public RequestManagerAllocate
{
public:
VMGroupAllocate():
RequestManagerAllocate("VMGroupAllocate",
"Allocates a new vm group",
"A:ss",
true)
{
Nebula& nd = Nebula::instance();
pool = nd.get_vmgrouppool();
auth_object = PoolObjectSQL::VMGROUP;
};
~VMGroupAllocate(){};
/* --------------------------------------------------------------------- */
Template * get_object_template()
{
return new Template;
};
Request::ErrorCode pool_allocate(xmlrpc_c::paramList const& paramList,
Template * tmpl,
int& id,
RequestAttributes& att);
};
#endif

View File

@ -449,7 +449,24 @@ protected:
int drop(PoolObjectSQL * obj, bool resive, RequestAttributes& att);
};
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
class VMGroupDelete : public RequestManagerDelete
{
public:
VMGroupDelete():
RequestManagerDelete("VMGroupDelete",
"Deletes a vm group")
{
Nebula& nd = Nebula::instance();
pool = nd.get_vmgrouppool();
auth_object = PoolObjectSQL::VMGROUP;
};
~VMGroupDelete(){};
};
#endif

View File

@ -371,7 +371,23 @@ public:
~MarketPlaceAppInfo(){};
};
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
class VMGroupInfo : public RequestManagerInfo
{
public:
VMGroupInfo():
RequestManagerInfo("VMGroupInfo",
"Returns vm group information")
{
Nebula& nd = Nebula::instance();
pool = nd.get_vmgrouppool();
auth_object = PoolObjectSQL::VMGROUP;
};
~VMGroupInfo(){};
};
#endif

View File

@ -553,4 +553,23 @@ public:
~MarketPlaceAppPoolInfo(){};
};
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
class VMGroupPoolInfo : public RequestManagerPoolInfoFilter
{
public:
VMGroupPoolInfo():
RequestManagerPoolInfoFilter("VMGroupPoolInfo",
"Returns the vm group pool",
"A:siii")
{
Nebula& nd = Nebula::instance();
pool = nd.get_vmgrouppool();
auth_object = PoolObjectSQL::VMGROUP;
};
~VMGroupPoolInfo(){};
};
#endif

View File

@ -277,7 +277,11 @@ private:
* @param error string describing the error if any
* @return 0 on success
*/
int post_update_template(string& error);
int post_update_template(string& error)
{
//TODO
return 0;
};
/**
* Factory method for VMGroup templates

View File

@ -550,6 +550,7 @@ BIN_FILES="src/nebula/oned \
src/cli/oneflow \
src/cli/oneflow-template \
src/cli/onesecgroup \
src/cli/onevmgroup \
src/cli/onevdc \
src/cli/onevrouter \
src/cli/onemarket \
@ -1280,6 +1281,8 @@ RUBY_OPENNEBULA_LIB_FILES="src/oca/ruby/opennebula/acl_pool.rb \
src/oca/ruby/opennebula/pool.rb \
src/oca/ruby/opennebula/security_group_pool.rb \
src/oca/ruby/opennebula/security_group.rb \
src/oca/ruby/opennebula/vm_group_pool.rb \
src/oca/ruby/opennebula/vm_group.rb \
src/oca/ruby/opennebula/system.rb \
src/oca/ruby/opennebula/template_pool.rb \
src/oca/ruby/opennebula/template.rb \
@ -1440,6 +1443,7 @@ ONE_CLI_LIB_FILES="src/cli/one_helper/onegroup_helper.rb \
src/cli/one_helper/onevdc_helper.rb \
src/cli/one_helper/oneacct_helper.rb \
src/cli/one_helper/onesecgroup_helper.rb \
src/cli/one_helper/onevmgroup_helper.rb \
src/cli/one_helper/onevrouter_helper.rb \
src/cli/one_helper/onemarketapp_helper.rb \
src/cli/one_helper/onemarket_helper.rb"
@ -1459,6 +1463,7 @@ CLI_BIN_FILES="src/cli/onevm \
src/cli/oneflow-template \
src/cli/oneacct \
src/cli/onesecgroup \
src/cli/onevmgroup \
src/cli/oneshowback \
src/cli/onevdc \
src/cli/onevrouter \
@ -1478,6 +1483,7 @@ CLI_CONF_FILES="src/cli/etc/onegroup.yaml \
src/cli/etc/onezone.yaml \
src/cli/etc/oneacct.yaml \
src/cli/etc/onesecgroup.yaml \
src/cli/etc/onevmgroup.yaml \
src/cli/etc/oneshowback.yaml \
src/cli/etc/onevdc.yaml \
src/cli/etc/onevrouter.yaml \

View File

@ -0,0 +1,25 @@
---
:ID:
:desc: ONE identifier for the VM Group
:size: 4
:NAME:
:desc: Name of the VM Group
:size: 20
:left: true
:USER:
:desc: Username of the VM Group owner
:size: 15
:left: true
:GROUP:
:desc: Group of the VM Group
:size: 15
:left: true
:default:
- :ID
- :USER
- :GROUP
- :NAME

View File

@ -0,0 +1,121 @@
# -------------------------------------------------------------------------- #
# Copyright 2002-2016, OpenNebula Project, OpenNebula Systems #
# #
# 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. #
#--------------------------------------------------------------------------- #
require 'one_helper'
class OneVMGroupHelper < OpenNebulaHelper::OneHelper
def self.rname
"VM_GROUP"
end
def self.conf_file
"onevmgroup.yaml"
end
def format_pool(options)
config_file = self.class.table_conf
table = CLIHelper::ShowTable.new(config_file, self) do
column :ID, "ONE identifier for the VM Group", :size=>4 do |d|
d["ID"]
end
column :NAME, "Name of the VM Group", :left, :size=>20 do |d|
d["NAME"]
end
column :USER, "Username of the VM Group owner", :left,
:size=>15 do |d|
helper.user_name(d, options)
end
column :GROUP, "Group of the VM Group", :left, :size=>15 do |d|
helper.group_name(d, options)
end
default :ID, :USER, :GROUP, :NAME
end
table
end
private
def factory(id=nil)
if id
OpenNebula::VMGroup.new_with_id(id, @client)
else
xml=OpenNebula::VMGroup.build_xml
OpenNebula::VMGroup.new(xml, @client)
end
end
def factory_pool(user_flag=-2)
OpenNebula::VMGroupPool.new(@client, user_flag)
end
def format_resource(vmgroup, options = {})
str="%-15s: %-20s"
str_h1="%-80s"
CLIHelper.print_header(
str_h1 % "VM GROUP #{vmgroup['ID']} INFORMATION")
puts str % ["ID", vmgroup.id.to_s]
puts str % ["NAME", vmgroup.name]
puts str % ["USER", vmgroup['UNAME']]
puts str % ["GROUP", vmgroup['GNAME']]
CLIHelper.print_header(str_h1 % "PERMISSIONS",false)
puts
["OWNER", "GROUP", "OTHER"].each { |e|
mask = "---"
mask[0] = "u" if vmgroup["PERMISSIONS/#{e}_U"] == "1"
mask[1] = "m" if vmgroup["PERMISSIONS/#{e}_M"] == "1"
mask[2] = "a" if vmgroup["PERMISSIONS/#{e}_A"] == "1"
puts str % [e, mask]
}
puts
CLIHelper.print_header(str_h1 % "ROLES", false)
if !vmgroup.to_hash['VM_GROUP']['TEMPLATE']['ROLE'].nil?
roles = [vmgroup.to_hash['VM_GROUP']['TEMPLATE']['ROLE']].flatten
end
CLIHelper::ShowTable.new(nil, self) do
column :ID, "", :left, :size=>4 do |d|
d["ID"]
end
column :NAME, "", :left, :size=>16 do |d|
d["NAME"]
end
column :VIRTUAL_MACHINES, "", :left, :size=>32 do |d|
d["VMS"]
end
end.show(roles, {})
puts
CLIHelper.print_header(str_h1 % "TEMPLATE CONTENTS",false)
puts vmgroup.template_str
end
end

218
src/cli/onevmgroup Executable file
View File

@ -0,0 +1,218 @@
#!/usr/bin/env ruby
# -------------------------------------------------------------------------- #
# Copyright 2002-2016, OpenNebula Project, OpenNebula Systems #
# #
# 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
$: << RUBY_LIB_LOCATION+"/cli"
require 'command_parser'
require 'one_helper/onevmgroup_helper'
cmd=CommandParser::CmdParser.new(ARGV) do
usage "`onevmgroup` <command> [<args>] [<options>]"
version OpenNebulaHelper::ONE_VERSION
helper = OneVMGroupHelper.new
before_proc do
helper.set_client(options)
end
########################################################################
# Global Options
########################################################################
set :option, CommandParser::OPTIONS+OpenNebulaHelper::CLIENT_OPTIONS
list_options = CLIHelper::OPTIONS
list_options << OpenNebulaHelper::XML
list_options << OpenNebulaHelper::NUMERIC
list_options << OpenNebulaHelper::DESCRIBE
########################################################################
# Formatters for arguments
########################################################################
set :format, :groupid, OpenNebulaHelper.rname_to_id_desc("GROUP") do |arg|
OpenNebulaHelper.rname_to_id(arg, "GROUP")
end
set :format, :userid, OpenNebulaHelper.rname_to_id_desc("USER") do |arg|
OpenNebulaHelper.rname_to_id(arg, "USER")
end
set :format, :vmgroupid, OneVMGroupHelper.to_id_desc do |arg|
helper.to_id(arg)
end
set :format, :vmgroupid_list, OneVMGroupHelper.list_to_id_desc do |arg|
helper.list_to_id(arg)
end
set :format, :filterflag, OneVMGroupHelper.filterflag_to_i_desc do |arg|
helper.filterflag_to_i(arg)
end
########################################################################
# Commands
########################################################################
create_desc = <<-EOT.unindent
Creates a new VM Group from the given description
EOT
command :create, create_desc, :file do
helper.create_resource(options) do |obj|
begin
template = File.read(args[0])
obj.allocate(template)
rescue => e
STDERR.puts e.messsage
exit -1
end
end
end
delete_desc = <<-EOT.unindent
Deletes the VM Group
EOT
command :delete, delete_desc, [:range, :vmgroupid_list] do
helper.perform_actions(args[0],options,"deleted") do |obj|
obj.delete
end
end
list_desc = <<-EOT.unindent
Lists VM Group in the pool
EOT
command :list, list_desc, [:filterflag, nil], :options=>list_options do
helper.list_pool(options, false, args[0])
end
show_desc = <<-EOT.unindent
Shows information for the given VM Group
EOT
command :show, show_desc, :vmgroupid, :options=>OpenNebulaHelper::XML do
helper.show_resource(args[0],options)
end
=begin
clone_desc = <<-EOT.unindent
Creates a new Security Group from an existing one
EOT
command :clone, clone_desc, :secgroupid, :name do
helper.perform_action(args[0],options,"cloned") do |obj|
res = obj.clone(args[1])
if !OpenNebula.is_error?(res)
puts "ID: #{res}"
else
puts res.message
end
end
end
chgrp_desc = <<-EOT.unindent
Changes the Security Group's group
EOT
command :chgrp, chgrp_desc,[:range, :secgroupid_list], :groupid do
helper.perform_actions(args[0],options,"Group changed") do |obj|
obj.chown(-1, args[1].to_i)
end
end
chown_desc = <<-EOT.unindent
Changes the Security Group's owner and group
EOT
command :chown, chown_desc, [:range, :secgroupid_list], :userid,
[:groupid,nil] do
gid = args[2].nil? ? -1 : args[2].to_i
helper.perform_actions(args[0],options,"Owner/Group changed") do |obj|
obj.chown(args[1].to_i, gid)
end
end
chmod_desc = <<-EOT.unindent
Changes the Security Group permissions
EOT
command :chmod, chmod_desc, [:range, :secgroupid_list], :octet do
helper.perform_actions(args[0],options, "Permissions changed") do |t|
t.chmod_octet(args[1])
end
end
update_desc = <<-EOT.unindent
Update the template contents. If a path is not provided the editor will
be launched to modify the current content.
EOT
command :update, update_desc, :secgroupid, [:file, nil],
:options=>OpenNebulaHelper::APPEND do
helper.perform_action(args[0],options,"modified") do |obj|
if options[:append]
str = OpenNebulaHelper.append_template(args[0], obj, args[1])
else
str = OpenNebulaHelper.update_template(args[0], obj, args[1])
end
helper.set_client(options)
obj = helper.retrieve_resource(obj.id)
obj.update(str, options[:append])
end
end
rename_desc = <<-EOT.unindent
Renames the Security Group
EOT
command :rename, rename_desc, :secgroupid, :name do
helper.perform_action(args[0],options,"renamed") do |o|
o.rename(args[1])
end
end
commit_desc = <<-EOT.unindent
Commit SG changes to associated VMs. This command is to propagate
security group rules to VMs when they are updated. This operation takes
time to iterate over all VMs in the security group, progress can be
checked through the outdated, updating and error VM sets.
EOT
command :commit, commit_desc, :secgroupid,
:options =>[OneSecurityGroupHelper::RECOVER] do
helper.perform_action(args[0], options, "commit") do |o|
o.commit(options[:recover]==true)
end
end
=end
end

View File

@ -323,6 +323,7 @@ void Nebula::start(bool bootstrap_only)
rc += GroupQuotas::bootstrap(db);
rc += SecurityGroupPool::bootstrap(db);
rc += VirtualRouterPool::bootstrap(db);
rc += VMGroupPool::bootstrap(db);
// Create the system tables only if bootstrap went well
if (rc == 0)
@ -597,6 +598,8 @@ void Nebula::start(bool bootstrap_only)
marketpool = new MarketPlacePool(db, is_federation_slave());
apppool = new MarketPlaceAppPool(db, is_federation_slave());
vmgrouppool = new VMGroupPool(db);
default_user_quota.select();
default_group_quota.select();
}

View File

@ -67,6 +67,7 @@ env.Prepend(LIBS=[
'nebula_vrouter',
'nebula_marketplace',
'nebula_ipamm',
'nebula_vmgroup',
'crypto',
'xml2'
])

View File

@ -62,6 +62,8 @@ require 'opennebula/marketplace'
require 'opennebula/marketplace_pool'
require 'opennebula/marketplaceapp'
require 'opennebula/marketplaceapp_pool'
require 'opennebula/vm_group'
require 'opennebula/vm_group_pool'
module OpenNebula

View File

@ -0,0 +1,173 @@
# -------------------------------------------------------------------------- #
# Copyright 2002-2016, OpenNebula Project, OpenNebula Systems #
# #
# 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. #
#--------------------------------------------------------------------------- #
require 'opennebula/pool_element'
module OpenNebula
class VMGroup < PoolElement
#######################################################################
# Constants and Class Methods
#######################################################################
VMGROUP_METHODS = {
:allocate => "vmgroup.allocate",
:info => "vmgroup.info",
#:update => "vmgroup.update",
:delete => "vmgroup.delete",
#:chown => "vmgroup.chown",
#:chmod => "vmgroup.chmod",
#:clone => "vmgroup.clone",
#:rename => "vmgroup.rename"
}
# Creates a VMGroup description with just its identifier
# this method should be used to create plain VMGroup objects.
# @param pe_id [Integer] the id of the object
def VMGroup.build_xml(pe_id=nil)
if pe_id
obj_xml = "<VM_GROUP><ID>#{pe_id}</ID></VM_GROUP>"
else
obj_xml = "<VM_GROUP></VM_GROUP>"
end
XMLElement.build_xml(obj_xml,'VM_GROUP')
end
# Class constructor
def initialize(xml, client)
super(xml,client)
@client = client
end
#######################################################################
# XML-RPC Methods for the VMGroup Object
#######################################################################
# Retrieves the information of the VMGroup.
def info()
super(VMGROUP_METHODS[:info], 'VM_GROUP')
end
alias_method :info!, :info
# Allocates a new VMGroup in OpenNebula
#
# @param description [String] The contents of the VMGroup.
#
# @return [nil, OpenNebula::Error] nil in case of success, Error
# otherwise
def allocate(description)
super(VMGROUP_METHODS[:allocate], description)
end
# Deletes the SecurityGroup
def delete()
super(VMGROUP_METHODS[:delete])
end
=begin
# Replaces the securitygroup contents
#
# @param new_securitygroup [String] New securitygroup contents
# @param append [true, false] True to append new attributes instead of
# replace the whole securitygroup
#
# @return [nil, OpenNebula::Error] nil in case of success, Error
# otherwise
def update(new_securitygroup, append=false)
super(SECGROUP_METHODS[:update], new_securitygroup, append ? 1 : 0)
end
# Changes the owner/group
#
# @param uid [Integer] the new owner id. Set to -1 to leave the current one
# @param gid [Integer] the new group id. Set to -1 to leave the current one
# @return [nil, OpenNebula::Error] nil in case of success, Error
# otherwise
def chown(uid, gid)
super(SECGROUP_METHODS[:chown], uid, gid)
end
# Changes the SecurityGroup permissions.
#
# @param octet [String] Permissions octed , e.g. 640
# @return [nil, OpenNebula::Error] nil in case of success, Error
# otherwise
def chmod_octet(octet)
super(SECGROUP_METHODS[:chmod], octet)
end
# Changes the SecurityGroup permissions.
# Each [Integer] argument must be 1 to allow, 0 deny, -1 do not change
#
# @return [nil, OpenNebula::Error] nil in case of success, Error
# otherwise
def chmod(owner_u, owner_m, owner_a, group_u, group_m, group_a, other_u,
other_m, other_a)
super(SECGROUP_METHODS[:chmod], owner_u, owner_m, owner_a, group_u,
group_m, group_a, other_u, other_m, other_a)
end
# Clones this SecurityGroup into a new one
#
# @param [String] name for the new SecurityGroup.
#
# @return [Integer, OpenNebula::Error] The new SecurityGroup ID in case
# of success, Error otherwise
def clone(name)
return Error.new('ID not defined') if !@pe_id
rc = @client.call(SECGROUP_METHODS[:clone], @pe_id, name)
return rc
end
# Renames this SecurityGroup
#
# @param name [String] New name for the SecurityGroup.
#
# @return [nil, OpenNebula::Error] nil in case of success, Error
# otherwise
def rename(name)
return call(SECGROUP_METHODS[:rename], @pe_id, name)
end
# Commit SG changes to associated VMs
#
# @param recover [Bool] If true will only operate on outdated and error
# VMs. This is intended for retrying updates of VMs or reinitialize the
# updating process if oned stopped or fail.
#
# @return [nil, OpenNebula::Error] nil in case of success, Error
# otherwise
def commit(recover)
return call(SECGROUP_METHODS[:commit], @pe_id, recover)
end
=end
#######################################################################
# Helpers to get VMGroup information
#######################################################################
# Returns the group identifier
# [return] _Integer_ the element's group ID
def gid
self['GID'].to_i
end
def owner_id
self['UID'].to_i
end
end
end

View File

@ -0,0 +1,78 @@
# -------------------------------------------------------------------------- #
# Copyright 2002-2016, OpenNebula Project, OpenNebula Systems #
# #
# 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. #
#--------------------------------------------------------------------------- #
require 'opennebula/pool'
module OpenNebula
class VMGroupPool < Pool
#######################################################################
# Constants and Class attribute accessors
#######################################################################
VMGROUP_POOL_METHODS = {
:info => "vmgrouppool.info"
}
#######################################################################
# Class constructor & Pool Methods
#######################################################################
# +client+ a Client object that represents an XML-RPC connection
# +user_id+ used to refer to a Pool with Templates from that user
def initialize(client, user_id=-1)
super('VM_GROUP_POOL','VM_GROUP',client)
@user_id = user_id
end
# Factory method to create Template objects
def factory(element_xml)
OpenNebula::VMGroup.new(element_xml,@client)
end
#######################################################################
# XML-RPC Methods for the Template Object
#######################################################################
# Retrieves all or part of the objects in the pool.
def info(*args)
case args.size
when 0
info_filter(VMGROUP_POOL_METHODS[:info], @user_id, -1, -1)
when 3
info_filter(VMGROUP_POOL_METHODS[:info], args[0], args[1],
args[2])
end
end
def info_all()
return super(VMGROUP_POOL_METHODS[:info])
end
def info_mine()
return super(VMGROUP_POOL_METHODS[:info])
end
def info_group()
return super(VMGROUP_POOL_METHODS[:info])
end
alias_method :info!, :info
alias_method :info_all!, :info_all
alias_method :info_mine!, :info_mine
alias_method :info_group!, :info_group
end
end

View File

@ -378,6 +378,7 @@ void RequestManager::register_xml_methods()
xmlrpc_c::methodPtr doc_allocate(new DocumentAllocate());
xmlrpc_c::methodPtr secg_allocate(new SecurityGroupAllocate());
xmlrpc_c::methodPtr vrouter_allocate(new VirtualRouterAllocate());
xmlrpc_c::methodPtr vmg_allocate(new VMGroupAllocate());
// Clone Methods
xmlrpc_c::methodPtr template_clone(new VMTemplateClone());
@ -394,6 +395,7 @@ void RequestManager::register_xml_methods()
xmlrpc_c::methodPtr doc_delete(new DocumentDelete());
xmlrpc_c::methodPtr secg_delete(new SecurityGroupDelete());
xmlrpc_c::methodPtr vrouter_delete(new VirtualRouterDelete());
xmlrpc_c::methodPtr vmg_delete(new VMGroupDelete());
// Info Methods
xmlrpc_c::methodPtr vm_info(new VirtualMachineInfo());
@ -406,6 +408,7 @@ void RequestManager::register_xml_methods()
xmlrpc_c::methodPtr doc_info(new DocumentInfo());
xmlrpc_c::methodPtr secg_info(new SecurityGroupInfo());
xmlrpc_c::methodPtr vrouter_info(new VirtualRouterInfo());
xmlrpc_c::methodPtr vmg_info(new VMGroupInfo());
// Lock Methods
xmlrpc_c::methodPtr doc_lock(new DocumentLock());
@ -421,6 +424,7 @@ void RequestManager::register_xml_methods()
xmlrpc_c::methodPtr clusterpool_info(new ClusterPoolInfo());
xmlrpc_c::methodPtr docpool_info(new DocumentPoolInfo());
xmlrpc_c::methodPtr secgpool_info(new SecurityGroupPoolInfo());
xmlrpc_c::methodPtr vmgpool_info(new VMGroupPoolInfo());
xmlrpc_c::methodPtr vrouter_pool_info(new VirtualRouterPoolInfo());
// Host Methods
@ -829,6 +833,14 @@ void RequestManager::register_xml_methods()
RequestManagerRegistry.addMethod("one.secgrouppool.info",secgpool_info);
/* VM Group objects related methods*/
RequestManagerRegistry.addMethod("one.vmgroup.allocate", vmg_allocate);
RequestManagerRegistry.addMethod("one.vmgroup.delete", vmg_delete);
RequestManagerRegistry.addMethod("one.vmgroup.info", vmg_info);
RequestManagerRegistry.addMethod("one.vmgrouppool.info", vmgpool_info);
/* Vdc related methods */
xmlrpc_c::method * vdc_allocate_pt;

View File

@ -1195,3 +1195,25 @@ Request::ErrorCode MarketPlaceAppAllocate::pool_allocate(
return Request::SUCCESS;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
Request::ErrorCode VMGroupAllocate::pool_allocate(
xmlrpc_c::paramList const& paramList,
Template * tmpl,
int& id,
RequestAttributes& att)
{
VMGroupPool * vmgpool = static_cast<VMGroupPool *>(pool);
int rc = vmgpool->allocate(att.uid, att.gid, att.uname, att.gname, att.umask
,tmpl, &id, att.resp_msg);
if (rc < 0)
{
return Request::INTERNAL;
}
return Request::SUCCESS;
}

View File

@ -322,6 +322,8 @@ error_common:
int VMGroup::insert(SqlDB *db, string& error_str)
{
int role_id;
vector<VectorAttribute*>::iterator it;
vector<VectorAttribute*> roles;
@ -340,8 +342,10 @@ int VMGroup::insert(SqlDB *db, string& error_str)
get_template_attribute("ROLE", roles);
for ( it = roles.begin(); it != roles.end(); it++ )
for ( it = roles.begin(), role_id = 0; it != roles.end(); ++it, ++role_id )
{
(*it)->replace("ID", role_id);
if (add_role(*it, error_str) == -1)
{
return -1;

View File

@ -0,0 +1,61 @@
/* -------------------------------------------------------------------------- */
/* Copyright 2002-2016, OpenNebula Project, OpenNebula Systems */
/* */
/* 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. */
/* -------------------------------------------------------------------------- */
#include "VMGroupPool.h"
int VMGroupPool::allocate(int uid, int gid, const string& uname,
const string& gname, int umask, Template * vmgroup_template, int * oid,
string& error_str)
{
VMGroup * vmgrp;
VMGroup * vmgrp_aux = 0;
string name;
ostringstream os;
vmgrp = new VMGroup(uid, gid, uname, gname, umask, vmgroup_template);
vmgrp->get_template_attribute("NAME", name);
if ( !PoolObjectSQL::name_is_valid(name, error_str) )
{
goto error_name;
}
vmgrp_aux = get(name, uid, false);
if( vmgrp_aux != 0 )
{
goto error_duplicated;
}
*oid = PoolSQL::allocate(vmgrp, error_str);
return *oid;
error_duplicated:
os << "NAME is already taken by VMGroup " << vmgrp_aux->get_oid() << ".";
error_str = os.str();
error_name:
delete vmgrp;
*oid = -1;
return *oid;
}