Exemple #1
0
    def connectToService(self, url = None, method = None, cred = None):
        '''Connect to a machination hierarchy service.
        '''
        if url is None:
            ok = self.d_service_url.exec_()
            if ok:
                url = self.d_service_url.textValue()
            else:
                return
        if method is None or cred is None:
            d = CredentialsDialog(self.ui, url)
            selt = etree.fromstring(
                "<service><hierarchy id='{}'/></service>".format(url)
                )
            tmpwc = WebClient(url, 'public', 'person')
            istr = tmpwc.call('ServiceConfig')
            info = etree.fromstring(istr)
            auth_type_elts = info.xpath('authentication/type')
            authtypes = [x.get("id") for x in auth_type_elts]
            d.setAuthMethodsList(authtypes)
            if method is None:
                method = info.xpath('authentication/objType[@id="person"]/@defaultAuth')[0]
            d.default_auth_method = method
            d.setAuthMethod(method)
            ok = d.exec_()
            if ok:
                cred = d.getCred()
            method = d.current_auth_method

        self.wcs[url] = WebClient(url, method, 'person', credentials = cred)
        self.model.add_service(self.wcs[url])
Exemple #2
0
    def test_compile(self):
        wc = WebClient('http://w4043.see.ed.ac.uk/machination/hierarchy',
                       'os_instance:test-win7-1')
        path = '/by_os/windows/by_version/7/os_instance:test-win7-1'
        idpair = wc.call("IdPair", path)
        channel = wc.call("ProfChannel", idpair['type_id'])
        data = wc.call("GetAssertionList", path, channel)
        ac = xmltools.AssertionCompiler(wc)
        st, res = ac.compile(data)
#        print(xmltools.pstring(st.getroot()))
        print(etree.tostring(st, pretty_print=True, encoding='utf8').decode('utf8'))
Exemple #3
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