Esempio n. 1
0
def terminate_resource(serialized_resource, serialized_user):
    resource = core_utils.deserialize_instance(serialized_resource)
    user = core_utils.deserialize_instance(serialized_user)
    view = views.ResourceViewSet.as_view({'post': 'terminate'})
    response = create_request(view, user, {}, uuid=resource.uuid.hex)

    if response.status_code != status.HTTP_200_OK:
        raise exceptions.ResourceTerminateException(response.rendered_content)
Esempio n. 2
0
def process_role_revoked(serialized_profile, serialized_structure):
    profile = core_utils.deserialize_instance(serialized_profile)
    structure = core_utils.deserialize_instance(serialized_structure)

    allocations = get_structure_allocations(structure)

    for allocation in allocations:
        allocation.get_backend().delete_user(allocation, profile.username)
Esempio n. 3
0
def update_remote_project_permissions(serialized_project,
                                      serialized_user,
                                      role,
                                      grant=True,
                                      expiration_time=None):
    project = deserialize_instance(serialized_project)
    user = deserialize_instance(serialized_user)
    new_expiration_time = (dateparse.parse_datetime(expiration_time)
                           if expiration_time else expiration_time)

    sync_project_permission(grant, project, role, user, new_expiration_time)
Esempio n. 4
0
def update_remote_customer_permissions(serialized_customer,
                                       serialized_user,
                                       role,
                                       grant=True,
                                       expiration_time=None):
    customer = deserialize_instance(serialized_customer)
    user = deserialize_instance(serialized_user)
    new_expiration_time = (dateparse.parse_datetime(expiration_time)
                           if expiration_time else expiration_time)

    for project in customer.projects.all():
        sync_project_permission(grant, project, role, user,
                                new_expiration_time)
Esempio n. 5
0
def update_referrable(serialized_referrable):
    referrable = core_utils.deserialize_instance(serialized_referrable)
    try:
        logger.debug('Updating referrals of a Referrable %s.' % referrable)
        get_datacite_info_helper(referrable)
    except Exception as e:
        logger.critical(e)
Esempio n. 6
0
def link_doi_with_collection(serialized_instance):
    instance = core_utils.deserialize_instance(serialized_instance)

    try:
        backend.DataciteBackend().link_doi_with_collection(instance)
    except exceptions.DataciteException as e:
        logger.critical(e)
Esempio n. 7
0
def submit_job(serialized_job):
    job = deserialize_instance(serialized_job)
    try:
        oauth_token = OAuthToken.objects.get(provider='keycloak', user=job.user)
    except OAuthToken.DoesNotExist:
        logger.debug('OAuth token for user %s is not found', job.user)
        job.state = Job.States.ERRED
        job.error_message = 'OAuth token is not found'
        job.save()
        return

    token = oauth_token.access_token
    if not token:
        logger.debug('Access token for user %s is not found', job.user)
        job.state = Job.States.ERRED
        job.error_message = 'Access token is not found'
        job.save()
        return

    api_url = job.service_settings.options.get('firecrest_api_url')
    if not api_url:
        logger.debug(
            'Service settings %s does not have Firecrest API URL', job.service_settings
        )
        job.state = Job.States.ERRED
        job.error_message = 'Service does not have Firecrest API URL'
        job.save()
        return

    try:
        utils.submit_job(api_url, token, job)
    except FirecrestException as e:
        job.state = Job.States.ERRED
        job.error_message = str(e)
        job.save()
Esempio n. 8
0
def send_change_email_notification(request_serialized):
    request = core_utils.deserialize_instance(request_serialized)
    link = core_utils.format_homeport_link('user_email_change/{code}/',
                                           code=request.uuid.hex)
    context = {'request': request, 'link': link}
    core_utils.broadcast_mail('structure', 'change_email_request', context,
                              [request.email])
Esempio n. 9
0
def create_report(serialized_report):
    report = deserialize_instance(serialized_report)

    today = datetime.datetime.today()
    timestamp = today.strftime('%Y%m%dT%H%M%S')
    archive_filename = 'waldur-logs-%s-%s.tar.gz' % (timestamp,
                                                     report.uuid.hex)

    try:
        cf = create_report_archive(
            settings.WALDUR_CORE['LOGGING_REPORT_DIRECTORY'],
            settings.WALDUR_CORE['LOGGING_REPORT_INTERVAL'],
        )
    except (tarfile.TarError, OSError, ValueError) as e:
        report.state = Report.States.ERRED
        error_message = 'Error message: %s. Traceback: %s' % (
            str(e),
            traceback.format_exc(),
        )
        report.error_message = error_message
        report.save()
    else:
        report.file.save(archive_filename, cf)
        report.file_size = cf.size
        report.state = Report.States.DONE
        report.save()
