def addIP(self, keys): """ """ value = keys.get("value", None) if value is None: raise Http404 serverObj = get_object_or_404(Server, id=keys.get("server", None)) ipRaw = keys.get("value", None) if not ipRaw: print "No id_value found" raise Http404 try: ipObj = IP.objects.get(ip=ipRaw) except IP.DoesNotExist: ipObj = IP() ipObj.ip = ipRaw try: ipObj.save() except ValidationError: print "Save failed" raise Http404 serverObj.ip.add(ipObj) rowHTML = getIpTableHtml(serverObj) value = {"row": rowHTML} return value
def addIP(self, keys): """ """ value = keys.get('value', None) if value is None: raise Http404 serverObj = get_object_or_404(Server, id=keys.get('server', None)) ipRaw = keys.get('value', None) if not ipRaw: print 'No id_value found' raise Http404 try: ipObj = IP.objects.get(ip=ipRaw) except IP.DoesNotExist: ipObj = IP() ipObj.ip = ipRaw try: ipObj.save() except ValidationError: print 'Save failed' raise Http404 serverObj.ip.add(ipObj) rowHTML = getIpTableHtml(serverObj) value = {'row': rowHTML} return value
def run(): count = 1000 print 'Generating %s random servers with some random attributes and ip adresses on each' % str( count) print randWords = 'yes no some random words used in example the names values the servers below hello yes no'.split( ' ') randChars = string.ascii_letters + string.digits for i in range(count): serverObj = Server() serverObj.name = ''.join( [random.choice(randChars) for _ in range(random.randint(4, 12))]) + '-' + str(i) serverObj.function = ' '.join( [random.choice(randWords) for _ in range(random.randint(0, 10))]) serverObj.description = ' '.join( [random.choice(randWords) for _ in range(random.randint(0, 20))]) serverObj.status = random.randint(1, 5) randTime = datetime.datetime.now() - datetime.timedelta( seconds=random.randint(1000, 4000000)) serverObj.reg_time = randTime serverObj.upd_time = randTime + datetime.timedelta( seconds=random.randint(1000, 100000)) serverObj.save() # So we will get an primary key.. for ipCount in range(random.randint(1, 5)): randomIP = getRandomIP() if not randomIP: continue randomIP = str(randomIP) try: ipObj = IP.objects.get(ip=randomIP) except IP.DoesNotExist: ipObj = IP() ipObj.ip = randomIP ipObj.save() serverObj.ip.add(ipObj) serverObj.save() for attrCount in range(random.randint(1, 3)): randomAttr = random.choice(AttributeType.objects.all()) attrValueObj = AttributeValue() attrValueObj.value = random.choice(randWords) attrValueObj.save() attrMapObj = AttributeMapping() attrMapObj.attributeType = randomAttr attrMapObj.attributeValue = attrValueObj attrMapObj.server = serverObj attrMapObj.save() print serverObj.name
def run(): count = 1000 print 'Generating %s random servers with some random attributes and ip adresses on each' % str(count) print randWords = 'yes no some random words used in example the names values the servers below hello yes no'.split(' ') randChars = string.ascii_letters + string.digits for i in range(count): serverObj = Server() serverObj.name = ''.join([ random.choice(randChars) for _ in range(random.randint(4,12)) ]) + '-' + str(i) serverObj.function = ' '.join([ random.choice(randWords) for _ in range(random.randint(0,10)) ]) serverObj.description = ' '.join([ random.choice(randWords) for _ in range(random.randint(0,20)) ]) serverObj.status = random.randint(1,5) randTime = datetime.datetime.now() - datetime.timedelta(seconds=random.randint(1000,4000000)) serverObj.reg_time = randTime serverObj.upd_time = randTime + datetime.timedelta(seconds=random.randint(1000,100000)) serverObj.save() # So we will get an primary key.. for ipCount in range(random.randint(1,5)): randomIP = getRandomIP() if not randomIP: continue randomIP = str(randomIP) try: ipObj = IP.objects.get(ip=randomIP) except IP.DoesNotExist: ipObj = IP() ipObj.ip = randomIP ipObj.save() serverObj.ip.add(ipObj) serverObj.save() for attrCount in range(random.randint(1, 3)): randomAttr = random.choice(AttributeType.objects.all()) attrValueObj = AttributeValue() attrValueObj.value = random.choice(randWords) attrValueObj.save() attrMapObj = AttributeMapping() attrMapObj.attributeType = randomAttr attrMapObj.attributeValue = attrValueObj attrMapObj.server = serverObj attrMapObj.save() print serverObj.name