예제 #1
0
    def data(self):

        n1 = SimpleNumManager('numgen1', next=1)

        n2 = SimpleNumManager('numgen2', maxnum=4, next=0)
        
        clusto.flush()
예제 #2
0
    def data(self):

        Entity('e1')
        Entity('e2')
        Entity('e3')

        clusto.flush()
예제 #3
0
파일: pooltests.py 프로젝트: egon010/clusto
    def testPoolsIterator(self):

        
        A = Pool('A')

        d1, d2 = [clusto.get_by_name(i) for i in ['d1', 'd2']]

        B = Pool('B')
        C = Pool('C')
        A1 = Pool('A1')
        B2 = Pool('B2')
        B1 = Pool('B1')
        C1 = Pool('C1')

        C1.insert(C)
        B1.insert(B)
        A1.insert(B)

        A1.insert(A)
        B2.insert(A)

        A.insert(d1)
        B.insert(d1)
        C.insert(d1)

        clusto.flush()

        self.assertEqual([x.name for x in Pool.get_pools(d1)],
                         [u'A', u'B', u'C', u'A1', u'B2', u'B1', u'A1', u'C1'])

        self.assertEqual([x.name for x in Pool.get_pools(d1, allPools=False)],
                         [u'A', u'B', u'C'])
예제 #4
0
    def testfqdn(self):

        s1 = clusto.get_by_name('bs1')
        s2 = clusto.get_by_name('bs2')

        self.assertEqual(s1.fqdns, [])

        s2.add_fqdn("test.example.com")

        self.assertEqual(["test.example.com"],
                         s2.fqdns)

        s2.add_fqdn("test2.example.com")
        
        clusto.flush()

        self.assertEqual(sorted(["test.example.com",
                                 "test2.example.com"]),
                         sorted(s2.fqdns))

        s2.remove_fqdn("test.example.com")

        
        self.assertEqual(["test2.example.com"],
                         s2.fqdns)
예제 #5
0
    def testEntityDeleteRelations(self):

        e1 = Entity.query().filter_by(name="e1").one()
        e2 = Entity.query().filter_by(name="e2").one()

        e1.add_attr("pointer1", e2)

        clusto.flush()

        self.assertEqual(Entity.query().filter_by(type="entity").count(), 3)

        self.assertEqual(
            Attribute.query().filter(and_(Entity.entity_id == Attribute.entity_id, Entity.type == "entity")).count(), 1
        )

        e2new = Entity.query().filter_by(name="e2").one()

        e2new.delete()

        self.assertEqual(Entity.query().filter_by(type="entity").count(), 2)

        self.assertEqual(
            Attribute.query().filter(and_(Entity.entity_id == Attribute.entity_id, Entity.type == "entity")).count(), 0
        )

        clusto.flush()

        self.assertEqual(Entity.query().filter_by(type="entity").count(), 2)
        self.assertEqual(
            Attribute.query().filter(and_(Entity.entity_id == Attribute.entity_id, Entity.type == "entity")).count(), 0
        )
예제 #6
0
    def data(self):

        Entity("e1")
        Entity("e2")
        Entity("e3")

        clusto.flush()
예제 #7
0
파일: pooltests.py 프로젝트: egon010/clusto
    def data(self):

        d1 = Driver('d1')
        d2 = Driver('d2')

        p1 = Pool('p1')

        clusto.flush()
예제 #8
0
    def testLocationRequirement(self):

        d = Datacenter('d1', 'san francisco')
        clusto.flush()

        z = clusto.get_by_name('d1')

        self.assert_(z.getAttr('location') == 'san francisco')
예제 #9
0
    def data(self):
        n1 = SimpleNameManager('foonamegen',
                               basename='foo',
                               digits=4,
                               startingnum=1,
                               )

        clusto.flush()
