Re: [Freeipa-devel] IPA Python API

2015-06-25 Thread Drew Erny

If I add the lines

if not api.Backend.rpcclient.isconnected():
api.Backend.rpcclient.connect()


before I call the api, the code works. Problem (pretty much) solved.

On 06/23/2015 04:36 PM, Drew Erny wrote:

Resurrecting this thread, because the problem is getting me again.

If I go through the python interpreter and import the code that calls 
the ipalib, and then manually call it myself the way the webserver 
does, the code works. If the same code is run in the course of the web 
server process, I get the error:


Traceback (most recent call last):
  File 
"/home/derny/freeipa/env/lib/python2.7/site-packages/cherrypy/_cprequest.py", 
line 670, in respond

response.body = self.handler()
  File 
"/home/derny/freeipa/env/lib/python2.7/site-packages/cherrypy/lib/encoding.py", 
line 217, in __call__

self.body = self.oldhandler(*args, **kwargs)
  File 
"/home/derny/freeipa/env/lib/python2.7/site-packages/cherrypy/_cpdispatch.py", 
line 61, in __call__

return self.callable(*self.args, **self.kwargs)
  File "freeipa_community_portal/app.py", line 39, in POST
errors = user.save()
  File "freeipa_community_portal/model/user.py", line 33, in save
self._call_api()
  File "freeipa_community_portal/model/user.py", line 45, in _call_api
mail=self.email
  File "/usr/lib/python2.7/site-packages/ipalib/frontend.py", line 
439, in __call__

ret = self.run(*args, **options)
  File "/usr/lib/python2.7/site-packages/ipalib/frontend.py", line 
755, in run

return self.forward(*args, **options)
  File "/usr/lib/python2.7/site-packages/ipalib/frontend.py", line 
776, in forward

return self.Backend.rpcclient.forward(self.name, *args, **kw)
  File "/usr/lib/python2.7/site-packages/ipalib/rpc.py", line 880, in 
forward

command = getattr(self.conn, name)
  File "/usr/lib/python2.7/site-packages/ipalib/backend.py", line 97, 
in __get_conn

self.id, threading.currentThread().getName())
AttributeError: no context.rpcclient in thread 'CP Server Thread-6'

The error shows up whether the server is run from within the python 
interpreter or by itself.


I kinit and have a TGT from the IPA server. The client machine is 
registered with the IPA server. When I run the commands "by hand", an 
HTTP ticket can be seen in the klist. When I run the webserver, no 
HTTP ticket is ever recieved, so the code is failing on the client 
side before it even gets to the server.


Which is obviously not what should be happening. It's the same error I 
got when I was using Flask, and now I'm using cherrypy and it's still 
broken. Could this have something to do with the web server being a 
multithreaded environment?




--
Manage your subscription for the Freeipa-devel mailing list:
https://www.redhat.com/mailman/listinfo/freeipa-devel
Contribute to FreeIPA: http://www.freeipa.org/page/Contribute/Code


Re: [Freeipa-devel] IPA Python API

2015-06-23 Thread Drew Erny

Resurrecting this thread, because the problem is getting me again.

If I go through the python interpreter and import the code that calls 
the ipalib, and then manually call it myself the way the webserver does, 
the code works. If the same code is run in the course of the web server 
process, I get the error:


Traceback (most recent call last):
  File 
"/home/derny/freeipa/env/lib/python2.7/site-packages/cherrypy/_cprequest.py", 
line 670, in respond
response.body = self.handler()
  File 
"/home/derny/freeipa/env/lib/python2.7/site-packages/cherrypy/lib/encoding.py", 
line 217, in __call__
self.body = self.oldhandler(*args, **kwargs)
  File 
"/home/derny/freeipa/env/lib/python2.7/site-packages/cherrypy/_cpdispatch.py", 
line 61, in __call__
return self.callable(*self.args, **self.kwargs)
  File "freeipa_community_portal/app.py", line 39, in POST
errors = user.save()
  File "freeipa_community_portal/model/user.py", line 33, in save
