Open ghost opened 9 years ago
I see you are doing some real ochopoding there :)
The dependencies are simply defined in the pod script's model. It's an array of identifiers. Each identifier maps to a cluster assumed to be running in the same namespace. Let's take an example (my internal Kafka image I use for my stuff at Autodesk) ->
class Model(Reactive):
damper = 15.0
grace = 300.0
probe_every = 30.0
sequential = True
depends_on = ['zookeeper']
That's it. If you run the Kafka container in namespace 'foo', it will only ever configure when it can find at least one container from namespace 'foo' called 'zookeeper'.
You can use the grep() helper on that Cluster wrapper to get you a connection string for a given port. So for instance if I was to do grep("zookeeper", 2181) in my example, i would get a bunch of IP:
look at https://github.com/autodesk-cloud/ochopod/blob/master/sdk/ochopod/models/piped.py line 50 to see how I use the dependencies dict.
another example .. this is my HAProxy pod script. In my case HAProxy is configuring itself against a cluster of Play! framework REST endpoint called "api" (which listens on TCP 9000).
class Model(Reactive):
depends_on = ['api']
class Strategy(Piped):
cwd = '/opt/haproxy'
def can_configure(self, cluster):
#
# - we need at least one downstream url to redirect traffic to
#
assert cluster.grep('api', 9000), 'need 1+ downstream listener'
def configure(self, cluster):
#
# - grep our listeners
# - render into our 'local' backend directive (which is a standalone file)
#
urls = cluster.grep(api,9000).split(',')
env = Environment(loader=FileSystemLoader(join(dirname(__file__), 'templates')))
logger.info('%d downstream urls ->\n - %s' % (len(urls), '\n - '.join(urls)))
mappings = \
{
'listeners': {'listener-%d' % index: endpoint for index, endpoint in enumerate(urls)}
}
Looks great. I'll give it a try.
Can you post an example for how to use the dependency information from the cluster in the configure(self, cluster) method?
I know I can do something like this.
Does the dependencies dict work the same way?