[node-patches] Change in ovirt-node[master]: edit-node: Support specify multiple users uid/gid elements c...

hadong0720 at gmail.com hadong0720 at gmail.com
Wed Nov 20 05:01:47 UTC 2013


hadong has uploaded a new change for review.

Change subject: edit-node: Support specify multiple users uid/gid elements changed
......................................................................

edit-node: Support specify multiple users uid/gid elements changed

Previously edit-node tools only support individual user uid/gid elements
changed.
Now multiple users can be specified by colon delimited list.(--uidmod=USER1,
UID1:USER2,UID2 or --gidmod=USERGROUP1,GID1:USERGROUP2,GID2)

Change-Id: I1cf2caa4dcc3af07eaa4b20b29e01fe2750b1806
Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=1032374
Signed-off-by: hadong <hadong0720 at gmail.com>
---
M tools/edit-node
1 file changed, 40 insertions(+), 37 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-node refs/changes/35/21435/1

diff --git a/tools/edit-node b/tools/edit-node
index 27d538a..5d60e68 100755
--- a/tools/edit-node
+++ b/tools/edit-node
@@ -673,45 +673,48 @@
         return True
 
     def _change_uid(self, options):
-        if "," in options.uidmod:
-            try:
-                user, new_uid = options.uidmod.split(",")
-            except:
-                print "Failed Parsing %s" % options.uidmod
-                return False
-            cmd = "id -u %s" % user
-            f = subprocess.Popen(cmd, shell=True, stdout=PIPE, stderr=STDOUT,
-                                 preexec_fn=self._chroot)
-            old_uid, err = f.communicate()
-            cmd = "usermod -u %s %s" % (new_uid, user)
-            f = subprocess.Popen(cmd, shell=True, stdout=PIPE, stderr=STDOUT,
-                                 preexec_fn=self._chroot)
-            output, err = f.communicate()
-            cmd = "find / -uid %s -exec chown %s {} \;" % (old_uid, new_uid)
-            f = subprocess.Popen(cmd, shell=True, stdout=PIPE, stderr=STDOUT,
-                                 preexec_fn=self._chroot)
-            output, err = f.communicate()
+        for key in options.uidmod.split(":"):
+            if "," in key:
+                try:
+                    user, new_uid = key.split(",")
+                except:
+                    print "Failed Parsing %s" % key
+                    return False
+                cmd = "id -u %s" % user
+                f = subprocess.Popen(cmd, shell=True, stdout=PIPE,
+                                     stderr=STDOUT, preexec_fn=self._chroot)
+                old_uid, err = f.communicate()
+                cmd = "usermod -u %s %s" % (new_uid, user)
+                f = subprocess.Popen(cmd, shell=True, stdout=PIPE,
+                                     stderr=STDOUT, preexec_fn=self._chroot)
+                output, err = f.communicate()
+                cmd = "find / -uid %s -exec chown %s {} \;" % \
+                    (old_uid, new_uid)
+                f = subprocess.Popen(cmd, shell=True, stdout=PIPE,
+                                     stderr=STDOUT, preexec_fn=self._chroot)
+                output, err = f.communicate()
 
     def _change_gid(self, options):
-        if "," in options.gidmod:
-            try:
-                group, new_gid = options.gidmod.split(",")
-            except:
-                print "Failed Parsing %s" % options.gidmod
-                return False
-            cmd = "getent group %s | cut -d: -f3" % group
-            f = subprocess.Popen(cmd, shell=True, stdout=PIPE, stderr=STDOUT,
-                                 preexec_fn=self._chroot)
-            old_gid, err = f.communicate()
-            cmd = "groupmod -g %s %s" % (new_gid, group)
-            f = subprocess.Popen(cmd, shell=True, stdout=PIPE, stderr=STDOUT,
-                                 preexec_fn=self._chroot)
-            output, err = f.communicate()
-            cmd = "find / -gid %s -exec chgrp %s {} \;" % \
-                (old_gid.strip(), new_gid)
-            f = subprocess.Popen(cmd, shell=True, stdout=PIPE, stderr=STDOUT,
-                                 preexec_fn=self._chroot)
-            output, err = f.communicate()
+        for key in options.gidmod.split(":"):
+            if "," in key:
+                try:
+                    group, new_gid = key.split(",")
+                except:
+                    print "Failed Parsing %s" % key
+                    return False
+                cmd = "getent group %s | cut -d: -f3" % group
+                f = subprocess.Popen(cmd, shell=True, stdout=PIPE,
+                                     stderr=STDOUT, preexec_fn=self._chroot)
+                old_gid, err = f.communicate()
+                cmd = "groupmod -g %s %s" % (new_gid, group)
+                f = subprocess.Popen(cmd, shell=True, stdout=PIPE,
+                                     stderr=STDOUT, preexec_fn=self._chroot)
+                output, err = f.communicate()
+                cmd = "find / -gid %s -exec chgrp %s {} \;" % \
+                    (old_gid.strip(), new_gid)
+                f = subprocess.Popen(cmd, shell=True, stdout=PIPE,
+                                     stderr=STDOUT, preexec_fn=self._chroot)
+                output, err = f.communicate()
 
     def _print_rpm_manifest(self):
         cmd = "rpm -qa|sort"


-- 
To view, visit http://gerrit.ovirt.org/21435
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I1cf2caa4dcc3af07eaa4b20b29e01fe2750b1806
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-node
Gerrit-Branch: master
Gerrit-Owner: hadong <hadong0720 at gmail.com>



More information about the node-patches mailing list