Beispiel #1
0
    def view_createContainer(self, user, tag, data={}):
        """ Create a new Container object.

            @param user:        User for which the container will be created.
            @type  user:        rce.core.user.User

            @param tag:         Tag which is used to identify the container
                                in subsequent requests.
            @type  tag:         str

            @param data:        Extra data used to configure the container.
            @type  data:        dict
        """
        try:
            validateName(tag)
        except IllegalName as e:
            raise InvalidRequest('Container tag is invalid: {0}'.format(e))

        if tag in user.containers or tag in user.robots:
            raise InvalidRequest('Tag is already used for a container '
                                 'or robot.')

        namespace, remote_container = user.realm.createContainer(user.userID,
                                                                 data)
        container = Container(namespace, remote_container)
        user.containers[tag] = container
        container.notifyOnDeath(user.containerDied)

        m = 'Container {0} successfully created.'.format(tag)
        d = DeferredList([namespace(), remote_container()],
                         fireOnOneErrback=True, consumeErrors=True)
        return d.addCallback(lambda _: m)
Beispiel #2
0
    def view_createContainer(self, user, tag):
        """ Create a new Container object.

            @param user:        User for which the container will be created.
            @type  user:        rce.core.user.User

            @param tag:         Tag which is used to identify the container
                                in subsequent requests.
            @type  tag:         str
        """
        try:
            validateName(tag)
        except IllegalName as e:
            raise InvalidRequest('Container tag is invalid: {0}'.format(e))

        if tag in user.containers or tag in user.robots:
            raise InvalidRequest('Tag is already used for a container '
                                 'or robot.')

        namespace, remote_container = user.realm.createContainer(user.userID)
        container = Container(namespace, remote_container)
        user.containers[tag] = container
        container.notifyOnDeath(user.containerDied)

        m = 'Container {0} successfully created.'.format(tag)
        d = DeferredList([namespace(), remote_container()],
                         fireOnOneErrback=True, consumeErrors=True)
        return d.addCallback(lambda _: m)
Beispiel #3
0
    def registerRobot(self, robot, robotID):
        """ Create a new Robot Wrapper.

            # TODO: Add description of arguments

            @raise:             rce.core.error.InvalidRequest
        """
        try:
            validateName(robotID)
        except IllegalName as e:
            raise InvalidRequest('Robot ID is invalid: {0}'.format(e))

        if (robotID in self.robots or robotID in self.containers):
            raise InvalidRequest('ID is already used for a container '
                                 'or robot.')

        robot = Robot(robot)
        self.robots[robotID] = robot
        robot.notifyOnDeath(self.robotDied)
Beispiel #4
0
    def addUser(self, username, password, provision=False):
        """ Change password for the username:

            @param username:    username
            @type  username:    str

            @param password:    password
            @type  password:    str

            @param provision:   Special flag to indicate provisioning mode
            @type  provision:   bool

            @return:            Result of Operation
            @rtype:             bool
        """
        try:
            validateName(username)
        except IllegalName as e:
            raise CredentialError(str(e))

        if not (self.pass_validator(password) or provision):
            raise CredentialError(_PASSWORD_FAIL)

        if provision:
            with open(self.filename, 'a') as f:
                f.write(
                    formatUser(username,
                               sha256(password).hexdigest(),
                               _DEFAULT_USER_MODE, _DEFAULT_GROUPS))
                f.write('\n')
            return True

        try:
            self.getUser(username)
            raise CredentialError('Given user already exists')
        except KeyError:
            with open(self.filename, 'a') as f:
                f.write(
                    formatUser(username,
                               sha256(password).hexdigest(),
                               _DEFAULT_USER_MODE, _DEFAULT_GROUPS))
                f.write('\n')
            return True
Beispiel #5
0
    def addInterface(self, iTag, iType, clsName, addr):
        """ Add an interface to the ROS environment inside the container.

            @param iTag:        Tag which is used to identify the interface in
                                subsequent requests.
            @type  iTag:        str

            @param iType:       Type of the interface. The type has to be of
                                the form:
                                    {prefix}Interface
                                whit valid prefixes:
                                    ServiceClient, ServiceProvider,
                                    Publisher, Subscriber
            @type  iType:       str

            @param clsName:     Message type/Service type consisting of the
                                package and the name of the message/service,
                                i.e. 'std_msgs/Int32'.
            @type  clsName:     str

            @param addr:        ROS name/address which the interface should
                                use.
            @type  addr:        str
        """
        try:
            validateName(iTag)
        except IllegalName:
            raise InvalidRequest('Interface tag is not a valid.')

        if iTag in self._interfaces:
            raise InvalidRequest("Can not use the same interface tag '{0}' "
                                 'in the same container twice.'.format(iTag))

        try:
            iType = Types.encode(iType)
        except TypeError:
            raise InvalidRequest('Interface type is invalid (Unknown prefix).')

        interface = self._obj.createInterface(iType, clsName, addr)
        interface = Interface(interface, iType, clsName)
        self._interfaces[iTag] = interface
        interface.notifyOnDeath(self._interfaceDied)
