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
resp = {'success': True, 'errorMessage' : ''} post_key = request.POST.get('key').strip() post_value = request.POST.get('value').strip() """ Create the key value acl object. We can use it to validate based on criteria below """ try: tmp = models.KeyValue.objects.get(id=id) system = tmp.system except Exception, e: print e pass acl = KeyValueACL(request) if post_key == 'shouldfailvalidation': resp['success'] = False resp['errorMessage'] = 'Validation Failed' validated = 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
validated = True resp = {'success': True, 'errorMessage': ''} post_key = request.POST.get('key').strip() post_value = request.POST.get('value').strip() """ Create the key value acl object. We can use it to validate based on criteria below """ try: tmp = models.KeyValue.objects.get(id=id) system = tmp.system except Exception, e: print e pass acl = KeyValueACL(request) if post_key == 'shouldfailvalidation': resp['success'] = False resp['errorMessage'] = 'Validation Failed' validated = 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