def _run(self, client: OpenrCtrl.Client, key: str) -> None: area = self.get_area_id() publication = None if area is None: publication = client.getKvStoreKeyVals([key]) else: publication = client.getKvStoreKeyValsArea([key], area) keyVals = publication.keyVals if key not in keyVals: print("Error: Key {} not found in KvStore.".format(key)) sys.exit(1) # Get and modify the key val = keyVals.get(key) val.value = None val.ttl = 256 # set new ttl to 256ms (its decremented 1ms on every hop) val.ttlVersion += 1 # bump up ttl version print(keyVals) if area is None: client.setKvStoreKeyVals(openr_types.KeySetParams(keyVals)) else: client.setKvStoreKeyVals(openr_types.KeySetParams(keyVals), area) print("Success: key {} will be erased soon from all KvStores.".format( key))
def _run(self, client: OpenrCtrl.Client, node_name: str) -> None: area = self.get_area_id() key = Consts.STATIC_PREFIX_ALLOC_PARAM_KEY # Retrieve previous allocation resp = None if area is None: resp = client.getKvStoreKeyVals([key]) else: resp = client.getKvStoreKeyValsArea([key], area) allocs = None if key in resp.keyVals: allocs = serializer.deserialize_thrift_object( resp.keyVals.get(key).value, openr_types.StaticAllocation) else: allocs = openr_types.StaticAllocation(nodePrefixes={node_name: ""}) # Return if there need no change if node_name not in allocs.nodePrefixes: print( "No changes needed. {}'s prefix is not set".format(node_name)) return # Update value in KvStore del allocs.nodePrefixes[node_name] value = serializer.serialize_thrift_object(allocs) super(AllocationsUnsetCmd, self)._run(client, key, value, "breeze", None, Consts.CONST_TTL_INF)
def _run(self, client: OpenrCtrl.Client, node_name: str, prefix_str: str) -> None: area = self.get_area_id() key = Consts.STATIC_PREFIX_ALLOC_PARAM_KEY # Retrieve previous allocation resp = None if area is None: resp = client.getKvStoreKeyVals([key]) else: resp = client.getKvStoreKeyValsArea([key], area) allocs = None if key in resp.keyVals: allocs = serializer.deserialize_thrift_object( resp.keyVals.get(key).value, alloc_types.StaticAllocation) else: allocs = alloc_types.StaticAllocation(nodePrefixes={}) # Return if there is no change prefix = ipnetwork.ip_str_to_prefix(prefix_str) if allocs.nodePrefixes.get(node_name) == prefix: print("No changes needed. {}'s prefix is already set to {}".format( node_name, prefix_str)) return # Update value in KvStore allocs.nodePrefixes[node_name] = prefix value = serializer.serialize_thrift_object(allocs) super(AllocationsSetCmd, self)._run(client, key, value, "breeze", None, Consts.CONST_TTL_INF)
def _run(self, client: OpenrCtrl.Client, keys: List[str]) -> None: if not self.area_feature: super()._run(client, keys) return for area in self.areas: resp = client.getKvStoreKeyValsArea(keys, area) if len(resp.keyVals): self.print_kvstore_values(resp, area)
def _run(self, client: OpenrCtrl.Client) -> None: if not self.area_feature: super()._run(client) return key = Consts.STATIC_PREFIX_ALLOC_PARAM_KEY for area in self.areas: resp = client.getKvStoreKeyValsArea([key], area) self.print_allocations(key, resp.keyVals, area)
def _run( self, client: OpenrCtrl.Client, key: str, value: Any, originator: str, version: Any, ttl: int, ) -> None: area = self.get_area_id() val = kv_store_types.Value() if version is None: # Retrieve existing Value from KvStore publication = None if area is None: publication = client.getKvStoreKeyVals([key]) else: publication = client.getKvStoreKeyValsArea([key], area) if key in publication.keyVals: existing_val = publication.keyVals.get(key) print( "Key {} found in KvStore w/ version {}. Overwriting with" " higher version ...".format(key, existing_val.version) ) version = existing_val.version + 1 else: version = 1 val.version = version val.originatorId = originator val.value = value val.ttl = ttl val.ttlVersion = 1 # Advertise publication back to KvStore keyVals = {key: val} if area is None: client.setKvStoreKeyVals(kv_store_types.KeySetParams(keyVals)) else: client.setKvStoreKeyVals(kv_store_types.KeySetParams(keyVals), area) print( "Success: Set key {} with version {} and ttl {} successfully" " in KvStore. This does not guarantee that value is updated" " in KvStore as old value can be persisted back".format( key, val.version, val.ttl if val.ttl != Consts.CONST_TTL_INF else "infinity", ) )