diff --git a/src/oca/java/src/org/opennebula/client/vnet/VirtualNetwork.java b/src/oca/java/src/org/opennebula/client/vnet/VirtualNetwork.java new file mode 100644 index 0000000000..6982498eb4 --- /dev/null +++ b/src/oca/java/src/org/opennebula/client/vnet/VirtualNetwork.java @@ -0,0 +1,126 @@ +/******************************************************************************* + * Copyright 2002-2010, 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.virtualNetwork; + + +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 virtual network. + * It also offers static XML-RPC call wrappers. + */ +public class VirtualNetwork extends PoolElement{ + + private static final String METHOD_PREFIX = "vn."; + private static final String ALLOCATE = METHOD_PREFIX + "allocate"; + private static final String INFO = METHOD_PREFIX + "info"; + private static final String DELETE = METHOD_PREFIX + "delete"; + + + /** + * Creates a new virtual network representation. + * + * @param id The virtual network id (nid) . + * @param client XML-RPC Client. + */ + public VirtualNetwork(int id, Client client) + { + super(id, client); + } + + /** + * @see PoolElement + */ + protected VirtualNetwork(Node xmlElement, Client client) + { + super(xmlElement, client); + } + + // ================================= + // Static XML-RPC methods + // ================================= + + /** + * Allocates a new virtual network in OpenNebula. + * + * @param client XML-RPC Client. + * @param description A string containing the template + * of the virtual network. + * @return If successful the message contains the associated + * id generated for this virtual network. + */ + public static OneResponse allocate(Client client, String description) + { + return client.call(ALLOCATE, description); + } + + /** + * Retrieves the information of the given virtual network + * + * @param client XML-RPC Client. + * @param id the virtual network id (nid) for the network 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 network from OpenNebula. + * + * @param client XML-RPC Client. + * @param id The virtual network id (nid) of the target network. + * @return A encapsulated response. + */ + public static OneResponse delete(Client client, int id) + { + return client.call(DELETE, id); + } + + + // ================================= + // Instanced object XML-RPC methods + // ================================= + + /** + * Loads the xml representation of the virtual network. + * The info is also stored internally. + * + * @see VirtualNetwork#info(Client, int) + */ + public OneResponse info() + { + OneResponse response = info(client, id); + super.processInfo(response); + return response; + } + + /** + * Deletes the network from OpenNebula. + * + * @return A encapsulated response. + */ + public OneResponse delete() + { + return delete(client, id); + } +} diff --git a/src/oca/java/src/org/opennebula/client/vnet/VirtualNetworkPool.java b/src/oca/java/src/org/opennebula/client/vnet/VirtualNetworkPool.java new file mode 100644 index 0000000000..cfc0dfd2d9 --- /dev/null +++ b/src/oca/java/src/org/opennebula/client/vnet/VirtualNetworkPool.java @@ -0,0 +1,128 @@ +/******************************************************************************* + * Copyright 2002-2010, 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.virtualNetwork; + +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 Virtual Network pool. + * It also offers static XML-RPC call wrappers. + */ +public class VirtualNetworkPool extends Pool implements Iterable{ + + private static final String ELEMENT_NAME = "VNET"; + private static final String INFO_METHOD = "vnpool.info"; + + private int filter; + + /** + * Creates a new VN pool with the default filter flag value + * set to 0 (VNs belonging to user with UID 0) + * + * @param client XML-RPC Client. + * + * @see VirtualNetworkPool#VirtualNetworkPool(Client, int) + */ + public VirtualNetworkPool(Client client) + { + super(ELEMENT_NAME, client); + this.filter = 0; + } + + /** + * Creates a new VN pool. + * + * @param client XML-RPC Client. + * @param filter Filter flag used by default in the method + * {@link VirtualNetworkPool#info()}. Possible values: + * + */ + public VirtualNetworkPool(Client client, int filter) + { + super(ELEMENT_NAME, client); + this.filter = filter; + } + + @Override + public PoolElement factory(Node node) + { + return new VirtualNetwork(node, client); + } + + /** + * Retrieves all or part of the VNs in the pool. + * + * @param client XML-RPC Client. + * @param filter Filter flag. Possible values: + * + * @return If successful the message contains the string + * with the information returned by OpenNebula. + */ + public static OneResponse info(Client client, int filter) + { + return client.call(INFO_METHOD, filter); + } + + /** + * Loads the xml representation of all or part of the + * VNs in the pool. The filter used is the one set in + * the constructor. + * + * @see VirtualNetworkPool#info(Client, int) + * @return If successful the message contains the string + * with the information returned by OpenNebula. + */ + public OneResponse info() + { + OneResponse response = info(client, filter); + super.processInfo(response); + return response; + } + + public Iterator iterator() + { + AbstractList ab = new AbstractList() + { + public int size() + { + return getLength(); + } + + public VirtualNetwork get(int index) + { + return (VirtualNetwork) item(index); + } + }; + + return ab.iterator(); + } +}