Beispiel #1
0
 def create_options(self, request):
     client = self.request.user.clients.filter(
         services__openstack_project__isnull=False).first()
     if not client:
         raise APIConflict(_('No client with an OpenStack project found'))
     selected_region, regions = get_regions(request, for_end_user=True)
     external_networks = [{
         'name': net.name,
         'id': net.id,
         'region': net.region
     } for net in Network.objects.get_networks_for_project(
         project_id=client.first_project.project_id, external=True).filter(
             router_external=True)]
     return Response({
         'regions':
         regions,
         'external_networks':
         external_networks,
         'selected_region':
         selected_region,
         'can_create_resource':
         check_if_enough_credit(
             client=self.request.user.clients.all().first(),
             update_uptodate_credit=False,
         ),
     })
Beispiel #2
0
    def create_options(self, request):
        client = request.user.clients.filter(
            services__openstack_project__isnull=False).first()
        if client is None:
            raise APIConflict(
                detail=_('No client with an Openstack project found'))
        networks = Network.objects.get_external_networks(
            project_id=client.first_project.project_id,
            subnet_count=True).filter(subnet_count__gt=0)

        fnets = [{
            'id': network.id,
            'name': network.name,
            'region': network.region,
            'description': network.description
        } for network in networks]

        return Response({
            'networks':
            fnets,
            'can_create_resource':
            check_if_enough_credit(
                client=self.request.user.clients.all().first(),
                update_uptodate_credit=False,
            ),
        })
Beispiel #3
0
 def create_options(self, request, *args, **kwargs):
     selected_region, regions = get_regions(request, for_end_user=True)
     return Response({
         'regions':
         regions,
         'selected_region':
         selected_region,
         'can_create_resource':
         check_if_enough_credit(
             client=self.request.user.clients.all().first(),
             update_uptodate_credit=False,
         ),
     })
Beispiel #4
0
 def create_options(self, request):
     selected_region, regions = get_regions(request, for_end_user=True)
     return Response({
         'regions':
         RegionSerializer(instance=regions, many=True).data,
         'selected_region':
         selected_region,
         'can_create_resource':
         check_if_enough_credit(
             client=self.request.user.clients.all().first(),
             update_uptodate_credit=False,
         )
     })
Beispiel #5
0
 def has_permission(self, request, view):
     credit_required = _(
         'Unable to perform this action. Your account credit is too low')
     client = request.user.clients.first()
     if client and hasattr(client, 'client_billing'):
         if view.action in ('create', 'rebuild', 'rescue', 'resize',
                            'create_snapshot', 'reset_state', 'extend',
                            'get_generated_key_pair', 'create_backup'):
             if not check_if_enough_credit(client=client,
                                           update_uptodate_credit=True):
                 self.message = credit_required
                 return False
     return True
Beispiel #6
0
 def create_options(self, request):
     selected_region, regions = get_regions(request, for_end_user=True)
     client = request.user.clients.first()
     openstack_settings = OpenstackSettings.for_client(
         client=client) if client else None
     create_options = {
         'regions':
         regions,
         'container_formats':
         [x for (x, y) in Image.IMAGE_CONTAINER_FORMAT],
         'disk_formats': [x for (x, y) in Image.IMAGE_DISK_FORMAT],
         'visibilities':
         OpenStackImageVisibility.get_user_choices(),
         'os_distros': [x for (x, y) in settings.OS_TYPES],
         'selected_region':
         selected_region,
         'hypervisor_types': [x for x in settings.OS_HYPERVISOR_TYPES],
         'statuses':
         statuses_dict_to_statuses_choices(Image.IMAGE_STATUS),
         'cleanup_enabled':
         openstack_settings.auto_cleanup_images
         if openstack_settings else False,
         'cleanup_days':
         openstack_settings.auto_cleanup_number_of_days
         if openstack_settings else False,
         'cleanup_formats':
         openstack_settings.auto_cleanup_image_types
         if openstack_settings else None,
         'allowed_formats':
         getattr(django_settings, 'OS_IMAGE_UPLOAD_FORMATS', []),
         'can_create_resource':
         check_if_enough_credit(
             client=self.request.user.clients.all().first(),
             update_uptodate_credit=False,
         ),
     }
     return Response(create_options)
Beispiel #7
0
    def create_options(self, request, *args, **kwargs):
        client = self.request.user.clients.filter(
            services__openstack_project__isnull=False).first()
        if client is None:
            raise APIConflict(detail=_(
                'No client with an OpenStack project associated found'))
        db_project = client.first_project
        conf = OSConfig()
        volume_size_increments = conf.volume_size_increments
        selected_region, regions = get_regions(request,
                                               filter_for='volumes',
                                               for_end_user=True)

        # get volume types
        volume_types = []
        for volume_type in VolumeType.objects.public().filter(
                region=selected_region):
            type_display = volume_type.description if volume_type.description else volume_type.name
            volume_types.append({
                'name':
                volume_type.name,
                'type_display':
                type_display,
                'sizeIncrement':
                self.get_size_increment(volume_size_increments,
                                        volume_type.name, selected_region)
            })

        available_images = Image.objects.get_images_for_project(
            project_id=db_project.project_id)
        available_images = available_images.filter(
            region=selected_region).distinct()

        # filter for reseller
        available_images = available_images.exclude(
            Q(visibility__in=[
                OpenStackImageVisibility.PUBLIC,
                OpenStackImageVisibility.COMMUNITY
            ]) & ~Q(reseller_resources=client.reseller_resources))

        available_volumes = Volume.objects.filter(
            project__service__client=client, region=selected_region)
        available_volumes = available_volumes.values('id', 'name', 'region')

        volume_sources = {
            'image':
            available_images.values('id', 'name', 'type', 'region',
                                    'min_disk'),
            'volume':
            available_volumes
        }

        return Response({
            'types':
            volume_types,
            'regions':
            regions,
            'sources':
            volume_sources,
            'selected_region':
            selected_region,
            'can_create_resource':
            check_if_enough_credit(
                client=self.request.user.clients.all().first(),
                update_uptodate_credit=False,
            ),
        })