예제 #10
0
    def testMaxRackPosition(self):

        r1 = clusto.get_by_name('r1')

        self.assertRaises(TypeError, r1.insert, BasicServer('s1'), 400)

        self.assertRaises(TypeError, r1.insert, BasicServer('s2'), -13)

        clusto.flush()
예제 #11
0
    def allocate(self, thing, resource=(), number=True, force=False):
        """allocates a resource element to the given thing.

        resource - is passed as an argument it will be checked 
                   before assignment.  

        refattr - the attribute name on the entity that will refer back
                  this resource manager.

        returns the resource that was either passed in and processed 
        or generated.
        """

        try:
            clusto.begin_transaction()
            if not isinstance(thing, Driver):
                raise TypeError("thing is not of type Driver")

            if resource is ():
                # allocate a new resource
                resource, number = self.allocator(thing)
                auto_allocated = True
            else:
                auto_allocated = False
                resource, number = self.ensure_type(resource, number, thing)
                if not force and not self.available(resource, number, thing):
                    raise ResourceException("Requested resource is not available.")

            if self._record_allocations:
                if number == True:
                    c = Counter.get(ClustoMeta().entity, self._attr_name)
                    attr = thing.add_attr(self._attr_name,
                                          resource,
                                          number=c.value
                                          )
                    c.next()
                else:
                    attr = thing.add_attr(self._attr_name, resource, number=number)
                    
                clusto.flush()

                a=thing.add_attr(self._attr_name,
                            self.entity,
                            number=attr.number,
                            subkey='manager',
                            )

                clusto.flush()
                self.additional_attrs(thing, resource, attr.number)
                
            else:
                attr = None
            clusto.commit()
        except Exception, x:
            clusto.rollback_transaction()
            raise x
예제 #12
0
    def testNamedDriverCreation(self):
        ngen = clusto.get_by_name('foonamegen')
        
        s1 = ngen.allocate(Driver)

        clusto.flush()

        d1 = clusto.get_by_name('foo0001')

        self.assertEquals(s1.name, d1.name)
예제 #13
0
    def data(self):

        e1 = Entity("e1")
        e2 = Entity("e2")
        e3 = Entity("e3")

        e3.add_attr(key="e1", value=e1)
        e3.add_attr(key="e2", value=e2)

        clusto.flush()
예제 #14
0
    def testIntAttribute(self):

        e4 = Entity("e4")
        e4.add_attr(key="someint", value=10)

        clusto.flush()

        q = Attribute.query().filter_by(entity=e4, key="someint").one()

        self.assertEqual(q.value, 10)
예제 #15
0
파일: pooltests.py 프로젝트: egon010/clusto
    def testPoolAttrsOverride(self):

        d1, d2, p1 = map(clusto.get_by_name, ('d1', 'd2', 'p1'))

        p1.add_attr('t1', 1)
        p1.add_attr('t2', 2)

        p1.insert(d1)
        d1.add_attr('t1', 'foo')
        clusto.flush()
예제 #16
0
    def data(self):
        
        e1 = Entity('e1')
        e2 = Entity('e2')
        e3 = Entity('e3')

        e3.add_attr(key='e1', value=e1)
        e3.add_attr(key='e2', value=e2)

        clusto.flush()
예제 #17
0
    def testOutputEntityObject(self):

        expectedout = "e1"
        
        e1 = Entity('e1')

        self.assertEqual(str(e1), expectedout)

        clusto.flush()

        self.assertEqual(str(Entity.query().filter_by(name='e1')[0]), expectedout)
예제 #18
0
    def data(self):

        d1 = Driver('d1')
        assert d1
        d2 = Driver('d2')
        assert d2

        p1 = Pool('p1')
        assert p1

        clusto.flush()
예제 #19
0
    def testGettingThingInRack(self):

        r1 = clusto.get_by_name('r1')

        r1.insert(BasicServer('s1'), 40)

        clusto.flush()

        s1 = r1.get_device_in(40)

        self.assertEqual(s1.name, 's1')
