def delete_key_value(request, id, system_id): kv = models.KeyValue.objects.get(id=id) matches = re.search('^nic\.(\d+)', str(kv.key)) if matches: try: existing_dhcp_scope = models.KeyValue.objects.filter( obj=kv.system).filter(key='nic.%s.dhcp_scope.0' % matches.group(1))[0].value models.ScheduledTask(task=existing_dhcp_scope, type='dhcp').save() except: pass kv.delete() system = models.System.objects.get(id=system_id) key_value_store = models.KeyValue.objects.filter(obj=system) return render_to_response('systems/key_value_store.html', { 'key_value_store': key_value_store, }, RequestContext(request))
def create_key_value(request, id): system = models.System.objects.get(id=id) key = 'None' value = 'None' if 'key' in request.POST: key = request.POST['key'].strip() if 'value' in request.POST: value = request.POST['value'].strip() kv = models.KeyValue(obj=system, key=key, value=value) print "Key is %s: Value is %s." % (key, value) kv.save() matches = re.search('^nic\.(\d+)', str(kv.key)) if matches: try: existing_dhcp_scope = models.KeyValue.objects.filter( obj=kv.system).filter(key='nic.%s.dhcp_scope.0' % matches.group(1))[0].value models.ScheduledTask(task=existing_dhcp_scope, type='dhcp').save() except: pass key_value_store = models.KeyValue.objects.filter(obj=system) return render_to_response('systems/key_value_store.html', { 'key_value_store': key_value_store, }, RequestContext(request))
Check to see if it's an ipv4_address key run KeyValueACL.check_ip_not_exist_other_system """ if re.search('^nic\.(\d+)\.ipv4_address', str(post_key).strip()): try: acl.check_ip_not_exist_other_system(system, post_value) except Exception, e: resp['success'] = False resp['errorMessage'] = str(e) return HttpResponse(json.dumps(resp)) try: existing_dhcp_scope = models.KeyValue.objects.filter( obj=kv.system).filter(key='nic.%s.dhcp_scope.0' % matches.group(1))[0].value if existing_dhcp_scope is not None: models.ScheduledTask(task=existing_dhcp_scope, type='dhcp').save() except Exception, e: pass try: existing_reverse_dns_zone = models.KeyValue.objects.filter( obj=kv.system).filter(key='nic.%s.reverse_dns_zone.0' % matches.group(1))[0].value if existing_reverse_dns_zone is not None: models.ScheduledTask(task=existing_reverse_dns_zone, type='reverse_dns_zone').save() except Exception, e: pass try: kv.key = request.POST.get('key').strip() kv.value = request.POST.get('value').strip() system_id = str(kv.system_id)