Beispiel #1
0
    def copy(self, request, *args, **kwargs):
        image = self.get_object()
        data = get_request_data(request)
        pool = CephPool.objects.get(id=data['pool'])

        logger.info("rbd copy from: %s to: %s/%s", image.id, pool.name,
                    data['name'])
        order = None
        obj_size = data.get('obj_size', None)
        if obj_size is not None and obj_size > 0:
            order = int(round(math.log(float(obj_size), 2)))

        data_pool = data.get('data_pool', None)
        if data_pool:
            data_pool_name = CephPool.objects.get(id=data_pool).name
        else:
            data_pool_name = None
        task = ceph.tasks.copy_rbd.delay(image.pool.cluster.fsid,
                                         image.pool.name, image.name,
                                         pool.name, data['name'],
                                         data.get('features', []), order,
                                         data.get('stripe_count', None),
                                         data.get('stripe_unit',
                                                  None), data_pool_name)
        return Response({'task_id': task.id}, status=status.HTTP_200_OK)
Beispiel #2
0
    def update(self, request, partial=False, *args, **kwargs):
        self.object = self.get_object()
        req_user = request.user

        if self.object == req_user or req_user.is_superuser:
            data = get_request_data(request)

            serializer = self.get_serializer(self.object,
                                             data=data,
                                             partial=partial)
            if not serializer.is_valid():
                return Response(serializer.errors,
                                status=status.HTTP_400_BAD_REQUEST)

            if 'password' in data:
                self.object.set_password(data['password'])
            self.object = serializer.save()

            return Response(serializer.data, status=status.HTTP_200_OK)

        return Response(
            {
                'detail':
                'Administrator privileges are required for updating the data of user {}.'
                .format(self.object.username)
            },
            status=status.HTTP_403_FORBIDDEN)
Beispiel #3
0
 def scrub(self, request, *args, **kwargs):
     deep_scrub = get_request_data(request).get('deep-scrub', False)
     res = {
         'command': "deep-scrub" if deep_scrub else "scrub",
         'result': self.get_object().scrub(deep_scrub=deep_scrub)
     }
     return Response(res, status=status.HTTP_200_OK)
Beispiel #4
0
    def create(self, request, *args, **kwargs):
        user_data = get_request_data(request)
        user = User.objects.create_user(username=user_data["username"],
                                        email=user_data["email"],
                                        password=user_data["password"])
        user.first_name = user_data["first_name"]
        user.last_name = user_data["last_name"]
        user.is_active = user_data["is_active"]
        user.is_superuser = user_data["is_superuser"]
        user.is_staff = user_data["is_staff"]
        user.save()
        permsidlist = user_data['user_permissions']

        user = User.objects.get(username=user_data["username"])
        if permsidlist != '':
            try:
                for x in permsidlist:
                    g = Group.objects.get(name=x)
                    user.groups.add(g)
            except:
                user_ret = UserSerializer(user, context={"request": request})
                return Response(user_ret.data,
                                status=status.HTTP_415_UNSUPPORTED_MEDIA_TYPE)
            else:
                user_ret = UserSerializer(user, context={"request": request})
                return Response(user_ret.data, status=status.HTTP_201_CREATED)
        else:
            user_ret = UserSerializer(user, context={"request": request})
            return Response(user_ret.data, status=status.HTTP_201_CREATED)
Beispiel #5
0
    def create(self, request, *args, **kwargs):
        profile, _ = UserProfile.objects.get_or_create(user=request.user)

        for key, value in get_request_data(request).items():
            profile[key] = value

        profile_ser = self.get_serializer(profile, many=False)
        return Response(profile_ser.data, status=status.HTTP_201_CREATED)
Beispiel #6
0
 def test_task(self, request, *args, **kwargs):
     if not settings.DEBUG:
         return Response(status=status.HTTP_404_NOT_FOUND)
     from taskqueue.tests import wait
     times = get_request_data(request)['times']
     task = wait.delay(times)
     serializer = self.get_serializer(task)
     return Response(serializer.data, status=status.HTTP_200_OK)
Beispiel #7
0
 def post(self, request):
     if request.method == 'POST':
         osd = get_request_data(request)
         osdname = osd["name"].encode('utf-8')
         hostname = osd["hostname"].encode('utf-8')
         exec_diskroam.execa(osdname, hostname)
         return HttpResponse(status=200)
     else:
         return HttpResponse(status=404)
         pass