예제 #20
0
    def testStringAttribute(self):

        e2 = Entity.query().filter_by(name="e2").one()

        e2.add_attr(key="somestring", value="thestring")

        clusto.flush()

        q = Attribute.query().filter_by(entity=e2, key="somestring").one()

        self.assertEqual(q.value, "thestring")
예제 #21
0
    def testAccessRelationAttributesMultipleTimes(self):
        e1 = Entity.query().filter_by(name='e1').one()
        e2 = Entity.query().filter_by(name='e2').one()

        e1.add_attr('foo', 2)
        e1.add_attr('foo', e2)

        clusto.flush()
        e1 = Entity.query().filter_by(name='e1').one()
        self.assertEqual(len(list(e1.attrs)), 2)
        self.assertEqual(len(list(e1.attrs)), 2)
        self.assertEqual(len(list(e1.attrs)), 2)
예제 #22
0
    def testStringAttribute(self):

        e2 = Entity.query().filter_by(name='e2').one()

        e2.add_attr(key='somestring', value='thestring')

        clusto.flush()

        q = Attribute.query().filter_by(entity=e2,
                                               key='somestring').one()

        self.assertEqual(q.value, 'thestring')
예제 #23
0
파일: driver.py 프로젝트: EricSchles/clusto
    def del_attrs(self, *args, **kwargs):
        "delete attribute with the given key and value optionally value also"

        clusto.flush()
        try:
            clusto.begin_transaction()
            for i in self.attr_query(*args, **kwargs):
                i.delete()
            clusto.commit()
        except Exception, x:
            clusto.rollback_transaction()
            raise x
예제 #24
0
파일: pooltests.py 프로젝트: egon010/clusto
    def testPoolCreate(self):

        p3 = Pool('p3')
        d3 = Driver('d3')
        
        clusto.flush()

        q = clusto.get_by_name('p3')

        self.assertTrue(isinstance(q, Pool))

        self.assertFalse(isinstance(clusto.get_by_name('d3'), Pool))
예제 #25
0
    def testAddingDateAttribute(self):

        e1 = Entity.query().filter_by(name="e1").one()

        d = datetime.datetime(2007, 12, 16, 7, 46)

        e1.add_attr("somedate", d)

        clusto.flush()

        q = Attribute.query().filter_by(entity_id=e1.entity_id, key="somedate").one()

        self.assertEqual(q.value, d)
예제 #26
0
    def testMultipleAttributes(self):

        e2 = Entity.query().filter_by(name="e2").one()

        e2.add_attr(key="somestring", number=1, subkey="foo", value="thestring")

        e2.add_attr(key="somestring", number=1, subkey="foo", value="thestring")

        clusto.flush()

        q = Attribute.query().filter_by(entity=e2, key="somestring").all()

        self.assertEqual([a.value for a in q], ["thestring", "thestring"])
예제 #27
0
    def testDeleteEntity(self):

        e1 = Entity('e1')

        clusto.flush()

        self.assertEqual(Entity.query().filter_by(type='entity').count(), 1)

        e1.delete()

        clusto.flush()

        self.assertEqual(Entity.query().filter_by(type='entity').count(), 0)
예제 #28
0
    def testInsert(self):

        d1 = Driver('d1')
        d2 = Driver('d2')

        d1.insert(d2)
        
        clusto.flush()

        d = clusto.get_by_name('d1')

        self.assertEqual(d.attr_items(ignore_hidden=False),
                         [(('_contains', 0, None), d2)])
예제 #29
0
    def testGettingAttrsMultipleTimes(self):
        d1 = Driver('d1')
        d2 = Driver('d2')
        
        d1.add_attr('foo', 'bar')
        d1.add_attr('foo0', 'bar1')
        d2.add_attr('d1', d1)

        clusto.flush()

        d = clusto.get_by_name('d1')
        
        self.assertEqual(len(d.references()), 1)
        self.assertEqual(len(d.attrs()), 2)
