Sapan Bhatia | 24836f1 | 2013-08-27 10:16:05 -0400 | [diff] [blame] | 1 | import os |
| 2 | import base64 |
| 3 | from planetstack.config import Config |
| 4 | |
| 5 | class SyncUsers(OpenStackSyncStep): |
| 6 | provides=[User] |
| 7 | def sync_record(self, user): |
| 8 | name = user.email[:user.email.find('@')] |
| 9 | user_fields = {'name': name, |
| 10 | 'email': user.email, |
| 11 | 'password': hashlib.md5(user.password).hexdigest()[:6], |
| 12 | 'enabled': True} |
| 13 | if not user.kuser_id: |
| 14 | keystone_user = self.driver.create_user(**user_fields) |
| 15 | user.kuser_id = keystone_user.id |
| 16 | else: |
| 17 | self.driver.update_user(user.kuser_id, user_fields) |
| 18 | |
| 19 | if user.site: |
| 20 | self.driver.add_user_role(user.kuser_id, user.site.tenant_id, 'user') |
| 21 | if user.is_admin: |
| 22 | self.driver.add_user_role(user.kuser_id, user.site.tenant_id, 'admin') |
| 23 | else: |
| 24 | # may have admin role so attempt to remove it |
| 25 | self.driver.delete_user_role(user.kuser_id, user.site.tenant_id, 'admin') |
| 26 | |
| 27 | if user.public_key: |
| 28 | self.init_caller(user, user.site.login_base) |
| 29 | self.save_key(user.public_key, user.keyname) |
| 30 | self.init_admin() |
| 31 | |
| 32 | user.save() |