Beispiel #1
0
    def read(self, request):
        "Return user name and superuser status as json"
        output = {"username": request.user.username,
                  "super_user": request.user.is_superuser}

        responder = JsonDictResponder(output)
        return responder.element(request)
Beispiel #2
0
 def create(self, request, config_type, config_name):
     "Default POST method for ConfigEntry"
     yaml_string = request.POST["yaml"]
     dispatcher = self.get_dispatcher()
     output = dispatcher.make_config_data(config_type, sanitize(config_name), yaml_string)
     responder = JsonDictResponder(output)
     return responder.element(request)
Beispiel #3
0
 def read(self, request, machine_name):
     "Show cached status for a machine"
     server_home = self.get_server_home()
     check_string(machine_name)
     status_path = os.path.join(server_home, "status", machine_name)
     machine_status = {}
     if os.path.isfile(status_path):
         machine_status = yaml.load(status_path)
     responder = JsonDictResponder(machine_status)
     return responder.element(request)
Beispiel #4
0
    def read(self, request):
        "Return json representation of server configuration"
        output = {}

        server_config = {}
        server_config_objects = ServerConfig.objects.all()
        for server_co in server_config_objects:
            server_config[server_co.name] = server_co.value
        output["server configuration"] = server_config
        responder = JsonDictResponder(output)
        return responder.element(request)
Beispiel #5
0
 def read(self, request):
     "Reject read if user is not authenticated"
     if not request.user.is_authenticated():
         status = "NOT_AUTHENTICATED"
         status_code = 403
     else:
         status = "OK"
         status_code = 200
     responder = JsonDictResponder({"status": status})
     response = responder.element(request)
     response.status_code = status_code
     return response
Beispiel #6
0
    def delete(self, request, username):
        "Choose to delete a user"

        command_output = []
        user = User.objects.get(username__exact=username)
        user.delete()
        output = "%s deleted" % username
        responder = JsonDictResponder({"command_status": OK,
                                       "command_output": output})
        response = responder.element(request)
        response.status_code = 200
        return response
Beispiel #7
0
    def create(self, request, username):
        "Create or update a user"

        query_dict = {}
        command_output = []
        if "yaml" in request.POST:
            yaml_string = request.POST["yaml"]
            try:
                query_dict = yaml.load(yaml_string)
            except Exception, x:
                output = {"command_status": FAIL, "command_output": "Bad YAML"}
                responder = JsonDictResponder(output)
                return responder.element(request)
Beispiel #8
0
 def read(self, request):
     "Default read method"
     from bombardier_server._version import version_info as srv
     from bombardier_core._version import version_info as crv
     output = ["Server: %s-%s" % (srv.get("branch_nick"), srv.get("revno")),
               "Server-core: %s-%s" % (crv.get("branch_nick"), crv.get("revno")),
              ]
     dispatcher = self.get_dispatcher()
     client_version_info = dispatcher.get_client_versions()
     for key in client_version_info:
         output.append("%s: %s" % (key, client_version_info[key]))
     responder = JsonDictResponder(output)
     open("/tmp/FOOP.txt", 'a').write("output: %s\n" % output)
     return responder.element(request)
Beispiel #9
0
 def create(self, request, machine_name):
     "Start a reconcile job on a machine"
     output = {"command_status": OK}
     if 1 == 1:
     #try:
         dispatcher = self.get_dispatcher()
         data = dispatcher.check_status()
         job_name = dispatcher.reconcile_job(request.user.username, machine_name)
         dispatcher.queue_job(job_name)
         output = dispatcher.get_job_status(job_name)
     else:
     #except Exception, x:
         output.update(self.dump_exception(request, x))
     responder = JsonDictResponder(output)
     return responder.element(request)
Beispiel #10
0
    def create(self, request):
        "Create or update configuration items on the server config collection."
        if not request.user.is_superuser:
            return HttpResponseForbidden()
        query_dict = request.POST

        if "form-0-name" in query_dict:
            self._form_update(query_dict)
        else:
            self._standard_update(query_dict)

        server_config_objects = ServerConfig.objects.all()
        output = {}
        for server_co in server_config_objects:
            output[server_co.name] = server_co.value
        responder = JsonDictResponder(output)
        return responder.element(request)
