Jim,

Thanks for the contribution.  I took your patch and made a few modifications to 
it:

1. The argument for getConfig is now "Agent" not "Client" for the 
examplepolicy.  This is in keeping with the settings in dhcpdnsagent.
2. The config file timeout value is stored in seconds, not milliseconds, also 
in keeping with the rest of the config file.
3. I separated out the host and port specification from the one in 
ClusterManagerService -- it is conceivable that you would want the CM to be 
dual-homed and to have NMs and clients refer to this machine differently.  Now 
these options are in a "Client" section of the config.
4. The client can still override the config with environment variables.
5. dhcpdnsagent was updated to also perform this config file lookup.

Thoughts?

Index: trunk/src/tashi/agents/examplepolicy.py
===================================================================
--- trunk/src/tashi/agents/examplepolicy.py     (revision 739303)
+++ trunk/src/tashi/agents/examplepolicy.py     (working copy)
@@ -26,6 +26,7 @@
 from thrift.protocol.TBinaryProtocol import TBinaryProtocol
 from thrift.transport.TTransport import TBufferedTransport
 from tashi.services import clustermanagerservice
+from tashi.util import getConfig
 
 class ExamplePolicy():
        def __init__(self, client, transport):
@@ -76,10 +77,11 @@
                                        print e
                                time.sleep(2)
 
-def createClient():
-       host = os.getenv('TASHI_CM_HOST', 'localhost')
-       port = os.getenv('TASHI_CM_PORT', '9882')
-       timeout = float(os.getenv('TASHI_CM_TIMEOUT', '5000.0'))
+def createClient(config):
+       host = config.get('Client', 'clusterManagerHost')
+       port = config.get('Client', 'clusterManagerPort')
+       timeout = float(config.get('Client', 'clusterManagerTimeout')) * 1000.0
+
        socket = TSocket(host, int(port))
        socket.setTimeout(timeout)
        transport = TBufferedTransport(socket)
@@ -89,7 +91,8 @@
        return (client, transport)
 
 def main():
-       (client, transport) = createClient()
+       (config, configFiles) = getConfig(["Agent"])
+       (client, transport) = createClient(config)
        agent = ExamplePolicy(client, transport)
        agent.start()
 
Index: trunk/src/tashi/agents/dhcpdnsscheduler.py
===================================================================
--- trunk/src/tashi/agents/dhcpdnsscheduler.py  (revision 739303)
+++ trunk/src/tashi/agents/dhcpdnsscheduler.py  (working copy)
@@ -207,10 +207,10 @@
                                        os.write(1, "%s\n" % (str(e)))
                                time.sleep(2)
 
-def createClient():
-       host = os.getenv('TASHI_CM_HOST', 'localhost')
-       port = os.getenv('TASHI_CM_PORT', '9882')
-       timeout = float(os.getenv('TASHI_CM_TIMEOUT', '5000.0'))
+def createClient(config):
+       host = config.get('Client', 'clusterManagerHost')
+       port = config.get('Client', 'clusterManagerPort')
+       timeout = float(config.get('Client', 'clusterManagerTimeout')) * 1000.0
        socket = TSocket(host, int(port))
        socket.setTimeout(timeout)
        transport = TBufferedTransport(socket)
@@ -221,7 +221,7 @@
 
 def main():
        (config, configFiles) = getConfig(["Agent"])
-       (client, transport) = createClient()
+       (client, transport) = createClient(config)
        agent = DhcpDnsScheduler(config, client, transport)
        agent.start()
 
Index: trunk/src/tashi/client/client.py
===================================================================
--- trunk/src/tashi/client/client.py    (revision 739303)
+++ trunk/src/tashi/client/client.py    (working copy)
@@ -29,6 +29,8 @@
 from tashi.services import clustermanagerservice
 from tashi import vmStates
 
+from tashi.util import getConfig
+
 def makeHTMLTable(list):
        (stdin_r, stdin_w) = os.pipe()
        pipe = os.popen("tput cols")
@@ -152,9 +154,15 @@
                for m in methods:
                        os.unlink(m)
                sys.exit(0)
-       host = os.getenv('TASHI_CM_HOST', 'localhost')
-       port = os.getenv('TASHI_CM_PORT', '9882')
-       timeout = float(os.getenv('TASHI_CM_TIMEOUT', '5000.0'))
+
+       (config,configFiles) = getConfig(["Client"])
+       cfgHost = config.get('Client', 'clusterManagerHost')
+       cfgPort = config.get('Client', 'clusterManagerPort')
+       cfgTimeout = float(config.get('Client', 'clusterManagerTimeout'))
+       host = os.getenv('TASHI_CM_HOST', cfgHost)
+       port = os.getenv('TASHI_CM_PORT', cfgPort)
+       timeout = float(os.getenv('TASHI_CM_TIMEOUT', cfgTimeout) * 1000.0
+
        socket = TSocket(host, int(port))
        socket.setTimeout(timeout)
        transport = TBufferedTransport(socket)
Index: trunk/etc/TashiDefaults.cfg
===================================================================
--- trunk/etc/TashiDefaults.cfg (revision 739303)
+++ trunk/etc/TashiDefaults.cfg (working copy)
@@ -57,6 +57,12 @@
 clusterManagerPort = 9882
 ;bind = 0.0.0.0 ; not supported (Thrift is missing support to specify what to 
bind to!)
 
+# Client configuration
+[Client]
+clusterManagerHost = localhost
+clusterManagerPort = 9882
+clusterManagerTimeout = 5.0
+
 [Qemu]
 qemuBin = /usr/local/bin/qemu-system-x86_64
 infoDir = /var/tmp/VmControlQemu/ 

- Michael

-----Original Message-----
From: Jim Cipar [mailto:[email protected]] 
Sent: Wednesday, January 21, 2009 6:17 PM
To: [email protected]
Subject: Re: Remove environment variables

Whoops, I had forgotten to restart the scheduler when testing this,  
when I did, I realized that I also forgot to add an import in the  
scheduler.  The correct patch for examplepolicy.py:

Reply via email to