|
Revision 4, 0.7 KB
(checked in by daedalus, 5 years ago)
|
|
Added initial code attempts
|
| Line | |
|---|
| 1 | from changeset import CommandChange |
|---|
| 2 | |
|---|
| 3 | class UnixAddUser(CommandChange): |
|---|
| 4 | """ |
|---|
| 5 | Add a user to a unix machine using the standard-ish useradd command. |
|---|
| 6 | """ |
|---|
| 7 | |
|---|
| 8 | def pre_apply_check(self, provisioner): |
|---|
| 9 | """ |
|---|
| 10 | Check that the user doesn't already exist. |
|---|
| 11 | """ |
|---|
| 12 | cmd = "grep %(username)s /etc/passwd" % self.namespace |
|---|
| 13 | (exitcode, stdout, stderr) = provisioner.run_command(cmd) |
|---|
| 14 | if exitcode == 0: |
|---|
| 15 | log.error("User already exists!") |
|---|
| 16 | return False |
|---|
| 17 | |
|---|
| 18 | return True |
|---|
| 19 | |
|---|
| 20 | def apply(self, provisioner): |
|---|
| 21 | """ |
|---|
| 22 | Add a user to the device. |
|---|
| 23 | """ |
|---|
| 24 | cmd = "useradd %(username)s" % self.namespace |
|---|
| 25 | return provisioner.run_command(cmd) |
|---|
| 26 | |
|---|