blob: 3f509ef5c2229e3c44d794a76da60790e0199c92 [file] [log] [blame]
Sapan Bhatia24836f12013-08-27 10:16:05 -04001import os
2import base64
3from planetstack.config import Config
Sapan Bhatia04c94ad2013-09-02 18:00:28 -04004from observer.openstacksyncstep import OpenStackSyncStep
5from core.models.user import User
Sapan Bhatia24836f12013-08-27 10:16:05 -04006
7class SyncUsers(OpenStackSyncStep):
8 provides=[User]
Sapan Bhatia2ef36c82013-09-02 14:30:37 -04009 requested_interval=0
Sapan Bhatia24836f12013-08-27 10:16:05 -040010 def sync_record(self, user):
Sapan Bhatia04c94ad2013-09-02 18:00:28 -040011 name = user.email[:user.email.find('@')]
12 user_fields = {'name': name,
13 'email': user.email,
14 'password': hashlib.md5(user.password).hexdigest()[:6],
15 'enabled': True}
16 if not user.kuser_id:
17 keystone_user = self.driver.create_user(**user_fields)
18 user.kuser_id = keystone_user.id
19 else:
20 self.driver.update_user(user.kuser_id, user_fields)
Sapan Bhatia24836f12013-08-27 10:16:05 -040021
Sapan Bhatia04c94ad2013-09-02 18:00:28 -040022 if user.site:
23 self.driver.add_user_role(user.kuser_id, user.site.tenant_id, 'user')
24 if user.is_admin:
25 self.driver.add_user_role(user.kuser_id, user.site.tenant_id, 'admin')
26 else:
27 # may have admin role so attempt to remove it
28 self.driver.delete_user_role(user.kuser_id, user.site.tenant_id, 'admin')
Sapan Bhatia24836f12013-08-27 10:16:05 -040029
Sapan Bhatia04c94ad2013-09-02 18:00:28 -040030 if user.public_key:
31 self.init_caller(user, user.site.login_base)
32 self.save_key(user.public_key, user.keyname)
33 self.init_admin()
Sapan Bhatia24836f12013-08-27 10:16:05 -040034
Sapan Bhatia04c94ad2013-09-02 18:00:28 -040035 user.save()