Beispiel #6
0
    def addInterface(self, iTag, iType, clsName):
        """ Add an interface to the Robot object.

            @param iTag:        Tag which is used to identify the interface in
                                subsequent requests.
            @type  iTag:        str

            @param iType:       Type of the interface. The type consists of a
                                prefix and a suffix.
                                 - Valid prefixes are:
                                     ServiceClient, ServiceProvider,
                                     Publisher, Subscriber
                                 - Valid suffixes are:
                                     Converter, Forwarder
            @type  iType:       str

            @param clsName:     Message type/Service type consisting of the
                                package and the name of the message/service,
                                i.e. 'std_msgs/Int32'.
            @type  clsName:     str
        """

        try:
            validateName(iTag)
        except IllegalName as e:
            raise InvalidRequest('Interface tag is invalid: {0}'.format(e))

        if iTag in self._interfaces:
            raise InvalidRequest("Can not use the same interface tag '{0}' "
                                 'in the same robot twice.'.format(iTag))

        modifier = 4 if iType.endswith('Forwarder') else 0

        try:
            iType = Types.encode(iType)
        except TypeError:
            raise InvalidRequest('Interface type is invalid (Unknown prefix).')

        interface = self._obj.createInterface(iType + modifier, clsName, iTag)
        interface = Interface(interface, iType, clsName)
        self._interfaces[iTag] = interface
        interface.notifyOnDeath(self._interfaceDied)
Beispiel #7
0
    def createRobotWrapper(self, robotNamespace, location, robotID):
        """ Create a new Robot Wrapper.

            # TODO: Add description of arguments

            @raise:             rce.core.error.InvalidRequest
        """
        try:
            validateName(robotID)
        except IllegalName as e:
            raise InvalidRequest('Robot ID is invalid: {0}'.format(e))

        if (robotID in self.robots or robotID in self.containers):
            raise InvalidRequest('ID is already used for a container '
                                 'or robot.')

        robot, status = location.createRobotProxy(robotID, robotNamespace)
        robot = Robot(robot)
        self.robots[robotID] = robot
        robot.notifyOnDeath(self.robotDied)
        return status
Beispiel #8
0
    def addNode(self, nTag, pkg, exe, args, name, namespace):
        """ Add a node to the ROS environment inside the container.

            @param nTag:        Tag which is used to identify the node in
                                subsequent requests.
            @type  nTag:        str

            @param pkg:         Name of ROS package where the node can be
                                found.
            @type  pkg:         str

            @param exe:         Name of executable (node) which should be
                                launched.
            @type  exe:         str

            @param args:        Additional arguments which should be used for
                                the launch.
            @type  args:        str

            @param name:        Name of the node under which the node should be
                                launched.
            @type  name:        str

            @param namespace:   Namespace in which the node should be started
                                in the environment.
            @type  namespace:   str
        """
        try:
            validateName(nTag)
        except IllegalName:
            raise InvalidRequest('Node tag is not a valid.')

        if nTag in self._nodes:
            raise InvalidRequest("Can not use the same node tag '{0}' in the "
                                 'same container twice.'.format(nTag))

        node = self._obj.createNode(pkg, exe, args, name, namespace)
        self._nodes[nTag] = node
        node.notifyOnDeath(self._nodeDied)
Beispiel #9
0
    def addUser(self, username, password, provision=False):
        """ Change password for the username:

            @param username:    username
            @type  username:    str

            @param password:    password
            @type  password:    str

            @param provision:   Special flag to indicate provisioning mode
            @type  provision:   bool

            @return:            Result of Operation
            @rtype:             bool
        """
        try:
            validateName(username)
        except IllegalName as e:
            raise CredentialError(str(e))

        if not (self.pass_validator(password) or provision):
            raise CredentialError(_PASSWORD_FAIL)

        if provision:
            with open(self.filename, 'a') as f:
                f.write(formatUser(username, sha256(password).hexdigest(),
                                   _DEFAULT_USER_MODE, _DEFAULT_GROUPS))
                f.write('\n')
            return True

        try:
            self.getUser(username)
            raise CredentialError('Given user already exists')
        except KeyError:
            with open(self.filename, 'a') as f:
                f.write(formatUser(username, sha256(password).hexdigest(),
                                   _DEFAULT_USER_MODE, _DEFAULT_GROUPS))
                f.write('\n')
            return True
