Exemplo n.º 1
0
 def test_delete_key_by_system(self):
     system = System.objects.get(hostname='fake-hostname2')
     k = KeyValue(system=system, key='testing', value='blahblah')
     k.save()
     resp = self.client.delete('/en-US/api/v2/keyvalue/?key_type=delete_key_by_system&system=fake-hostname2&key=testing', follow=True)
     try:
         count = KeyValue.objects.get(system=system, key='testing').count()
     except KeyValue.DoesNotExist:
         count = 0
     self.assertEqual(resp.status_code, 200)
     self.assertEqual(int(json.loads(resp.content.split(" = ")[1])['id']), 14)
     self.assertEqual(count, 0)
 def test_delete_key_by_system(self):
     system = System.objects.get(hostname='fake-hostname2')
     k = KeyValue(obj=system, key='testing', value='blahblah')
     k.save()
     resp = self.client.delete(
         '/en-US/api/v2/keyvalue/?key_type=delete_key_by_system&system=fake-hostname2&key=testing',
         follow=True)
     try:
         count = KeyValue.objects.get(obj=system, key='testing').count()
     except KeyValue.DoesNotExist:
         count = 0
     self.assertEqual(resp.status_code, 200)
     self.assertEqual(int(json.loads(resp.content.split(" = ")[1])['id']),
                      14)
     self.assertEqual(count, 0)
Exemplo n.º 3
0
 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.obj = 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:
         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):
     n = KeyValue()
     if 'truth_id' in request.POST:
         truth = Truth.objects.get(id=request.POST['truth_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
Exemplo n.º 6
0
 def create(self, request, key_value_id=None):
     n = KeyValue()
     if 'truth_id' in request.POST:
         truth = Truth.objects.get(id=request.POST['truth_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
Exemplo n.º 7
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.obj = 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
     elif '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
     else:
         resp = rc.NOT_FOUND
         resp.write('system_id or truth_name required')
Exemplo n.º 8
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.obj = 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
     elif '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
     else:
         resp = rc.NOT_FOUND
         resp.write('system_id or truth_name required')