Beispiel #8
0
    def post(self, request):
        data = get_request_data(request)
        deepsea = data['deepsea']
        Settings.SALT_API_HOST = deepsea['host']
        Settings.SALT_API_PORT = deepsea['port']
        Settings.SALT_API_EAUTH = deepsea['eauth']
        Settings.SALT_API_USERNAME = deepsea['username']
        Settings.SALT_API_PASSWORD = deepsea['password']
        Settings.SALT_API_SHARED_SECRET = deepsea['shared_secret']

        rgw = data['rgw']
        if not rgw['managed_by_deepsea']:
            Settings.RGW_API_HOST = rgw['host']
            Settings.RGW_API_PORT = rgw['port']
            Settings.RGW_API_ACCESS_KEY = rgw['access_key']
            Settings.RGW_API_SECRET_KEY = rgw['secret_key']
            Settings.RGW_API_ADMIN_RESOURCE = rgw['admin_path']
            Settings.RGW_API_USER_ID = rgw['user_id']
            Settings.RGW_API_SCHEME = 'https' if rgw['use_ssl'] else 'http'
        else:
            Settings.RGW_API_HOST = ''
            Settings.RGW_API_USER_ID = ''
            Settings.RGW_API_ACCESS_KEY = ''
            Settings.RGW_API_SECRET_KEY = ''

        grafana = data['grafana']
        Settings.GRAFANA_API_HOST = grafana['host']
        Settings.GRAFANA_API_PORT = grafana['port']
        Settings.GRAFANA_API_USERNAME = grafana['username']
        Settings.GRAFANA_API_PASSWORD = grafana['password']
        Settings.GRAFANA_API_SCHEME = 'https' if grafana['use_ssl'] else 'http'

        save_settings()

        if 'ceph' in data:
            serializers = []
            for index, cluster_data in enumerate(data['ceph']):
                if not 'fsid' in cluster_data:
                    raise ValidationError(
                        'No fsid in cluster {}'.format(index + 1))
                orig_cluster = CephCluster.objects.get(
                    fsid=cluster_data['fsid'])

                serializer = CephClusterSettingsSerializer(orig_cluster,
                                                           cluster_data,
                                                           partial=True)
                if not serializer.is_valid():
                    raise ValidationError(serializer.errors)
                serializers.append(serializer)

            for serializer in serializers:  # new loop to raise all errors before saving
                serializer.object.save(update_fields=('keyring_file_path',
                                                      'keyring_user'))

        return Response({'success': True})
Beispiel #9
0
    def snapshots(self, request, *args, **kwargs):
        """
        If you are wondering, why you don't get an error, if a snapshot already exists:
        http://tracker.ceph.com/projects/ceph/repository/revisions/43d62c00c99f1cd311d44b0b0c272e6d67685256/diff/src/m
           on/OSDMonitor.cc

        :type request: Request
        """
        pool = CephPool.objects.get(pk=kwargs['pk'])
        if request.method == 'GET':
            return Response(pool.pool_snaps, status=status.HTTP_200_OK)
        elif request.method == 'POST':
            pool.create_snapshot(get_request_data(request)['name'])
            return Response(CephPool.objects.get(pk=kwargs['pk']).pool_snaps,
                            status=status.HTTP_201_CREATED)
        elif request.method == 'DELETE':
            pool.delete_snapshot(get_request_data(request)['name'])
            return Response(CephPool.objects.get(pk=kwargs['pk']).pool_snaps,
                            status=status.HTTP_200_OK)
        else:
            raise ValueError('{}. Method not allowed.'.format(request.method))
    def _do_scrub(self, request, object_list):
        deep_scrub = get_request_data(request).get('deep-scrub', False)
        if not object_list:
            logger.info('scrub triggered without minions')
        results = []
        for minion in object_list:
            results.append(minion.scrub(deep_scrub=deep_scrub))

        res = {
            'command': "deep-scrub" if deep_scrub else "scrub",
            'result': aggregate_dict(*results)
        }
        return Response(res, status=status.HTTP_200_OK)
Beispiel #11
0
    def create(self, request, *args, **kwargs):
        user_data = get_request_data(request)
        user = User.objects.create_user(user_data["username"],
                                        user_data["email"],
                                        user_data["password"])
        user.first_name = user_data["first_name"]
        user.last_name = user_data["last_name"]
        user.is_active = user_data["is_active"]
        user.is_superuser = user_data["is_superuser"]
        user.is_staff = user_data["is_staff"]
        user.save()

        user_ret = UserSerializer(user, context={"request": request})
        return Response(user_ret.data, status=status.HTTP_201_CREATED)
Beispiel #12
0
    def destroy(self, request, *args, **kwargs):
        profile = self.get_object()

        if profile.user != request.user:
            return Response({'detail': 'You are not allowed to delete preferences of other users'},
                            status=status.HTTP_401_UNAUTHORIZED)

        settings = get_request_data(request)["settings"]

        for setting in settings:
            try:
                del profile[setting]
            except:
                pass

        return Response(status=status.HTTP_204_NO_CONTENT)
Beispiel #13
0
    def update(self, request, partial=False, *args, **kwargs):
        self.object = self.get_object()
        req_user = request.user

        if self.object == req_user or req_user.is_superuser:
            data = get_request_data(request)
            if 'user_permissions' in data:
                user = User.objects.get(username=self.object)
                if req_user.is_superuser:
                    if len(data['user_permissions']) == 0:
                        user.groups.clear()
                    else:
                        user.groups.clear()
                        for x in data['user_permissions']:
                            g = Group.objects.get(name=x)
                            user.groups.add(g)
                    pers = list(user.get_all_permissions())
                    data['user_permissions'] = {'user_permissions': pers}
                else:
                    pass

            serializer = self.get_serializer(self.object,
                                             data=data,
                                             partial=partial)
            if not serializer.is_valid():
                return Response(serializer.errors,
                                status=status.HTTP_400_BAD_REQUEST)

            if 'password' in data:
                self.object.set_password(data['password'])
            self.object = serializer.save()

            return Response(serializer.data, status=status.HTTP_200_OK)

        return Response(
            {
                'detail':
                'Administrator privileges are required for updating the data of user {}.'
                .format(self.object.username)
            },
            status=status.HTTP_403_FORBIDDEN)