Small cloudfoundry client implemented in python

Overview

Cloudfoundry python client

The cf-python-client repo contains a Python client library for Cloud Foundry.

Installing

Supported versions

warning: Starting version 1.11.0, versions older that python 3.6.0 will not be supported anymore. This late version was released by the end 2016.

For those that are still using python 2.7, it won't be supported by the end of 2020 and all library shall stop supporting it.

From pip

$ pip install cloudfoundry-client

From sources

To build the library run :

$ python setup.py install

Run the client

To run the client, enter the following command :

$ cloudfoundry-client

This will explains you how the client works. At first execution, it will ask you information about the platform you want to reach (url, login and so on). Please note that your credentials won't be saved on your disk: only tokens will be kept for further use.

Use the client in your code

You may build the client and use it in your code

Client

To instantiate the client, nothing easier

from cloudfoundry_client.client import CloudFoundryClient
target_endpoint = 'https://somewhere.org'
proxy = dict(http=os.environ.get('HTTP_PROXY', ''), https=os.environ.get('HTTPS_PROXY', ''))
client = CloudFoundryClient(target_endpoint, proxy=proxy, verify=False)
# init with user credentials
client.init_with_user_credentials('login', 'password')
# init with refresh token (that will retrieve a fresh access token)
client.init_with_token('refresh-token')
# init with access and refresh token (if the above method is not convenient)
client.refresh_token = 'refresh-token'
client._access_token = 'access-token'

It can also be instantiated with oauth code flow if you possess a dedicated oauth application with its redirection

from flask import request
from cloudfoundry_client.client import CloudFoundryClient
target_endpoint = 'https://somewhere.org'
proxy = dict(http=os.environ.get('HTTP_PROXY', ''), https=os.environ.get('HTTPS_PROXY', ''))
client = CloudFoundryClient(target_endpoint, proxy=proxy, verify=False, client_id='my-client-id', client_secret='my-client-secret')

@app.route('/login')
def login():
    global client
    return redirect(client.generate_authorize_url('http://localhost:9999/code', '666'))

@app.route('/code')
def code():
    global client
    client.init_authorize_code_process('http://localhost:9999/code', request.args.get('code'))

And then you can use it as follows:

for organization in client.v2.organizations:
    print(organization['metadata']['guid'])

API V2

Entities

