Ejemplo n.º 1
0
        def store():
            defaults = {'key_1': ['should_be_overriden']}

            p = Properties(self.storage, SECTION, defaults)

            assert (isinstance(p, dict))

            def set_item_1(result):
                p['key_1'] = [u'value_a', 'value_b']

            def modify_item_1(result):
                p['key_1'] = ['value_c', 'value_d']
                p['key_1'][0] = 'value_0'

            def set_item_2(result):
                p['key_2'] = ['value_X', 'value_Y', u'value_Z']

            def get_item_1(result):
                a = p['key_1']

            def commit(result):
                return p.commit()

            return p.begin().\
                addCallback(set_item_1).\
                addCallback(modify_item_1).\
                addCallback(set_item_2).\
                addCallback(get_item_1).\
                addCallback(commit)
Ejemplo n.º 2
0
        def load(ignore):
            defaults = {
                'key_1': ['should_be_overriden'],
                'default': ['default']
            }

            p = Properties(self.storage, SECTION, defaults)

            def verify_contents(r):
                assert (len(p['key_1']) == 2)
                assert (len(p['key_2']) == 3)
                assert (len(p['default']) == 1)

                assert (p['key_1'][0] == 'value_0')
                assert (p['key_1'][1] == 'value_d')

                assert (p['key_2'][0] == 'value_X')
                assert (p['key_2'][1] == 'value_Y')
                assert (p['key_2'][2] == u'value_Z')

                assert (p['default'][0] == 'default')

            def begin(r):
                return p.begin()

            def modify_contents(r):
                p['key_2'][0] = 'value_X'
                p['key_2'][1] = 'value_Y'
                p['key_2'][2] = u'value_Z'
                p['key_2'].reverse()
                p['key_2'].sort()
                p['key_2'].remove(u'value_Z')

                assert (p['key_2'][0] == 'value_X')
                assert (p['key_2'][1] == 'value_Y')

                p['key_2'].insert(2, u'value_Z')
                p['key_2'].sort()

                assert (p['key_2'][0] == 'value_X')
                assert (p['key_2'][1] == 'value_Y')
                assert (p['key_2'][2] == u'value_Z')

                assert (len(p['key_2']) == 3)

                # Test the iterators
                keys = p.keys()
                assert (len(keys) == 3)
                assert ('key_1' in keys)
                assert ('key_2' in keys)
                assert (len(p['key_1']) == 2)

            def commit(result):
                return p.commit()

            return p.load().\
                addCallback(verify_contents).\
                addCallback(begin).\
                addCallback(modify_contents).\
                addCallback(commit)
Ejemplo n.º 3
0
        def store():
            defaults = { 'key_1' : [ 'should_be_overriden' ] }

            p = Properties(self.storage, SECTION, defaults)

            assert(isinstance(p, dict))
        
            def set_item_1(result):
                p['key_1'] = [u'value_a', 'value_b']
            
            def modify_item_1(result):
                p['key_1'] = ['value_c', 'value_d']
                p['key_1'][0] = 'value_0'

            def set_item_2(result):
                p['key_2'] = ['value_X', 'value_Y', u'value_Z']

            def get_item_1(result):
                a = p['key_1']

            def commit(result):
                return p.commit()

            return p.begin().\
                addCallback(set_item_1).\
                addCallback(modify_item_1).\
                addCallback(set_item_2).\
                addCallback(get_item_1).\
                addCallback(commit)
Ejemplo n.º 4
0
        def load(ignore):
            defaults = { 'key_1' : [ 'should_be_overriden' ],
                         'default' : [ 'default'] }

            p = Properties(self.storage, SECTION, defaults)

            def verify_contents(r):
                assert(len(p['key_1']) == 2)
                assert(len(p['key_2']) == 3)
                assert(len(p['default']) == 1)

                assert(p['key_1'][0] == 'value_0')
                assert(p['key_1'][1] == 'value_d')

                assert(p['key_2'][0] == 'value_X')
                assert(p['key_2'][1] == 'value_Y')
                assert(p['key_2'][2] == u'value_Z')

                assert(p['default'][0] == 'default')

            def begin(r):
                return p.begin()

            def modify_contents(r):
                p['key_2'][0] = 'value_X'
                p['key_2'][1] = 'value_Y'
                p['key_2'][2] = u'value_Z'
                p['key_2'].reverse()
                p['key_2'].sort()
                p['key_2'].remove(u'value_Z')

                assert(p['key_2'][0] == 'value_X')
                assert(p['key_2'][1] == 'value_Y')

                p['key_2'].insert(2, u'value_Z')
                p['key_2'].sort()

                assert(p['key_2'][0] == 'value_X')
                assert(p['key_2'][1] == 'value_Y')
                assert(p['key_2'][2] == u'value_Z')

                assert(len(p['key_2']) == 3)

                # Test the iterators
                keys = p.keys()
                assert(len(keys) == 3)
                assert('key_1' in keys)
                assert('key_2' in keys)
                assert(len(p['key_1']) == 2)
                    
            def commit(result):
                return p.commit()

            return p.load().\
                addCallback(verify_contents).\
                addCallback(begin).\
                addCallback(modify_contents).\
                addCallback(commit)
