--- a/cwconfig.py Mon Aug 03 16:50:22 2009 +0200
+++ b/cwconfig.py Mon Aug 03 17:20:20 2009 +0200
@@ -169,14 +169,7 @@
{'type' : 'string',
'default': '',
'help': 'Pyro name server\'s host. If not set, will be detected by a \
-broadcast query',
- 'group': 'pyro-name-server', 'inputlevel': 1,
- }),
- ('pyro-ns-port',
- {'type' : 'int',
- 'default': None,
- 'help': 'Pyro name server\'s listening port. If not set, default \
-port will be used.',
+broadcast query. It may contains port information using <host>:<port> notation.',
'group': 'pyro-name-server', 'inputlevel': 1,
}),
('pyro-ns-group',
--- a/dbapi.py Mon Aug 03 16:50:22 2009 +0200
+++ b/dbapi.py Mon Aug 03 17:20:20 2009 +0200
@@ -101,24 +101,14 @@
from cubicweb.server.repository import Repository
return Repository(config, vreg=vreg)
else: # method == 'pyro'
- from Pyro import core, naming
- from Pyro.errors import NamingError, ProtocolError
- core.initClient(banner=0)
- nsid = ':%s.%s' % (config['pyro-ns-group'], database)
- locator = naming.NameServerLocator()
# resolve the Pyro object
+ from logilab.common.pyro_ext import ns_get_proxy
try:
- nshost, nsport = config['pyro-ns-host'], config['pyro-ns-port']
- uri = locator.getNS(nshost, nsport).resolve(nsid)
- except ProtocolError:
- raise ConnectionError('Could not connect to the Pyro name server '
- '(host: %s:%i)' % (nshost, nsport))
- except NamingError:
- raise ConnectionError('Could not get repository for %s '
- '(not registered in Pyro), '
- 'you may have to restart your server-side '
- 'instance' % nsid)
- return core.getProxyForURI(uri)
+ return ns_get_proxy(database,
+ defaultnsgroup=config['pyro-ns-group'],
+ nshost=config['pyro-ns-host'])
+ except Exception, ex:
+ raise ConnectionError(str(ex))
def repo_connect(repo, login, password, cnxprops=None):
"""Constructor to create a new connection to the CubicWeb repository.
@@ -132,9 +122,8 @@
cnx.vreg = repo.vreg
return cnx
-def connect(database=None, login=None, password=None, host=None,
- group=None, cnxprops=None, port=None, setvreg=True, mulcnx=True,
- initlog=True):
+def connect(database=None, login=None, password=None, host=None, group=None,
+ cnxprops=None, setvreg=True, mulcnx=True, initlog=True):
"""Constructor for creating a connection to the CubicWeb repository.
Returns a Connection object.
@@ -145,8 +134,6 @@
config = cwconfig.CubicWebNoAppConfiguration()
if host:
config.global_set_option('pyro-ns-host', host)
- if port:
- config.global_set_option('pyro-ns-port', port)
if group:
config.global_set_option('pyro-ns-group', group)
cnxprops = cnxprops or ConnectionProperties()
--- a/goa/goaconfig.py Mon Aug 03 16:50:22 2009 +0200
+++ b/goa/goaconfig.py Mon Aug 03 17:20:20 2009 +0200
@@ -17,8 +17,8 @@
from cubicweb.goa.dbmyams import load_schema
UNSUPPORTED_OPTIONS = set(('connections-pool-size',
- 'pyro-port', 'pyro-id', 'pyro-instance-id',
- 'pyro-ns-host', 'pyro-ns-port', 'pyro-ns-group',
+ 'pyro-host', 'pyro-id', 'pyro-instance-id',
+ 'pyro-ns-host', 'pyro-ns-group',
'https-url', 'host', 'pid-file', 'uid', 'base-url', 'log-file',
'smtp-host', 'smtp-port',
'embed-allowed',
--- a/server/repository.py Mon Aug 03 16:50:22 2009 +0200
+++ b/server/repository.py Mon Aug 03 17:20:20 2009 +0200
@@ -1164,36 +1164,16 @@
def pyro_register(self, host=''):
"""register the repository as a pyro object"""
- from Pyro import core
- port = self.config['pyro-port']
- nshost, nsgroup = self.config['pyro-ns-host'], self.config['pyro-ns-group']
- nsgroup = ':' + nsgroup
- core.initServer(banner=0)
- daemon = core.Daemon(host=host, port=port)
- daemon.useNameServer(self.pyro_nameserver(nshost, nsgroup))
- # use Delegation approach
- impl = core.ObjBase()
- impl.delegateTo(self)
- nsid = self.config['pyro-id'] or self.config.appid
- daemon.connect(impl, '%s.%s' % (nsgroup, nsid))
+ from logilab.common.pyro_ext import register_object
+ appid = self.config['pyro-id'] or self.config.appid
+ daemon = register_object(self, appid, self.config['pyro-ns-group'],
+ self.config['pyro-host'],
+ self.config['pyro-ns-host'])
msg = 'repository registered as a pyro object using group %s and id %s'
- self.info(msg, nsgroup, nsid)
+ self.info(msg, self.config['pyro-ns-group'], appid)
self.pyro_registered = True
return daemon
- def pyro_nameserver(self, host=None, group=None):
- """locate and bind the the name server to the daemon"""
- from Pyro import naming, errors
- # locate the name server
- nameserver = naming.NameServerLocator().getNS(host)
- if group is not None:
- # make sure our namespace group exists
- try:
- nameserver.createGroup(group)
- except errors.NamingError:
- pass
- return nameserver
-
# multi-sources planner helpers ###########################################
@cached
@@ -1217,21 +1197,9 @@
def pyro_unregister(config):
"""unregister the repository from the pyro name server"""
- nshost, nsgroup = config['pyro-ns-host'], config['pyro-ns-group']
+ from logilab.common.pyro_ext import ns_unregister
appid = config['pyro-id'] or config.appid
- from Pyro import core, naming, errors
- core.initClient(banner=False)
- try:
- nameserver = naming.NameServerLocator().getNS(nshost)
- except errors.PyroError, ex:
- # name server not responding
- config.error('can\'t locate pyro name server: %s', ex)
- return
- try:
- nameserver.unregister(':%s.%s' % (nsgroup, appid))
- config.info('%s unregistered from pyro name server', appid)
- except errors.NamingError:
- config.warning('%s already unregistered from pyro name server', appid)
+ ns_unregister(appid, config['pyro-ns-group'], config['pyro-ns-host'])
from logging import getLogger
--- a/server/serverconfig.py Mon Aug 03 16:50:22 2009 +0200
+++ b/server/serverconfig.py Mon Aug 03 17:20:20 2009 +0200
@@ -165,10 +165,12 @@
'group': 'email', 'inputlevel': 2,
}),
# pyro server.serverconfig
- ('pyro-port',
+ ('pyro-host',
{'type' : 'int',
'default': None,
- 'help': 'Pyro server port. If not set, it will be choosen randomly',
+ 'help': 'Pyro server host, if not detectable correctly through \
+gethostname(). It may contains port information using <host>:<port> notation, \
+and if not set, it will be choosen randomly',
'group': 'pyro-server', 'inputlevel': 2,
}),
('pyro-id', # XXX reuse pyro-instance-id
--- a/server/sources/pyrorql.py Mon Aug 03 16:50:22 2009 +0200
+++ b/server/sources/pyrorql.py Mon Aug 03 17:20:20 2009 +0200
@@ -79,14 +79,7 @@
{'type' : 'string',
'default': None,
'help': 'Pyro name server\'s host. If not set, default to the value \
-from all_in_one.conf.',
- 'group': 'pyro-source', 'inputlevel': 1,
- }),
- ('pyro-ns-port',
- {'type' : 'int',
- 'default': None,
- 'help': 'Pyro name server\'s listening port. If not set, default to \
-the value from all_in_one.conf.',
+from all_in_one.conf. It may contains port information using <host>:<port> notation.',
'group': 'pyro-source', 'inputlevel': 1,
}),
('pyro-ns-group',
@@ -214,13 +207,12 @@
def _get_connection(self):
"""open and return a connection to the source"""
nshost = self.config.get('pyro-ns-host') or self.repo.config['pyro-ns-host']
- nsport = self.config.get('pyro-ns-port') or self.repo.config['pyro-ns-port']
nsgroup = self.config.get('pyro-ns-group') or self.repo.config['pyro-ns-group']
#cnxprops = ConnectionProperties(cnxtype=self.config['cnx-type'])
return dbapi.connect(database=self.config['pyro-ns-id'],
login=self.config['cubicweb-user'],
password=self.config['cubicweb-password'],
- host=nshost, port=nsport, group=nsgroup,
+ host=nshost, group=nsgroup,
setvreg=False) #cnxprops=cnxprops)
def get_connection(self):