Beispiel #11
0
 def read(self, request, username):
     "Return user info as json if user exists"
     try:
         user = User.objects.get(username__exact=username)
     except User.DoesNotExist:
         raise Http404
     output = {"username": user.username,
               "is_superuser": user.is_superuser,
               "is_active": user.is_active,
               "first_name": user.first_name,
               "last_name": user.last_name,
               "email": user.email,
              }
     responder = JsonDictResponder(output)
     response = responder.element(request)
     response.status_code = 200
     return response
Beispiel #12
0
                              publish=publish_flag)
            comment.save()
            for job_name in job_names:
                machine_name = dispatcher.get_machine_name(job_name)
                commented_job = CommentedJob(comment_id=comment,
                                             job_name=job_name,
                                             username=str(request.user.username),
                                             machine_name=machine_name,
                                            )
                commented_job.save()
                output[job_name] = "comment applied."
                dispatcher.note_comment(job_name)
        except Exception, x:
            output["command_status"] = FAIL
            output.update(self.dump_exception(request, x))
        responder = JsonDictResponder(output)
        return responder.element(request)

class JobJoinEntry(CnmResource):
    "Job join class"
    @login_required
    def read(self, request, job_name):
        "Tell dispatcher to wait a job thread to return"
        output = {"command_status": OK}
        try:
            dispatcher = self.get_dispatcher()
            output = dispatcher.job_join(request.user.username, job_name, 10)
        except Exception, x:
            output.update(self.dump_exception(request, x))
        responder = JsonDictResponder(output)
        return responder.element(request)
Beispiel #13
0
 def read(self, request, config_type, config_name):
     "Default read method for ConfigEntry"
     dispatcher = self.get_dispatcher()
     config_data = dispatcher.read_config_data(config_type, config_name)
     responder = JsonDictResponder(config_data)
     return responder.element(request)
Beispiel #14
0
 def read(self, request, config_type, config_name):
     "Default read method for ConfigCollection"
     dispatcher = self.get_dispatcher()
     output = dispatcher.get_config_info(config_type, sanitize(config_name))
     responder = JsonDictResponder(output)
     return responder.element(request)
Beispiel #15
0
 def read(self, request, dist_name):
     "Create dictionary from Dist object and return as json"
     dispatcher = self.get_dispatcher()
     output = dispatcher.get_dist_name_info(dist_name)
     responder = JsonDictResponder(output)
     return responder.element(request)
Beispiel #16
0
 def read(self, request, dist_name):
     "Expose custom fields for Dist type collection and return as json"
     dispatcher = self.get_dispatcher()
     output = dispatcher.get_dist_info(dist_name)
     responder = JsonDictResponder(output)
     return responder.element(request)
Beispiel #17
0
            user.first_name = first_name
            command_output.append("First name set for user %s" % username)

        last_name = query_dict.get("last_name")
        if last_name:
            user.last_name = last_name
            command_output.append("Last name set for user %s" % username)

        email = query_dict.get("email")
        if email:
            user.email = email
            command_output.append("Email set for user %s" % username)

        user.save()
        output_string = '|'.join(command_output)
        responder = JsonDictResponder({"command_status": OK,
                                       "command_output": output_string})
        response = responder.element(request)
        response.status_code = 200
        return response

urlpatterns = patterns('',
   url(r'^json/check_authentication', AuthEntry(permitted_methods=['GET'])),
   url(r'^json/user/search/(?P<username>.*)', UsersCollection()),
   url(r'^json/user/name/(?P<username>.*)',
       UsersEntry(permitted_methods=['POST', 'GET', 'DELETE'])),
   url(r'^accounts/login.*',  login),
   url(r'^accounts/logout.*', logout),
   url(r'^accounts/profile.*', UserProfileEntry()),
)