self._call_api()
  File "freeipa_community_portal/model/user.py", line 45, in _call_api
mail=self.email
  File "/usr/lib/python2.7/site-packages/ipalib/frontend.py", line 439, in 
__call__
ret = self.run(*args, **options)
  File "/usr/lib/python2.7/site-packages/ipalib/frontend.py", line 755, in run
return self.forward(*args, **options)
  File "/usr/lib/python2.7/site-packages/ipalib/frontend.py", line 776, in 
forward
return self.Backend.rpcclient.forward(self.name, *args, **kw)
  File "/usr/lib/python2.7/site-packages/ipalib/rpc.py", line 880, in forward
command = getattr(self.conn, name)
  File "/usr/lib/python2.7/site-packages/ipalib/backend.py", line 97, in 
__get_conn
self.id, threading.currentThread().getName())
AttributeError: no context.rpcclient in thread 'CP Server Thread-6'

The error shows up whether the server is run from within the python 
interpreter or by itself.


I kinit and have a TGT from the IPA server. The client machine is 
registered with the IPA server. When I run the commands "by hand", an 
HTTP ticket can be seen in the klist. When I run the webserver, no HTTP 
ticket is ever recieved, so the code is failing on the client side 
before it even gets to the server.


Which is obviously not what should be happening. It's the same error I 
got when I was using Flask, and now I'm using cherrypy and it's still 
broken. Could this have something to do with the web server being a 
multithreaded environment?


--
Manage your subscription for the Freeipa-devel mailing list:
https://www.redhat.com/mailman/listinfo/freeipa-devel
Contribute to FreeIPA: http://www.freeipa.org/page/Contribute/Code


Re: [Freeipa-devel] IPA Python API

2015-06-17 Thread Jan Cholasta

Dne 17.6.2015 v 19:18 Drew Erny napsal(a):



On 06/17/2015 01:24 AM, Jan Cholasta wrote:

Dne 16.6.2015 v 20:29 Drew Erny napsal(a):

Hi, All,
...

Call


api.Backend.rpcclient.connect(ccache=krbV.default_context().default_ccache())


to make the problem go away.

This doesn't work. The Flask application runs (as I mentioned in a
different email) with or without this change, but it will not run in
debug mode either way.



That's probably because there are no credentials in the default ccache. 
You might try to kinit first and/or supply a different ccache.


--
Jan Cholasta

--
Manage your subscription for the Freeipa-devel mailing list:
https://www.redhat.com/mailman/listinfo/freeipa-devel
Contribute to FreeIPA: http://www.freeipa.org/page/Contribute/Code


Re: [Freeipa-devel] IPA Python API

2015-06-17 Thread Drew Erny



On 06/17/2015 01:24 AM, Jan Cholasta wrote:

Dne 16.6.2015 v 20:29 Drew Erny napsal(a):

Hi, All,
...

Call


api.Backend.rpcclient.connect(ccache=krbV.default_context().default_ccache()) 



to make the problem go away.
This doesn't work. The Flask application runs (as I mentioned in a 
different email) with or without this change, but it will not run in 
debug mode either way.


--
Manage your subscription for the Freeipa-devel mailing list:
https://www.redhat.com/mailman/listinfo/freeipa-devel
Contribute to FreeIPA: http://www.freeipa.org/page/Contribute/Code


Re: [Freeipa-devel] IPA Python API

2015-06-17 Thread Petr Spacek
On 17.6.2015 07:24, Jan Cholasta wrote:
> Dne 16.6.2015 v 20:29 Drew Erny napsal(a):
>> Hi, All,
>>
>> I'm using the IPA Python API to write the Community Portal. Most of the
>> documentation for using the IPA Python API is targeted a plugin authors,
>> and this isn't a plugin for (what I think are) good reasons. I'm doing
>>
>>  # in the main program
>>  import api from ipalib
>>  api.bootstrap(context="client")
>>  api.finalize()
>>  api.Backend.rpcclient.connect()
> 
> Call
> 
> 
> api.Backend.rpcclient.connect(ccache=krbV.default_context().default_ccache())
> 
> to make the problem go away.

