def refresh(self): interval = super(BlippConfigure, self).refresh() if interval != int(self.config['properties']['configurations']['unis_poll_interval']): return interval # unis.get returns a list of config if isinstance(self.config, list): self.config = self.config[0] self.initial_probes = self._strip_probes(self.config) if self.initial_probes: self._post_probes() self.unis.put("/services/" + self.config["id"], data=self.config) qmeas = self.unis.get("/measurements?service=" + self.config["selfRef"]) if qmeas: self.measurements = qmeas self.measurements = get_most_recent(self.measurements) for m in self.measurements: size_orig = len(m["configuration"]) merge_into(m["configuration"], self.probe_defaults) if size_orig < len(m["configuration"]): self.unis.put("/measurements/"+m["id"], m) r = self.unis.get("/measurements/"+m["id"]) m['ts'] = r['ts'] else: ''' If measurements don't exist then create them again - i.e register them again ''' self.measurements = get_most_recent(self.measurements) for m in self.measurements: self.unis.post("/measurements/", m) return interval
def refresh(self): super(BlippConfigure, self).refresh() self.initial_probes = self._strip_probes(self.config) if self.initial_probes: self._post_probes() self.unis.put("/services/" + self.config["id"], data=self.config) qmeas = self.unis.get("/measurements?service=" + self.config["selfRef"]) if qmeas: self.measurements = qmeas self.measurements = get_most_recent(self.measurements) for m in self.measurements: size_orig = len(m["configuration"]) merge_into(m["configuration"], self.probe_defaults) if size_orig < len(m["configuration"]): self.unis.put("/measurements/"+m["id"], m) else: ''' If measurements don't exist then create them again - i.e register them again ''' self.measurements = get_most_recent(self.measurements) for m in self.measurements: self.unis.post("/measurements/", m)
def initialize(self): super(BlippConfigure, self).initialize() if not self.service_setup: logger.error("initialize", msg="Could not reach UNIS to initialize service") exit(-1) self.initial_measurements = self.unis.get("/measurements?service=" + self.config["selfRef"]) self.initial_measurements = get_most_recent(self.initial_measurements) # use any pre-existing measurements found in UNIS right away if self.pem=="use": for m in self.initial_measurements: self.measurements.append(m) # now strip and add to measurements any probes found in the merged initial config self.initial_probes = self._strip_probes(self.config) if self.initial_probes: self._post_probes() self.unis.put("/services/" + self.config["id"], data=self.config)
def post_port(self, post_dict, headers=None): if "$schema" not in post_dict: post_dict.update({"$schema":settings.SCHEMAS['ports']}) if "urn" not in post_dict: post_dict.update({"urn":settings.HOST_URN + "port=" + \ post_dict.get("name", "")}) if "location" not in post_dict and "location" in self.service: post_dict.update({"location": self.service["location"]}) port_post = self.pc.do_req("post", "/ports", data=post_dict) # Update the node to have these ports as well if port_post: node_rep = self.get(self.service["runningOn"]["href"]) if isinstance(node_rep, list): node_rep = get_most_recent(node_rep) if len(node_rep) == 1: node_rep = node_rep[0] node_rep.setdefault("ports", []).append({"href":port_post["selfRef"], "rel": "full"}) self.put(node_rep["selfRef"], data=node_rep) return port_post