コード例 #1
0
 def delete(self, request, *args, **kwargs):
     token = request.auth
     if token:
         key = token.key
         token.delete()
         return base.Response("Token {} removed.".format(key), 204).resp
     raise excepts.ParseError("Token not found.")
コード例 #2
0
 def modules(self, request):
     detailed = int(request.query_params.get("detailed", "0"))
     fields = request.query_params.get("fields", "")
     _mods = utils.AnsibleModules(detailed, fields).get(
         request.query_params.get("filter", "")
     )
     return base.Response(_mods, 200).resp
コード例 #3
0
 def user_settings(self, request, *args, **kwargs):
     obj = self.get_object()
     method = request.method
     if method != "GET":
         obj.settings.data = request.data if method == "POST" else {}
         obj.settings.save()
     return base.Response(obj.settings.data, 200).resp
コード例 #4
0
 def cancel(self, request, *args, **kwargs):
     '''
     Cencel working task.
     '''
     obj = self.get_object()
     exch = KVExchanger(utils.CmdExecutor.CANCEL_PREFIX + str(obj.id))
     exch.send(True, 60) if obj.working else None
     return base.Response("Task canceled: {}".format(obj.id), status.HTTP_200_OK).resp
コード例 #5
0
 def use_it(self, request, *args, **kwargs):
     '''
     Create project based on this template.
     '''
     serializer = self.get_serializer(self.get_object(), data=request.data)
     serializer.is_valid(raise_exception=True)
     serializer.save()
     return base.Response(serializer.data, status=status.HTTP_201_CREATED).resp
コード例 #6
0
ファイル: views.py プロジェクト: hummermania/polemarch
 def clear(self, request, *args, **kwargs):
     default_message = "Output trancated.\n"
     obj = self.get_object()
     if obj.status in ["RUN", "DELAY"] or obj.raw_stdout == default_message:
         raise excepts.NotAcceptable("Job is running or already trancated")
     obj.raw_stdout = default_message
     result = self.get_serializer(obj).get_raw(request)
     return base.Response(result, 204).resp
コード例 #7
0
    def import_inventory(self, request, **kwargs):
        # pylint: disable=no-member
        serializer = self.get_serializer(data=request.data)
        serializer.is_valid(True)
        instance = serializer.save()
        if hasattr(self, 'nested_manager'):
            self.nested_manager.add(instance)

        return base.Response(serializer.data, status.HTTP_201_CREATED).resp
コード例 #8
0
ファイル: views.py プロジェクト: xtha/polemarch
 def import_inventory(self, request, **kwargs):
     serializer = sers.InventoryImportSerializer(data=request.data)
     serializer.is_valid(True)
     serializer.save()
     if hasattr(self, 'nested_manager'):
         data = {self.lookup_field: serializer.data['inventory_id']}
         self._data_create(self.prepare_request_data(data, False),
                           self.lookup_field)
     return base.Response(serializer.data, status.HTTP_201_CREATED).resp
コード例 #9
0
 def user_settings(self, request, *args, **kwargs):
     '''
     Return user settings.
     '''
     obj = self.get_object()
     method = request.method
     if method != "GET":
         obj.settings.data = request.data if method == "POST" else {}
         obj.settings.save()
     return base.Response(obj.settings.data, status.HTTP_200_OK).resp
コード例 #10
0
 def set_owner(self, request, **kwargs):
     # pylint: disable=unused-argument
     '''
     Change instance owner.
     '''
     serializer = sers.SetOwnerSerializer(
         self.get_object(), data=request.data, context=self.get_serializer_context()
     )
     serializer.is_valid(True)
     serializer.save()
     return base.Response(serializer.data, status.HTTP_201_CREATED).resp
コード例 #11
0
 def list(self, request, *args, **kwargs):
     # pylint: disable=unused-argument
     stats = OrderedDict()
     stats['projects'] = self._get_count_by_user(sers.models.Project)
     stats['templates'] = self._get_count_by_user(sers.models.Template)
     stats['inventories'] = self._get_count_by_user(sers.models.Inventory)
     stats['groups'] = self._get_count_by_user(sers.models.Group)
     stats['hosts'] = self._get_count_by_user(sers.models.Host)
     stats['teams'] = self._get_count_by_user(sers.models.UserGroup)
     stats['users'] = self._get_count_by_user(sers.User)
     stats['jobs'] = self._get_history_stats(request)
     return base.Response(stats, status.HTTP_200_OK).resp
コード例 #12
0
 def list(self, request, *args, **kwargs):
     # pylint: disable=unused-argument
     stats = OrderedDict(
         projects=self._get_count_by_user(serializers.models.Project),
         templates=self._get_count_by_user(serializers.models.Template),
         inventories=self._get_count_by_user(serializers.models.Inventory),
         groups=self._get_count_by_user(serializers.models.Group),
         hosts=self._get_count_by_user(serializers.models.Host),
         teams=self._get_count_by_user(serializers.models.UserGroup),
         users=self._get_count_by_user(serializers.User),
     )
     stats['jobs'] = self._get_history_stats(request)
     return base.Response(stats, 200).resp
コード例 #13
0
ファイル: hosts.py プロジェクト: Lesiuk/vstutils
 def test2(self, request, *args, **kwargs):
     """ test description """
     obj = self.get_object()
     assert hasattr(obj, 'filter_applied')
     return base.Response("OK", 201).resp
コード例 #14
0
 def cancel(self, request, *args, **kwargs):
     obj = self.get_object()
     exch = KVExchanger(utils.CmdExecutor.CANCEL_PREFIX + str(obj.id))
     exch.send(True, 10)
     return base.Response("Task canceled: {}".format(obj.id), 200).resp
コード例 #15
0
 def facts(self, request, *args, **kwargs):
     objs = self.get_serializer(self.get_object()).get_facts(request)
     return base.Response(objs, 200).resp
コード例 #16
0
 def facts(self, request, *args, **kwargs):
     '''
     Get compilated history facts (only for execution 'module' with module 'setup').
     '''
     objs = self.get_serializer(self.get_object()).get_facts(request)
     return base.Response(objs, status.HTTP_200_OK).resp
コード例 #17
0
 def supported_kinds(self, request):
     return base.Response(self.model.template_fields, 200).resp
コード例 #18
0
 def types(self, request):
     data = dict(
         types=self.model.handlers.list().keys(),
         when=self.model.handlers.when_types_names
     )
     return base.Response(data, 200).resp
コード例 #19
0
 def cli_reference(self, request):
     reference = utils.AnsibleArgumentsReference()
     return base.Response(reference.as_gui_dict(
         request.query_params.get("filter", "")
     ), 200).resp
コード例 #20
0
ファイル: views.py プロジェクト: xtha/polemarch
 def change_password(self, request, *args, **kwargs):
     serializer = self.get_serializer(self.get_object(), data=request.data)
     serializer.is_valid(raise_exception=True)
     serializer.save()
     return base.Response(serializer.data, status.HTTP_201_CREATED).resp
コード例 #21
0
 def supported_repos(self, request):
     return base.Response(self.model.repo_handlers.keys(), 200).resp