Exemple #1
0
    def desired_status(self):
        """Get the desired status. Will download and compile status if necessary."""
        if self._desired_status is None:
            services = context.machination_worker_elt.xpath("services/service")
            # TODO download from all services and merge. For now just
            # do the first one.
            #            hurl = services[0].xpath('hierarchy/@id')
            service_id = services[0].get("id")
            l.lmsg('Connecting to service "{}"'.format(service_id))
            # find the machination id for this service
            mid = context.get_id(service_id)
            wc = WebClient.from_service_id(service_id, "os_instance")
            #            channel = wc.call("ProfChannel", 'os_instance')
            try:
                data = wc.call("GetAssertionList", "os_instance", mid)
            except:
                # couldn't dowload assertions - go with last desireed
                # status. Should already be canonicalized.
                l.wmsg("Failed to download assertions - using desired status from context.")
                self._desired_status = copy.deepcopy(context.desired_status.getroot())
            else:
                # we do have some assertions - compile them
                #                pprint.pprint(data)
                ac = AssertionCompiler(wc)
                self._desired_status, res = ac.compile(data)
                mc14n(self._desired_status)
                # Save as desired-status.xml
                with open(os.path.join(context.status_dir(), "desired-status.xml"), "w") as ds:
                    ds.write(etree.tostring(self._desired_status, pretty_print=True).decode())

        return self._desired_status