Пример #1
0
 def post(self, request):
     if "name" not in request.POST:
         return HttpResponse("Instance name is missing", status=500)
     name = request.POST.get("name")
     if not name:
         return HttpResponse("Instance name is empty", status=500)
     instance = Instance(name=canonicalize_db_name(name))
     try:
         create_database(instance, self._client)
     except Exception as e:
         return HttpResponse(e.args[-1], status=500)
     return HttpResponse("", status=201)
Пример #2
0
 def post(self, request):
     if "name" not in request.POST:
         return HttpResponse("Instance name is missing", status=500)
     name = request.POST.get("name")
     if not name:
         return HttpResponse("Instance name is empty", status=500)
     instance = Instance(name=canonicalize_db_name(name))
     try:
         create_database(instance, self._client)
     except Exception as e:
         return HttpResponse(e.args[-1], status=500)
     return HttpResponse("", status=201)
Пример #3
0
 def post(self, request, name, *args, **kwargs):
     name = canonicalize_db_name(name)
     try:
         instance = Instance.objects.get(name=name)
     except Instance.DoesNotExist:
         return HttpResponse("Instance not found", status=404)
     if instance.state != "running":
         msg = u"You can't bind to this instance because it's not running."
         return HttpResponse(msg, status=412)
     db = instance.db_manager()
     try:
         username, password = db.create_user(name, None)
     except Exception, e:
         return HttpResponse(e.args[-1], status=500)
Пример #4
0
 def post(self, request, name, *args, **kwargs):
     name = canonicalize_db_name(name)
     try:
         instance = Instance.objects.get(name=name)
     except Instance.DoesNotExist:
         return HttpResponse("Instance not found", status=404)
     if instance.state != "running":
         msg = u"You can't bind to this instance because it's not running."
         return HttpResponse(msg, status=412)
     db = instance.db_manager()
     try:
         username, password = db.create_user(name, None)
     except Exception, e:
         return HttpResponse(e.args[-1], status=500)
Пример #5
0
 def delete(self, request, name, *args, **kwargs):
     name = canonicalize_db_name(name)
     try:
         instance = Instance.objects.get(name=name)
     except Instance.DoesNotExist:
         msg = "Can't drop database '%s'; database doesn't exist" % name
         return HttpResponse(msg, status=404)
     if instance.shared:
         db = instance.db_manager()
         db.drop_database()
     elif instance.ec2_id is None:
         pi = ProvisionedInstance.objects.get(instance=instance)
         pi.dealloc()
     elif self._client.unauthorize(instance) and \
             self._client.terminate(instance):
         pass
     else:
         return HttpResponse("Failed to terminate the instance.",
                             status=500)
     instance.delete()
     return HttpResponse("", status=200)
Пример #6
0
 def delete(self, request, name, *args, **kwargs):
     name = canonicalize_db_name(name)
     try:
         instance = Instance.objects.get(name=name)
     except Instance.DoesNotExist:
         msg = "Can't drop database '%s'; database doesn't exist" % name
         return HttpResponse(msg, status=404)
     if instance.shared:
         db = instance.db_manager()
         db.drop_database()
     elif instance.ec2_id is None:
         pi = ProvisionedInstance.objects.get(instance=instance)
         pi.dealloc()
     elif self._client.unauthorize(instance) and \
             self._client.terminate(instance):
         pass
     else:
         return HttpResponse("Failed to terminate the instance.",
                             status=500)
     instance.delete()
     return HttpResponse("", status=200)