예제 #30
0
    def testGettingAttrValues(self):
        d1 = Driver('d1')
        d2 = Driver('d2')
        
        d1.add_attr('foo', 'bar')
        d1.add_attr('foo0', 'bar1')
        d2.add_attr('d1', d1)

        clusto.flush()

        self.assertEqual(sorted(['bar', 'bar1']),
                         sorted(d1.attr_values('foo.*', regex=True)))

        self.assertEqual([d1], d2.attr_values())
예제 #31
0
    def testReferenceDelete(self):

        e1 = Entity.query().filter_by(name=u'e1').one()


        e3 = Entity.query().filter_by(name=u'e3').one()

        
        e3.delete()

        self.assertEqual(len(list(e1.references)), 0)

        clusto.flush()

        e1a = Entity.query().filter_by(name=u'e1').one()

        self.assertEqual(len(list(e1a.references)), 0)
        self.assertEqual(id(e1a), id(e1))

        e2 = Entity.query().filter_by(name=u'e2').one()

        self.assertEqual(len(list(e2.references)), 0)
예제 #32
0
    def testPoolAttrs(self):

        d1, d2, p1 = map(clusto.get_by_name, ('d1', 'd2', 'p1'))

        p1.add_attr('t1', 1)
        p1.add_attr('t2', 2)

        d1.add_attr('t3', 3)

        p1.insert(d1)
        p1.insert(d2)

        clusto.flush()

        d2 = clusto.get_by_name('d2')

        self.assertEqual(sorted(d2.attrs(merge_container_attrs=True)),
                         sorted(p1.attrs()))

        self.assertEqual(
            sorted(['t1', 't2', 't3']),
            sorted([x.key for x in d1.attrs(merge_container_attrs=True)]))
예제 #33
0
파일: driver.py 프로젝트: wt/clusto
    def do_attr_query(cls, key=(), value=(), number=(),
                    subkey=(), ignore_hidden=True, sort_by_keys=False,
                    glob=False, count=False, querybase=None, return_query=False,
                    entity=None):
        """Does queries against all Attributes using the DB."""

        clusto.flush()
        if querybase:
            query = querybase
        else:
            query = Attribute.query()

        ### This is bunk, gotta fix it
        if isinstance(cls, Driver):
            query = query.filter(and_(Attribute.entity_id==Entity.entity_id,
                                      Entity.driver == cls._driver_name,
                                      Entity.type == cls._clusto_type))

        if entity:
            query = query.filter_by(entity_id=entity.entity_id)

        if key is not ():
            if glob:
                query = query.filter(Attribute.key.like(key.replace('*', '%')))
            else:
                query = query.filter_by(key=key)

        if subkey is not ():
            if glob and subkey:
                query = query.filter(Attribute.subkey.like(subkey.replace('*', '%')))
            else:
                query = query.filter_by(subkey=subkey)

        if value is not ():
            typename = Attribute.get_type(value)

            if typename == 'relation':
                if isinstance(value, Driver):
                    value = value.entity.entity_id
                query = query.filter_by(relation_id=value)

            else:
                query = query.filter_by(**{typename+'_value':value})

        if number is not ():
            if isinstance(number, bool) or number is None:
                if number == True:
                    query = query.filter(Attribute.number != None)
                else:
                    query = query.filter(Attribute.number == None)
            elif isinstance(number, (int, long)):
                query = query.filter_by(number=number)

            else:
                raise TypeError("number must be either a boolean or an integer.")

        if ignore_hidden and ((key and not key.startswith('_')) or key is ()):
            query = query.filter(not_(Attribute.key.like('\\_%', escape='\\')))

        if sort_by_keys:
            query = query.order_by(Attribute.key)

        if count:
            return query.count()

        if return_query:
            return query

        return query.all()
예제 #34
0
파일: basicracktests.py 프로젝트: wt/clusto
    def data(self):

        r1 = BasicRack('r1')
        r2 = BasicRack('r2')

        clusto.flush()