def __pre_check(self): # Check if the name of the new node is given if not self.node_id: emsg = "Missing name of the new virtual node that should be created." self.logger.error("[localhost] HappyNodeAdd: %s" % (emsg)) self.exit() # Check if dot is in the name if IP.isDomainName(self.node_id): emsg = "Using . (dot) in the name is not allowed." self.logger.error("[localhost] HappyNodeAdd: %s" % (emsg)) self.exit() # Check if node type is valid if self.type is not None and self.type not in self.node_special_type: emsg = "Unknown node type %s." % (self.type) self.logger.error("[localhost] HappyNodeAdd: %s" % (emsg)) self.exit() # Check if the name of new node is not a duplicate (that it does not already exists). if self._nodeExists(): emsg = "virtual node %s already exists." % (self.node_id) self.logger.warning("[%s] HappyNodeAdd: %s" % (self.node_id, emsg)) self.__deleteExistingNode() # Check if there is some old record of a node if self.node_id in self.getNodeIds(): self.__deleteExistingNode()
def __pre_check(self): # Check if the name of the new network is given if not self.network_id: emsg = "Missing name of the new virtual network that should be created." self.logger.error("[localhost] HappyNetworkAdd: %s" % (emsg)) self.exit() # Check if dot is in the name if IP.isDomainName(self.network_id): emsg = "Using . (dot) in the name is not allowed." self.logger.error("[localhost] HappyNetworkAdd: %s" % (emsg)) self.exit() # Check if the type of the new network is given if not self.type: emsg = "Missing type of the new virtual network that should be created." self.logger.error("[%s] HappyNetworkAdd: %s" % (self.network_id, emsg)) self.exit() # Check if the type of the new network is given if self.type.lower() not in list(self.network_type.keys()): emsg = "Invalid virtual network type: " + self.type + "." self.logger.error("[%s] HappyNetworkAdd: %s" % (self.network_id, emsg)) self.exit() self.type = self.type.lower() # Check if bridge name won't be too long if len(self.uniquePrefix(self.network_id)) > 15: emsg = "network name or state ID too long (%s, %s)." % ( self.network_id, self.getStateId()) self.logger.error("[%s] HappyNetworkAdd: %s" % (self.network_id, emsg)) self.exit() # Check if the name of new network is not a duplicate (that it does not already exists). if self._networkExists(): emsg = "virtual network %s already exists." % (self.network_id) self.logger.warning("[%s] HappyNetworkAdd: %s" % (self.network_id, emsg)) self.__deleteExistingNetwork()
def __pre_check(self): # clear network info self.clients_info = [] # Make sure that fabric was created if self.getFabricId() == None: emsg = "Weave Fabric has not been created yet." self.logger.error("[localhost] WeaveBle: %s" % (emsg)) sys.exit(1) for client in self.clients: client_node_id = None # Check if Weave Ble client node is given. if client == None: emsg = "Missing name or address of the Weave Ble client node." self.logger.error("[localhost] WeaveBle: %s" % (emsg)) sys.exit(1) # Check if Weave Ble client node exists. if self._nodeExists(client): client_node_id = client # Check if client is provided in a form of IP address if IP.isIpAddress(client): client_node_id = self.getNodeIdFromAddress(client) if client_node_id == None: emsg = "Unknown identity of the client node." self.logger.error("[localhost] WeaveBle: %s" % (emsg)) sys.exit(1) if self.getNodeType(client_node_id) == "service": client_ip = self.getServiceWeaveIPAddress( self.endpoint, client_node_id) client_weave_id = self.getServiceWeaveID( self.endpoint, client_node_id) else: client_ip = self.getNodeWeaveIPAddress(client_node_id) client_weave_id = self.getWeaveNodeID(client_node_id) if client_ip == None: emsg = "Could not find IP address of the client node." self.logger.error("[localhost] WeaveBle: %s" % (emsg)) sys.exit(1) if client_weave_id == None: emsg = "Could not find Weave node ID of the client node." self.logger.error("[localhost] WeaveBle: %s" % (emsg)) sys.exit(1) self.clients_info.append({ 'client': client, 'client_node_id': client_node_id, 'client_ip': client_ip, 'client_weave_id': client_weave_id, 'client_process_tag': client + "_" + self.client_process_tag + client }) # Check if Weave Ble server node is given. if self.server == None: emsg = "Missing name or address of the Weave Ble server node." self.logger.error("[localhost] WeaveBle: %s" % (emsg)) sys.exit(1) # Check if Weave Ble server node exists. if self._nodeExists(self.server): self.server_node_id = self.server # Check if server is provided in a form of IP address if IP.isIpAddress(self.server): self.no_service = True self.server_ip = self.server self.server_weave_id = self.IPv6toWeaveId(self.server) elif IP.isDomainName(self.server) or self.server == "service": self.no_service = True self.server_ip = self.getServiceWeaveIPAddress(self.endpoint) self.server_weave_id = self.IPv6toWeaveId(self.server_ip) else: # Check if server is a true clound service instance if self.getNodeType(self.server) == self.node_type_service: self.no_service = True if not self.no_service and self.server_node_id == None: emsg = "Unknown identity of the server node." self.logger.error("[localhost] WeaveBle: %s" % (emsg)) sys.exit(1) if self.getNodeType(self.server_node_id) == "service": self.server_ip = self.getServiceWeaveIPAddress( self.endpoint, self.server_node_id) self.server_weave_id = self.getServiceWeaveID( self.endpoint, self.server_node_id) else: if not self.no_service: self.server_ip = self.getNodeWeaveIPAddress( self.server_node_id) self.server_weave_id = self.getWeaveNodeID(self.server_node_id) # Check if all unknowns were found if self.server_ip == None: emsg = "Could not find IP address of the server node." self.logger.error("[localhost] WeaveBle: %s" % (emsg)) sys.exit(1) if not self.no_service and self.server_weave_id == None: emsg = "Could not find Weave node ID of the server node." self.logger.error("[localhost] WeaveBle: %s" % (emsg)) sys.exit(1)
def __pre_check(self): # Make sure that fabric was created if self.getFabricId() == None: emsg = "Weave Fabric has not been created yet." self.logger.error("[localhost] WeaveWdmNext: %s" % (emsg)) sys.exit(1) # Check if Weave WDM server node is given. if self.server == None: emsg = "Missing name or address of the WeaveWdmNext server node." self.logger.error("[localhost] WeaveWdmNext: %s" % (emsg)) sys.exit(1) # Check if WeaveWdmNext server node exists. if self._nodeExists(self.server): self.server_node_id = self.server self.server_process_tag = self.server_node_id + "_" + self.server_process_tag # Check if server is provided in a form of IP address if IP.isIpAddress(self.server): self.no_service = True self.server_ip = self.server self.server_weave_id = self.IPv6toWeaveId(self.server) elif IP.isDomainName(self.server) or self.server == "service": self.no_service = True self.server_ip = self.getServiceWeaveIPAddress("DataManagement") self.server_weave_id = self.IPv6toWeaveId(self.server_ip) else: # Check if server is a true cloud service instance if self.getNodeType(self.server) == self.node_type_service: self.no_service = True if not self.no_service and self.server_node_id is None: emsg = "Unknown identity of the server node." self.logger.error("[localhost] WeaveWdmNext: %s" % emsg) sys.exit(1) if self.getNodeType(self.server_node_id) == "service": self.server_ip = self.getServiceWeaveIPAddress( "WeaveWdmNext", self.server_node_id) self.server_weave_id = self.getServiceWeaveID( "WeaveWdmNext", self.server_node_id) else: if not self.no_service: self.server_ip = self.getNodeWeaveIPAddress( self.server_node_id) self.server_weave_id = self.getWeaveNodeID(self.server_node_id) if self.server_ip is None: emsg = "Could not find IP address of the server node." self.logger.error("[localhost] WeaveWdmNext: %s" % emsg) sys.exit(1) if not self.no_service and self.server_weave_id is None: emsg = "Could not find Weave node ID of the server node." self.logger.error("[localhost] WeaveWdmNext: %s" % emsg) sys.exit(1) for client in self.clients: client_node_id = None client_ip = None client_weave_id = None # Check if Weave Wdm Next client node is given. if client == None: emsg = "Missing name or address of the WeaveWdmNext client node." self.logger.error("[localhost] WeaveWdmNext: %s" % (emsg)) sys.exit(1) # Check if WeaveWdmNext client node exists. if self._nodeExists(client): client_node_id = client # Check if client is provided in a form of IP address if IP.isIpAddress(client): client_node_id = self.getNodeIdFromAddress(client) if client_node_id is None: emsg = "Unknown identity of the client node." self.logger.error("[localhost] WeaveWdmNext: %s" % emsg) sys.exit(1) if self.getNodeType(client_node_id) == "service": client_ip = self.getServiceWeaveIPAddress( "WeaveWdmNext", client_node_id) client_weave_id = self.getServiceWeaveID( "WeaveWdmNext", client_node_id) else: client_ip = self.getNodeWeaveIPAddress(client_node_id) client_weave_id = self.getWeaveNodeID(client_node_id) if client_ip is None: emsg = "Could not find IP address of the client node." self.logger.error("[localhost] WeaveWdmNext: %s" % emsg) sys.exit(1) if client_weave_id is None: emsg = "Could not find Weave node ID of the client node." self.logger.error("[localhost] WeaveWdmNext: %s" % emsg) sys.exit(1) self.clients_info.append({ "client": client, "client_node_id": client_node_id, "client_ip": client_ip, "client_weave_id": client_weave_id, "client_process_tag": client + "_" + self.client_process_tag }) if self.wdm_option == "view": self.wdm_client_option = " --wdm-simple-view-client" self.wdm_server_option = " --wdm-simple-view-server" print("view disabled") sys.exit(1) elif self.wdm_option == "one_way_subscribe": self.wdm_client_option = " --wdm-one-way-sub-client" self.wdm_server_option = " --wdm-one-way-sub-publisher" elif self.wdm_option == "mutual_subscribe": self.wdm_client_option = " --wdm-init-mutual-sub" self.wdm_server_option = " --wdm-resp-mutual-sub" elif self.wdm_option == "subless_notify": self.wdm_client_option = " --wdm-simple-subless-notify-client" self.wdm_server_option = " --wdm-simple-subless-notify-server" else: emsg = "NOT SUPPORTED WDM OPTION" self.logger.error("[localhost] WeaveWdmNext: %s" % emsg) sys.exit(1)
def __pre_check(self): device_node_id = None # Set the produce resource that mock-device is paired to resourceDictionaries = self.getResourceIds() resourceIndexList = os.environ.get("RESOURCE_IDS", "thd1").split(" ") self.resources = [ resourceDictionaries[resourceIndex] for resourceIndex in resourceIndexList ] # Check if Weave Pairing device node is given. if self.devices is None: emsg = "Missing name or address of the Weave Pairing device node." self.logger.error("[localhost] WeavePairing: %s" % (emsg)) sys.exit(1) # Check if Weave Pairing mobile node is given. if self.mobile is None: emsg = "Missing name or address of the Weave Pairing mobile node." self.logger.error("[localhost] WeavePairing: %s" % (emsg)) sys.exit(1) # Check if Weave Pairing server info is given. if self.server is None: emsg = "Missing name or address of the Weave Pairing server node." self.logger.error("[localhost] WeavePairing: %s" % (emsg)) sys.exit(1) # Make sure that fabric was created if self.getFabricId() == None: emsg = "Weave Fabric has not been created yet." self.logger.error("[localhost] WeavePairing: %s" % (emsg)) sys.exit(1) # Check if Weave Pairing mobile node exists. if self._nodeExists(self.mobile): self.mobile_node_id = self.mobile # Check if mobile is provided in a form of IP address if IP.isIpAddress(self.mobile): self.mobile_node_id = self.getNodeIdFromAddress(self.mobile) if self.mobile_node_id is None: emsg = "Unknown identity of the mobile node." self.logger.error("[localhost] WeavePairing: %s" % (emsg)) sys.exit(1) # Find out whether to use a local mock server or a server # reachable over the internet if self._nodeExists(self.server): self.server_node_id = self.server self.server_ip = self.getNodeWeaveIPAddress(self.server_node_id) self.server_weave_id = self.getWeaveNodeID(self.server_node_id) elif IP.isIpAddress(self.server): self.server_ip = self.server self.server_weave_id = self.IPv6toWeaveId(self.server) elif IP.isDomainName(self.server) or self.server == "service": self.server_ip = self.getServiceWeaveIPAddress( "ServiceProvisioning") self.server_weave_id = self.IPv6toWeaveId(self.server_ip) self.mobile_ip = self.getNodeWeaveIPAddress(self.mobile_node_id) self.mobile_weave_id = self.getWeaveNodeID(self.mobile_node_id) for device, resource in zip(self.devices, self.resources): # Check if Weave Pairing device node exists. if self._nodeExists(device): device_node_id = device # Check if device is provided in a form of IP address if IP.isIpAddress(device): device_node_id = self.getNodeIdFromAddress(device) if device_node_id is None: emsg = "Unknown identity of the device node." self.logger.error("[localhost] WeavePairing: %s" % (emsg)) sys.exit(1) device_ip = self.getNodeWeaveIPAddress(device_node_id) if device_ip is None: emsg = "Could not find IP address of the device node." self.logger.error("[localhost] WeavePairing: %s" % (emsg)) sys.exit(1) device_weave_id = self.getWeaveNodeID(device_node_id) if device_weave_id is None: emsg = "Could not find Weave node ID of the device node." self.logger.error("[localhost] WeavePairing: %s" % (emsg)) sys.exit(1) device_serial_num = self.getSerialNum(device_node_id) if device_serial_num is None: emsg = "Could not find serial number of the device node." self.logger.error("[localhost] WeavePairing: %s" % (emsg)) sys.exit(1) self.devices_info.append({ 'device': device, 'device_node_id': device_node_id, 'device_ip': device_ip, 'device_weave_id': device_weave_id, 'device_serial_num': device_serial_num, 'device_process_tag': device + "_" + self.device_process_tag, 'resource': resource }) if self.mobile_ip is None: emsg = "Could not find IP address of the mobile node." self.logger.error("[localhost] WeavePairing: %s" % (emsg)) sys.exit(1) if self.mobile_weave_id is None: emsg = "Could not find Weave node ID of the mobile node." self.logger.error("[localhost] WeavePairing: %s" % (emsg)) sys.exit(1) if self.server_ip is None: emsg = "Could not find IP address of the server." self.logger.error("[localhost] WeavePairing: %s" % (emsg)) sys.exit(1) if self.server_weave_id is None: emsg = "Could not find Weave node ID of the server." self.logger.error("[localhost] WeavePairing: %s" % (emsg)) sys.exit(1)
def __pre_check(self): if self.border_gateway: if self.border_gateway != self.getTunnelGatewayNodeId(): emsg = "Incorrect border-gateway node id. Entered %s vs %s on the record." % \ (self.border_gateway, self.getTunnelGatewayNodeId()) self.logger.error("[localhost] WeaveTunnelStart: %s" % (emsg)) self.exit() else: self.border_gateway = self.getTunnelGatewayNodeId() # Check if border-gateway node was given if not self.border_gateway: emsg = "Border-gateway node id not specified and there is none on the record." self.logger.error("[localhost] WeaveTunnelStart: %s" % (emsg)) self.exit() if not self._nodeExists(self.border_gateway): emsg = "Border-gateway node %s does not exist." % ( self.border_gateway) self.logger.error("[localhost] WeaveTunnelStart: %s" % (emsg)) self.exit() # Check if service node was given in the environment if not self.service: self.service = self.getTunnelServiceNodeId() if not self.service and self.service_dir: if self.service_dir_server: self.skip_service_end = True self.logger.debug( "[localhost] WeaveTunnelStart against tier %s." % self.service_dir_server) else: self.service_dir_server = self.getTunnelServiceDir() if not self.service_dir_server: # Check if service node was given emsg = "Service node id (or IP address or service directory) not specified." self.logger.error("[localhost] WeaveTunnelStart: %s" % (emsg)) self.exit() else: self.skip_service_end = True self.logger.debug( "[localhost] WeaveTunnelStart against tier %s." % self.service_dir_server) if self.service: # If service is a domain name, convert it to IP if IP.isDomainName(self.service): ip = IP.getHostByName(self.service) self.service = ip if not IP.isIpAddress(self.service): if self.service: if self.service != self.getTunnelServiceNodeId(): emsg = "Incorrect service node id. Entered %s vs %s on the record." % \ (self.service, self.getTunnelServiceNodeId()) self.logger.error("[localhost] WeaveTunnelStart: %s" % (emsg)) self.exit() if not IP.isIpAddress(self.service) and not self._nodeExists( self.service): emsg = "Service node %s does not exist." % (self.service) self.logger.error("[localhost] WeaveTunnelStart: %s" % (emsg)) self.exit() if IP.isIpAddress(self.service): self.skip_service_end = True # Check if there is no fabric if not self.getFabricId(): emsg = "There is not Weave fabric." self.logger.error("[localhost] WeaveTunnelStart: %s" % (emsg)) self.exit() # Check if there is a tunnel if not self.getTunnelServiceNodeId() and not self.getTunnelServiceDir( ): emsg = "There is no Weave tunnel on the record." self.logger.error("[localhost] WeaveTunnelStart: %s" % (emsg)) self.exit()
def __pre_check(self): # Check if border-gateway node was given if not self.border_gateway: emsg = "Border-gateway node id not specified." self.logger.error("[localhost] WeaveTunnelStart: %s" % (emsg)) self.exit() if not self._nodeExists(self.border_gateway): emsg = "Border-gateway node %s does not exist." % ( self.border_gateway) self.logger.error("[localhost] WeaveTunnelStart: %s" % (emsg)) self.exit() # Check if service node was given in the environment if not self.service and not self.service_dir: if "weave_service_address" in os.environ.keys(): self.service = os.environ['weave_service_address'] emsg = "Found weave_service_address %s." % (self.service) self.logger.debug("[localhost] Weave: %s" % (emsg)) if not self.service and self.service_dir: if self.service_dir_server: self.skip_service_end = True self.logger.debug( "[localhost] WeaveTunnelStart against tier %s." % self.service_dir_server) else: if "weave_service_address" in os.environ.keys(): self.skip_service_end = True self.service_dir_server = os.environ[ 'weave_service_address'] self.logger.debug( "[localhost] WeaveTunnelStart against tier %s." % self.service_dir_server) else: # Check if service node was given emsg = "Service node id (or IP address or service directory) not specified." self.logger.error("[localhost] WeaveTunnelStart: %s" % (emsg)) self.exit() if self.service and not self.use_lwip: # If service is a domain name, convert it to IP if IP.isDomainName(self.service): ip = IP.getHostByName(self.service) self.service = ip if not IP.isIpAddress(self.service) and not self._nodeExists( self.service): emsg = "Service node %s does not exist." % (self.service) self.logger.error("[localhost] WeaveTunnelStart: %s" % (emsg)) self.exit() if IP.isIpAddress(self.service): self.service_ipv4_addr = self.service self.skip_service_end = True else: self.service_ipv4_addr = self.getNodePublicIPv4Address( self.service) if self.service_ipv4_addr == None: emsg = "Could not find IP address of the service node." self.logger.error("[localhost] WeaveTunnel: %s" % (emsg)) self.exit() self.fabric_id = self.getFabricId() # Check if there is no fabric if self.fabric_id == None: emsg = "There is not Weave fabric." self.logger.error("[localhost] WeaveTunnelStart: %s" % (emsg)) self.exit() # Check if there is a tunnel if self.getTunnelServiceNodeId() or self.getTunnelServiceDir(): emsg = "There already exist a Weave tunnel." self.logger.error("[localhost] WeaveTunnelStart: %s" % (emsg)) self.__stopExistingTunnel() self.service_weave_id = self.getServiceWeaveID("Tunnel") self.gateway_weave_id = self.getWeaveNodeID(self.border_gateway) if self.service_weave_id == None: emsg = "Could not find Weave node ID of the service node." self.logger.error("[localhost] WeaveTunnel: %s" % (emsg)) self.exit() if self.gateway_weave_id == None: emsg = "Could not find Weave node ID of the border-gateway node." self.logger.error("[localhost] WeaveTunnel: %s" % (emsg)) self.exit()