From 0e5a252ffdf4b35e0bd2128947299c8f9889800a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Tue, 8 Apr 2014 12:17:37 +0200 Subject: [PATCH 1/6] Feature #2828: add new param to java oca --- include/RequestManagerVirtualMachine.h | 2 +- .../opennebula/client/vm/VirtualMachine.java | 23 ++++++++++++------- src/oca/ruby/opennebula/virtual_machine.rb | 1 - 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/include/RequestManagerVirtualMachine.h b/include/RequestManagerVirtualMachine.h index e752a79818..3ca57720a0 100644 --- a/include/RequestManagerVirtualMachine.h +++ b/include/RequestManagerVirtualMachine.h @@ -176,7 +176,7 @@ public: VirtualMachineSaveDisk(): RequestManagerVirtualMachine("VirtualMachineSaveDisk", "Saves a disk from virtual machine as a new image", - "A:siissb"){}; + "A:siissbb"){}; ~VirtualMachineSaveDisk(){}; diff --git a/src/oca/java/src/org/opennebula/client/vm/VirtualMachine.java b/src/oca/java/src/org/opennebula/client/vm/VirtualMachine.java index 764b83201e..d4a38167cf 100644 --- a/src/oca/java/src/org/opennebula/client/vm/VirtualMachine.java +++ b/src/oca/java/src/org/opennebula/client/vm/VirtualMachine.java @@ -365,12 +365,16 @@ public class VirtualMachine extends PoolElement{ * the default type * @param hot True to save the disk immediately, false will perform * the operation when the VM shuts down + * @param doTemplate True to clone also the VM originating template + * and replace the disk with the saved image * @return If an error occurs the error message contains the reason. */ public static OneResponse diskSnapshot(Client client, int id, - int diskId, String imageName, String imageType, boolean hot) + int diskId, String imageName, String imageType, + boolean hot, boolean doTemplate) { - return client.call(SAVEDISK, id ,diskId, imageName, imageType, hot); + return client.call(SAVEDISK, id ,diskId, imageName, imageType, + hot, doTemplate); } /** @@ -707,12 +711,15 @@ public class VirtualMachine extends PoolElement{ * the default type * @param hot True to save the disk immediately, false will perform * the operation when the VM shuts down + * @param doTemplate True to clone also the VM originating template + * and replace the disk with the saved image * @return If an error occurs the error message contains the reason. */ public OneResponse diskSnapshot(int diskId, String imageName, - String imageType, boolean hot) + String imageType, boolean hot, boolean doTemplate) { - return diskSnapshot(client, id, diskId, imageName, imageType, hot); + return diskSnapshot(client, id, diskId, imageName, imageType, + hot, doTemplate); } /** @@ -725,7 +732,7 @@ public class VirtualMachine extends PoolElement{ */ public OneResponse diskSnapshot(int diskId, String imageName) { - return diskSnapshot(diskId, imageName, "", false); + return diskSnapshot(diskId, imageName, "", false, false); } /** @@ -739,7 +746,7 @@ public class VirtualMachine extends PoolElement{ */ public OneResponse diskSnapshot(int diskId, String imageName, boolean hot) { - return diskSnapshot(diskId, imageName, "", hot); + return diskSnapshot(diskId, imageName, "", hot, false); } /** @@ -1136,11 +1143,11 @@ public class VirtualMachine extends PoolElement{ } /** - * @deprecated Replaced by {@link #diskSnapshot(int,String,String,boolean)} + * @deprecated Replaced by {@link #diskSnapshot(int,String,String,boolean,boolean)} */ public OneResponse savedisk(int diskId, String imageName, String imageType) { - return diskSnapshot(diskId, imageName, imageType, false); + return diskSnapshot(diskId, imageName, imageType, false, false); } /** diff --git a/src/oca/ruby/opennebula/virtual_machine.rb b/src/oca/ruby/opennebula/virtual_machine.rb index 51165c3437..87bbd37a97 100644 --- a/src/oca/ruby/opennebula/virtual_machine.rb +++ b/src/oca/ruby/opennebula/virtual_machine.rb @@ -393,7 +393,6 @@ module OpenNebula # perform the operation when the VM shuts down # @param do_template [true|false] True to clone also the VM originating # template and replace the disk with the saved image - # perform the operation when the VM shuts down # # @return [Integer, OpenNebula::Error] the new Image ID in case of # success, error otherwise From 386d9cfff3f9c51c141c2f73638d28f192ece728 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Tue, 8 Apr 2014 13:11:38 +0200 Subject: [PATCH 2/6] Feature #2562: Java classes for zone pool --- .../src/org/opennebula/client/zone/Zone.java | 187 ++++++++++++++++++ .../org/opennebula/client/zone/ZonePool.java | 103 ++++++++++ 2 files changed, 290 insertions(+) create mode 100644 src/oca/java/src/org/opennebula/client/zone/Zone.java create mode 100644 src/oca/java/src/org/opennebula/client/zone/ZonePool.java diff --git a/src/oca/java/src/org/opennebula/client/zone/Zone.java b/src/oca/java/src/org/opennebula/client/zone/Zone.java new file mode 100644 index 0000000000..91a31a2b90 --- /dev/null +++ b/src/oca/java/src/org/opennebula/client/zone/Zone.java @@ -0,0 +1,187 @@ +/******************************************************************************* + * Copyright 2002-2014, OpenNebula Project (OpenNebula.org), C12G Labs + * + * 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. + ******************************************************************************/ +package org.opennebula.client.zone; + + +import org.opennebula.client.Client; +import org.opennebula.client.OneResponse; +import org.opennebula.client.PoolElement; +import org.w3c.dom.Node; + +/** + * This class represents an OpenNebula zone. + * It also offers static XML-RPC call wrappers. + */ +public class Zone extends PoolElement{ + + private static final String METHOD_PREFIX = "zone."; + private static final String INFO = METHOD_PREFIX + "info"; + private static final String ALLOCATE = METHOD_PREFIX + "allocate"; + private static final String UPDATE = METHOD_PREFIX + "update"; + private static final String RENAME = METHOD_PREFIX + "rename"; + private static final String DELETE = METHOD_PREFIX + "delete"; + + /** + * Creates a new Zone representation. + * + * @param id The zone id. + * @param client XML-RPC Client. + */ + public Zone(int id, Client client) + { + super(id, client); + } + + /** + * @see PoolElement + */ + protected Zone(Node xmlElement, Client client) + { + super(xmlElement, client); + } + + + // ================================= + // Static XML-RPC methods + // ================================= + + /** + * Allocates a new Zone in OpenNebula. + * + * @param client XML-RPC Client. + * @param description A string containing the template of the zone. + * @return If successful the message contains the associated + * id generated for this Zone. + */ + public static OneResponse allocate(Client client, String description) + { + return client.call(ALLOCATE, description); + } + + /** + * Retrieves the information of the given zone. + * + * @param client XML-RPC Client. + * @param id The zone id. + * @return If successful the message contains the string + * with the information returned by OpenNebula. + */ + public static OneResponse info(Client client, int id) + { + return client.call(INFO, id); + } + + /** + * Deletes a zone from OpenNebula. + * + * @param client XML-RPC Client. + * @param id The zone id. + * @return A encapsulated response. + */ + public static OneResponse delete(Client client, int id) + { + return client.call(DELETE, id); + } + + /** + * Replaces the template contents. + * + * @param client XML-RPC Client. + * @param id The zone id of the target zone we want to modify. + * @param new_template New template contents + * @param append True to append new attributes instead of replace the whole template + * @return If successful the message contains the zone id. + */ + public static OneResponse update(Client client, int id, String new_template, + boolean append) + { + return client.call(UPDATE, id, new_template, append ? 1 : 0); + } + + /** + * Renames this Zone + * + * @param client XML-RPC Client. + * @param id The Zone id of the target Zone. + * @param name New name for the Zone. + * @return If an error occurs the error message contains the reason. + */ + public static OneResponse rename(Client client, int id, String name) + { + return client.call(RENAME, id, name); + } + + // ================================= + // Instanced object XML-RPC methods + // ================================= + + /** + * Loads the xml representation of the zone. + * The info is also stored internally. + * + * @see Zone#info(Client, int) + */ + public OneResponse info() + { + OneResponse response = info(client, id); + super.processInfo(response); + return response; + } + + /** + * Deletes the zone from OpenNebula. + * + * @see Zone#delete(Client, int) + */ + public OneResponse delete() + { + return delete(client, id); + } + + /** + * Renames this Zone + * + * @param name New name for the Zone. + * @return If an error occurs the error message contains the reason. + */ + public OneResponse rename(String name) + { + return rename(client, id, name); + } + + /** + * Replaces the template contents. + * + * @param new_template New template contents + * @return If successful the message contains the zone id. + */ + public OneResponse update(String new_template) + { + return update(new_template, false); + } + + /** + * Replaces the template contents. + * + * @param new_template New template contents + * @param append True to append new attributes instead of replace the whole template + * @return If successful the message contains the zone id. + */ + public OneResponse update(String new_template, boolean append) + { + return update(client, id, new_template, append); + } +} diff --git a/src/oca/java/src/org/opennebula/client/zone/ZonePool.java b/src/oca/java/src/org/opennebula/client/zone/ZonePool.java new file mode 100644 index 0000000000..4f781c815b --- /dev/null +++ b/src/oca/java/src/org/opennebula/client/zone/ZonePool.java @@ -0,0 +1,103 @@ +/******************************************************************************* + * Copyright 2002-2014, OpenNebula Project (OpenNebula.org), C12G Labs + * + * 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. + ******************************************************************************/ +package org.opennebula.client.zone; + +import java.util.AbstractList; +import java.util.Iterator; + + +import org.opennebula.client.Client; +import org.opennebula.client.OneResponse; +import org.opennebula.client.Pool; +import org.opennebula.client.PoolElement; +import org.w3c.dom.Node; + +/** + * This class represents an OpenNebula zone pool. + * It also offers static XML-RPC call wrappers. + */ +public class ZonePool extends Pool implements Iterable{ + + private static final String ELEMENT_NAME = "ZONE"; + private static final String INFO_METHOD = "zonepool.info"; + + /** + * Creates a new zone pool + * @param client XML-RPC Client. + */ + public ZonePool(Client client) + { + super(ELEMENT_NAME, client, INFO_METHOD); + } + + @Override + public PoolElement factory(Node node) + { + return new Zone(node, client); + } + + /** + * Retrieves all the zones in the pool. + * + * @param client XML-RPC Client. + * @return If successful the message contains the string + * with the information returned by OpenNebula. + */ + public static OneResponse info(Client client) + { + return Pool.info(client, INFO_METHOD); + } + + /** + * Loads the xml representation of the zone pool. + * + * @see ZonePool#info(Client) + */ + public OneResponse info() + { + return super.info(); + } + + public Iterator iterator() + { + AbstractList ab = new AbstractList() + { + public int size() + { + return getLength(); + } + + public Zone get(int index) + { + return (Zone) item(index); + } + }; + + return ab.iterator(); + } + + /** + * Returns the Zone with the given Id from the pool. If it is not found, + * then returns null. The method {@link #info()} must be called before. + * + * @param id of the Zone to retrieve + * @return The Image with the given Id, or null if it was not found. + */ + public Zone getById(int id) + { + return (Zone) super.getById(id); + } +} From 22fa9960a4ea0695dafd46d66a7c538c3a12445f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Tue, 8 Apr 2014 15:48:04 +0200 Subject: [PATCH 3/6] Feature #2562: java oca methods for group add/del provider --- .../org/opennebula/client/group/Group.java | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/src/oca/java/src/org/opennebula/client/group/Group.java b/src/oca/java/src/org/opennebula/client/group/Group.java index 8b3edb2705..d056b1de8f 100644 --- a/src/oca/java/src/org/opennebula/client/group/Group.java +++ b/src/oca/java/src/org/opennebula/client/group/Group.java @@ -32,6 +32,8 @@ public class Group extends PoolElement{ private static final String INFO = METHOD_PREFIX + "info"; private static final String DELETE = METHOD_PREFIX + "delete"; private static final String QUOTA = METHOD_PREFIX + "quota"; + private static final String ADD_PROVIDER = METHOD_PREFIX + "addprovider"; + private static final String DEL_PROVIDER = METHOD_PREFIX + "delprovider"; /** * Creates a new Group representation. @@ -108,6 +110,36 @@ public class Group extends PoolElement{ return client.call(QUOTA, id, quota_template); } + /** + * Adds a resource provider to this group + * + * @param client XML-RPC Client. + * @param id The group id. + * @param zoneId The zone id. + * @param clusterId The cluster id. + * @return A encapsulated response. + */ + public static OneResponse addProvider(Client client, int id, + int zoneId, int clusterId) + { + return client.call(ADD_PROVIDER, id, zoneId, clusterId); + } + + /** + * Deletes a resource provider from this group + * + * @param client XML-RPC Client. + * @param id The group id. + * @param zoneId The zone id. + * @param clusterId The cluster id. + * @return A encapsulated response. + */ + public static OneResponse delProvider(Client client, int id, + int zoneId, int clusterId) + { + return client.call(DEL_PROVIDER, id, zoneId, clusterId); + } + // ================================= // Instanced object XML-RPC methods // ================================= @@ -146,6 +178,30 @@ public class Group extends PoolElement{ return setQuota(client, id, quota_template); } + /** + * Adds a resource provider to this group + * + * @param zoneId The zone id. + * @param clusterId The cluster id. + * @return A encapsulated response. + */ + public OneResponse addProvider(int zoneId, int clusterId) + { + return addProvider(client, id, zoneId, clusterId); + } + + /** + * Deletes a resource provider from this group + * + * @param zoneId The zone id. + * @param clusterId The cluster id. + * @return A encapsulated response. + */ + public OneResponse delProvider(int zoneId, int clusterId) + { + return delProvider(client, id, zoneId, clusterId); + } + // ================================= // Helpers // ================================= From 0589944e636737704b6964475b577982b9253cb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Tue, 8 Apr 2014 15:53:30 +0200 Subject: [PATCH 4/6] Feature #2696: add group update call to java oca --- .../org/opennebula/client/group/Group.java | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/oca/java/src/org/opennebula/client/group/Group.java b/src/oca/java/src/org/opennebula/client/group/Group.java index d056b1de8f..15a7fb054b 100644 --- a/src/oca/java/src/org/opennebula/client/group/Group.java +++ b/src/oca/java/src/org/opennebula/client/group/Group.java @@ -34,6 +34,7 @@ public class Group extends PoolElement{ private static final String QUOTA = METHOD_PREFIX + "quota"; private static final String ADD_PROVIDER = METHOD_PREFIX + "addprovider"; private static final String DEL_PROVIDER = METHOD_PREFIX + "delprovider"; + private static final String UPDATE = METHOD_PREFIX + "update"; /** * Creates a new Group representation. @@ -140,6 +141,21 @@ public class Group extends PoolElement{ return client.call(DEL_PROVIDER, id, zoneId, clusterId); } + /** + * Replaces the template contents. + * + * @param client XML-RPC Client. + * @param id The group id of the target group we want to modify. + * @param new_template New template contents + * @param append True to append new attributes instead of replace the whole template + * @return If successful the message contains the group id. + */ + public static OneResponse update(Client client, int id, String new_template, + boolean append) + { + return client.call(UPDATE, id, new_template, append ? 1 : 0); + } + // ================================= // Instanced object XML-RPC methods // ================================= @@ -202,6 +218,29 @@ public class Group extends PoolElement{ return delProvider(client, id, zoneId, clusterId); } + /** + * Replaces the template contents. + * + * @param new_template New template contents + * @return If successful the message contains the group id. + */ + public OneResponse update(String new_template) + { + return update(new_template, false); + } + + /** + * Replaces the template contents. + * + * @param new_template New template contents + * @param append True to append new attributes instead of replace the whole template + * @return If successful the message contains the group id. + */ + public OneResponse update(String new_template, boolean append) + { + return update(client, id, new_template, append); + } + // ================================= // Helpers // ================================= From c258ba8f238b503b978ea252b9a7f854d82c8c6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Tue, 8 Apr 2014 16:49:16 +0200 Subject: [PATCH 5/6] Bug #2504: Improve defaultquota help text --- src/cli/one_helper/onequota_helper.rb | 25 +++++++++++++++++++++++-- src/cli/onegroup | 2 +- src/cli/oneuser | 2 +- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/cli/one_helper/onequota_helper.rb b/src/cli/one_helper/onequota_helper.rb index 7fa9cf9d2c..286d1fb59f 100644 --- a/src/cli/one_helper/onequota_helper.rb +++ b/src/cli/one_helper/onequota_helper.rb @@ -46,9 +46,12 @@ class OneQuotaHelper # ID = # RVMS = # ] + EOT + + HELP_QUOTA_FOOTER = <<-EOT.unindent # # In any quota: - # -1 means use the default limit ('defaultquota' command) + # -1 means use the default limit (set with the 'defaultquota' command) # 0 means unlimited. # # The usage counters "*_USED" are shown for information @@ -56,12 +59,23 @@ class OneQuotaHelper #----------------------------------------------------------------------- EOT + HELP_DEFAULT_QUOTA_FOOTER = <<-EOT.unindent + # + # In any quota: + # 0 means unlimited. + # + # The usage counters "*_USED" will always be 0 for the default + # quotas, and can be ignored. + #----------------------------------------------------------------------- + EOT + # Edits the quota template of a resource # @param [XMLElement] resource to get the current info from # @param [String] path to the new contents. If nil a editor will be # used + # @param [True|False] is_default To change the help text # @return [String] contents of the new quotas - def self.set_quota(resource, path) + def self.set_quota(resource, path, is_default=false) str = "" if path.nil? @@ -71,6 +85,13 @@ class OneQuotaHelper path = tmp.path tmp << HELP_QUOTA + + if (is_default) + tmp << HELP_DEFAULT_QUOTA_FOOTER + else + tmp << HELP_QUOTA_FOOTER + end + tmp << resource.template_like_str("DATASTORE_QUOTA") << "\n" tmp << resource.template_like_str("VM_QUOTA") << "\n" tmp << resource.template_like_str("NETWORK_QUOTA") << "\n" diff --git a/src/cli/onegroup b/src/cli/onegroup index 60f7c97a7f..29eb5d03c9 100755 --- a/src/cli/onegroup +++ b/src/cli/onegroup @@ -232,7 +232,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do exit(-1) end - str = OneQuotaHelper.set_quota(default_quotas, args[0]) + str = OneQuotaHelper.set_quota(default_quotas, args[0], true) rc = system.set_group_quotas(str) diff --git a/src/cli/oneuser b/src/cli/oneuser index 2f3e908427..2e11338ee5 100755 --- a/src/cli/oneuser +++ b/src/cli/oneuser @@ -265,7 +265,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do exit(-1) end - str = OneQuotaHelper.set_quota(default_quotas, args[0]) + str = OneQuotaHelper.set_quota(default_quotas, args[0], true) rc = system.set_user_quotas(str) From cbe7788117a964bea16dd02274bdabd6c2b632a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Tue, 8 Apr 2014 18:15:38 +0200 Subject: [PATCH 6/6] Formatting for onegroup create help --- src/cli/one_helper.rb | 16 ++++++++-------- src/cli/onegroup | 6 +----- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/cli/one_helper.rb b/src/cli/one_helper.rb index 7db81ff2aa..0f7c1979c4 100644 --- a/src/cli/one_helper.rb +++ b/src/cli/one_helper.rb @@ -147,7 +147,7 @@ EOT }, { :name => 'admin_password', - :large => '--admin_password password', + :large => '--admin_password pass', :short => "-p", :description => 'Password for the admin user of the group', @@ -155,7 +155,7 @@ EOT }, { :name => 'admin_driver', - :large => '--admin_driver auth_driver', + :large => '--admin_driver driver', :short => "-d", :description => 'Auth driver for the admin user of the group', @@ -163,20 +163,20 @@ EOT }, { :name => 'resources', - :large => '--resources resources_str', + :large => '--resources res_str', :short => "-r", :description => - 'Which resources can be created by group users "\ - "(VM+NET+IMAGE+TEMPLATE by default)', + "Which resources can be created by group users "<< + "(VM+NET+IMAGE+TEMPLATE by default)", :format => String }, { :name => 'admin_resources', - :large => '--admin_resources resources_str', + :large => '--admin_resources res_str', :short => "-o", :description => - 'Which resources can be created by group users "\ - "(VM+NET+IMAGE+TEMPLATE by default)', + "Which resources can be created by the admin user "<< + "(VM+NET+IMAGE+TEMPLATE by default)", :format => String } ] diff --git a/src/cli/onegroup b/src/cli/onegroup index 29eb5d03c9..8c3958af3d 100755 --- a/src/cli/onegroup +++ b/src/cli/onegroup @@ -79,17 +79,13 @@ cmd=CommandParser::CmdParser.new(ARGV) do Examples: - - using a template description file: - - onegroup create group_description.tmpl - - create a group with admin user and allow group users to only create new templates and VMs, and group admin to manage templates, vms, images and virtual networks onegroup create --name groupA --admin_user admin_userA --admin_password somestr - --resource TEMPLATE+VM + --resources TEMPLATE+VM --admin_resources TEMPLATE+VM+IMAGE+NET EOT