def getInternalIP(self): """ Get the IP address of the network interface used for the internal communication. @return: IP address of the network interface. @rtype: str """ if self._intIP is None: self._intIP = getIP(self._intIF) return self._intIP
def __init__(self, reactor, commPort, extIF, extPort, loader, converter): """ Initialize the Robot Client. @param reactor: Reference to the twisted reactor used in this robot process. @type reactor: twisted::reactor @param commPort: Port where the server for the cloud engine internal communication is listening for incoming connections. @type commPort: int @param extIF: Name of network interface used for the external communication. @type extIF: str @param extPort: Port where the server for the external communication is listening for websocket connections. @type extPort: int @param loader: Object which is used to load python modules from ROS packages. @type loader: rce.util.loader.Loader @param converter: Converter which takes care of converting the messages from JSON to ROS message and vice versa. @type converter: rce.util.converter.Converter """ Endpoint.__init__(self, reactor, commPort) self._extAddress = "{0}:{1}".format(getIP(extIF), extPort) self._converter = converter self._loader = loader self._robots = set() self._pendingRobots = {} self._deathCandidates = {}
def __init__(self, reactor, masterIP, intIF, bridgeIF, envPort, rootfsDir, confDir, dataDir, srcDir, pkgDir): """ Initialize the Container Client. @param reactor: Reference to the twisted reactor. @type reactor: twisted::reactor @param masterIP: IP address of the Master process. @type masterIP: str @param intIF: Name of the network interface used for the internal network. @type intIF: str @param bridgeIF: Name of the bridge interface used for the container network. @type bridgeIF: str @param envPort: Port where the environment process running inside the container is listening for connections to other endpoints. (Used for port forwarding.) @type envPort: int @param rootfsDir: Filesystem path to the root directory of the container filesystem. @type rootfsDir: str @param confDir: Filesystem path to the directory where container configuration files should be stored. @type confDir: str @param dataDir: Filesystem path to the directory where temporary data of a container should be stored. @type dataDir: str @param srcDir: Filesystem path to the directory where the source of the cloud engine is located. @type srcDir: str @param pkgDir: Filesystem paths to the package directories as a list of tuples where each tuple contains the path to the directory in the host machine and the path to the directory to which the host directory will be bound in the container filesystem (without the @param rootfsDir). @type pkgDir: [(str, str)] """ self._reactor = reactor self._internalIP = getIP(intIF) self._envPort = envPort bridgeIP = getIP(bridgeIF) if masterIP in ('localhost', '127.0.0.1'): self._masterIP = bridgeIP else: self._masterIP = masterIP self._rootfs = rootfsDir self._confDir = confDir self._dataDir = dataDir self._srcDir = srcDir # Validate directory paths checkPath(self._confDir, 'Configuration') checkPath(self._dataDir, 'Data') checkPath(self._rootfs, 'Container file system') checkPath(self._srcDir, 'RCE source') # Validate executable paths checkExe(self._srcDir, 'environment.py') #checkExe(self._srcDir, 'launcher.py') # Process ROS package paths self._pkgDir = processPkgPath(pkgDir) for _, path in self._pkgDir: os.mkdir(os.path.join(self._rootfs, path)) self._nrs = set(range(100, 200)) self._containers = set() # Network configuration self._network = bridgeIP[:bridgeIP.rfind('.')] self._networkConf = _NETWORK_INTERFACES.format(network=self._network) # Common iptables references nat = iptc.Table(iptc.Table.NAT) self._prerouting = iptc.Chain(nat, 'PREROUTING') self._output = iptc.Chain(nat, 'OUTPUT')