Created
December 15, 2018 17:25
-
-
Save fabianvf/3d880d188ee5908a2c5fc9118f1b8285 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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