Beispiel #10
0
    def load(cls, parser):
        """ Factory method which creates a new Settings object using the
            provided cloud engine settings parser.

            @param parser:      Cloud engine settings parser which is used to
                                parse the configuration file.
            @type  parser:      rce.util.settings._RCESettingsParser

            @return:            New _Settings instance containing the parsed
                                settings.
            @rtype:             rce.util.settings._Settings
        """
        settings = cls()

        # Global
        settings._gzip_lvl = parser.getint('global', 'gzip_lvl')
        settings._dev_mode = parser.getboolean('global', 'dev_mode')
        settings._pw_file = parser.get('global', 'password_file')

        # Network
        settings._external_ip = parser.getIP('network', 'external_if')
        settings._internal_ip = parser.getIP('network', 'internal_if')
        settings._container_ip = parser.getIP('network', 'container_if')
        settings._localhost_ip = _getIP('lo')

        # Comm
        settings._http_port = parser.getint('comm', 'http_port')
        settings._ws_port = parser.getint('comm', 'ws_port')
        settings._internal_port = parser.getint('comm', 'internal_port')
        settings._external_port = parser.getint('comm', 'external_port')
        settings._comm_port = parser.getint('comm', 'comm_port')
        settings._ros_proxy_port = parser.getint('comm', 'ros_proxy_port')

        # Converters
        settings._converters = tuple(c for _, c in parser.items('converters'))

        # Machine
        settings._max_container = parser.getint('machine', 'max_container')
        settings._rootfs = parser.get('machine', 'rootfs')
        settings._conf_dir = parser.get('machine', 'conf_dir')
        settings._data_dir = parser.get('machine', 'data_dir')

        # ROS packages
        settings._packages = []
        usedNames = set()

        for name, path in parser.items('machine/packages'):
            _valid_dir(path, "ROS package '{0}'".format(name))

            try:
                validateName(name)
            except IllegalName:
                raise ValueError("Package name '{0}' is not a legal "
                                 'name.'.format(name))

            if name in usedNames:
                raise ValueError("Package name '{0}' is not "
                                 'unique.'.format(name))

            usedNames.add(name)

            # TODO: Contains container specific configuration: opt/rce/packages
            settings._packages.append((path,
                                       os.path.join('opt/rce/packages', name)))

        settings._packages = tuple(settings._packages)

        # Validate paths
        _valid_dir(settings._rootfs, 'Container file system')
        _valid_dir(settings._conf_dir, 'Configuration directory')
        _valid_dir(settings._data_dir, 'Data directory')

        return settings
Beispiel #11
0
    def load(cls, parser, checks):
        """ Factory method which creates a new Settings object using the
            provided cloud engine settings parser.

            @param parser:      Cloud engine settings parser which is used to
                                parse the configuration file.
            @type  parser:      rce.util.settings._RCESettingsParser

            @param checks:      Enable/Disable path checks.
            @type  checks:      bool

            @return:            New _Settings instance containing the parsed
                                settings.
            @rtype:             rce.util.settings._Settings
        """
        settings = cls()

        # Global
        settings._gzip_lvl = parser.getint("global", "gzip_lvl")
        settings._dev_mode = parser.getboolean("global", "dev_mode")
        settings._pw_file = parser.get("global", "password_file")
        settings._host_ubuntu = get_host_ubuntu_release()
        settings._host_ros = parser.get("global", "host_ros_release")
        settings._container_ros = parser.get("global", "container_ros_release")
        settings._container_ubuntu = parser.get("global", "container_ubuntu_release")

        # Network
        settings._container_if = parser.get("network", "container_if")
        settings._external_ip = parser.getIP("network", "external_if")
        settings._internal_ip = parser.getIP("network", "internal_if")
        settings._container_ip = parser.getIP("network", "container_if")
        settings._localhost_ip = _getIP("lo")

        # Comm
        settings._http_port = parser.getint("comm", "http_port")
        settings._ws_port = parser.getint("comm", "ws_port")
        settings._internal_port = parser.getint("comm", "internal_port")
        settings._external_port = parser.getint("comm", "external_port")
        settings._comm_port = parser.getint("comm", "comm_port")
        settings._ros_proxy_port = parser.getint("comm", "ros_proxy_port")

        # Converters
        settings._converters = tuple(c for _, c in parser.items("converters"))

        # Machine
        settings._size = parser.getint("machine", "size")
        settings._cpu = parser.getint("machine", "cpu")
        settings._memory = parser.getint("machine", "memory")
        settings._bandwidth = parser.getint("machine", "bandwidth")
        settings._rootfs = parser.get("machine", "rootfs")
        settings._conf_dir = parser.get("machine", "conf_dir")
        settings._data_dir = parser.get("machine", "data_dir")
        # Figure out the special features
        special_features = parser.get("machine", "special_features")
        settings._special_features = [i.strip() for i in special_features.strip("[]").split(",")]

        # ROS packages
        settings._packages = []
        usedNames = set()

        if checks:
            for name, path in parser.items("machine/packages"):
                _valid_dir(path, "ROS package '{0}'".format(name))

                try:
                    validateName(name)
                except IllegalName:
                    raise ValueError("Package name '{0}' is not a legal " "name.".format(name))

                if name in usedNames:
                    raise ValueError("Package name '{0}' is not " "unique.".format(name))

                usedNames.add(name)

                settings._packages.append((path, os.path.join("opt/rce/packages", name)))

            settings._packages = tuple(settings._packages)

            # Validate paths
            _valid_dir(settings._rootfs, "Container file system")
            _valid_dir(settings._conf_dir, "Configuration directory")
            _valid_dir(settings._data_dir, "Data directory")

        return settings
