mirror of
https://github.com/OpenNebula/one.git
synced 2026-11-15 09:13:15 +09:00
Feature #2858: Update Java OCA
This commit is contained in:
1 parent
c6bb0c2223
commit
302b82aafc
2 files changed
+218
-97
No files matched your search
@@ -31,14 +31,17 @@ public class VirtualNetwork extends PoolElement{
|
||||
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 ADDLEASES = METHOD_PREFIX + "addleases";
|
||||
private static final String RMLEASES = METHOD_PREFIX + "rmleases";
|
||||
private static final String ADDAR = METHOD_PREFIX + "add_ar";
|
||||
private static final String RMAR = METHOD_PREFIX + "rm_ar";
|
||||
private static final String UPDATEAR = METHOD_PREFIX + "update_ar";
|
||||
private static final String CHOWN = METHOD_PREFIX + "chown";
|
||||
private static final String CHMOD = METHOD_PREFIX + "chmod";
|
||||
private static final String UPDATE = METHOD_PREFIX + "update";
|
||||
private static final String HOLD = METHOD_PREFIX + "hold";
|
||||
private static final String RELEASE = METHOD_PREFIX + "release";
|
||||
private static final String RENAME = METHOD_PREFIX + "rename";
|
||||
private static final String RESERVE = METHOD_PREFIX + "reserve";
|
||||
private static final String FREEAR = METHOD_PREFIX + "free_ar";
|
||||
|
||||
/**
|
||||
* Creates a new virtual network representation.
|
||||
@@ -142,29 +145,53 @@ public class VirtualNetwork extends PoolElement{
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a lease to the VirtualNetwork
|
||||
* Adds an Address Range to the VirtualNetwork
|
||||
*
|
||||
* @param client XML-RPC Client.
|
||||
* @param id The virtual network id (nid) of the target network.
|
||||
* @param template IP to add, e.g. "LEASES = [ IP = 192.168.0.5 ]"
|
||||
* @param template AR to add, example:
|
||||
* AR = [
|
||||
* TYPE = IP4,
|
||||
* IP = 192.168.0.5,
|
||||
* SIZE = 10 ]
|
||||
*
|
||||
* @return A encapsulated response.
|
||||
*/
|
||||
public static OneResponse addLeases(Client client, int id, String template)
|
||||
public static OneResponse addAr(Client client, int id, String template)
|
||||
{
|
||||
return client.call(ADDLEASES, id, template);
|
||||
return client.call(ADDAR, id, template);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a lease from the VirtualNetwork
|
||||
* Removes an Address Range from the VirtualNetwork
|
||||
*
|
||||
* @param client XML-RPC Client.
|
||||
* @param id The virtual network id (nid) of the target network.
|
||||
* @param template IP to remove, e.g. "LEASES = [ IP = 192.168.0.5 ]"
|
||||
* @param arId Id of the Address Range to remove
|
||||
* @return A encapsulated response.
|
||||
*/
|
||||
public static OneResponse rmLeases(Client client, int id, String template)
|
||||
public static OneResponse rmAr(Client client, int id, int arId)
|
||||
{
|
||||
return client.call(RMLEASES, id, template);
|
||||
return client.call(RMAR, id, arId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Upates an Address Range from the VirtualNetwork
|
||||
*
|
||||
* @param client XML-RPC Client.
|
||||
* @param id The virtual network id (nid) of the target network.
|
||||
* @param template AR to update, example:
|
||||
* AR = [
|
||||
* AR_ID = 3,
|
||||
* TYPE = IP4,
|
||||
* IP = 192.168.0.5,
|
||||
* SIZE = 10 ]
|
||||
*
|
||||
* @return A encapsulated response.
|
||||
*/
|
||||
public static OneResponse updateAr(Client client, int id, String template)
|
||||
{
|
||||
return client.call(UPDATEAR, id, template);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -172,7 +199,10 @@ public class VirtualNetwork extends PoolElement{
|
||||
*
|
||||
* @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 ]"
|
||||
* @param template Address to hold, examples:
|
||||
* LEASES = [ IP = 192.168.0.5 ]
|
||||
* LEASES = [ MAC = 02:00:0a:00:00:96 ]
|
||||
* LEASES = [ IP = 192.168.0.5, AR_ID = 3 ]
|
||||
* @return A encapsulated response.
|
||||
*/
|
||||
public static OneResponse hold(Client client, int id, String template)
|
||||
@@ -185,7 +215,10 @@ public class VirtualNetwork extends PoolElement{
|
||||
*
|
||||
* @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 ]"
|
||||
* @param template Address to release, examples:
|
||||
* LEASES = [ IP = 192.168.0.5 ]
|
||||
* LEASES = [ MAC = 02:00:0a:00:00:96 ]
|
||||
* LEASES = [ IP = 192.168.0.5, AR_ID = 3 ]
|
||||
* @return A encapsulated response.
|
||||
*/
|
||||
public static OneResponse release(Client client, int id, String template)
|
||||
@@ -288,6 +321,43 @@ public class VirtualNetwork extends PoolElement{
|
||||
return client.call(RENAME, id, name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reserve a set of addresses from this virtual network
|
||||
*
|
||||
* @param client XML-RPC Client.
|
||||
* @param id The virtual network id (nid) of the target network.
|
||||
* @param template of the reservation. Examples:
|
||||
*<pre>
|
||||
* SIZE = 10
|
||||
*
|
||||
* SIZE = 10
|
||||
* AR_ID = 3
|
||||
* NAME = "new_network"
|
||||
*
|
||||
* SIZE = 10
|
||||
* IP = 192.168.10.50
|
||||
* NETWORK_ID = 9
|
||||
*</pre>
|
||||
* @return A encapsulated response.
|
||||
*/
|
||||
public static OneResponse reserve(Client client, int id, String template)
|
||||
{
|
||||
return client.call(RESERVE, id, template);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes an Address Range from the VirtualNetwork
|
||||
*
|
||||
* @param client XML-RPC Client.
|
||||
* @param id The virtual network id (nid) of the target network.
|
||||
* @param arId Id of the Address Range to remove
|
||||
* @return A encapsulated response.
|
||||
*/
|
||||
public static OneResponse free(Client client, int id, int arId)
|
||||
{
|
||||
return client.call(FREEAR, id, arId);
|
||||
}
|
||||
|
||||
// =================================
|
||||
// Instanced object XML-RPC methods
|
||||
// =================================
|
||||
@@ -347,72 +417,110 @@ public class VirtualNetwork extends PoolElement{
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a lease to the VirtualNetwork
|
||||
* Adds an Address Range to the VirtualNetwork
|
||||
*
|
||||
* @param template AR to add, example:
|
||||
* AR = [
|
||||
* TYPE = IP4,
|
||||
* IP = 192.168.0.5,
|
||||
* SIZE = 10 ]
|
||||
*
|
||||
* @param ip IP to add, e.g. "192.168.0.5"
|
||||
* @return A encapsulated response.
|
||||
*/
|
||||
public OneResponse addLeases(String ip)
|
||||
public OneResponse addAr(String template)
|
||||
{
|
||||
return addLeases(ip, null);
|
||||
return addAr(client, id, template);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a lease to the VirtualNetwork
|
||||
* Removes an Address Range from the VirtualNetwork
|
||||
*
|
||||
* @param ip IP to add, e.g. "192.168.0.5"
|
||||
* @param mac MAC address associated to the IP. Can be null, in which case
|
||||
* OpenNebula will generate it using the following rule:
|
||||
* MAC = MAC_PREFFIX:IP
|
||||
* @param arId Id of the Address Range to remove
|
||||
* @return A encapsulated response.
|
||||
*/
|
||||
public OneResponse addLeases(String ip, String mac)
|
||||
public OneResponse rmAr(int arId)
|
||||
{
|
||||
String lease_template = "LEASES = [ IP = " + ip;
|
||||
|
||||
if( mac != null )
|
||||
{
|
||||
lease_template += ", MAC = " + mac;
|
||||
}
|
||||
|
||||
lease_template += " ]";
|
||||
|
||||
return addLeases(client, id, lease_template);
|
||||
return rmAr(client, id, arId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a lease from the VirtualNetwork
|
||||
* Upates an Address Range from the VirtualNetwork
|
||||
*
|
||||
* @param template AR to update, example:
|
||||
* AR = [
|
||||
* AR_ID = 3,
|
||||
* TYPE = IP4,
|
||||
* IP = 192.168.0.5,
|
||||
* SIZE = 10 ]
|
||||
*
|
||||
* @param ip IP to remove, e.g. "192.168.0.5"
|
||||
* @return A encapsulated response.
|
||||
*/
|
||||
public OneResponse rmLeases(String ip)
|
||||
public OneResponse updateAr(String template)
|
||||
{
|
||||
String lease_template = "LEASES = [ IP = " + ip + " ]";
|
||||
return rmLeases(client, id, lease_template);
|
||||
return updateAr(client, id, template);
|
||||
}
|
||||
|
||||
/**
|
||||
* Holds a VirtualNetwork lease, marking it as used
|
||||
*
|
||||
* @param ip IP to hold, e.g. "192.168.0.5"
|
||||
* @param ip IP or MAC to hold, e.g. "192.168.0.5", "02:00:0a:00:00:96"
|
||||
* @return A encapsulated response.
|
||||
*/
|
||||
public OneResponse hold(String ip)
|
||||
{
|
||||
String lease_template = "LEASES = [ IP = " + ip + " ]";
|
||||
String addr_name = ip.contains(":") ? "MAC" : "IP";
|
||||
|
||||
String lease_template = "LEASES = [ "+addr_name+" = "+ip+"]";
|
||||
|
||||
return hold(client, id, lease_template);
|
||||
}
|
||||
|
||||
/**
|
||||
* Holds a VirtualNetwork lease, marking it as used
|
||||
*
|
||||
* @param ip IP or MAC to hold, e.g. "192.168.0.5", "02:00:0a:00:00:96"
|
||||
* @param arId Id of the Address Range to hold the lease from
|
||||
* @return A encapsulated response.
|
||||
*/
|
||||
public OneResponse hold(String ip, int arId)
|
||||
{
|
||||
String addr_name = ip.contains(":") ? "MAC" : "IP";
|
||||
|
||||
String lease_template =
|
||||
"LEASES = [ "+addr_name+" = "+ip+", AR_ID = "+arId+" ]";
|
||||
|
||||
return hold(client, id, lease_template);
|
||||
}
|
||||
|
||||
/**
|
||||
* Releases a VirtualNetwork lease on hold
|
||||
*
|
||||
* @param ip IP to release, e.g. "192.168.0.5"
|
||||
* @param ip IP or MAC to hold, e.g. "192.168.0.5", "02:00:0a:00:00:96"
|
||||
* @return A encapsulated response.
|
||||
*/
|
||||
public OneResponse release(String ip)
|
||||
{
|
||||
String lease_template = "LEASES = [ IP = " + ip + " ]";
|
||||
String addr_name = ip.contains(":") ? "MAC" : "IP";
|
||||
|
||||
String lease_template = "LEASES = [ "+addr_name+" = "+ip+"]";
|
||||
|
||||
return release(client, id, lease_template);
|
||||
}
|
||||
|
||||
/**
|
||||
* Releases a VirtualNetwork lease on hold
|
||||
*
|
||||
* @param ip IP or MAC to hold, e.g. "192.168.0.5", "02:00:0a:00:00:96"
|
||||
* @param arId Id of the Address Range to release the lease from
|
||||
* @return A encapsulated response.
|
||||
*/
|
||||
public OneResponse release(String ip, int arId)
|
||||
{
|
||||
String addr_name = ip.contains(":") ? "MAC" : "IP";
|
||||
|
||||
String lease_template =
|
||||
"LEASES = [ "+addr_name+" = "+ip+", AR_ID = "+arId+" ]";
|
||||
|
||||
return release(client, id, lease_template);
|
||||
}
|
||||
|
||||
@@ -530,6 +638,39 @@ public class VirtualNetwork extends PoolElement{
|
||||
return rename(client, id, name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reserve a set of addresses from this virtual network
|
||||
*
|
||||
* @param template of the reservation. Examples:
|
||||
*<pre>
|
||||
* SIZE = 10
|
||||
*
|
||||
* SIZE = 10
|
||||
* AR_ID = 3
|
||||
* NAME = "new_network"
|
||||
*
|
||||
* SIZE = 10
|
||||
* IP = 192.168.10.50
|
||||
* NETWORK_ID = 9
|
||||
*</pre>
|
||||
* @return A encapsulated response.
|
||||
*/
|
||||
public OneResponse reserve(String template)
|
||||
{
|
||||
return reserve(client, id, template);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes an Address Range from the VirtualNetwork
|
||||
*
|
||||
* @param arId Id of the Address Range to remove
|
||||
* @return A encapsulated response.
|
||||
*/
|
||||
public OneResponse free(int arId)
|
||||
{
|
||||
return free(client, id, arId);
|
||||
}
|
||||
|
||||
// =================================
|
||||
// Helpers
|
||||
// =================================
|
||||
|
||||
@@ -39,16 +39,14 @@ public class VirtualNetworkTest
|
||||
|
||||
private static String template =
|
||||
"NAME = " + name + "\n"+
|
||||
"TYPE = RANGED\n" +
|
||||
"BRIDGE = vbr0\n" +
|
||||
"NETWORK_SIZE = C\n" +
|
||||
"NETWORK_ADDRESS = 192.168.0.0\n";
|
||||
"NETWORK_ADDRESS = 192.168.0.0\n"+
|
||||
"AR = [ TYPE = IP4, IP = 192.168.0.1, SIZE = 254 ]\n";
|
||||
|
||||
private static String fixed_template =
|
||||
private static String second_template =
|
||||
"NAME = \"Net number one\"\n" +
|
||||
"TYPE = FIXED\n" +
|
||||
"BRIDGE = br1\n" +
|
||||
"LEASES = [IP=130.10.0.1]";
|
||||
"AR = [ TYPE = IP4, IP=130.10.0.1, SIZE = 1]";
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
@@ -93,17 +91,6 @@ public class VirtualNetworkTest
|
||||
@Test
|
||||
public void allocate()
|
||||
{
|
||||
// String template = "NAME = " + name + "\n"+
|
||||
// "TYPE = RANGED\n" +
|
||||
// "PUBLIC = NO\n" +
|
||||
// "BRIDGE = vbr0\n" +
|
||||
// "NETWORK_SIZE = C\n" +
|
||||
// "NETWORK_ADDRESS = 192.168.0.0\n";
|
||||
//
|
||||
// res = VirtualNetwork.allocate(client, template);
|
||||
// assertTrue( res.getErrorMessage(), !res.isError() );
|
||||
// assertTrue( res.getMessage().equals("0") );
|
||||
|
||||
vnetPool.info();
|
||||
|
||||
boolean found = false;
|
||||
@@ -120,9 +107,6 @@ public class VirtualNetworkTest
|
||||
{
|
||||
res = vnet.info();
|
||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
||||
|
||||
// assertTrue( vnet.getId().equals("0") );
|
||||
// assertTrue( vnet.id() == 0 );
|
||||
assertTrue( vnet.getName().equals(name) );
|
||||
}
|
||||
|
||||
@@ -132,7 +116,6 @@ public class VirtualNetworkTest
|
||||
res = vnet.info();
|
||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
||||
|
||||
// assertTrue( vnet.xpath("ID").equals("0") );
|
||||
assertTrue( vnet.xpath("NAME").equals(name) );
|
||||
assertTrue( vnet.xpath("BRIDGE").equals("vbr0") );
|
||||
}
|
||||
@@ -148,89 +131,84 @@ public class VirtualNetworkTest
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addLeases()
|
||||
public void addAr()
|
||||
{
|
||||
res = VirtualNetwork.allocate(client, fixed_template);
|
||||
res = VirtualNetwork.allocate(client, second_template);
|
||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
||||
|
||||
VirtualNetwork fixed_vnet =
|
||||
VirtualNetwork second_vnet =
|
||||
new VirtualNetwork(Integer.parseInt(res.getMessage()), client);
|
||||
|
||||
res = fixed_vnet.addLeases("130.10.0.5");
|
||||
res = second_vnet.addAr("AR = [IP = 130.10.0.5, SIZE = 1, TYPE = IP4]");
|
||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
||||
|
||||
res = fixed_vnet.addLeases("130.10.0.6", "50:20:20:20:20:20");
|
||||
res = second_vnet.addAr("AR = [IP = 130.10.0.6, MAC = 50:20:20:20:20:20, SIZE = 1, TYPE = IP4]");
|
||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
||||
|
||||
res = fixed_vnet.addLeases("130.10.0.6");
|
||||
res = second_vnet.addAr("130.10.0.6");
|
||||
assertTrue( res.isError() );
|
||||
|
||||
fixed_vnet.delete();
|
||||
second_vnet.delete();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rmLeases()
|
||||
public void rmAr()
|
||||
{
|
||||
res = VirtualNetwork.allocate(client, fixed_template);
|
||||
res = VirtualNetwork.allocate(client, second_template);
|
||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
||||
|
||||
VirtualNetwork fixed_vnet =
|
||||
VirtualNetwork second_vnet =
|
||||
new VirtualNetwork(Integer.parseInt(res.getMessage()), client);
|
||||
|
||||
res = fixed_vnet.rmLeases("130.10.0.1");
|
||||
res = second_vnet.rmAr(0);
|
||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
||||
|
||||
res = fixed_vnet.rmLeases("130.10.0.5");
|
||||
res = second_vnet.rmAr(0);
|
||||
assertTrue( res.isError() );
|
||||
|
||||
fixed_vnet.delete();
|
||||
second_vnet.delete();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void holdFixed()
|
||||
public void updateAr()
|
||||
{
|
||||
res = VirtualNetwork.allocate(client, fixed_template);
|
||||
String new_template =
|
||||
"AR = [ AR_ID = 0, ATT2 = NEW_VAL, ATT3 = VAL3 ]";
|
||||
|
||||
res = vnet.updateAr(new_template);
|
||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
||||
|
||||
VirtualNetwork fixed_vnet =
|
||||
new VirtualNetwork(Integer.parseInt(res.getMessage()), client);
|
||||
|
||||
res = fixed_vnet.hold("130.10.0.1");
|
||||
res = vnet.info();
|
||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
||||
|
||||
res = fixed_vnet.hold("130.10.0.5");
|
||||
assertTrue( res.isError() );
|
||||
|
||||
res = fixed_vnet.release("130.10.0.1");
|
||||
assertTrue( res.getErrorMessage(), !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();
|
||||
assertTrue( vnet.xpath("AR_POOL/AR[AR_ID=0]/ATT1").equals( "" ) );
|
||||
assertTrue( vnet.xpath("AR_POOL/AR[AR_ID=0]/ATT2").equals( "NEW_VAL" ) );
|
||||
assertTrue( vnet.xpath("AR_POOL/AR[AR_ID=0]/ATT3").equals( "VAL3" ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void holdRanged()
|
||||
public void hold()
|
||||
{
|
||||
res = vnet.hold("192.168.0.10");
|
||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
||||
|
||||
res = vnet.hold("192.168.0.11", 0);
|
||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
||||
|
||||
res = vnet.hold("192.168.100.1");
|
||||
assertTrue( res.isError() );
|
||||
|
||||
res = vnet.release("192.168.0.10");
|
||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
||||
|
||||
res = vnet.release("192.168.0.11", 0);
|
||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
||||
//*
|
||||
res = vnet.release("192.168.0.10");
|
||||
assertTrue( res.isError() );
|
||||
|
||||
res = vnet.release("192.168.100.1");
|
||||
assertTrue( res.isError() );
|
||||
|
||||
//*/
|
||||
vnet.delete();
|
||||
}
|
||||
|
||||
@@ -250,4 +228,6 @@ public class VirtualNetworkTest
|
||||
assertTrue( vnet.xpath("TEMPLATE/ATT3").equals( "VAL3" ) );
|
||||
}
|
||||
|
||||
// TODO: reserve, free
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user