def getInterfaceId(self, interface_id, node_id=None): eui = self.getInterfaceEUI64(interface_id, node_id) if eui is None: return None iid = IP.EUI64toIID(eui) return iid
def __get_weave_params(self, node_name=None, node_params={}): """ Returns weave params for a node. If weave_node_id is empty, it will pick one at random from a list of test weave node ids. """ weave_node_id = node_params.get('weave_node_id', None) cert = node_params.get('weave_certificate', None) key = node_params.get('private_key', None) pairing_code = node_params.get('pairing_code', None) if weave_node_id: # bail if it is already in use by a different node nodes = self.weave_state.getWeaveNodeRecord() for node in nodes.keys(): if node == node_name: continue if nodes[node].get("weave_node_id", None) == weave_node_id: emsg = "weave_node_id (%s) already in use." % weave_node_id self.logger.error("[localhost] WeaveNodeConfigure: %s" % emsg) self.weave_state.exit() else: weave_node_id = self.__get_available_weave_node_id() if not (cert and key): # check if a cert/key are available and use them node_cert = self.weave_device_certs.get(weave_node_id, None) if node_cert: cert = self.weave_device_certs[weave_node_id].get('cert', None) key = self.weave_device_certs[weave_node_id].get('key', None) # NOTE: self.weave_device_certs[weave_node_id]['cert-256'] is also available else: emsg = "WARNING: could not find weave cert/key for id=%s" % ( weave_node_id) self.weave_state.logger.debug( "[localhost] WeaveNodeConfigure: %s" % emsg) # while we don't sys.exit() at this point, note that tests # that require cert/key will fail if they are not configured. params = {} params['weave_node_id'] = weave_node_id params['eui64'] = self.weave_state.WeaveIdtoEUI64(weave_node_id) params['iid'] = IP.EUI64toIID(params['eui64']) params['serial_num'] = weave_node_id if cert and key: # these keys are only written if they are available params['weave_certificate'] = cert params['private_key'] = key params['pairing_code'] = self.__get_pairing_code(pairing_code) return params
def getServiceWeaveIPAddress(self, service, node_id=None, state=None): weave_global_prefix = self.getFabricGlobalPrefix(state) global_prefix_addr, _ = weave_global_prefix.split("::") if weave_global_prefix is None: return None weave_id = self.getServiceWeaveID(service, node_id=None, state=None) if weave_id is None: return None subnet = 5 subnet_hex = "%04x" % (subnet) eui = self.WeaveIdtoEUI64(weave_id) iid = IP.EUI64toIID(eui) addr = global_prefix_addr + ":" + subnet_hex + ":" + iid return addr