Exemplo n.º 1
0
 def create(self, request, key_value_id=None):
     if 'system_id' in request.POST:
         n = KeyValue()
         system = System.objects.get(id=request.POST['system_id'])
         n.system = system
         if 'key' in request.POST:
             n.key = request.POST['key']
         if 'value' in request.POST:
             n.value = request.POST['value']
         try:
             n.save()
             resp = rc.ALL_OK
             resp.write('json = {"id":%i}' % (n.id))
         except:
             resp = rc.NOT_FOUND
             resp.write('Unable to Create Key/Value Pair')
         return resp
     if 'truth_name' in request.POST:
         n = TruthKeyValue()
         truth = Truth.objects.get(name=request.POST['truth_name'])
         n.truth = truth
         if 'key' in request.POST:
             n.key = request.POST['key']
         if 'value' in request.POST:
             n.value = request.POST['value']
         try:
             n.save()
             resp = rc.ALL_OK
             resp.write('json = {"id":%i}' % (n.id))
         except:
             resp = rc.NOT_FOUND
             resp.write('Unable to Create Key/Value Pair')
         return resp
 def create(self, request, key_value_id=None):
     if 'system_id' in request.POST:
         post_key = request.POST.get('key')
         post_value = request.POST.get('value')
         system_id = request.POST.get('system_id')
         n = KeyValue()
         system = System.objects.get(id=system_id)
         if re.search('^nic\.(\d+)\.ipv4_address', str(post_key).strip() ):
             try:
                 acl = KeyValueACL(request)
                 acl.check_ip_not_exist_other_system(system, post_value)
             except Exception, e:
                 resp = rc.FORBIDDEN
                 resp.write(e)
                 return resp
         try:
             n.system = system
             if 'key' in request.POST:
                 n.key = request.POST['key']
             if 'value' in request.POST:
                 n.value = request.POST['value']
             n.save()
             resp = rc.ALL_OK
             resp.write('json = {"id":%i}' % (n.id))
         except:
             resp = rc.NOT_FOUND
             resp.write('Unable to Create Key/Value Pair')
         return resp
 def create(self, request, key_value_id=None):
     if 'system_id' in request.POST:
         n = KeyValue()
         system = System.objects.get(id=request.POST['system_id'])
         n.system = system
         if 'key' in request.POST:
             n.key = request.POST['key']
         if 'value' in request.POST:
             n.value = request.POST['value']
         try:
             n.save()
             resp = rc.ALL_OK
             resp.write('json = {"id":%i}' % (n.id))
         except:
             resp = rc.NOT_FOUND
             resp.write('Unable to Create Key/Value Pair')
         return resp
     if 'truth_name' in request.POST:
         n = TruthKeyValue()
         truth = Truth.objects.get(name=request.POST['truth_name'])
         n.truth = truth
         if 'key' in request.POST:
             n.key = request.POST['key']
         if 'value' in request.POST:
             n.value = request.POST['value']
         try:
             n.save()
             resp = rc.ALL_OK
             resp.write('json = {"id":%i}' % (n.id))
         except:
             resp = rc.NOT_FOUND
             resp.write('Unable to Create Key/Value Pair')
         return resp