cloudfoundry-community / cf-python-client

Small cloudfoundry client implemented in python
Apache License 2.0
53 stars 50 forks source link

Error 'CloudFoundryClient' object has no attribute 'v3' #31

Closed paragsangoi closed 5 years ago

paragsangoi commented 5 years ago

Hi,

I have installed latest package. As per instruction i have first created client object by calling

client = CloudFoundryClient(target_endpoint, verify=false) client.init_with_user_credentials(username, password)

this gives me client object

for V3 as per suggestion when i am trying app = client.v3.apps['guid']

i am getting error CloudFoundryClient has no attribute v3

am i missing some step?

Thanks a lot in advance

antechrestos commented 5 years ago

Hi did you install it from pypi or from sources. Because I wanted to wait before releasing it but when I think of it, master should reflect the release. So, if it is from pypi, wait a little, if from sources... Well I have to check some things!

paragsangoi commented 5 years ago

I have installed from source. I have downloaded it from git hub

antechrestos commented 5 years ago

My guess is you have two versions of the client coexisting in the same environment.

Using a clean environment created with virtualenv

(I also use virtualenvwrapper)

$> git status
Sur la branche master
Votre branche est à jour avec 'origin/master'.
rien à valider, la copie de travail est propre
$> mkvirtualenv CfQualif
(CfQualif) $> python setup.py clean install
...
(CfQualif) $> pip freeze
certifi==2018.10.15
chardet==3.0.4
cloudfoundry-client==1.2.0
idna==2.7
oauth2-client==1.0.0
protobuf==3.6.1
requests==2.20.1
six==1.11.0
urllib3==1.24.1
websocket-client==0.53.0
(CfQualif) $> python
>>> from cloudfoundry_client.client import CloudFoundryClient
>>> client=CloudFoundryClient('https://api.cf.**.**', verify=False)
>>> client.init_with_user_credentials('***', '***')
>>> for app in client.v3.apps:
...     print(app['guid'])
... 
39ba1d8a-c682-43b6-818e-306953d9c3df
...
>>> print(client.v3.apps['39ba1d8a-c682-43b6-818e-306953d9c3df'])
{u'relationships': {u'space': {u'data': {u'guid': u'5b040f90-61b3-47dc-8d6d-f882a006d469'}}}, u'name': u'zipkin', u'links': {u'processes': {u'href': u'https://api.cf.**.**/v3/apps/39ba1d8a-c682-43b6-818e-306953d9c3df/processes'}, u'tasks': {u'href': u'https://api.cf.**.**/v3/apps/39ba1d8a-c682-43b6-818e-306953d9c3df/tasks'}, u'route_mappings': {u'href': u'https://api.cf.**.**/v3/apps/39ba1d8a-c682-43b6-818e-306953d9c3df/route_mappings'}, u'space': {u'href': u'https://api.cf.**.**/v3/spaces/5b040f90-61b3-47dc-8d6d-f882a006d469'}, u'droplets': {u'href': u'https://api.cf.**.**/v3/apps/39ba1d8a-c682-43b6-818e-306953d9c3df/droplets'}, u'self': {u'href': u'https://api.cf.**.**/v3/apps/39ba1d8a-c682-43b6-818e-306953d9c3df'}, u'stop': {u'href': u'https://api.cf.**.**/v3/apps/39ba1d8a-c682-43b6-818e-306953d9c3df/actions/stop', u'method': u'POST'}, u'start': {u'href': u'https://api.cf.**.**/v3/apps/39ba1d8a-c682-43b6-818e-306953d9c3df/actions/start', u'method': u'POST'}, u'current_droplet': {u'href': u'https://api.cf.***.**/v3/apps/39ba1d8a-c682-43b6-818e-306953d9c3df/droplets/current'}, u'environment_variables': {u'href': u'https://api.cf.**.**/v3/apps/39ba1d8a-c682-43b6-818e-306953d9c3df/environment_variables'}, u'packages': {u'href': u'https://api.cf.**.**/v3/apps/39ba1d8a-c682-43b6-818e-306953d9c3df/packages'}}, u'created_at': u'2018-07-30T09:33:31Z', u'updated_at': u'2018-09-11T04:28:02Z', u'state': u'STARTED', u'guid': u'39ba1d8a-c682-43b6-818e-306953d9c3df', u'lifecycle': {u'data': {u'buildpacks': [], u'stack': u'cflinuxfs2'}, u'type': u'buildpack'}}
paragsangoi commented 5 years ago

I have checked on version I have latest version installed using python install ...zip file downloaded from github. i have not run command python setup.py install. I am having miniconda environment and not sure where should i run this command.

when i am trying to run cloudfoundry-client.exe from script folder

It is asking me target end point, SSL verification, user id, pwd. i am supplying true for SSL verification and it gives me warning unverified HTTPS request is being made

after warning i am getting error

cloudfoundryclient/main.py line 263 in main elif arguments.action.find(list) == 0 attribute error 'NoneType' object has no attribute 'find'

do you think i am missing some step?

antechrestos commented 5 years ago

Please use the latest sources as the main file only has 205 lines. I was asking about environment because I wondered whether you were installing the package got from source in an environment where you already installed an older version got from pypi

As soon you have installed it from latest sources, run python and do:

>>> import cloudfoundry_client
>>> cloudfoundry_client.__version__
'1.2.0'

The version 1.2.0 is not released yet on pypi, it will validate the installation.

When you run the exe, it indeed prompts you about information

It will do a login and put the token got in the file ~/.cf_client_python.json. After that you should be able to run some commands from the command line. If otherwise you want to do it pythonly, you may write some scripts or run python.exe and write the command I wrote above.

paragsangoi commented 5 years ago

I have got the release from

https://github.com/cloudfoundry-community/cf-python-client/releases/tag/v1.1.0

it is 1.1.0. However in your reply you are referring to v1.2.0. From where i can get this version.

I have taken latest from github master still not able to resolve. Can you please share the path from where i should download the latest version. Then i will try and let you know

Appreciate your help and support

antechrestos commented 5 years ago

You clould install it from sources. I've just released it.

paragsangoi commented 5 years ago

Thanks for your help. I am able to run now v3 api.

I see your example about task.cancel. on similar line i have tried task.create. I am getting entity object has no attribute create.

Also when i am trying app.task.create i am getting error as entity object has no attribute task.

Also one thing i want to mention you that in my case target is https:// (Secure) where as api url is http://(not secure).

thanks Parag

antechrestos commented 5 years ago

The cancel can only be executed on an existing object. As the documentation explains it, v3 entities provides link to interact with itself. Hence there are link to start, stop an application, cancel a task. Please refer to the V3 API specification. The library will only map every link provided by the API entities as a method on the object returned.

To create a task, use the client.v3.tasks.create method. See the TaskManager class.

I don't understand your last point: aren't the target and api hosted behind the same address? Because I don't see any specific entry under /v2/info for the api.

BR

paragsangoi commented 5 years ago

thanks it is working for me.

in Last point i am saying we have target endpoint running on https (secure). where as apis are pointing to http route and on successful authentication it will be redirected to https route

antechrestos commented 5 years ago

The /v2/info endpoint is secure or insecure? The authentication host is got from this endpoint. Can you share the result of /v2/info. If /v2/info is secure then API is too in my understanding...

paragsangoi commented 5 years ago

Thank for your help and support

antechrestos commented 5 years ago

You're welcome :smile: