<jupyter_start><jupyter_text>Interacting with the infrastructure with your own credentialsThis code shows how to get a valid access token to interact with Check-in integrated services. **Beware the API for refreshing tokens is still under development and may change in the future**In this example we use the token to list the VM on one of the providers of the EGI Cloud<jupyter_code># Install OpenStack client
%pip install -q keystoneauth1 python-novaclient tabulate
import requests
import os

api_url = os.environ.get('JUPYTERHUB_API_URL')
token = os.environ.get('JUPYTERHUB_API_TOKEN')

r = requests.get(api_url + '/refresh',
    headers={
             'Authorization': 'token %s' % token,
            }
    )
checkin_token = r.json()['access_token']
print("Got an access token: %s..." % checkin_token[0:10])
# Now use that token into another service
# Shown as example one provider of the EGI Cloud

from keystoneauth1 import session
from keystoneauth1.identity import v3
import novaclient.client

# This is from GOCDB
auth_url="https://sbgcloud.in2p3.fr:5000/v3"
project_id="a5eb30bba2c2497b90645fb199e34b39"

s = session.Session(auth=v3.OidcAccessToken(auth_url=auth_url,
                                            identity_provider="egi.eu",
                                            protocol="openid",
                                            access_token=checkin_token,
                                            project_id=project_id))
nova = novaclient.client.Client(2, session=s)


servers_table = []
for server in nova.servers.list():
    servers_table.append((server.id, server.name, server.status))

from tabulate import tabulate

print(tabulate(servers_table, headers=("Server ID", "Name", "Status")))<jupyter_output>Server ID                             Name             Status
------------------------------------  ---------------  --------
70f7ca69-e488-4ba4-b6e4-6775694e18e6  ocims-01         ACTIVE
6cc317e0-a56b-418d-b451-d95c0a570c3a  sectest-ext-net  ACTIVE
46fc3784-b592-4493-88fa-0b1c1459a7eb  sectest          ACTIVE
a09fa34e-4479-455e-a9cb-deaadae5a0c5  Kubernetes       ACTIVE
76863ff3-02c2-45c9-901e-7966031c73ad  Kubernetes       ACTIVE
6fe857b8-d66f-4d74-857c-b5d5bb42d53d  Kubernetes       ACTIVE
4435dea2-5b29-458e-a224-460a5d9dda3e  Kubernetes       ACTIVE
22056396-12cd-4038-8831-ad17ba3a99d1  Kubernetes       ACTIVE
19faffdb-4a1c-4367-8494-0d339b04bbc4  infopro          ACTIVE
5b7d02c3-d0df-4c47-ab4c-337089ff91c7  im_userimage     ACTIVE
{'fraction_non_alphanumeric': 0.10305958132045089, 'fraction_numerical': 0.09742351046698873, 'mean_word_length': 2.708955223880597, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 9, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '259646', 'license': 'Apache-2.0', 'n_tokens_mistral': 950, 'n_tokens_neox': 843, 'n_words': 182, 'path': 'samples/03-egi-services.ipynb', 'repo_name': 'enolfc/notebooks', 'size': '2484'}