Login | Register
My pages Projects Community openCollabNet

Discussions > commits > svn commit: r201 - branches/stateengine/src

Project highlights: Stable Version: 1.6.1, Development Version: 1.7.6

current
Discussion topic

Back to topic list

svn commit: r201 - branches/stateengine/src

Reply

Author jjneely
Full name Jack Neely
Date 2005-10-21 12:13:05 PDT
Message Author: jjneely
Date: Fri Oct 21 12:13:05 2005
New Revision: 201

Modified:
   branches/stateengine​/src/hostconfig.py
   branches/stateengine​/src/hosts.py
   branches/stateengine​/src/server.py
Log:
Make Hosts.addHost() do the right thing if the added host already exists
in the database.

HostDict.load() now ignores files and directories that start with a '.'

The Server.incorperate() method is written and works. Right now this
just loads up all the entries in the HostDict() into the database Queue and
Hosts tables.

If you assign the 'DummyAction' to a client in one of the host config files
the client will now print out 'Hello World'.



Modified: branches/stateengine​/src/hostconfig.py
Url: http://current.tigri​s.org/source/browse/​current/branches/sta​teengine/src/hostcon​fig.py?view=diff​&rev=201&p1=bran​ches/stateengine/src​/hostconfig.py&r​1=200&p2=branche​s/stateengine/src/ho​stconfig.py&r2=2​01
====================​====================​====================​==================
--- branches/stateengine​/src/hostconfig.py (original)
+++ branches/stateengine​/src/hostconfig.py Fri Oct 21 12:13:05 2005
@@ -44,15 +44,19 @@
         
         for file in files:
             key = os.path.basename(file)
+ if key.startswith('.'):
+ continue
+
             if self.has_key(key):
- if not ingoreDups:
+ if not ignoreDups:
                     print "Multiple Config files for %s" % file
                     # Leave existing value in place
             else:
                 dict.__setitem__(self, key, file)
 
         for dir in dirs:
- self.load(dir)
+ if not os.path.basename(dir​).startswith('.'):
+ self.load(dir)
 
     def __getitem__(self, key):
         value = dict.__getitem__(self, key)

Modified: branches/stateengine​/src/hosts.py
Url: http://current.tigri​s.org/source/browse/​current/branches/sta​teengine/src/hosts.p​y?view=diff&rev=​201&p1=branches/​stateengine/src/host​s.py&r1=200&​p2=branches/stateeng​ine/src/hosts.py​&r2=201
====================​====================​====================​==================
--- branches/stateengine​/src/hosts.py (original)
+++ branches/stateengine​/src/hosts.py Fri Oct 21 12:13:05 2005
@@ -63,6 +63,11 @@
     
     def addHost(self, hostname):
         q = """insert into hosts (hostname) values (%s)"""
+
+ id = self.getHostID(hostname)
+ if id != None:
+ return id
+
         self.c.execute(q, (hostname,))
         self.db.commit()
 

Modified: branches/stateengine​/src/server.py
Url: http://current.tigri​s.org/source/browse/​current/branches/sta​teengine/src/server.​py?view=diff&rev​=201&p1=branches​/stateengine/src/ser​ver.py&r1=200​&p2=branches/statee​ngine/src/server.py​&r2=201
====================​====================​====================​==================
--- branches/stateengine​/src/server.py (original)
+++ branches/stateengine​/src/server.py Fri Oct 21 12:13:05 2005
@@ -30,30 +30,72 @@
     def incorperate(self):
         """Check for changes in host configuration"""
 
- dict = hostconfig.HostDict()
- for key in dict.keys():
- cnf = dict[key]
+ configs = hostconfig.HostDict()
+ configs.load()
+
+ for host in configs.keys():
+ print " Incorperating %s" % host
+ cnf = configs[host]
             # Check version from DB
             # reload if needed
 
+ hostID = self.hosts.addHost(host)
+
+ stateKeys = cnf.getStateKeys()
+ for state in stateKeys:
+ args = cnf.getArguments(state)
+ kwargs = cnf.getKWArguments(state)
+
+ try:
+ stateClass = modules.getClass("state/",
+ prototypes.State, state)
+ if not stateClass:
+ print "State %s not in system." % state
+ continue
+ else:
+ stateInstance = stateClass(*args, **kwargs)
+ except Exception, e:
+ print "Exception occured incorperating state"
+ print str(e)
+ print
+ continue
+
+ stateInstance.setup()
+ q = stateInstance.getQueue()
+
+ while not q.empty():
+ act, args, kwargs = q.get()
+ print "Action: %s\nArgs: %s\nKwargs: %s" % (act,
+ args, kwargs)
+ self.actions.put(hostID, act, args, kwargs)
+
+
         
     def deployActions(self):
         for host in self.hosts:
             name = self.hosts[host]
             print "Deploying actions for %s" % name
+ act = self.actions.get(host)
+
+ if not act:
+ continue
 
             url = "http://%s:%s" % (name, clientPort)
             client = xmlrpclib.ServerProxy(url)
- act = self.actions.get(host)
 
- if act:
- print "Action: (%s, %s, %s)" % (act['actionID'],
- act['args'],
- act['kwargs'])
-
- ret = client.runAction(act​['actionID'], act['args'], act['kwargs'])
- print "Action returned: %s" % ret
- self.actions.remove(​act['actionKey'])
+ print "Action: (%s, %s, %s)" % (act['actionID'],
+ act['args'],
+ act['kwargs'])
+
+ try:
+ ret = client.runAction(act​['actionID'],
+ act['args'], act['kwargs'])
+ except Exception, e:
+ print "Exception Occured: %s" % str(e)
+ continue
+
+ print "Action returned: %s" % ret
+ self.actions.remove(​act['actionKey'])
 
         
     def stop(self):
@@ -61,9 +103,11 @@
 
 
     def run(self):
+ print "Incorperating..."
+ self.incorperate()
+
         while not self._stop:
             print "Deploying Actions..."
- self.incorperate()
             self.deployActions()
             time.sleep(5)

« Previous message in topic | 1 of 1 | Next message in topic »

Messages

Show all messages in topic

svn commit: r201 - branches/stateengine/src jjneely Jack Neely 2005-10-21 12:13:05 PDT
Messages per page: