| from datetime import datetime |
| from django.db.models import F, Q |
| from planetstack.config import Config |
| from ec2_observer.syncstep import SyncStep |
| from core.models.user import User |
| from core.models.site import * |
| from ec2_observer.awslib import * |
| from ec2_observer.creds import * |
| class SyncUsers(SyncStep): |
| def fetch_pending(self, deletion): |
| users = User.objects.filter(Q(enacted__lt=F('updated')) | Q(enacted=None)) |
| e = get_creds(user=u, site=u.site) |
| key_sig = aws_run('ec2 describe-key-pairs', env=e) |
| ec2_keys = key_sig['KeyPairs'] |
| for user,ec2_keys,e in zip(users,keys,creds): |
| key_name = user.email.lower().replace('@', 'AT').replace('.', '') |
| if (key['KeyName']==key_name): |
| aws_run('ec2 import-key-pair --key-name %s --public-key-material "%s"'%(key_name, user.public_key),env=e) |
| def sync_record(self, node): |