[ome-users] omero scripts: getting hostname and port to server from BaseClient

Carnë Draug carandraug+dev at gmail.com
Thu Sep 4 18:26:35 BST 2014


Hi

I am trying to get the hostname (or IP address) and port of the omero server
from an omero script so I can import images back into the server using the
following:

    cli = omero.cli.CLI()
    cli.loadplugins()
    cli.invoke(["-s", hostname, "-k", port, "import", filepath])

However, I'm struggling to get the correct hostname. The best I've managed was
the following:

    >>> client.getRouter(client.getCommunicator())
    OMERO.Glacier2/router -t -e 1.0:tcp -h 129.67.77.159 -p 4063

and while I can easily parse that string to get the value for "-h", will this
one day break when it becomes "--host", "--hostname", or something else?  Is
there a sanctioned method that gives the correct hostname that a client
somewhere in the grid should use when importing images?

Using Python, if I start a client from the command-line, I can get the hostname
and port in the following way:

    >>> import omero
    >>> c = omero.client (hostname = "localhost")
    >>> c.createSession (username = "user", password = "pass")
    session-8d06752b-87cd-4d0d-af0c-b2524c4500fc/0f62ebed-f024-4a06-bf5d-c30181bc0515
-t -e 1.0 @ BlitzAdapters
    >>> c.getProperty ("omero.host")
    'localhost'
    >>> c.getProperty ("omero.port")
    '4064'

However, when using an omero script:

    client = omero.scripts.client(script_name, doc, script_args)

a value for "hostname" is not passed to the constructor and only the port is
available (set on omero.clients.BaseClient.__init__() line 134 [1] from
omero.constants.GLACIER2PORT).  The router configuration is set on
omero.clients.BaseClient._initData() lines 234-242 [2], but even there it
has the value of:

    OMERO.Glacier2/router:tcp -p 4063 -h 129.67.77.159

What is the recommended way to reliably get the hostname to use (or IP address)?
And does it make sense to be a property of BaseClient like port is?

Thank you,
Carnë

[1] https://github.com/openmicroscopy/openmicroscopy/blob/develop/components/tools/OmeroPy/src/omero/clients.py#L134
[2] https://github.com/openmicroscopy/openmicroscopy/blob/develop/components/tools/OmeroPy/src/omero/clients.py#L234



More information about the ome-users mailing list