mirror of
https://github.com/OpenNebula/one.git
synced 2025-01-19 10:03:36 +03:00
feature #198: User related classes for the OCA-JAVA Bindings
This commit is contained in:
parent
e2cd528831
commit
ffc71b6fc1
130
src/oca/java/src/org/opennebula/client/user/User.java
Normal file
130
src/oca/java/src/org/opennebula/client/user/User.java
Normal file
@ -0,0 +1,130 @@
|
||||
/*******************************************************************************
|
||||
* 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.user;
|
||||
|
||||
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 User.
|
||||
* It also offers static XML-RPC call wrappers.
|
||||
*/
|
||||
public class User extends PoolElement {
|
||||
|
||||
private static final String ROOT_NAME = "USER";
|
||||
|
||||
private static final String METHOD_PREFIX = "user.";
|
||||
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 User representation.
|
||||
*
|
||||
* @param id The user id (uid).
|
||||
* @param client XML-RPC Client.
|
||||
*/
|
||||
public User(int id, Client client)
|
||||
{
|
||||
super(id, client);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see PoolElement
|
||||
*/
|
||||
protected User(Node xmlElement, Client client)
|
||||
{
|
||||
super(xmlElement, client);
|
||||
}
|
||||
|
||||
|
||||
// =================================
|
||||
// Static XML-RPC methods
|
||||
// =================================
|
||||
|
||||
/**
|
||||
* Allocates a new user in OpenNebula.
|
||||
*
|
||||
* @param client XML-RPC Client.
|
||||
* @param username Username for the new user.
|
||||
* @param password Password for the new user
|
||||
* @return If successful the message contains
|
||||
* the associated id (int uid) generated for this user.
|
||||
*/
|
||||
public static OneResponse allocate(Client client,
|
||||
String username,
|
||||
String password)
|
||||
{
|
||||
return client.call(ALLOCATE, username, password);
|
||||
}
|
||||
|
||||
/** Retrieves the information of the given user.
|
||||
*
|
||||
* @param client XML-RPC Client.
|
||||
* @param id The user id (uid) for the user to
|
||||
* retrieve the information from.
|
||||
* @return if successful the message contains the
|
||||
* string with the information about the user returned by OpenNebula.
|
||||
*/
|
||||
public static OneResponse info(Client client, int id)
|
||||
{
|
||||
return client.call(INFO, id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a user from OpenNebula.
|
||||
*
|
||||
* @param client XML-RPC Client.
|
||||
* @param id The user id (uid) of the target user we want to delete.
|
||||
* @return If an error occurs the error message contains the reason.
|
||||
*/
|
||||
public static OneResponse delete(Client client, int id)
|
||||
{
|
||||
return client.call(DELETE, id);
|
||||
}
|
||||
|
||||
// =================================
|
||||
// Instanced object XML-RPC methods
|
||||
// =================================
|
||||
|
||||
/**
|
||||
* Loads the xml representation of the user.
|
||||
* The info is also stored internally.
|
||||
*
|
||||
* @see User#info(Client, int)
|
||||
*/
|
||||
public OneResponse info()
|
||||
{
|
||||
OneResponse response = info(client, id);
|
||||
|
||||
super.processInfo(response);
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes the user from OpenNebula.
|
||||
*
|
||||
* @see User#delete(Client, int)
|
||||
*/
|
||||
public OneResponse delete()
|
||||
{
|
||||
return delete(client, id);
|
||||
}
|
||||
}
|
84
src/oca/java/src/org/opennebula/client/user/UserPool.java
Normal file
84
src/oca/java/src/org/opennebula/client/user/UserPool.java
Normal file
@ -0,0 +1,84 @@
|
||||
/*******************************************************************************
|
||||
* 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.user;
|
||||
|
||||
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 user pool.
|
||||
* It also offers static XML-RPC call wrappers.
|
||||
*/
|
||||
public class UserPool extends Pool implements Iterable<User>
|
||||
{
|
||||
|
||||
private static final String ELEMENT_NAME = "USER";
|
||||
private static final String INFO_METHOD = "userpool.info";
|
||||
|
||||
/**
|
||||
* Creates a new user pool
|
||||
* @param client XML-RPC Client.
|
||||
*/
|
||||
public UserPool(Client client)
|
||||
{
|
||||
super(ELEMENT_NAME, client);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PoolElement factory(Node node)
|
||||
{
|
||||
return new User(node, client);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the xml representation of the user pool.
|
||||
*
|
||||
* @see UserPool#info(Client)
|
||||
*/
|
||||
public OneResponse info()
|
||||
{
|
||||
OneResponse response = client.call(INFO_METHOD);
|
||||
|
||||
super.processInfo(response);
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
public Iterator<User> iterator()
|
||||
{
|
||||
AbstractList<User> ab = new AbstractList<User>()
|
||||
{
|
||||
public int size()
|
||||
{
|
||||
return getLength();
|
||||
}
|
||||
|
||||
public User get(int index)
|
||||
{
|
||||
return (User) item(index);
|
||||
}
|
||||
};
|
||||
|
||||
return ab.iterator();
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user