@rbac(('owner', 'user'))
    def create(self, typname, version=None, server=None,
               res_desc=None, **ctor_args):
        """
        Create a new `typname` object in `server` or a new
        :class:`ObjectServer`.  Returns a proxy for for the new object.
        Starts servers in a subdirectory of the current directory.

        typname: string
            Type of object to create. If null, then a proxy for the new
            :class:`ObjServer` is returned.

        version: string or None
            Version of `typname` to create.

        server: proxy
            :class:`ObjServer` on which to create `typname`.
            If none, then a new server is created.

        res_desc: dict or None
            Required resources. ``working_directory`` is used to set a
            created server's directory, other keys are ignored.
            If `allow_shell` has been set, then an absolute directory
            reference may be used (including '~' expansion). If not, then
            the reference must be relative and the working directory will be
            relative to the factory's directory. If the directory already
            exists, a new name will be used of the form ``<directory>_N``

        ctor_args: dict
            Other constructor arguments.
            If `name` or `allowed_users` are specified, they are used when
            creating the :class:`ObjServer`. If no `allowed_users` are
            specified, the server is private to the current user.
        """
        self._logger.info('create typname %r, version %r server %s,'
                          ' res_desc %s, args %s', typname, version, server,
                          res_desc, ctor_args)

        if server is None:
            name = ctor_args.get('name', '')
            if not name:
                name = 'Server_%d' % (len(self._managers) + 1)

            allowed_users = ctor_args.get('allowed_users')
            if not allowed_users:
                credentials = get_credentials()
                allowed_users = {credentials.user: credentials.public_key}
            else:
                del ctor_args['allowed_users']

            if self._address is None or \
               isinstance(self._address, basestring) or \
               self._allow_tunneling:
                # Local access only via pipe if factory accessed by pipe
                # or factory is accessed via tunnel.
                address = None
            else:
                # Network access via same IP as factory, system-selected port.
                address = (self._address[0], 0)

            manager = self.manager_class(address, self._authkey, name=name,
                                         allowed_users=allowed_users)

            # Set (unique) working directory of server.
            # Server cleanup removes this directory, so we avoid any
            # existing directory to not delete existing files.
            base = None
            if res_desc is not None:
                base = res_desc.get('working_directory')
                if base:
                    if self._allow_shell:  # Absolute allowed.
                        base = os.path.expanduser(base)
                    elif os.path.isabs(base) or base.startswith('..'):
                        raise ValueError('working_directory %r must be subdirectory'
                                         % base)
                    res_desc = res_desc.copy()
                    del res_desc['working_directory']
            if not base:
                base = name
            count = 1
            root_dir = base
            while os.path.exists(root_dir):
                count += 1
                root_dir = '%s_%d' % (base, count)
            os.mkdir(root_dir)

            # On Windows, when running the full test suite under Nose,
            # starting the process starts a new Nose test session, which
            # will eventually get here and start a new Nose session, which...
            orig_main = None
            if sys.platform == 'win32':  #pragma no cover
                scripts = ('openmdao-script.py', 'openmdao_test-script.py')
                try:
                    main_file = sys.modules['__main__'].__file__
                except __HOLE__:
                    pass
                else:
                    if main_file.endswith(scripts):
                        orig_main = main_file
                        sys.modules['__main__'].__file__ = \
                            pkg_resources.resource_filename('openmdao.main',
                                                            'objserverfactory.py')
            owner = get_credentials()
            self._logger.log(LOG_DEBUG2, '%s starting server %r in dir %s',
                             owner, name, root_dir)
            try:
                manager.start(cwd=root_dir,
                              log_level=self._logger.getEffectiveLevel())
            finally:
                if orig_main is not None:  #pragma no cover
                    sys.modules['__main__'].__file__ = orig_main

            self._logger.info('new server %r for %s', name, owner)
            self._logger.info('    in dir %s', root_dir)
            self._logger.info('    listening on %s', manager.address)
            server_class = getattr(manager, self.server_classname)
            server = server_class(name=name, allow_shell=self._allow_shell,
                                  allowed_types=self._allowed_types)
            self._managers[server] = (manager, root_dir, owner)

        if typname:
            obj = server.create(typname, version, None, res_desc, **ctor_args)
        else:
            obj = server

        self._logger.log(LOG_DEBUG2, 'create returning %r at %r',
                         obj, obj._token.address)
        return obj
dataset/ETHPy150Open OpenMDAO/OpenMDAO-Framework/openmdao.main/src/openmdao/main/objserverfactory.py/ObjServerFactory.create