Is there a simple way how to get a reasonable error message ('not connected to
IPA server' or so) here?

Calling commands from Python should not be that hard to debug :-)

Petr^2 Spacek

>>  # and then, inside of a separate class
>>  api.Command.stageuser_add(...)
>>
>> Which is how doc/examples/python-api.py shows it.
>>
>> However, calling api.Command.stageuser_add(...) causes
>>  AttributeError: No context.rpcclient_... in thread 'Thread-1'
>>
>> I think this is probably related to the fact that I haven't configured
>> my program to connect to any particular IPA server, because before the
>> program errors out, it prints:
>>  ipa: INFO: Forwarding 'stageuser_add' to json server 'None'
>>
>> If the problem is the lack of a target server, as I suspect, how would I
>> configure the program to connect to a particular IPA server? If this
>> isn't caused by that, what could the causes be?

-- 
Manage your subscription for the Freeipa-devel mailing list:
https://www.redhat.com/mailman/listinfo/freeipa-devel
Contribute to FreeIPA: http://www.freeipa.org/page/Contribute/Code


Re: [Freeipa-devel] IPA Python API

2015-06-16 Thread Jan Cholasta

Dne 16.6.2015 v 20:29 Drew Erny napsal(a):

Hi, All,

I'm using the IPA Python API to write the Community Portal. Most of the
documentation for using the IPA Python API is targeted a plugin authors,
and this isn't a plugin for (what I think are) good reasons. I'm doing

 # in the main program
 import api from ipalib
 api.bootstrap(context="client")
 api.finalize()
 api.Backend.rpcclient.connect()


Call


api.Backend.rpcclient.connect(ccache=krbV.default_context().default_ccache())

to make the problem go away.



 # and then, inside of a separate class
 api.Command.stageuser_add(...)

Which is how doc/examples/python-api.py shows it.

However, calling api.Command.stageuser_add(...) causes
 AttributeError: No context.rpcclient_... in thread 'Thread-1'

I think this is probably related to the fact that I haven't configured
my program to connect to any particular IPA server, because before the
program errors out, it prints:
 ipa: INFO: Forwarding 'stageuser_add' to json server 'None'

If the problem is the lack of a target server, as I suspect, how would I
configure the program to connect to a particular IPA server? If this
isn't caused by that, what could the causes be?




--
Jan Cholasta

--
Manage your subscription for the Freeipa-devel mailing list:
https://www.redhat.com/mailman/listinfo/freeipa-devel
Contribute to FreeIPA: http://www.freeipa.org/page/Contribute/Code


Re: [Freeipa-devel] IPA Python API

2015-06-16 Thread Drew Erny



On 06/16/2015 04:17 PM, Rob Crittenden wrote:

Drew Erny wrote:

On 06/16/2015 02:29 PM, Drew Erny wrote:

Hi, All,

I'm using the IPA Python API to write the Community Portal. Most of
the documentation for using the IPA Python API is targeted a plugin
authors, and this isn't a plugin for (what I think are) good reasons.
I'm doing

# in the main program
import api from ipalib
api.bootstrap(context="client")
api.finalize()
api.Backend.rpcclient.connect()

# and then, inside of a separate class
api.Command.stageuser_add(...)

Which is how doc/examples/python-api.py shows it.

However, calling api.Command.stageuser_add(...) causes
AttributeError: No context.rpcclient_... in thread 'Thread-1'

I think this is probably related to the fact that I haven't configured
my program to connect to any particular IPA server, because before the
program errors out, it prints:
ipa: INFO: Forwarding 'stageuser_add' to json server 'None'

If the problem is the lack of a target server, as I suspect, how would
I configure the program to connect to a particular IPA server? If this
isn't caused by that, what could the causes be?


