1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-22 18:50:08 +03:00

Feature #602: Add VNet hold and release methods in Java OCA

This commit is contained in:
Carlos Martín 2011-11-30 13:19:15 +01:00
parent a173e7bd75
commit f0efbf09b6
2 changed files with 100 additions and 1 deletions

View File

@ -36,7 +36,8 @@ public class VirtualNetwork extends PoolElement{
private static final String RMLEASES = METHOD_PREFIX + "rmleases";
private static final String CHOWN = METHOD_PREFIX + "chown";
private static final String UPDATE = METHOD_PREFIX + "update";
private static final String HOLD = METHOD_PREFIX + "hold";
private static final String RELEASE = METHOD_PREFIX + "release";
/**
* Creates a new virtual network representation.
@ -140,6 +141,32 @@ public class VirtualNetwork extends PoolElement{
return client.call(RMLEASES, id, template);
}
/**
* Holds a VirtualNetwork lease, marking it as used
*
* @param client XML-RPC Client.
* @param id The virtual network id (nid) of the target network.
* @param template IP to hold, e.g. "LEASES = [ IP = 192.168.0.5 ]"
* @return A encapsulated response.
*/
public static OneResponse hold(Client client, int id, String template)
{
return client.call(HOLD, id, template);
}
/**
* Releases a VirtualNetwork lease on hold
*
* @param client XML-RPC Client.
* @param id The virtual network id (nid) of the target network.
* @param template IP to release, e.g. "LEASES = [ IP = 192.168.0.5 ]"
* @return A encapsulated response.
*/
public static OneResponse release(Client client, int id, String template)
{
return client.call(RELEASE, id, template);
}
/**
* Changes the owner/group
*
@ -271,6 +298,30 @@ public class VirtualNetwork extends PoolElement{
return rmLeases(client, id, lease_template);
}
/**
* Holds a VirtualNetwork lease, marking it as used
*
* @param ip IP to hold, e.g. "192.168.0.5"
* @return A encapsulated response.
*/
public OneResponse hold(String ip)
{
String lease_template = "LEASES = [ IP = " + ip + " ]";
return hold(client, id, lease_template);
}
/**
* Releases a VirtualNetwork lease on hold
*
* @param ip IP to release, e.g. "192.168.0.5"
* @return A encapsulated response.
*/
public OneResponse release(String ip)
{
String lease_template = "LEASES = [ IP = " + ip + " ]";
return release(client, id, lease_template);
}
/**
* Changes the owner/group
*

View File

@ -209,6 +209,54 @@ public class VirtualNetworkTest
fixed_vnet.delete();
}
@Test
public void holdFixed()
{
res = VirtualNetwork.allocate(client, fixed_template);
assertTrue( !res.isError() );
VirtualNetwork fixed_vnet =
new VirtualNetwork(Integer.parseInt(res.getMessage()), client);
res = fixed_vnet.hold("130.10.0.1");
assertTrue( !res.isError() );
res = fixed_vnet.hold("130.10.0.5");
assertTrue( res.isError() );
res = fixed_vnet.release("130.10.0.1");
assertTrue( !res.isError() );
res = fixed_vnet.release("130.10.0.1");
assertTrue( res.isError() );
res = fixed_vnet.release("130.10.0.5");
assertTrue( res.isError() );
fixed_vnet.delete();
}
@Test
public void holdRanged()
{
res = vnet.hold("192.168.0.10");
assertTrue( !res.isError() );
res = vnet.hold("192.168.100.1");
assertTrue( res.isError() );
res = vnet.release("192.168.0.10");
assertTrue( !res.isError() );
res = vnet.release("192.168.0.10");
assertTrue( res.isError() );
res = vnet.release("192.168.100.1");
assertTrue( res.isError() );
vnet.delete();
}
@Test
public void update()
{