Esempio n. 1
0
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
Esempio n. 2
0
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
Esempio n. 3
0
    def addAttribute(self, keys):
        value = keys.get("value", None)
        if value is None:
            raise Http404

        serverObj = get_object_or_404(Server, id=keys.get("server", None))
        attrTypeObj = get_object_or_404(AttributeType, id=keys.get("attrtype", None))

        attrValueObj = AttributeValue(value=value)
        attrValueObj.save()

        attrObj = AttributeMapping(attributeValue=attrValueObj, attributeType=attrTypeObj, server=serverObj)
        attrObj.save()

        rowHTML = getAttributeTableHtml(serverObj)
        value = {"row": rowHTML, "multipleAllowed": attrTypeObj.multiple_allowed, "id": attrTypeObj.id}
        return value
Esempio n. 4
0
    def addAttribute(self, keys):
        value = keys.get('value', None)
        if value is None:
            raise Http404

        serverObj = get_object_or_404(Server, id=keys.get('server', None))
        attrTypeObj = get_object_or_404(AttributeType, id=keys.get('attrtype', None))

        attrValueObj = AttributeValue(value=value)
        attrValueObj.save()

        attrObj = AttributeMapping(attributeValue=attrValueObj, attributeType=attrTypeObj, server=serverObj)
        attrObj.save()

        rowHTML = getAttributeTableHtml(serverObj)
        value = {'row': rowHTML, 'multipleAllowed': attrTypeObj.multiple_allowed, 'id': attrTypeObj.id}
        return value