Reviewed-by: Rodrigo Trujillo <rodrigo.trujillo(a)linux.vnet.ibm.com>
On 04/17/2014 06:04 PM, Aline Manera wrote:
From: Aline Manera <alinefm(a)br.ibm.com>
Signed-off-by: Aline Manera <alinefm(a)br.ibm.com>
---
src/kimchi/control/host.py | 14 +++++++++++++-
src/kimchi/mockmodel.py | 6 ++++++
src/kimchi/model/host.py | 18 ++++++++++++++++++
3 files changed, 37 insertions(+), 1 deletion(-)
diff --git a/src/kimchi/control/host.py b/src/kimchi/control/host.py
index a0818c7..003c4b9 100644
--- a/src/kimchi/control/host.py
+++ b/src/kimchi/control/host.py
@@ -19,7 +19,7 @@
import cherrypy
-from kimchi.control.base import Collection, Resource
+from kimchi.control.base import Collection, Resource, SimpleCollection
from kimchi.control.utils import UrlSubNode, validate_method
from kimchi.exception import OperationFailed
from kimchi.template import render
@@ -37,6 +37,8 @@ class Host(Resource):
self.devices = Devices(self.model)
self.packagesupdate = PackagesUpdate(self.model)
self.repositories = Repositories(self.model)
+ self.users = Users(self.model)
+ self.groups = Groups(self.model)
@cherrypy.expose
def swupdate(self):
@@ -128,3 +130,13 @@ class Repository(Resource):
@property
def data(self):
return self.info
+
+
+class Users(SimpleCollection):
+ def __init__(self, model):
+ super(Users, self).__init__(model)
+
+
+class Groups(SimpleCollection):
+ def __init__(self, model):
+ super(Groups, self).__init__(model)
diff --git a/src/kimchi/mockmodel.py b/src/kimchi/mockmodel.py
index 8c7d7bb..b235e1e 100644
--- a/src/kimchi/mockmodel.py
+++ b/src/kimchi/mockmodel.py
@@ -798,6 +798,12 @@ class MockModel(object):
'net_recv_rate': round(random.uniform(0, 4000), 1),
'net_sent_rate': round(random.uniform(0, 4000), 1)}
+ def users_get_list(self):
+ return ["userA", "userB", "userC"]
+
+ def groups_get_list(self):
+ return ["groupA", "groupB", "groupC",
"groupD"]
+
def vms_get_list_by_state(self, state):
ret_list = []
for name in self.vms_get_list():
diff --git a/src/kimchi/model/host.py b/src/kimchi/model/host.py
index 7b151f2..e0ac760 100644
--- a/src/kimchi/model/host.py
+++ b/src/kimchi/model/host.py
@@ -17,9 +17,11 @@
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+import grp
import os
import time
import platform
+import pwd
from collections import defaultdict
import psutil
@@ -364,3 +366,19 @@ class RepositoryModel(object):
raise InvalidOperation('KCHREPOS0014E')
return self._repositories.removeRepository(repo_id)
+
+
+class UsersModel(object):
+ def __init__(self, **kargs):
+ pass
+
+ def get_list(self):
+ return [user.pw_name for user in pwd.getpwall()]
+
+
+class GroupsModel(object):
+ def __init__(self, **kargs):
+ pass
+
+ def get_list(self):
+ return [group.gr_name for group in grp.getgrall()]