Esempio n. 10
0
    def execute(self, tenant, serialized_new_template, serialized_old_package,
                serialized_service_settings, *args, **kwargs):
        new_template = core_utils.deserialize_instance(serialized_new_template)
        old_package = core_utils.deserialize_instance(serialized_old_package)
        service_settings = core_utils.deserialize_instance(serialized_service_settings)

        with transaction.atomic():
            serializers._set_tenant_quotas(tenant, new_template)
            serializers._set_related_service_settings_quotas(tenant, new_template)
            serializers._set_tenant_extra_configuration(tenant, new_template)
            old_package.delete()
            models.OpenStackPackage.objects.create(
                template=new_template,
                service_settings=service_settings,
                tenant=tenant
            )
Esempio n. 11
0
def send_change_email_notification(request_serialized):
    request = core_utils.deserialize_instance(request_serialized)
    link = settings.WALDUR_CORE['EMAIL_CHANGE_URL'].format(
        code=request.uuid.hex)
    context = {'request': request, 'link': link}
    core_utils.broadcast_mail('structure', 'change_email_request', context,
                              [request.email])
Esempio n. 12
0
def send_issue_updated_notification(serialized_issue, changed):
    issue = core_utils.deserialize_instance(serialized_issue)

    _send_issue_notification(
        issue=issue,
        template='issue_updated',
        extra_context={'changed': changed},
    )
Esempio n. 13
0
 def execute(self, droplet, serialized_size, *args, **kwargs):
     size = utils.deserialize_instance(serialized_size)
     logger.info('Successfully resized droplet %s', droplet.uuid.hex)
     log.event_logger.droplet_resize.info(
         'Droplet {droplet_name} has been resized.',
         event_type='droplet_resize_succeeded',
         event_context={'droplet': droplet, 'size': size},
     )
Esempio n. 14
0
def send_comment_added_notification(serialized_comment):
    comment = core_utils.deserialize_instance(serialized_comment)

    _send_issue_notification(
        issue=comment.issue,
        template='comment_added',
        extra_context={'comment': comment},
    )
Esempio n. 15
0
 def run(self, serialized_instance):
     instance = core_utils.deserialize_instance(serialized_instance)
     try:
         self.pull(instance)
     except ServiceBackendError as e:
         self.on_pull_fail(instance, e)
     else:
         self.on_pull_success(instance)
Esempio n. 16
0
    def run(self, serialized_executor, serialized_model, serialized_project,
            *args, **kwargs):
        executor = core_utils.deserialize_class(serialized_executor)
        model_cls = core_utils.deserialize_class(serialized_model)
        project = core_utils.deserialize_instance(serialized_project)

        for resource in model_cls.objects.filter(project=project):
            executor.execute(resource, async=False, force=True, **kwargs)
Esempio n. 17
0
def send_comment_updated_notification(serialized_comment, old_description):
    comment = core_utils.deserialize_instance(serialized_comment)

    _send_issue_notification(
        issue=comment.issue,
        template='comment_updated',
        extra_context={'comment': comment, 'old_description': old_description,},
    )
Esempio n. 18
0
def detect_vm_coordinates(serialized_virtual_machine):

    try:
        vm = utils.deserialize_instance(serialized_virtual_machine)
    except exceptions.ObjectDoesNotExist:
        logger.warning('Missing virtual machine %s.',
                       serialized_virtual_machine)
        return

    geo_ip_utils.detect_coordinates(vm)
Esempio n. 19
0
def create_confirmation_comment(serialized_issue):
    issue = core_utils.deserialize_instance(serialized_issue)
    try:
        backend.get_active_backend().create_confirmation_comment(issue)
    except Exception as e:
        issue.error_message = str(e)
        issue.save(update_fields=['error_message'])
    else:
        issue.error_message = ''
        issue.save(update_fields=['error_message'])
Esempio n. 20
0
 def run(self, action_id, serialized_droplet):
     droplet = utils.deserialize_instance(serialized_droplet)
     backend = droplet.get_backend()
     action = backend.manager.get_action(action_id)
     if action.status == 'completed':
         backend_droplet = backend.get_droplet(droplet.backend_id)
         droplet.ip_address = backend_droplet.ip_address
         droplet.save(update_fields=['ip_address'])
         return True
     else:
         self.retry()
Esempio n. 21
0
def send_expert_comment_added_notification(serialized_comment):
    # Send Expert notifications
    comment = core_utils.deserialize_instance(serialized_comment)
    expert_request = comment.issue.expertrequest_set.first()
    expert_contract = getattr(expert_request, 'contract', None)

    if expert_contract:
        experts = expert_contract.team.get_users(structure_models.ProjectRole.ADMINISTRATOR)

        if comment.author.user not in experts:
            for expert in experts:
                _send_issue_notification(comment.issue, 'comment_added', receiver=expert)