Entities returned by api V2 calls (organization, space, app..) are navigable ie you can call the method associated with the xxx_url entity attribute (note that if the attribute's name ends with a list, it will be interpreted as a list of object. Other wise you will get a single entity).

for organization in client.v2.organizations:
    for space in organization.spaces(): # perform a GET on spaces_url attribute
        organization_reloaded = space.organization()  # perform a GET on organization_url attribute
Application object provides more methods such as
  • instances
  • stats
  • start
  • stop
  • summary

As instance, you can get all the summaries as follows:

Or else:

for app in client.v2.apps:
    print(app.summary())

Available managers

So far the implemented managers that are available are:

  • service_plans
  • service_plan_visibilities
  • service_instances
  • service_keys
  • service_bindings
  • service_brokers
  • apps
  • events
  • buildpacks
  • organizations
  • spaces
  • services
  • routes
  • shared_domains
  • private_domains
  • security_groups

Note that even if, while navigating, you reach an entity manager that does not exist, the get will be performed and you will get the expected entities. For example, event entity manager is not yet implemented but you can do

for app in client.v2.apps:
    for event in app.events():
        handle_event_object()

All managers provide the following methods:

  • list(**kwargs): return an iterator on entities, according to the given filtered parameters
  • get_first(**kwargs): return the first matching entity according to the given parameters. Returns `None if none returned
  • get: perform a GET on the entity. If the entity cannot be find it will raise an exception due to http NOT FOUND response status
  • __iter__: iteration on the manager itself. Alias for a no-filter list
  • __getitem__: alias for the get operation
  • _create: the create operation. Since it is a generic operation (only takes a dict object), this operation is protected
  • _update: the update operation. Since it is a generic operation (only takes a the resource id and a dict object), this operation is protected
  • _remove: the delete operation. This operation is maintained protected.
# Assume you have an organization named `test-org` with a guid of `test-org-guid`
org_get = client.v2.organizations.get('test-org-guid')
org_get_first = client.v2.organizations.get_first(**{'name': 'test-org'})
org_from_list = list(client.v2.organizations.list(**{'name': 'test-org'}))[0]
assert org_get == org_get_first == org_from_list

# You can also specify multiple values for a query parameter.
for organization in client.v2.organizations.list(**{'name': ['org1', 'org2']}):
    print(organization['metadata']['guid'])

# Order and Paging parameters are also supported.
query = {
    'order-by': 'name',
    'order-direction': 'desc',
    'results-per-page': 100
}
for organization in client.v2.organizations.list(**query):
    print(organization['entity']['name'])

API V3

Entities

Entities returned by API V3 calls transcripts links by providing a call on the object with the name of the link itself. Let's explain it with the next code

for app in client.v3.apps.list(space_guids='space_guid'):
  for task in app.tasks():
      print('Task %s' % task['guid'])
  app.stop()
  space = app.space()

Another example:

app = client.v3.apps['app-guid']
for task in app.tasks():
    task.cancel()
for task in client.v3.tasks.list(app_guids=['app-guid-1', 'app-guid-2']):
    task.cancel()

When supported by the API, parent entities can be included in a single call. The included entities replace the links mentioned above. The following code snippet issues three requests to the API in order to get app, space and organization data:

app = client.v3.apps.get("app-guid")
print("App name: %s" % app["name"])
space = app.space()
print("Space name: %s" % space["name"])
org = space.organization()
print("Org name: %s" % org["name"])

By changing the first line only, a single request fetches all the data. The navigation from app to space and space to organization remains unchanged.

app = client.v3.apps.get("app-guid", include="space.organization")

Available managers on API V3 are:

  • apps
  • buildpacks
  • domains
  • feature_flags
  • isolation_segments
  • jobs
  • organizations
  • organization_quotas
  • processes
  • service_brokers
  • service_credential_bindings
  • service_instances
  • service_offerings
  • service_plans
  • spaces
  • tasks

The managers provide the same methods as the V2 managers with the following differences:

  • get(**kwargs): supports keyword arguments that are passed on to the API, e.g. "include"

Networking

policy server

At the moment we have only the network policies implemented

for policy in client.network.v1.external.policies.list():
  print('destination protocol = {}'.format(policy['destination']['protocol']))
  print('destination from port = {}'.format(policy['destination']['ports']['start']))
  print('destination to port = {}'.format(policy['destination']['ports']['end']))

Available managers on API V3 are:

  • policy

This manager provides:

  • list(**kwargs): return an iterator on entities, according to the given filtered parameters
  • __iter__: iteration on the manager itself. Alias for a no-filter list
  • _create: the create operation. Since it is a generic operation (only takes a dict object), this operation is protected
  • _remove: the delete operation. This operation is maintained protected.

Application logs

Recent logs of an application can be get as follows:

app = client.v2.apps['app-guid']
for log in app.recent_logs():
    print(log)

Logs can also be streamed using a websocket as follows:

app = client.v2.apps['app-guid']
for log in app.stream_logs():
    # read message infinitely (use break to exit... it will close the underlying websocket)
    print(log)
# or
for log in client.doppler.stream_logs('app-guid'):
    # read message infinitely (use break to exit... it will close the underlying websocket)
    print(log)

Logs can also be streamed directly from RLP Gateway:

import asyncio
from cloudfoundry_client.client import CloudFoundryClient

target_endpoint = 'https://somewhere.org'
proxy = dict(http=os.environ.get('HTTP_PROXY', ''), https=os.environ.get('HTTPS_PROXY', ''))
rlp_client = CloudFoundryClient(target_endpoint, client_id='client_id', client_secret='client_secret', verify=False)
# init with client credentials
rlp_client.init_with_client_credentials()

async def get_logs_for_app(rlp_client, app_guid):
    async for log in rlp_client.rlpgateway.stream_logs(app_guid,
                                                       params={'counter': '', 'gauge': ''},
                                                       headers={'User-Agent': 'cf-python-client'})):
        print(log)

loop = asyncio.get_event_loop()
loop.create_task(get_logs_for_app(rlp_client, "app_guid"))
loop.run_forever()
loop.close()

Command Line Interface

The client comes with a command line interface. Run cloudfoundry-client command. At first execution, it will ask you information about the target platform and your credential (do not worry they are not saved). After that you may have a help by running cloudfoundry-client -h

Operations (experimental)

For now the only operation that is implemented is the push one.

from cloudfoundry_client.operations.push.push import PushOperation
operation = PushOperation(client)
operation.push(client.v2.spaces.get_first(name='My Space')['metadata']['guid'], path)

Issues and contributions

Please submit issue/pull request.

You can run tests by doing so. In the project directory:

$ export PYTHONPATH=main
$ python -m unittest discover test
# or even
$ python setup.py test
Comments
  • Max retries exceeded with url: /v2/info (Caused by SSLError(SSLError(

    Max retries exceeded with url: /v2/info (Caused by SSLError(SSLError("bad handshake: SysCallError(104, 'ECONNRESET')",),))

    Hi, cloudfoundry python client was not able to communicate with IBM's bluemix account.. somehow cloudfoundry python client has blocked all the requests going to that bluemix account and its giving the following error..

    Max retries exceeded with url: /v2/info (Caused by SSLError(SSLError("bad handshake: SysCallError(104, 'ECONNRESET')",),))

    opened by ntoolingmigration 21
  • Cannot push vendorized 1.16.0 version

    Cannot push vendorized 1.16.0 version

    Hello,

    We are getting the following error while trying to cf push a vendored tar.gz file of the 1.16.0 version:

              Processing ./vendor/cloudfoundry-client-1.16.0.tar.gz
                  Preparing wheel metadata: started
                  Preparing wheel metadata: finished with status 'error'
                  ERROR: Command errored out with exit status 1:
                   command: /tmp/contents051346007/deps/0/bin/python /tmp/contents051346007/deps/0/python/lib/python3.8/site-packages/pip/_vendor/pep517/_in_process.py prepare_metadata_for_build_wheel /tmp/tmpn3bbyhzm
                       cwd: /tmp/pip-install-m0fzbeh1/cloudfoundry-client
                  Complete output (13 lines):
                  running dist_info
                  creating /tmp/pip-modern-metadata-u1vp_m5i/cloudfoundry_client.egg-info
                  writing /tmp/pip-modern-metadata-u1vp_m5i/cloudfoundry_client.egg-info/PKG-INFO
                  writing dependency_links to /tmp/pip-modern-metadata-u1vp_m5i/cloudfoundry_client.egg-info/dependency_links.txt
                  writing entry points to /tmp/pip-modern-metadata-u1vp_m5i/cloudfoundry_client.egg-info/entry_points.txt
                  writing requirements to /tmp/pip-modern-metadata-u1vp_m5i/cloudfoundry_client.egg-info/requires.txt
                  writing top-level names to /tmp/pip-modern-metadata-u1vp_m5i/cloudfoundry_client.egg-info/top_level.txt
                  writing manifest file '/tmp/pip-modern-metadata-u1vp_m5i/cloudfoundry_client.egg-info/SOURCES.txt'
                  reading manifest file '/tmp/pip-modern-metadata-u1vp_m5i/cloudfoundry_client.egg-info/SOURCES.txt'
                  reading manifest template 'MANIFEST.in'
                  writing manifest file '/tmp/pip-modern-metadata-u1vp_m5i/cloudfoundry_client.egg-info/SOURCES.txt'
                  creating '/tmp/pip-modern-metadata-u1vp_m5i/cloudfoundry_client.dist-info'
                  error: invalid command 'bdist_wheel'
                  ----------------------------------------
              ERROR: Command errored out with exit status 1: /tmp/contents051346007/deps/0/bin/python /tmp/contents051346007/deps/0/python/lib/python3.8/site-packages/pip/_vendor/pep517/_in_process.py prepare_metadata_for_build_wheel /tmp/tmpn3bbyhzm Check the logs for full command output.
    

    Version 1.15.0 would work fine with the same instructions.

    Steps to reproduce:

    • Add cloudfoundry-client==1.16.0 as dependency
    • Vendorize with pip download -r requirements.txt --no-binary=:none: -d vendor
    • Try to cf push and the error should appear

    Further information: Buildpack: Python Buildpack version 1.7.29

    opened by 51acorsi 14
  • Cloud Foundry API Version

    Cloud Foundry API Version

    Can you please document the versions of the Cloud Foundry Restful API that this client works with.

    We have been trying to use it with 2.54 and have discovered this is not a working against this CF REST API but does work against Pivotal's latest public offering

    opened by wendymcameron 14
  • Error 'CloudFoundryClient' object has no attribute 'v3'

    Error 'CloudFoundryClient' object has no attribute 'v3'

    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

    opened by paragsangoi 13
  • cf task

    cf task

    Hi All,

    I want to retrieve task created / attached to my application and want to schedule it to run. Can you please let me know how can i achieve it using cf-python-client.

    Thanks a lot in advance Parag

    enhancement 
    opened by paragsangoi 12
  • UAA endpoint retrieval results in KeyError

    UAA endpoint retrieval results in KeyError

    In TAS 2.7.32, the UAA endpoint cannot be retrieved with the key/value combo that was updated in 0b2e8989d947ba0484fe69d4ea7fe622378db472

    This results in:

      File "/Users/reesek/opt/miniconda3/envs/tas/lib/python3.9/site-packages/cloudfoundry_client/client.py", line 196, in _get_info
        root_links["login"]["href"]
    

    CF_TRACE shows the response is:

    {
      "links": {
        "app_ssh": {
          "href": "ssh.devcf01.example.com:2222",
          "meta": {
            "host_key_fingerprint": "fingerprint",
            "oauth_client": "ssh-proxy"
          }
        },
        "bits_service": null,
        "cloud_controller_v2": {
          "href": "https://api.devcf01.example.com/v2",
          "meta": {
            "version": "2.139.0"
          }
        },
        "cloud_controller_v3": {
          "href": "https://api.devcf01.example.com/v3",
          "meta": {
            "version": "3.74.0"
          }
        },
        "credhub": null,
        "log_stream": {
          "href": "https://log-stream.devcf01.example.com"
        },
        "logging": {
          "href": "wss://doppler.devcf01.example.com:443"
        },
        "network_policy_v0": {
          "href": "https://api.devcf01.example.com/networking/v0/external"
        },
        "network_policy_v1": {
          "href": "https://api.devcf01.example.com/networking/v1/external"
        },
        "routing": {
          "href": "https://api.devcf01.example.com/routing"
        },
        "self": {
          "href": "https://api.devcf01.example.com"
        },
        "uaa": {
          "href": "https://uaa.devcf01.example.com"
        }
      }
    }
    

    Updating client.py to root_links["uaa"]["href"] corrects the error.

    opened by ktreese 11
  • better documentation on how to use

    better documentation on how to use

    I am trying to use basic features in a python program like starting/stopping an app and checking the status. It is not apparent how to do this. The two samples in the readme are not complete and do not even run. For example, the example printing all of the organizations in the target does not show how to create client, the sample just starts using client. Can you give a complete sample how to use the library from a python program? Maybe a sample how to check on the status of an app for a particular endpoint, organization, space, and app.

    help wanted 
    opened by webe3 11
  • Add cf client login to client library

    Add cf client login to client library

    Implements parts of #172:

    client.init_with_cf_config() will read a config file generated with cf login and use endpoint and token from there

    The problem was that the constructor for CloudFoundryClient already expects the endpoint and uses the endpoint to retrieve further information. Therefore, the constructor already needs to know that it needs to parse the file to get the endpoint.

    opened by svenXY 10
  • I'm unable to get app.stats()

    I'm unable to get app.stats()

    I'm trying to get the current stats using the following code

    code

    for organization in client.v2.organizations: for space in organization.spaces(): for app in space.apps(): print(app.stats())

    Error

    Traceback (most recent call last): File "C:\Users\FakeUser\Desktop\cf_python_test\app_stats.py", line 27, in print(app.stats()) File "C:\Users\FakeUser\AppData\Local\Programs\Python\Python38-32\lib\site-packages\cloudfoundry_client\v2\apps.py", line 30, in stats return self.client.v2.apps.get_stats(self['metadata']['guid']) File "C:\Users\FakeUser\AppData\Local\Programs\Python\Python38-32\lib\site-packages\cloudfoundry_client\v2\apps.py", line 59, in get_stats return self._get('%s/%s/stats' % (self.entity_uri, application_guid), JsonObject) File "C:\Users\FakeUser\AppData\Local\Programs\Python\Python38-32\lib\site-packages\cloudfoundry_client\v2\entities.py", line 67, in _get response = self.client.get(url) File "C:\Users\FakeUser\AppData\Local\Programs\Python\Python38-32\lib\site-packages\cloudfoundry_client\client.py", line 225, in get return CloudFoundryClient._check_response(response) File "C:\Users\FakeUser\AppData\Local\Programs\Python\Python38-32\lib\site-packages\cloudfoundry_client\client.py", line 252, in _check_response raise InvalidStatusCode(response.status_code, body) cloudfoundry_client.errors.InvalidStatusCode: <exception str() failed>

    I'm on Windows 10 using Python 3.8.2

    opened by coobr01 10
  • Authentication issue on init (oauth2_client.credentials_manager.OAuthError)

    Authentication issue on init (oauth2_client.credentials_manager.OAuthError)

    I believe I have run into some sort of dependency problem here, where I cannot figure out what common libraries / binaries may be expected to be available for this library (or probably the oauth2-client) to initialize properly.

    I am running on python 3.7.6 with oauth2-client==1.2.1 and cloudfoundry-client==1.12.4.

    When trying to call client.init_with_user_credentials(CF_USER, CF_SECRET) or use the commandline tool (cloudfoundry-client) I get the following error:

    Traceback (most recent call last):
      File "/home/vcap/deps/0/bin/cloudfoundry-client", line 11, in <module>
        load_entry_point('cloudfoundry-client==1.12.4', 'console_scripts', 'cloudfoundry-client')()
      File "/home/vcap/deps/0/python/lib/python3.7/site-packages/cloudfoundry_client/main/main.py", line 238, in main
        client = build_client_from_configuration()
      File "/home/vcap/deps/0/python/lib/python3.7/site-packages/cloudfoundry_client/main/main.py", line 92, in build_client_from_configuration
        client.init_with_user_credentials(login, password)
      File "/home/vcap/deps/0/python/lib/python3.7/site-packages/oauth2_client/credentials_manager.py", line 140, in init_with_user_credentials
        self._token_request(self._grant_password_request(login, password), True)
      File "/home/vcap/deps/0/python/lib/python3.7/site-packages/oauth2_client/credentials_manager.py", line 190, in _token_request
        CredentialManager._handle_bad_response(response)
      File "/home/vcap/deps/0/python/lib/python3.7/site-packages/oauth2_client/credentials_manager.py", line 78, in _handle_bad_response
        raise OAuthError(HTTPStatus(response.status_code), error.get('error'), error.get('error_description'))
    oauth2_client.credentials_manager.OAuthError: 401  - unauthorized : Bad credentials
    

    I have made sure 100 times that the credentials are correct :)

    In fact, I have initially been using the exact same code and environment setup successfully, but I was running that code inside a Docker container on CloudFoundry. (This Docker container was based on an official python Docker container: python:3-slim-stretch). I have since changed my CF deployment to no longer use Docker containers, but now use the "native" python_buildpack.

    Since then I am seeing the error above and assume that there may be some OS level dependency that is now missing? Is there any advice you could possibly offer to determine any

    What have I tried?

    1. curl -X GET "https://api.$CF_DOMAIN" (inside a deployed CF app)
    • works just fine
    1. requests.get("https://api.$CF_DOMAIN") (inside a deployed CF app)
    • also works well
    1. cloudfoundry-client (inside a deployed CF app)
    • manually entering the API endpoint and login credentials
    • results in the above error
    1. client.init_with_user_credentials(CF_USER, CF_SECRET) (inside a deployed CF app)
    • using system level environment variables as well as manually executing this in a python console
    • either way I end up with the above error
    1. I also still have a deployment running inside that "old" Docker container mentioned above, where everything actually continues to work as expected and I don't see any authentication errors. I therefore assume that neither the CF installation nor my account are causing the issue.
    opened by r-chris 9
  • Login with SSO or LDAP and/or using import_from_cf_cli within the library

    Login with SSO or LDAP and/or using import_from_cf_cli within the library

    Hi,

    the cf tools provide some means of login in with SSO

    cf login -a api.example.com --sso (which then queries for a temporary authentication code) - or can this temporary code be used somehow?

    as well as via LDAP:

    cf login -a api.example.com --origin=ldap -u <user>

    Can any of these be used with cf-python-client and if so, how?

    Furthermore, there is

    cloudfoundry-client import_from_cf_cli which, if I understand correctly, uses the token created by cf login. Is there any possibility of using this feature in the library as well?

    Thanks a lot, Sven

    opened by svenXY 8
  • cf push does not support service parameter

    cf push does not support service parameter

    The following manifest.yml is not supported:

    applications:

    • name: my-app services:
      • name: my-service1 parameters: foo: bar herp: derp
      • name: my-service2 parameters: foo: bar
    opened by hebelal 2
  • Invalid Auth Token when auth token is expired after 12h

    Invalid Auth Token when auth token is expired after 12h

    Hi,

    we are using cloudfoundry-client==1.30.0.

    Our code is part of a servicebroker with the openbrokerapi framework. We are trying to access the cf api with a client_id and a client_secret.

    Our code is as follows in the constructor:

    self._client = CloudFoundryClient(url, verify=cacert_path, client_id=client_id, client_secret=client_secret)
    self._client.init_with_client_credentials()
    

    to access one result we later use:

    app_guid_response = self._client.v3.apps.get(app_guid)
    

    If the login with init_with_client_credentials() is more than 12h ago, the token expires and accessing the api fails with:

    2022-08-18T08:20:42.746+02:00 [APP/PROC/WEB/0] [OUT] {"message": "GET: url=https://our.cf.api/v3/service_credential_bindings/9f103727-baab-464f-887e-f28d084119c0 - status_code=401 - vcap-request-id=e395a697-22ba-495c-9213-1667df377148::edc717be-bcd4-4f8a-b8eb-65ded1283297 - response={\n \"errors\": [\n {\n \"detail\": \"Invalid Auth Token\",\n \"title\": \"CF-InvalidAuthToken\",\n \"code\": 1000\n }\n ]\n}", "time": "2022-08-18T06:20:42.746518"} 
    2022-08-18T08:20:42.746+02:00 [APP/PROC/WEB/0] [ERR] DEBUG:cloudfoundry_client.client:GET: url=https://our.cf.api/v3/service_credential_bindings/9f103727-baab-464f-887e-f28d084119c0 - status_code=401 - vcap-request-id=e395a697-22ba-495c-9213-1667df377148::edc717be-bcd4-4f8a-b8eb-65ded1283297 - response={ 
    2022-08-18T08:20:42.746+02:00 [APP/PROC/WEB/0] [ERR] "errors": [ 
    2022-08-18T08:20:42.746+02:00 [APP/PROC/WEB/0] [ERR] { 
    2022-08-18T08:20:42.746+02:00 [APP/PROC/WEB/0] [ERR] "detail": "Invalid Auth Token", 
    2022-08-18T08:20:42.746+02:00 [APP/PROC/WEB/0] [ERR] "title": "CF-InvalidAuthToken", 
    2022-08-18T08:20:42.746+02:00 [APP/PROC/WEB/0] [ERR] "code": 1000 
    2022-08-18T08:20:42.746+02:00 [APP/PROC/WEB/0] [ERR] } 
    2022-08-18T08:20:42.746+02:00 [APP/PROC/WEB/0] [ERR] ] 
    2022-08-18T08:20:42.746+02:00 [APP/PROC/WEB/0] [ERR] } 
    

    The stacktrace is part of some more elements, here are the parts from cloudfoundry-client:

    2022-08-18T08:20:42.751+02:00 [APP/PROC/WEB/0] [ERR] service_binding_response = self._client.v3.service_credential_bindings.get(service_binding_guid) 
    2022-08-18T08:20:42.751+02:00 [APP/PROC/WEB/0] [ERR] File "/home/vcap/deps/0/python/lib/python3.8/site-packages/cloudfoundry_client/v3/entities.py", line 238, in get 
    2022-08-18T08:20:42.751+02:00 [APP/PROC/WEB/0] [ERR] return self._get(requested_path, **kwargs) 
    2022-08-18T08:20:42.751+02:00 [APP/PROC/WEB/0] [ERR] File "/home/vcap/deps/0/python/lib/python3.8/site-packages/cloudfoundry_client/v3/entities.py", line 133, in _get 
    2022-08-18T08:20:42.751+02:00 [APP/PROC/WEB/0] [ERR] response = self.client.get(url_requested) 
    2022-08-18T08:20:42.751+02:00 [APP/PROC/WEB/0] [ERR] File "/home/vcap/deps/0/python/lib/python3.8/site-packages/cloudfoundry_client/client.py", line 271, in get 
    2022-08-18T08:20:42.751+02:00 [APP/PROC/WEB/0] [ERR] return CloudFoundryClient._check_response(response) 
    2022-08-18T08:20:42.751+02:00 [APP/PROC/WEB/0] [ERR] File "/home/vcap/deps/0/python/lib/python3.8/site-packages/cloudfoundry_client/client.py", line 309, in _check_response 
    2022-08-18T08:20:42.751+02:00 [APP/PROC/WEB/0] [ERR] raise InvalidStatusCode(HTTPStatus(response.status_code), body, response.headers.get("x-vcap-request-id")) 
    2022-08-18T08:20:42.751+02:00 [APP/PROC/WEB/0] [ERR] cloudfoundry_client.errors.InvalidStatusCode: UNAUTHORIZED = {"errors": [{"detail": "Invalid Auth Token", "title": "CF-InvalidAuthToken", "code": 1000}]} - vcap-request-id = e395a697-22ba-495c-9213-1667df377148::edc717be-bcd4-4f8a-b8eb-65ded1283297 
    

    I thought https://github.com/cloudfoundry-community/cf-python-client/pull/88 was supposed to fix that problem? Thanks!

    • Lorenz
    opened by hanswurscht 0
  • Graceful continuation on NOT_FOUND

    Graceful continuation on NOT_FOUND

    Hi - We are using cf-python-client as part of a task which downloads each app-blob in turn. As we have tens of thousands of containers, this job takes 8-10 hours to complete.

    The job is theoretically quite straightforward...

    for app in cfClient.v3.apps:
        space_name=app.space()['name']
        org_name=app.space().organization()['name']
        ...
    

    More often than not, during the running of this task, we'll encounter an error along the lines of...

    cloudfoundry_client.errors.InvalidStatusCode: NOT_FOUND = {"errors": [{"detail": "Space not found", "title": "CF-ResourceNotFound", "code": 10010}]}
    

    or

    cloudfoundry_client.errors.InvalidStatusCode: NOT_FOUND = {"errors": [{"detail": "App not found", "title": "CF-ResourceNotFound", "code": 10010}]} 
    

    Given the number of orgs/spaces/apps we have in service, it is not too surprising that an app or space which was present at the start of the task is no longer around 6-8 hours later.

    When we encounter an error like this we have no options but to restart the 8-10 hour task from the beginning again and hope that it manages to make it through without an error.

    I was just wondering if there are any options to allow for more graceful continuation when objects are no longer found? This doesn't seem to be something that I can handle with a try: except: - Are there any options to make errors like this non-fatal?

    Cheers!!

    opened by jimconner 2
  • health-check-type is ignored from manifest.yml when pushing application

    health-check-type is ignored from manifest.yml when pushing application

    When using the pushoperation health-check-type and related fields are ignored from a manifest file. This is caused by the v2 api of cf using the same field names, but the dashes are converted to underscores.

    The fields with dashes are dropped in _generate_application_update_request in apps.py because AppManager.APPLICATION_FIELDS does not contain them, but the underscored versions.

    opened by ivankoster 1
Owner
Cloud Foundry Community
Cloud Foundry Community
Raphtory-client - The python client for the Raphtory project

Raphtory Client This is the python client for the Raphtory project Install via p

Raphtory 5 Apr 28, 2022
Drcom-pt-client - Drcom Pt version client with refresh timer

drcom-pt-client Drcom Pt version client with refresh timer Dr.com Pt版本客户端 可用于网页认

null 4 Nov 16, 2022
Joshua McDonagh 1 Jan 24, 2022
A discord.py bot template with Cogs implemented.

discord-cogs-template A discord.py bot template with Cogs implemented. Instructions Before you start ⚠ Basic knowledge of python is required. Steps If

censor 2 Sep 2, 2022
A small discord bot to interface with python-discord's snekbox.

A small discord bot to interface with python-discord's snekbox.

Hassan Abouelela 0 Oct 5, 2021
Small Python Tracker clone of Electra

Discord Bot Tracker - Python Simply Track your Bots (Status) to get notified when one of those go offline/online. Paste IDs into the config.py files,

Koni 2 Nov 23, 2021
A small and fun Discord Bot that is written in Python and discord-interactions (with discord.py)

Articuno (discord-interactions) A small and fun Discord Bot that is written in Python and discord-interactions (with discord.py) Get started If you wa

Blue 8 Dec 26, 2022
A small Python app to create Notion pages from Jira issues

Jira to Notion This little program will capture a Jira issue and create a corresponding Notion subpage. Mac users can fetch the current issue from the

Dr. Kerem Koseoglu 12 Oct 27, 2022
Asyncevents: a small library to help developers perform asynchronous event handling in Python

asyncevents - Asynchronous event handling for modern Python asyncevents is a small library to help developers perform asynchronous event handling in m

Mattia 5 Aug 7, 2022
This repo contains a small project i've done using PILLOW module in python

This repo contains a small project i've done using PILLOW module in python. I wrote an automated script which generates more than 5k+ unique nfts with 0 hassle in less time.

SasiVatsal 11 Nov 5, 2022
A small python script which runs a speedtest using speedtest.net and inserts it into a Google Docs Spreadsheet.

speedtest-google-sheets This is a small python script which runs a speedtest using speedtest.net and inserts it into a Google Docs Spreadsheet. Setup

marie 2 Feb 10, 2022
A small repository with convenience functions for working with the Notion API.

Welcome! Within this respository are a few convenience functions to assist with the pulling and pushing of data from the Notion API.

null 10 Jul 9, 2022
A small script to migrate or synchronize users & groups from Okta to AWS SSO

aws-sso-sync-okta A small script to migrate or synchronize users & groups from Okta to AWS SSO Changelog Version Remove hardcoded values on variables

Paul 4 Feb 11, 2022
Migration Manager (MM) is a very small utility that can list source servers in a target account and apply mass launch template modifications.

Migration Manager Migration Manager (MM) is a very small utility that can list source servers in a target account and apply mass launch template modif

Cody 2 Nov 4, 2021
This is a small Messnger with the cmd as an interface

Messenger This is a small messenger with the cmd as an interface. It started as a project to learn more about Python 3. If you want to run a version o

null 1 Feb 24, 2022
A small bot to interact with the reddit API. Get top viewers and update the sidebar widget.

LiveStream_Reddit_Bot Get top twitch and facebook stream viewers for a game and update the sidebar widget and old reddit sidebar to show your communit

Tristan Wise 1 Nov 21, 2021
a small cli to generate AWS Well Architected Reports on the road

well-architected-review This repo intends to publish some scripts related to Well Architected Reviews. war.py extracts in txt & xlsx files all the WAR

null 4 Mar 18, 2022
A very basic starter bot based on CryptoKKing with a small balance

starterbot A very basic starter bot based on CryptoKKing with a small balance, use at your own risk. I have since upgraded this script significantly a

Danny Kendrick 2 Dec 5, 2021
This is a small package to interact with the OpenLigaDB API.

OpenLigaDB This is a small package to interact with the OpenLigaDB API. Installation Run the following to install: pip install openligadb Usage from o

null 1 Dec 31, 2021