daily pastebin goal
46%
SHARE
TWEET

Untitled

a guest Apr 25th, 2016 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from charms.reactive import hook  
  2. from charms.reactive import RelationBase  
  3. from charms.reactive import scopes  
  4. from charmhelpers.core.hookenv import log  
  5.  
  6. class DcosRequires(RelationBase):  
  7.     scope = scopes.UNIT  
  8.  
  9.     @hook('dcosmaster-relation-{joined,changed}')  
  10.     def changed(self):  
  11.         #conv = self.conversation()  
  12.         #conv.set_state('{relation_name}.available')  
  13.         log("here!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")  
  14.  
  15.     @hook('dcosmaster-relation-{departed,broken}')  
  16.     def broken(self):  
  17.         #conv = self.conversation()  
  18.         #conv.remove_state('{relation_name}.available')  
  19.         log("not here!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")  
  20.  
  21.     def services(self):  
  22.         """  
  23.         Returns a list of available HTTP services and their associated hosts  
  24.         and ports.  
  25.         The return value is a list of dicts of the following form::  
  26.             [  
  27.                 {  
  28.                     'service_name': name_of_service,  
  29.                     'hosts': [  
  30.                         {  
  31.                             'hostname': address_of_host,
  32.                             'port': port_for_host,
  33.                         },
  34.                         # ...
  35.                     ],
  36.                 },
  37.                 # ...
  38.             ]
  39.         """
  40.         services = {}
  41.         for conv in self.conversations():
  42.             service_name = conv.scope.split('/')[0]
  43.             service = services.setdefault(service_name, {
  44.                 'service_name': service_name,
  45.                 'hosts': [],
  46.             })
  47.             host = conv.get_remote('hostname') or conv.get_remote('private-address')
  48.             port = conv.get_remote('port')
  49.             if host and port:
  50.                 service['hosts'].append({
  51.                     'hostname': host,
  52.                     'port': port,
  53.                 })
  54.         return [s for s in services.values() if s['hosts']]
RAW Paste Data
Top