Esempio n. 22
0
    def execute(self, tenant, event, new_package, old_package, service_settings, *args, **kwargs):
        service_settings = core_utils.deserialize_instance(service_settings)
        event_type = 'openstack_package_change_succeeded' if event == 'succeeded' else 'openstack_package_change_failed'

        event_logger.openstack_package.info(
            'Tenant package changing has %s. '
            'Old value: %s, new value: {package_template_name}' % (event, old_package),
            event_type=event_type,
            event_context={
                'tenant': tenant,
                'package_template_name': new_package,
                'service_settings': service_settings,
            })
Esempio n. 23
0
    def _get_issue_details(self, validated_data):
        issue_details = super(OfferingCreateSerializer,
                              self)._get_issue_details(validated_data)
        order_item_serialized = self.context['request'].data.get('order_item')

        if order_item_serialized:
            order_item = core_utils.deserialize_instance(order_item_serialized)
            issue_details['resource_object_id'] = order_item.id
            issue_details[
                'resource_content_type'] = ContentType.objects.get_for_model(
                    order_item)

        return issue_details
Esempio n. 24
0
def create_doi(serialized_instance):
    instance = core_utils.deserialize_instance(serialized_instance)

    if instance.datacite_doi:
        logger.warning(
            'Registration of %s has been skipped because datacite_doi field is not empty.'
            % instance)
        return

    try:
        backend.DataciteBackend().create_doi(instance)
    except exceptions.DataciteException as e:
        logger.critical(e)
Esempio n. 25
0
def send_issue_feedback_notification(serialized_issue):
    issue = core_utils.deserialize_instance(serialized_issue)
    signer = signing.TimestampSigner()
    token = signer.sign(issue.uuid.hex)
    extra_context = {
        'feedback_link':
        get_feedback_link(token),
        'feedback_links': [{
            'label': value,
            'link': get_feedback_link(token, key),
        } for (key, value) in models.Feedback.Evaluation.CHOICES],
    }
    _send_issue_feedback(
        issue=issue,
        template='issue_feedback',
        extra_context=extra_context,
    )
Esempio n. 26
0
    def run(self, serialized_instance, *args, **kwargs):
        """ Deserialize input data and start backend operation execution """
        try:
            instance = utils.deserialize_instance(serialized_instance)
        except ObjectDoesNotExist:
            raise ObjectDoesNotExist(
                'Cannot restore instance from serialized object %s. Probably it was deleted.'
                % serialized_instance)

        self.args = args
        self.kwargs = kwargs

        self.pre_execute(instance)
        result = self.execute(instance, *self.args, **self.kwargs)
        self.post_execute(instance)
        if result and isinstance(result, django_models.Model):
            result = utils.serialize_instance(result)
        return result
Esempio n. 27
0
def detect_vm_coordinates(serialized_virtual_machine):

    try:
        vm = core_utils.deserialize_instance(serialized_virtual_machine)
    except exceptions.ObjectDoesNotExist:
        logger.warning('Missing virtual machine %s.', serialized_virtual_machine)
        return

    try:
        coordinates = vm.detect_coordinates()
    except utils.GeoIpException as e:
        logger.warning('Unable to detect coordinates for virtual machines %s: %s.', serialized_virtual_machine, e)
        return

    if coordinates:
        vm.latitude = coordinates.latitude
        vm.longitude = coordinates.longitude
        vm.save(update_fields=['latitude', 'longitude'])
Esempio n. 28
0
def send_issue_feedback_notification(serialized_issue):
    issue = core_utils.deserialize_instance(serialized_issue)
    signer = signing.TimestampSigner()
    token = signer.sign(issue.uuid.hex)
    extra_context = {
        'feedback_links': [{
            'label':
            value,
            'link':
            settings.ISSUE_FEEDBACK_LINK_TEMPLATE.format(token=token,
                                                         evaluation=key),
        } for (key, value) in models.Feedback.Evaluation.CHOICES],
    }
    _send_issue_feedback(
        issue=issue,
        template='issue_feedback',
        extra_context=extra_context,
    )
Esempio n. 29
0
def create_invoice_pdf(serialized_invoice):
    invoice = core_utils.deserialize_instance(serialized_invoice)
    utils.create_invoice_pdf(invoice)
Esempio n. 30
0
def process_order(serialized_order, serialized_user):
    order = core_utils.deserialize_instance(serialized_order)
    user = core_utils.deserialize_instance(serialized_user)
    for item in order.items.all():
        process_order_item(item, user)