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

Feature : Polish a bit the chmod methods in Java OCA

This commit is contained in:
Carlos Martín 2012-01-11 12:20:18 +01:00
parent bd4df10204
commit d698d4fc63
7 changed files with 243 additions and 12 deletions

@ -157,7 +157,7 @@ public abstract class PoolElement {
}
/**
* Changes the template permissions
* Changes the permissions
*
* @param client XML-RPC Client.
* @param method XML-RPC method.

@ -192,6 +192,32 @@ public class Image extends PoolElement
other_u, other_m, other_a);
}
/**
* Changes the permissions
*
* @param client XML-RPC Client.
* @param id The id of the target object.
* @param octet Permissions octed , e.g. 640
* @return If an error occurs the error message contains the reason.
*/
public static OneResponse chmod(Client client, int id, String octet)
{
return chmod(client, CHMOD, id, octet);
}
/**
* Changes the permissions
*
* @param client XML-RPC Client.
* @param id The id of the target object.
* @param octet Permissions octed , e.g. 640
* @return If an error occurs the error message contains the reason.
*/
public static OneResponse chmod(Client client, int id, int octet)
{
return chmod(client, CHMOD, id, octet);
}
/**
* Changes the Image type
*
@ -317,6 +343,28 @@ public class Image extends PoolElement
return chown(client, id, uid, gid);
}
/**
* Changes the owner
*
* @param uid The new owner user ID.
* @return If an error occurs the error message contains the reason.
*/
public OneResponse chown(int uid)
{
return chown(uid, -1);
}
/**
* Changes the group
*
* @param gid The new group ID.
* @return If an error occurs the error message contains the reason.
*/
public OneResponse chgrp(int gid)
{
return chown(-1, gid);
}
/**
* Changes the Image permissions
*
@ -342,25 +390,25 @@ public class Image extends PoolElement
}
/**
* Changes the owner
*
* @param uid The new owner user ID.
* Changes the permissions
*
* @param octet Permissions octed , e.g. 640
* @return If an error occurs the error message contains the reason.
*/
public OneResponse chown(int uid)
public OneResponse chmod(String octet)
{
return chown(uid, -1);
return chmod(client, id, octet);
}
/**
* Changes the group
*
* @param gid The new group ID.
* Changes the permissions
*
* @param octet Permissions octed , e.g. 640
* @return If an error occurs the error message contains the reason.
*/
public OneResponse chgrp(int gid)
public OneResponse chmod(int octet)
{
return chown(-1, gid);
return chmod(client, id, octet);
}
/**

@ -166,6 +166,32 @@ public class Template extends PoolElement
other_u, other_m, other_a);
}
/**
* Changes the permissions
*
* @param client XML-RPC Client.
* @param id The id of the target object.
* @param octet Permissions octed , e.g. 640
* @return If an error occurs the error message contains the reason.
*/
public static OneResponse chmod(Client client, int id, String octet)
{
return chmod(client, CHMOD, id, octet);
}
/**
* Changes the permissions
*
* @param client XML-RPC Client.
* @param id The id of the target object.
* @param octet Permissions octed , e.g. 640
* @return If an error occurs the error message contains the reason.
*/
public static OneResponse chmod(Client client, int id, int octet)
{
return chmod(client, CHMOD, id, octet);
}
/**
* Creates a VM instance from a Template
*
@ -306,6 +332,28 @@ public class Template extends PoolElement
other_u, other_m, other_a);
}
/**
* Changes the permissions
*
* @param octet Permissions octed , e.g. 640
* @return If an error occurs the error message contains the reason.
*/
public OneResponse chmod(String octet)
{
return chmod(client, id, octet);
}
/**
* Changes the permissions
*
* @param octet Permissions octed , e.g. 640
* @return If an error occurs the error message contains the reason.
*/
public OneResponse chmod(int octet)
{
return chmod(client, id, octet);
}
/**
* Creates a VM instance from a Template
*

@ -241,6 +241,32 @@ public class VirtualMachine extends PoolElement{
other_u, other_m, other_a);
}
/**
* Changes the permissions
*
* @param client XML-RPC Client.
* @param id The id of the target object.
* @param octet Permissions octed , e.g. 640
* @return If an error occurs the error message contains the reason.
*/
public static OneResponse chmod(Client client, int id, String octet)
{
return chmod(client, CHMOD, id, octet);
}
/**
* Changes the permissions
*
* @param client XML-RPC Client.
* @param id The id of the target object.
* @param octet Permissions octed , e.g. 640
* @return If an error occurs the error message contains the reason.
*/
public static OneResponse chmod(Client client, int id, int octet)
{
return chmod(client, CHMOD, id, octet);
}
// =================================
// Instanced object XML-RPC methods
// =================================
@ -398,6 +424,28 @@ public class VirtualMachine extends PoolElement{
other_u, other_m, other_a);
}
/**
* Changes the permissions
*
* @param octet Permissions octed , e.g. 640
* @return If an error occurs the error message contains the reason.
*/
public OneResponse chmod(String octet)
{
return chmod(client, id, octet);
}
/**
* Changes the permissions
*
* @param octet Permissions octed , e.g. 640
* @return If an error occurs the error message contains the reason.
*/
public OneResponse chmod(int octet)
{
return chmod(client, id, octet);
}
// =================================
// Helpers
// =================================

