Beispiel #1
0
  def run_relation_hook(self, relation_name, action):
    # TODO: It would be nice to use our own relation here, rather than reusing the 'website' relation
    if relation_name == 'website':
      return self._run_loadbalancer_hook(action)

    # TODO: Only on certain actions?
    logger.info("Running relation hook %s %s", relation_name, action)

    relation = Relation.default()

    properties = {}
    if not action == "broken":
        properties = relation.get_properties()

    logger.info("Got relation properties %s", properties)

    xaas = self._privateclient()

    config = Juju.config()
    service_name = Juju.service_name()
    unit_id = Juju.unit_name()
    remote_name = os.environ["JUJU_REMOTE_UNIT"]
    relation_id = relation.relation_id

    new_properties = xaas.update_relation_properties(service_name=service_name,
                                                     relation=relation_name,
                                                     relation_id=relation_id,
                                                     unit_id=unit_id,
                                                     remote_name=remote_name,
                                                     action=action,
                                                     properties=properties)

    if new_properties:
        logger.info("Setting relation properties to: %s", new_properties)
        relation.set_properties(new_properties)
Beispiel #2
0
    def run_relation_hook(self, relation_name, action, interface_id=None):
        logger.info("Running relation hook %s %s", relation_name, action)

        # TODO: Only on certain actions?
        if action == "broken":
            return

        xaas = self._client()

        bundle_type = self.config["charm"]
        instance_id = Juju.service_name()

        if interface_id is None:
            interface_id = instance_id

        logger.info("Fetching service properties for %s/%s/%s", bundle_type, instance_id, interface_id)
        response = xaas.get_relation_properties(bundle_type=bundle_type, instance_id=instance_id, relation=interface_id)

        relation_properties = response.get("Properties", {})

        protocol = relation_properties.get("protocol")
        if protocol == "tls":
            relation_properties = self._ensure_tls(bundle_type, relation_properties)

        relation = Relation.default()

        logger.info("Setting relation properties to: %s", relation_properties)
        relation.set_properties(relation_properties)
Beispiel #3
0
    def on_config_changed(self):
        xaas = self._client()

        options = Juju.config()
        bundle_type = self.config["charm"]
        instance_id = Juju.service_name()

        logger.info("Ensuring that service is configured: %s %s", bundle_type, instance_id)
        service = xaas.ensure_instance(bundle_type=bundle_type, instance_id=instance_id, options=options)

        # TODO: Timeout & throw error after a while
        while service.get("Status") != "started":
            logger.info("Waiting for service to reach active state.  Current state %s", service.get("Status"))
            time.sleep(5)
            service = xaas.get_instance_state(bundle_type=bundle_type, instance_id=instance_id)

        return service