Ejemplo n.º 5
0
    def reconfigure(self):
        """
        Load the configuration and restart the daemon.
        """
        log.debug('Reconfiguring and restarting the DHCP daemon...')

        # Don't set the daemon running status here, but let the status
        # check take care of that.

        p = Properties(self.storage, CONFIG_SECTION)
        p.addCallback(self.changed).\
            addCallback(lambda trigger: p.load()).\
            addCallback(self.emit_config, p).\
            addCallback(self.restart_daemon).\
            addErrback(self.restart_error)
Ejemplo n.º 6
0
    def get_config(self,section_id,update_cb=None,defaults={}): 
        
        p = Properties(self.storage,section_id,defaults)
        def get_dict(res): 
          dict = p.get_simple_dict()
          if update_cb:
            cb = lambda: self._handle_trigger(section_id,update_cb,defaults)
            p.addCallback(cb)
          return dict

        d = p.begin()
        d.addCallback(lambda x : p.load())
        d.addCallback(lambda x : p.commit())
        d.addCallback(get_dict)
        return d
Ejemplo n.º 7
0
    def reconfigure(self):
        """
        Load the configuration and restart the daemon.
        """
        log.debug('Reconfiguring and restarting the DHCP daemon...')

        # Don't set the daemon running status here, but let the status
        # check take care of that.

        p = Properties(self.storage, CONFIG_SECTION)
        p.addCallback(self.changed).\
            addCallback(lambda trigger: p.load()).\
            addCallback(self.emit_config, p).\
            addCallback(self.restart_daemon).\
            addErrback(self.restart_error)
Ejemplo n.º 8
0
 def set_config(self,section_id, dict): 
     p = Properties(self.storage,section_id)
     d = p.begin()
     
     def set_values(res):
       for key,value in dict.iteritems():
           if value or value == 0:
               p[key] = value
           else:
               # Since the value was None, remove the key-value
               # pair.
               try:
                   del p[key]
               except Exception, e:
                   # Already deleted
                   pass
Ejemplo n.º 9
0
    def install(self):
        self.cfg = self.resolve(local_config)
        self.storage = self.resolve(TransactionalStorage)
        self.register_for_bootstrap_complete(self.changed)
        self.register_handler(interface_change_event.static_get_name(),
                              self.changed)

        ws = self.resolve(str(webservice.webservice))
        v1 = ws.get_version("1")
        reg = v1.register_request

        # /ws.v1/nox
        noxpath = ( webservice.WSPathStaticString("nox"), )

        # /ws.v1/nox/stat
        noxstatpath = noxpath + ( webservice.WSPathStaticString("dhcp"), )

        reg(self.get_dhcp_status, "GET", noxstatpath, """Get DHCP status""")

        # Store the defaults to the database, if necessary.
        p = Properties(self.storage, CONFIG_SECTION, DEFAULTS)
        return p.begin().\
            addCallback(lambda ign: p.commit())
Ejemplo n.º 10
0
    def install(self):
        self.cfg = self.resolve(local_config)
        self.storage = self.resolve(TransactionalStorage)
        self.register_for_bootstrap_complete(self.changed)
        self.register_handler(interface_change_event.static_get_name(),
                              self.changed)

        ws = self.resolve(str(webservice.webservice))
        v1 = ws.get_version("1")
        reg = v1.register_request

        # /ws.v1/nox
        noxpath = (webservice.WSPathStaticString("nox"), )

        # /ws.v1/nox/stat
        noxstatpath = noxpath + (webservice.WSPathStaticString("dhcp"), )

        reg(self.get_dhcp_status, "GET", noxstatpath, """Get DHCP status""")

        # Store the defaults to the database, if necessary.
        p = Properties(self.storage, CONFIG_SECTION, DEFAULTS)
        return p.begin().\
            addCallback(lambda ign: p.commit())
Ejemplo n.º 11
0
 def lock_test(self):
     props = Properties(self.storage, 'test')
     d = props.load()
     d.addCallback(lambda x: props.begin())
     return d
Ejemplo n.º 12
0
 def lock_test(self):
     props = Properties(self.storage, 'test')
     d = props.load()
     d.addCallback(lambda x : props.begin())
     return d