@ -210,6 +210,32 @@ public class VirtualNetwork extends PoolElement{
other_u, other_m, other_a);
}
/**
* Changes the permissions
*
* @param client XML-RPC Client.
* @param id The id of the target object.
* @param octet Permissions octed , e.g. 640
* @return If an error occurs the error message contains the reason.
*/
public static OneResponse chmod(Client client, int id, String octet)
{
return chmod(client, CHMOD, id, octet);
}
/**
* Changes the permissions
*
* @param client XML-RPC Client.
* @param id The id of the target object.
* @param octet Permissions octed , e.g. 640
* @return If an error occurs the error message contains the reason.
*/
public static OneResponse chmod(Client client, int id, int octet)
{
return chmod(client, CHMOD, id, octet);
}
/**
* Replaces the VirtualNetwork template contents.
*
@ -409,6 +435,28 @@ public class VirtualNetwork extends PoolElement{
other_u, other_m, other_a);
}
/**
* Changes the permissions
*
* @param octet Permissions octed , e.g. 640
* @return If an error occurs the error message contains the reason.
*/
public OneResponse chmod(String octet)
{
return chmod(client, id, octet);
}
/**
* Changes the permissions
*
* @param octet Permissions octed , e.g. 640
* @return If an error occurs the error message contains the reason.
*/
public OneResponse chmod(int octet)
{
return chmod(client, id, octet);
}
/**
* Replaces the VirtualNetwork template contents.
*

@ -187,6 +187,45 @@ public class TemplateTest
assertTrue( template.xpath("PERMISSIONS/OTHER_M").equals("1") );
assertTrue( template.xpath("PERMISSIONS/OTHER_A").equals("0") );
}
@Test
public void chmod_octet()
{
res = template.info();
assertTrue( !res.isError() );
res = template.chmod(640);
assertTrue( !res.isError() );
res = template.info();
assertTrue( !res.isError() );
assertTrue( template.xpath("PERMISSIONS/OWNER_U").equals("1") );
assertTrue( template.xpath("PERMISSIONS/OWNER_M").equals("1") );
assertTrue( template.xpath("PERMISSIONS/OWNER_A").equals("0") );
assertTrue( template.xpath("PERMISSIONS/GROUP_U").equals("1") );
assertTrue( template.xpath("PERMISSIONS/GROUP_M").equals("0") );
assertTrue( template.xpath("PERMISSIONS/GROUP_A").equals("0") );
assertTrue( template.xpath("PERMISSIONS/OTHER_U").equals("0") );
assertTrue( template.xpath("PERMISSIONS/OTHER_M").equals("0") );
assertTrue( template.xpath("PERMISSIONS/OTHER_A").equals("0") );
res = template.chmod("147");
assertTrue( !res.isError() );
res = template.info();
assertTrue( !res.isError() );
assertTrue( template.xpath("PERMISSIONS/OWNER_U").equals("0") );
assertTrue( template.xpath("PERMISSIONS/OWNER_M").equals("0") );
assertTrue( template.xpath("PERMISSIONS/OWNER_A").equals("1") );
assertTrue( template.xpath("PERMISSIONS/GROUP_U").equals("1") );
assertTrue( template.xpath("PERMISSIONS/GROUP_M").equals("0") );
assertTrue( template.xpath("PERMISSIONS/GROUP_A").equals("0") );
assertTrue( template.xpath("PERMISSIONS/OTHER_U").equals("1") );
assertTrue( template.xpath("PERMISSIONS/OTHER_M").equals("1") );
assertTrue( template.xpath("PERMISSIONS/OTHER_A").equals("1") );
}
@Test
public void attributes()

@ -41,7 +41,7 @@ PID=$$
oned -f &
sleep 4s;
sleep 10s;
java -cp ../lib/*:../jar/*:$JUNIT_JAR:. org.junit.runner.JUnitCore $1