diff --git a/src/oca/java/src/org/opennebula/client/image/ImagePool.java b/src/oca/java/src/org/opennebula/client/image/ImagePool.java index 37a24176cb..a571ac33ab 100644 --- a/src/oca/java/src/org/opennebula/client/image/ImagePool.java +++ b/src/oca/java/src/org/opennebula/client/image/ImagePool.java @@ -22,7 +22,6 @@ import org.opennebula.client.Client; import org.opennebula.client.OneResponse; import org.opennebula.client.Pool; import org.opennebula.client.PoolElement; -import org.opennebula.client.vm.VirtualMachinePool; import org.w3c.dom.Node; /** @@ -42,7 +41,7 @@ public class ImagePool extends Pool implements Iterable * * @param client XML-RPC Client. * - * @see VirtualMachinePool#VirtualMachinePool(Client, int) + * @see ImagePool#ImagePool(Client, int) */ public ImagePool(Client client) { @@ -58,8 +57,8 @@ public class ImagePool extends Pool implements Iterable * {@link ImagePool#info()}. Possible values: * */ public ImagePool(Client client, int filter) @@ -85,8 +84,8 @@ public class ImagePool extends Pool implements Iterable * {@link ImagePool#info()}. Possible values: * * @return If successful the message contains the string * with the information returned by OpenNebula. diff --git a/src/oca/java/src/org/opennebula/client/template/Template.java b/src/oca/java/src/org/opennebula/client/template/Template.java new file mode 100644 index 0000000000..acdb2530c5 --- /dev/null +++ b/src/oca/java/src/org/opennebula/client/template/Template.java @@ -0,0 +1,236 @@ +/******************************************************************************* + * Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org) + * + * 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.template; + +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 template. + * It also offers static XML-RPC call wrappers. + */ +public class Template extends PoolElement +{ + + private static final String METHOD_PREFIX = "template."; + private static final String ALLOCATE = METHOD_PREFIX + "allocate"; + private static final String INFO = METHOD_PREFIX + "info"; + private static final String DELETE = METHOD_PREFIX + "delete"; + private static final String UPDATE = METHOD_PREFIX + "update"; + private static final String RMATTR = METHOD_PREFIX + "rmattr"; + private static final String PUBLISH = METHOD_PREFIX + "publish"; + + /** + * Creates a new Template representation. + * @param id The template id. + * @param client XML-RPC Client. + */ + public Template(int id, Client client) + { + super(id, client); + } + + /** + * @see PoolElement + */ + protected Template(Node xmlElement, Client client) + { + super(xmlElement, client); + } + + // ================================= + // Static XML-RPC methods + // ================================= + + + /** + * Allocates a new Template in OpenNebula. + * + * @param client XML-RPC Client. + * @param description A string containing the template of the template. + * @return If successful the message contains the associated + * id generated for this Template. + */ + public static OneResponse allocate(Client client, String description) + { + return client.call(ALLOCATE, description); + } + + /** + * Retrieves the information of the given Template. + * + * @param client XML-RPC Client. + * @param id The template id for the template to retrieve the information from + * @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 template from OpenNebula. + * + * @param client XML-RPC Client. + * @param id The template id of the target template we want to delete. + * @return A encapsulated response. + */ + public static OneResponse delete(Client client, int id) + { + return client.call(DELETE, id); + } + + /** + * Modifies a template attribute. + * + * @param client XML-RPC Client. + * @param id The template id of the target template we want to modify. + * @param att_name The name of the attribute to update. + * @param att_val The new value for the attribute. + * @return If successful the message contains the template id. + */ + public static OneResponse update(Client client, int id, + String att_name, String att_val) + { + return client.call(UPDATE, id, att_name, att_val); + } + + /** + * Removes a template attribute. + * + * @param client XML-RPC Client. + * @param id The template id of the target template we want to modify. + * @param att_name The name of the attribute to remove. + * @return If successful the message contains the template id. + */ + public static OneResponse rmattr(Client client, int id, String att_name) + { + return client.call(RMATTR, id, att_name); + } + + /** + * Publishes or unpublishes a template. + * + * @param client XML-RPC Client. + * @param id The template id of the target template we want to modify. + * @param publish True for publishing, false for unpublishing. + * @return If successful the message contains the template id. + */ + public static OneResponse publish(Client client, int id, boolean publish) + { + return client.call(PUBLISH, id, publish); + } + + + // ================================= + // Instanced object XML-RPC methods + // ================================= + + /** + * Retrieves the information of the Template. + * + * @return If successful the message contains the string + * with the information returned by OpenNebula. + */ + public OneResponse info() + { + OneResponse response = info(client, id); + super.processInfo(response); + return response; + } + + /** + * Deletes the template from OpenNebula. + * + * @return A encapsulated response. + */ + public OneResponse delete() + { + return delete(client, id); + } + + /** + * Modifies a template attribute. + * + * @param att_name The name of the attribute to update. + * @param att_val The new value for the attribute. + * @return If successful the message contains the template id. + */ + public OneResponse update(String att_name, String att_val) + { + return update(client, id, att_name, att_val); + } + + /** + * Removes a template attribute. + * + * @param att_name The name of the attribute to remove. + * @return If successful the message contains the template id. + */ + public OneResponse rmattr(String att_name) + { + return rmattr(client, id, att_name); + } + + /** + * Publishes or unpublishes the template. + * + * @param publish True for publishing, false for unpublishing. + * @return If successful the message contains the template id. + */ + public OneResponse publish(boolean publish) + { + return publish(client, id, publish); + } + + /** + * Publishes the template. + * + * @return If successful the message contains the template id. + */ + public OneResponse publish() + { + return publish(true); + } + + /** + * Unpublishes the template. + * + * @return If successful the message contains the template id. + */ + public OneResponse unpublish() + { + return publish(false); + } + + // ================================= + // Helpers + // ================================= + + /** + * Returns true if the template is public. + * + * @return True if the template is public. + */ + public boolean isPublic() + { + String isPub = xpath("PUBLIC"); + return isPub != null && isPub.equals("1"); + } +} diff --git a/src/oca/java/src/org/opennebula/client/template/TemplatePool.java b/src/oca/java/src/org/opennebula/client/template/TemplatePool.java new file mode 100644 index 0000000000..4d95e5dcee --- /dev/null +++ b/src/oca/java/src/org/opennebula/client/template/TemplatePool.java @@ -0,0 +1,132 @@ +/******************************************************************************* + * Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org) + * + * 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.template; + +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 Template pool. + * It also offers static XML-RPC call wrappers. + */ +public class TemplatePool extends Pool implements Iterable