def _send_instance_email(driverCls, provider, identity, instance_id): try: logger.debug("_send_instance_email task started at %s." % datetime.now()) driver = get_driver(driverCls, provider, identity) instance = driver.get_instance(instance_id) #Breakout if instance has been deleted at this point if not instance: logger.debug("Instance has been teminated: %s." % instance_id) return username = identity.user.username profile = UserProfile.objects.get(user__username=username) if profile.send_emails: #Only send emails if allowed by profile setting created = datetime.strptime(instance.extra['created'], "%Y-%m-%dT%H:%M:%SZ") send_instance_email(username, instance.id, instance.name, instance.ip, created, username) else: logger.debug("User %s elected NOT to receive new instance emails" % username) logger.debug("_send_instance_email task finished at %s." % datetime.now()) except Exception as exc: logger.warn(exc) _send_instance_email.retry(exc=exc)
def _email_instance_owner(self, request, params): """ OLD API """ instance_token = params.get("token") username = params.get("userid") vm_info = params.get("vminfo") instance_name = params.get("name") instance = CoreInstance.objects.filter(provider_alias=vm_info["instance-id"]) error_list = [] if not instance: error_list.append("The token %s did not match a core instance." % instance_token) instance = CoreInstance.objects.filter(ip_address=request.META["REMOTE_ADDR"]) if not instance: error_list.append("The IP Address %s did not match a core instance." % request.META["REMOTE_ADDR"]) return failure_response(status.HTTP_404_NOT_FOUND, str(error_list)) instance = instance[0] ip_address = vm_info.get("public-ipv4", request.META.get("REMOTE_ADDR")) if ip_address: instance.ip_address = ip_address instance.save() launch_time = instance.start_date linuxusername = vm_info.get("linuxusername", instance.created_by) instance_id = vm_info.get("instance-id", instance.provider_alias) # Only send email if the provider isn't OpenStack. if instance.created_by_identity.provider.type.name != "OpenStack": send_instance_email(username, instance_id, instance_name, ip_address, launch_time, linuxusername)
def _email_instance_owner(self, request, params): ''' OLD API ''' instance_token = params.get('token') username = params.get('userid') vm_info = params.get('vminfo') instance_name = params.get('name') instance = CoreInstance.objects.filter( provider_alias=vm_info['instance-id']) error_list = [] if not instance: error_list.append("The token %s did not match a core instance." % instance_token) instance = CoreInstance.objects.filter( ip_address=request.META['REMOTE_ADDR']) if not instance: error_list.append( "The IP Address %s did not match a core instance." % request.META['REMOTE_ADDR']) return failure_response(status.HTTP_404_NOT_FOUND, str(error_list)) instance = instance[0] ip_address = vm_info.get('public-ipv4', request.META.get('REMOTE_ADDR')) if ip_address: instance.ip_address = ip_address instance.save() launch_time = instance.start_date linuxusername = vm_info.get('linuxusername', instance.created_by) instance_id = vm_info.get('instance-id', instance.provider_alias) # Only send email if the provider isn't OpenStack. if instance.created_by_identity.provider.type.name != "OpenStack": send_instance_email(username, instance_id, instance_name, ip_address, launch_time, linuxusername)
def _email_instance_owner(self, request, params): ''' OLD API ''' instance_token = params.get('token') username = params.get('userid') vm_info = params.get('vminfo', {}) instance_name = params.get('name') instance_id = vm_info.get('instance-id') instance = None if instance_id: instance = CoreInstance.objects.filter(provider_alias=instance_id) elif instance_token: instance = CoreInstance.objects.filter(token=instance_token) error_list = [] if not instance: error_list.append( "The token %s did not match a core instance." % instance_token ) instance = CoreInstance.objects.filter( ip_address=request.META['REMOTE_ADDR'] ) # TODO: AND filter no end_date if not instance: error_list.append( "The IP Address %s did not match a new core instance." % request.META['REMOTE_ADDR'] ) return failure_response(status.HTTP_404_NOT_FOUND, str(error_list)) # Get out of the filter instance = instance[0] ip_address = vm_info.get('public-ipv4', request.META.get('REMOTE_ADDR')) if ip_address: instance.ip_address = ip_address instance.save() launch_time = instance.start_date linuxusername = vm_info.get('linuxusername', instance.created_by) instance_id = vm_info.get('instance-id', instance.provider_alias) # Only send email if the provider isn't OpenStack. if instance.created_by_identity.provider.type.name != "OpenStack": send_instance_email( username, instance_id, instance_name, ip_address, launch_time, linuxusername )