Beispiel #12
0
    def load(cls, parser, checks):
        """ Factory method which creates a new Settings object using the
            provided cloud engine settings parser.

            @param parser:      Cloud engine settings parser which is used to
                                parse the configuration file.
            @type  parser:      rce.util.settings._RCESettingsParser

            @param checks:      Enable/Disable path checks.
            @type  checks:      bool

            @return:            New _Settings instance containing the parsed
                                settings.
            @rtype:             rce.util.settings._Settings
        """
        settings = cls()

        # Global
        settings._gzip_lvl = parser.getint('global', 'gzip_lvl')
        settings._dev_mode = parser.getboolean('global', 'dev_mode')
        settings._pw_file = parser.get('global', 'password_file')
        settings._host_ubuntu = get_host_ubuntu_release()
        settings._host_ros = parser.get('global', 'host_ros_release')
        settings._container_ros = parser.get('global', 'container_ros_release')
        settings._container_ubuntu = parser.get('global',
                                                'container_ubuntu_release')

        # Network
        settings._container_if = parser.get('network', 'container_if')
        settings._external_ip = parser.getIP('network', 'external_if')
        settings._internal_ip = parser.getIP('network', 'internal_if')
        settings._container_ip = parser.getIP('network', 'container_if')
        settings._localhost_ip = _getIP('lo')

        # Comm
        settings._http_port = parser.getint('comm', 'http_port')
        settings._ws_port = parser.getint('comm', 'ws_port')
        settings._internal_port = parser.getint('comm', 'internal_port')
        settings._external_port = parser.getint('comm', 'external_port')
        settings._comm_port = parser.getint('comm', 'comm_port')
        settings._ros_proxy_port = parser.getint('comm', 'ros_proxy_port')

        # Converters
        settings._converters = tuple(c for _, c in parser.items('converters'))

        # Machine
        settings._size = parser.getint('machine', 'size')
        settings._cpu = parser.getint('machine', 'cpu')
        settings._memory = parser.getint('machine', 'memory')
        settings._bandwidth = parser.getint('machine', 'bandwidth')
        settings._rootfs = parser.get('machine', 'rootfs')
        settings._conf_dir = parser.get('machine', 'conf_dir')
        settings._data_dir = parser.get('machine', 'data_dir')
        # Figure out the special features
        special_features = parser.get('machine', 'special_features')
        settings._special_features = [
            i.strip() for i in special_features.strip('[]').split(',')
        ]

        # ROS packages
        settings._packages = []
        usedNames = set()

        if checks:
            for name, path in parser.items('machine/packages'):
                _valid_dir(path, "ROS package '{0}'".format(name))

                try:
                    validateName(name)
                except IllegalName:
                    raise ValueError("Package name '{0}' is not a legal "
                                     'name.'.format(name))

                if name in usedNames:
                    raise ValueError("Package name '{0}' is not "
                                     'unique.'.format(name))

                usedNames.add(name)

                settings._packages.append(
                    (path, os.path.join('opt/rce/packages', name)))

            settings._packages = tuple(settings._packages)

            # Validate paths
            _valid_dir(settings._rootfs, 'Container file system')
            _valid_dir(settings._conf_dir, 'Configuration directory')
            _valid_dir(settings._data_dir, 'Data directory')

        return settings