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

Josh Moore josh at glencoesoftware.com
Mon Sep 8 10:55:20 BST 2014


Hi Carnë,

On Sep 4, 2014, at 7:26 PM, Carnë Draug wrote:

> 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?


You can actually use these strings directly by passing them to the client constructor:


import omero
import omero.cli
import omero.scripts

c = omero.scripts.client("test.py")
h = c.getRouter(c.getCommunicator())

copy = omero.client(["--Ice.Default.Router=%s" % h])
copy.createSession("root", "XXX")
try:
    cli = omero.cli.CLI()
    cli.loadplugins()
    # https://trac.openmicroscopy.org.uk/ome/ticket/12388
    cli._client = copy
    cli.invoke(["hql", "select e from Experimenter e where e.omeName = 'root'"])
finally:
    copy.__del__()


NB:  https://trac.openmicroscopy.org.uk/ome/ticket/12388 proposes to improve the
`cli._client = copy`.


At the same time, though, the environment variable "ICE_CONFIG" is set for the entire process, so there should be no need to set any property:

import omero
import omero.cli
import omero.scripts

c = omero.scripts.client("test.py")

copy = omero.client()
copy.createSession()
try:
    cli = omero.cli.CLI()
    cli.loadplugins()
    cli._client = copy
    ...
finally:
    copy.__del__()

> 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ë

A final option which is what I would probably use is the "createClient" method:

import omero
import omero.cli
import omero.scripts

c = omero.scripts.client("test.py")
copy = c.createClient(secure=True)
try:
    cli = omero.cli.CLI()
    cli.loadplugins()
    cli._client = copy
    ...
finally:
    copy.__del__()

Cheers,
~Josh.

P.S. while working on this script, I saw that createClient(secure=False) does not work from scripts which is likely related to your issue of not being able to find the hostname. I can add you to https://trac.openmicroscopy.org.uk/ome/ticket/12555 if you are interested in getting updates.



More information about the ome-users mailing list