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

Bug #847 - #899: Add user and vnet update methods to Java OCA

This commit is contained in:
Carlos Martín 2011-10-17 17:20:20 +02:00
parent 64bd883283
commit c42364d9d9
4 changed files with 84 additions and 2 deletions

View File

@ -34,6 +34,7 @@ public class User extends PoolElement{
private static final String PASSWD = METHOD_PREFIX + "passwd";
private static final String CHGRP = METHOD_PREFIX + "chgrp";
private static final String CHAUTH = METHOD_PREFIX + "chauth";
private static final String UPDATE = METHOD_PREFIX + "update";
/**
* Creates a new User representation.
@ -157,6 +158,19 @@ public class User extends PoolElement{
return client.call(CHAUTH, id, auth);
}
/**
* Replaces the user template contents.
*
* @param client XML-RPC Client.
* @param id The user id of the target user we want to modify.
* @param new_template New template contents.
* @return If successful the message contains the user id.
*/
public static OneResponse update(Client client, int id, String new_template)
{
return client.call(UPDATE, id, new_template);
}
// =================================
// Instanced object XML-RPC methods
// =================================
@ -218,6 +232,17 @@ public class User extends PoolElement{
return chauth(client, id, auth);
}
/**
* Replaces the user template contents.
*
* @param new_template New template contents.
* @return If successful the message contains the user id.
*/
public OneResponse update(String new_template)
{
return update(client, id, new_template);
}
// =================================
// Helpers
// =================================

View File

@ -35,6 +35,7 @@ public class VirtualNetwork extends PoolElement{
private static final String ADDLEASES = METHOD_PREFIX + "addleases";
private static final String RMLEASES = METHOD_PREFIX + "rmleases";
private static final String CHOWN = METHOD_PREFIX + "chown";
private static final String UPDATE = METHOD_PREFIX + "update";
/**
@ -153,6 +154,19 @@ public class VirtualNetwork extends PoolElement{
return client.call(CHOWN, id, uid, gid);
}
/**
* Replaces the VirtualNetwork template contents.
*
* @param client XML-RPC Client.
* @param id The user id of the target vnet we want to modify.
* @param new_template New template contents.
* @return If successful the message contains the vnet id.
*/
public static OneResponse update(Client client, int id, String new_template)
{
return client.call(UPDATE, id, new_template);
}
// =================================
// Instanced object XML-RPC methods
// =================================
@ -291,6 +305,17 @@ public class VirtualNetwork extends PoolElement{
return chown(-1, gid);
}
/**
* Replaces the VirtualNetwork template contents.
*
* @param new_template New template contents.
* @return If successful the message contains the vnet id.
*/
public OneResponse update(String new_template)
{
return update(client, id, new_template);
}
// =================================
// Helpers
// =================================

View File

@ -94,7 +94,7 @@ public class UserTest
}
@Test
public void update()
public void info()
{
res = user.info();
assertTrue( res.getErrorMessage(), !res.isError() );
@ -129,6 +129,22 @@ public class UserTest
assertTrue( user.xpath("AUTH_DRIVER").equals("new_driver") );
}
@Test
public void update()
{
String new_template = "ATT2 = NEW_VAL\n" +
"ATT3 = VAL3";
res = user.update(new_template);
assertTrue( !res.isError() );
res = user.info();
assertTrue( !res.isError() );
assertTrue( user.xpath("TEMPLATE/ATT1").equals( "" ) );
assertTrue( user.xpath("TEMPLATE/ATT2").equals( "NEW_VAL" ) );
assertTrue( user.xpath("TEMPLATE/ATT3").equals( "VAL3" ) );
}
@Test
public void delete()
{

View File

@ -117,7 +117,7 @@ public class VirtualNetworkTest
}
@Test
public void update()
public void info()
{
res = vnet.info();
assertTrue( !res.isError() );
@ -208,4 +208,20 @@ public class VirtualNetworkTest
fixed_vnet.delete();
}
@Test
public void update()
{
String new_template = "ATT2 = NEW_VAL\n" +
"ATT3 = VAL3";
res = vnet.update(new_template);
assertTrue( !res.isError() );
res = vnet.info();
assertTrue( !res.isError() );
assertTrue( vnet.xpath("TEMPLATE/ATT1").equals( "" ) );
assertTrue( vnet.xpath("TEMPLATE/ATT2").equals( "NEW_VAL" ) );
assertTrue( vnet.xpath("TEMPLATE/ATT3").equals( "VAL3" ) );
}
}