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 update(self, request, key_value_id=None): ###TODO This whole method is not functioning correctly. Just for version 2. Not getting the system_id or truth_id from the poster firefox plugin if 'system_id' in request.POST: n = None found = False post_key = request.POST.get('key') post_value = request.POST.get('value') system_id = request.POST.get('system_id') key_validated, validation_error_string = self.validate(post_key, post_value) if re.search('^nic\.(\d+)\.ipv4_address', str(post_key).strip() ): try: acl = KeyValueACL(request) system = System.objects.get(id=system_id) acl.check_ip_not_exist_other_system(system, post_value) except Exception, e: resp = rc.FORBIDDEN resp.write(e) return resp if key_validated is False: resp = rc.FORBIDDEN resp.write('Validation Failed for %s %s' % (request.POST['key'], validation_error_string) ) return resp try: n = KeyValue.objects.get(id=key_value_id,key=request.POST['key']) system = System.objects.get(id=request.POST['system_id']) found = True except Exception, e: #print e found = False
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 update(self, request, key_value_id=None): ###TODO This whole method is not functioning correctly. Just for version 2. Not getting the system_id or truth_id from the poster firefox plugin if 'system_id' in request.POST: n = None found = False post_key = request.POST.get('key') post_value = request.POST.get('value') system_id = request.POST.get('system_id') key_validated, validation_error_string = self.validate( post_key, post_value) if re.search('^nic\.(\d+)\.ipv4_address', str(post_key).strip()): try: acl = KeyValueACL(request) system = System.objects.get(id=system_id) acl.check_ip_not_exist_other_system(system, post_value) except Exception, e: resp = rc.FORBIDDEN resp.write(e) return resp if key_validated is False: resp = rc.FORBIDDEN resp.write('Validation Failed for %s %s' % (request.POST['key'], validation_error_string)) return resp try: n = KeyValue.objects.get(id=key_value_id, key=request.POST['key']) system = System.objects.get(id=request.POST['system_id']) found = True except Exception, e: #print e found = False
kv = models.KeyValue.objects.get(id=id) if kv is not None and validated: ##Here we eant to check if the existing key is a network adapter. If so we want to find out if it has a dhcp scope. If so then we want to add it to ScheduledTasks so that the dhcp file gets regenerated matches = re.search('^nic\.(\d+)', str(kv.key).strip() ) """ Check to see if we have a network adapter If so we need to flag the dhcp zone file to be regenerated """ if matches and matches.group(1): """ 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:
kv = models.KeyValue.objects.get(id=id) if kv is not None and validated: ##Here we eant to check if the existing key is a network adapter. If so we want to find out if it has a dhcp scope. If so then we want to add it to ScheduledTasks so that the dhcp file gets regenerated matches = re.search('^nic\.(\d+)', str(kv.key).strip()) """ Check to see if we have a network adapter If so we need to flag the dhcp zone file to be regenerated """ if matches and matches.group(1): """ 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(