← Back to team overview

cf-charmers team mailing list archive

Re: [Merge] lp:~johnsca/charms/trusty/cloudfoundry/reconciler into lp:~cf-charmers/charms/trusty/cloudfoundry/trunk

 

Review: Approve

Cool, this looks like a nice start, thanks a bunch.

Diff comments:

> === modified file 'cloudfoundry/model.py'
> --- cloudfoundry/model.py	2014-10-02 18:02:19 +0000
> +++ cloudfoundry/model.py	2014-10-03 18:51:03 +0000
> @@ -1,6 +1,5 @@
>  import logging
>  import threading
> -import os
>  
>  import tornado.ioloop
>  from tornado import gen
> @@ -41,7 +40,8 @@
>              return self._env
>          c = self.config
>          self._env = self.get_env(
> -            c['juju.environment'],
> +            env_name=c.get('juju.environment'),
> +            api_address=c.get('juju.api_address'),
>              user=c['credentials.user'],
>              password=c['credentials.password'])
>          return self._env
> @@ -146,16 +146,16 @@
>              self.exec_lock.release()
>  
>      @classmethod
> -    def get_env(cls, name=None, user=None, password=None):
> -        # A hook env will have this set
> -        api_addresses = os.environ.get('JUJU_API_ADDRESSES')
> -        if not api_addresses:
> -            # use the local option/connect which
> -            # parses local jenv info
> -            env = Environment.connect(name)
> -        else:
> -            env = Environment(api_addresses.split()[0])
> +    def get_env(cls, env_name=None, api_address=None, user=None, password=None):
> +        if api_address:
> +            # use the explicit API address option
> +            env = Environment(api_address)
>              env.login(user=user, password=password)
> +        elif env_name:
> +            # use the local option which parses local jenv info
> +            env = Environment.connect(env_name)
> +        else:
> +            raise ValueError('Either name or api_address must be given')
>          return env
>  
>  
> 
> === modified file 'cloudfoundry/reconciler.py' (properties changed: -x to +x)
> --- cloudfoundry/reconciler.py	2014-09-18 19:34:19 +0000
> +++ cloudfoundry/reconciler.py	2014-10-03 18:51:03 +0000
> @@ -106,6 +106,11 @@
>          tornado.ioloop.IOLoop.instance().add_callback(reconcile)
>  
>  
> +class StatusHandler(tornado.web.RequestHandler):
> +    def get(self):
> +        self.write(json.dumps(db.real, indent=2, default=utils.serializable))
> +
> +
>  class StrategyHandler(tornado.web.RequestHandler):
>      def get(self):
>          self.write(utils.jsonify(db.strategy))
> @@ -131,6 +136,7 @@
>          'server.port': 8888,
>          'credentials.user': 'user-admin',
>          'server.repository': 'build',
> +        'juju.api_address': utils.api_address(),
>          'juju.environment': utils.current_env(),
>          'runtime.observe': True,
>          'runtime.modify': True
> @@ -139,6 +145,7 @@
>      global application
>      application = ReconcilerWebApp([
>          (r"/api/v1/", StateHandler),
> +        (r"/api/v1/status", StatusHandler),
>          (r"/api/v1/strategy", StrategyHandler),
>          (r"/api/v1/reset", ResetHandler),
>      ],
> 
> === modified file 'cloudfoundry/utils.py'
> --- cloudfoundry/utils.py	2014-09-30 17:22:35 +0000
> +++ cloudfoundry/utils.py	2014-10-03 18:51:03 +0000
> @@ -12,7 +12,17 @@
>  
>  
>  def current_env():
> -    return subprocess.check_output(['juju', 'switch']).strip()
> +    try:
> +        return subprocess.check_output(['juju', 'switch']).strip()
> +    except OSError:
> +        return None
> +
> +
> +def api_address():
> +    api_addresses = os.environ.get('JUJU_API_ADDRESSES')
> +    if api_addresses:
> +        return api_addresses.split()[0]
> +    return None
>  
>  
>  def record_pid():
> @@ -123,6 +133,12 @@
>          except KeyError:
>              raise AttributeError(key)
>  
> +    def get(self, key, default=None):

Not sure where/why this is used.

> +        try:
> +            return self[key]
> +        except KeyError:
> +            return default
> +
>      def update(self, other):
>          deepmerge(self, other)
>  
> @@ -193,6 +209,7 @@
>          # continue w/o
>          pass
>  
> +
>  def linux_image_extra_package():
>      """
>      Get the explicitly tagged LIE package for the current kernel release.
> 
> === modified file 'hooks/common.py'
> --- hooks/common.py	2014-10-03 16:31:53 +0000
> +++ hooks/common.py	2014-10-03 18:51:03 +0000
> @@ -182,6 +182,21 @@
>              'stop': [],
>          },
>          {
> +            'service': 'reconciler',
> +            'ports': [8888],
> +            'required_data': [
> +                JujuAPICredentials(),
> +                RequiredConfig('artifacts_url') != '',
> +                {'charm_dir': hookenv.charm_dir()},
> +            ],
> +            'data_ready': [
> +                services.render_template('reconciler-upstart.conf',
> +                                         target='/etc/init/reconciler.conf'),
> +                services.render_template('reconciler-config.conf',
> +                                         target='/etc/juju-deployer/server.conf'),
> +            ],
> +        },
> +        {
>              'service': 'nfs-kernel-server',
>              'required_data': [
>                  RequiredConfig('mirror_artifacts') == True,  # noqa
> 
> === modified file 'hooks/install'
> --- hooks/install	2014-10-02 20:06:08 +0000
> +++ hooks/install	2014-10-03 18:51:03 +0000
> @@ -10,10 +10,11 @@
>  
>  hookenv.juju_status('installing')
>  fetch.apt_install(fetch.filter_installed_packages([
> -    'juju-deployer', 'nfs-kernel-server', 'python-pip']))
> +    'juju-deployer', 'nfs-kernel-server', 'python-pip', 'python-tornado']))
>  
>  if not ssh_key.exists():
>      subprocess.check_call(['ssh-keygen', '-f', ssh_key, '-N', ''])
>  
>  subprocess.check_call([
>      'pip', 'install', '--use-wheel', '-f', './wheelhouse', '--pre', 'raindance'])
> +subprocess.check_call(['pip', 'install', '--upgrade', 'jujuclient'])
> 
> === added file 'templates/reconciler-config.conf'
> --- templates/reconciler-config.conf	1970-01-01 00:00:00 +0000
> +++ templates/reconciler-config.conf	2014-10-03 18:51:03 +0000
> @@ -0,0 +1,18 @@
> +{
> +    "juju": {
> +        "api_address": "{{api_address}}"
> +    },
> +    "credentials": {
> +        "user": "user-admin",
> +        "password": "{{api_password}}"
> +    },
> +    "server": {
> +        "address": "0.0.0.0",
> +        "port": 8888,
> +        "repository": "build"
> +    },
> +    "runtime": {
> +        "observe": true,
> +        "modify": false
> +    }
> +}
> 
> === added file 'templates/reconciler-upstart.conf'
> --- templates/reconciler-upstart.conf	1970-01-01 00:00:00 +0000
> +++ templates/reconciler-upstart.conf	2014-10-03 18:51:03 +0000
> @@ -0,0 +1,3 @@
> +env PYTHONPATH="{{charm_dir}}"
> +
> +exec {{charm_dir}}/cloudfoundry/reconciler.py
> 


-- 
https://code.launchpad.net/~johnsca/charms/trusty/cloudfoundry/reconciler/+merge/237126
Your team Cloud Foundry Charmers is subscribed to branch lp:~cf-charmers/charms/trusty/cloudfoundry/trunk.


References