I think this may be a bug. Even after doing ipa-client-install and
following exactly the guide outlined in this email
(https://www.redhat.com/archives/freeipa-users/2012-June/msg00334.html)
I still get the same error. I've poked around in the code around this,
though, and if it is a bug then I might need help because it's WAY deep
in the FreeIPA internals.

Also, forgot to mention, all of the ellipses (...) in the code in the
first email are elided code, not literal ellipses.



I wonder if it's detecting that you are in-tree so trying to use 
~/.ipa/default.conf.


This code:

from ipalib import api
api.bootstrap(context="client")
api.finalize()
api.Backend.rpcclient.connect()

# and then, inside of a separate class
print api.Command.user_show(u'admin')

produces this:

$ python derny.py
ipa: INFO: trying https://ipadev.greyoak.com/ipa/session/json
ipa: INFO: Forwarding 'user_show' to json server 
'https://ipadev.greyoak.com/ipa/session/json'
{u'result': {u'dn': 
u'uid=admin,cn=users,cn=accounts,dc=greyoak,dc=com', u'has_keytab': 
True, u'uid': (u'admin',), u'loginshell': (u'/bin/bash',), 
u'uidnumber': (u'59000',), u'gidnumber': (u'59000',), 
u'memberof_group': (u'admins', u'trust admins'), u'has_password': 
True, u'sn': (u'Administrator',), u'homedirectory': (u'/home/admin',), 
u'nsaccountlock': False}, u'value': u'admin', u'summary': None}


rob
I've sort of figured out the problem. I uninstalled the master-branch 
rpms I had, and then installed the latest FreeIPA from the fedora repos. 
Then, I was able to run the commands from the interpreter but the 
program still threw the same error. However, after some knob-twiddling, 
I've narrowed it down: running a Flask app with debug = True causes the 
error, but removing the debug line makes the code work. This doesn't 
explain why with the master build, the code throws errors in the python 
interpreter for me, which means something else is probably afoot (and 
probably our fault instead of Flask's), but I don't have any clue what 
it is.


--
Manage your subscription for the Freeipa-devel mailing list:
https://www.redhat.com/mailman/listinfo/freeipa-devel
Contribute to FreeIPA: http://www.freeipa.org/page/Contribute/Code


Re: [Freeipa-devel] IPA Python API

2015-06-16 Thread Rob Crittenden

Drew Erny wrote:

On 06/16/2015 02:29 PM, Drew Erny wrote:

Hi, All,

I'm using the IPA Python API to write the Community Portal. Most of
the documentation for using the IPA Python API is targeted a plugin
authors, and this isn't a plugin for (what I think are) good reasons.
I'm doing

# in the main program
import api from ipalib
api.bootstrap(context="client")
api.finalize()
api.Backend.rpcclient.connect()

# and then, inside of a separate class
api.Command.stageuser_add(...)

Which is how doc/examples/python-api.py shows it.

However, calling api.Command.stageuser_add(...) causes
AttributeError: No context.rpcclient_... in thread 'Thread-1'

I think this is probably related to the fact that I haven't configured
my program to connect to any particular IPA server, because before the
program errors out, it prints:
ipa: INFO: Forwarding 'stageuser_add' to json server 'None'

If the problem is the lack of a target server, as I suspect, how would
I configure the program to connect to a particular IPA server? If this
isn't caused by that, what could the causes be?


I think this may be a bug. Even after doing ipa-client-install and
following exactly the guide outlined in this email
(https://www.redhat.com/archives/freeipa-users/2012-June/msg00334.html)
I still get the same error. I've poked around in the code around this,
though, and if it is a bug then I might need help because it's WAY deep
in the FreeIPA internals.

Also, forgot to mention, all of the ellipses (...) in the code in the
first email are elided code, not literal ellipses.



I wonder if it's detecting that you are in-tree so trying to use 
~/.ipa/default.conf.


This code:

from ipalib import api
api.bootstrap(context="client")
api.finalize()
api.Backend.rpcclient.connect()

# and then, inside of a separate class
print api.Command.user_show(u'admin')

produces this:

$ python derny.py
ipa: INFO: trying https://ipadev.greyoak.com/ipa/session/json
ipa: INFO: Forwarding 'user_show' to json server 
'https://ipadev.greyoak.com/ipa/session/json'
{u'result': {u'dn': u'uid=admin,cn=users,cn=accounts,dc=greyoak,dc=com', 
u'has_keytab': True, u'uid': (u'admin',), u'loginshell': 
(u'/bin/bash',), u'uidnumber': (u'59000',), u'gidnumber': 
(u'59000',), u'memberof_group': (u'admins', u'trust admins'), 
u'has_password': True, u'sn': (u'Administrator',), u'homedirectory': 
(u'/home/admin',), u'nsaccountlock': False}, u'value': u'admin', 
u'summary': None}


rob

--
Manage your subscription for the Freeipa-devel mailing list:
https://www.redhat.com/mailman/listinfo/freeipa-devel
Contribute to FreeIPA: http://www.freeipa.org/page/Contribute/Code


Re: [Freeipa-devel] IPA Python API

2015-06-16 Thread Drew Erny

On 06/16/2015 02:29 PM, Drew Erny wrote:

Hi, All,

I'm using the IPA Python API to write the Community Portal. Most of 
the documentation for using the IPA Python API is targeted a plugin 
authors, and this isn't a plugin for (what I think are) good reasons. 
I'm doing


# in the main program
import api from ipalib
api.bootstrap(context="client")
api.finalize()
api.Backend.rpcclient.connect()

# and then, inside of a separate class
api.Command.stageuser_add(...)

Which is how doc/examples/python-api.py shows it.

However, calling api.Command.stageuser_add(...) causes
AttributeError: No context.rpcclient_... in thread 'Thread-1'

I think this is probably related to the fact that I haven't configured 
my program to connect to any particular IPA server, because before the 
program errors out, it prints:

ipa: INFO: Forwarding 'stageuser_add' to json server 'None'

If the problem is the lack of a target server, as I suspect, how would 
I configure the program to connect to a particular IPA server? If this 
isn't caused by that, what could the causes be?


I think this may be a bug. Even after doing ipa-client-install and 
following exactly the guide outlined in this email 
(https://www.redhat.com/archives/freeipa-users/2012-June/msg00334.html) 
I still get the same error. I've poked around in the code around this, 
though, and if it is a bug then I might need help because it's WAY deep 
in the FreeIPA internals.


Also, forgot to mention, all of the ellipses (...) in the code in the 
first email are elided code, not literal ellipses.


--
Manage your subscription for the Freeipa-devel mailing list:
https://www.redhat.com/mailman/listinfo/freeipa-devel
Contribute to FreeIPA: http://www.freeipa.org/page/Contribute/Code


[Freeipa-devel] IPA Python API

2015-06-16 Thread Drew Erny

Hi, All,

I'm using the IPA Python API to write the Community Portal. Most of the 
documentation for using the IPA Python API is targeted a plugin authors, 
and this isn't a plugin for (what I think are) good reasons. I'm doing


# in the main program
import api from ipalib
api.bootstrap(context="client")
api.finalize()
api.Backend.rpcclient.connect()

# and then, inside of a separate class
api.Command.stageuser_add(...)

Which is how doc/examples/python-api.py shows it.

However, calling api.Command.stageuser_add(...) causes
AttributeError: No context.rpcclient_... in thread 'Thread-1'

I think this is probably related to the fact that I haven't configured 
my program to connect to any particular IPA server, because before the 
program errors out, it prints:

ipa: INFO: Forwarding 'stageuser_add' to json server 'None'

If the problem is the lack of a target server, as I suspect, how would I 
configure the program to connect to a particular IPA server? If this 
isn't caused by that, what could the causes be?


--
Manage your subscription for the Freeipa-devel mailing list:
https://www.redhat.com/mailman/listinfo/freeipa-devel
Contribute to FreeIPA: http://www.freeipa.org/page/Contribute/Code