Skip to content

Instantly share code, notes, and snippets.

@fabianvf
Created December 15, 2018 17:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fabianvf/3d880d188ee5908a2c5fc9118f1b8285 to your computer and use it in GitHub Desktop.
Save fabianvf/3d880d188ee5908a2c5fc9118f1b8285 to your computer and use it in GitHub Desktop.
import kubernetes
from openshift.dynamic import DynamicClient
import urllib3
urllib3.disable_warnings()
def get_client(**kwargs):
configuration = kubernetes.client.Configuration()
for k, v in kwargs.items():
setattr(configuration, k, v)
kubernetes.client.Configuration.set_default(configuration)
# k8s_client = config.new_client_from_config()
k8s_client = kubernetes.client.ApiClient(configuration)
# rest is straight from example
return DynamicClient(k8s_client)
def main():
token_auth = dict(
api_key={'authorization': 'Bearer {}'.format('<api-token>')},
host='<host>',
verify_ssl=False
)
try:
client = get_client(**token_auth)
v1_projects = client.resources.get(api_version='project.openshift.io/v1', kind='Project')
for project in v1_projects.get().items:
print('\t{}'.format(project.metadata.name))
except Exception as e:
print("\tFailed with exception: {}".format(type(e)))
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment