def test_get_users(self, mock_get, mock_post): client = ContainerPlatformClient( username="******", password="******", api_host="127.0.0.1", api_port=8080, use_ssl=True, ) # Makes POST Request: https://127.0.0.1:8080/api/v1/login client.create_session() # Makes GET Request: https://127.0.0.1:8080/api/v1/user users = client.user.list() # Test that json response is saved in each WorkerK8s object assert users[0].json is not None # Test UserList subscriptable access and property setters assert users[0].is_service_account is False assert users[0].is_siteadmin is False assert users[0].default_tenant == "" assert users[0].is_external is False assert users[0].is_group_added_user is False assert users[0].name == "csnow" assert users[0].description == "chris" assert users[0]._links == {"self": {"href": "/api/v1/user/16"}}
def test_get_k8shosts(self, mock_get, mock_post): client = ContainerPlatformClient( username='******', password='******', api_host='127.0.0.1', api_port=8080, use_ssl=True) # Makes POST Request: https://127.0.0.1:8080/api/v1/login client.create_session() # Makes GET Request: https://127.0.0.1:8080/api/v2/worker/k8shost/ workers = client.k8s_worker.list() # Test that json response is saved in each WorkerK8s object assert client.k8s_worker.list()[0].json is not None # Test WorkerK8sList subscriptable access and property setters assert workers[0].worker_id == 4 assert workers[0].status == WorkerK8sStatus.unlicensed.name assert workers[0].hostname == 'ip-10-1-0-238.eu-west-2.compute.internal' assert workers[0].ipaddr == '10.1.0.238' assert workers[0].href == '/api/v2/worker/k8shost/4' # Test WorkerK8sList iterators assert [ worker.worker_id for worker in client.k8s_worker.list() ] == [ 4, 5 ]
def test_epic_tenant_list(self, mock_post): client = ContainerPlatformClient( username="******", password="******", api_host="127.0.0.1", api_port=8080, use_ssl=True, ) client.create_session() client.config.auth( { "external_identity_server": { "bind_pwd": "5ambaPwd@", "user_attribute": "sAMAccountName", "bind_type": "search_bind", "bind_dn": "cn=Administrator,CN=Users,DC=samdom,DC=example,DC=com", "host": "1.1.1.1", "security_protocol": "ldaps", "base_dn": "CN=Users,DC=samdom,DC=example,DC=com", "verify_peer": False, "type": "Active Directory", "port": 636, } } )
def test_tenant_list(self, mock_get, mock_post): client = ContainerPlatformClient( username="******", password="******", api_host="127.0.0.1", api_port=8080, use_ssl=True, ) # Makes POST Request: https://127.0.0.1:8080/api/v1/login client.create_session() # Makes GET Request: https://127.0.0.1:8080/api/v1/tenant tenants = client.tenant.list() # Test that json response is saved in each Tenant object self.assertIsNotNone(client.tenant.list()[0].json) # Test TenantList subscriptable access and Tenant property setters self.assertEqual(tenants[0].id, "/api/v1/tenant/1") self.assertEqual(tenants[0].status, "ready") self.assertEqual(tenants[0].name, "Site Admin") self.assertEqual(tenants[0].description, "Site Admin Tenant for BlueData clusters") # Test TenantList iterators self.assertEqual( [tenant.id for tenant in client.tenant.list()], ["/api/v1/tenant/1", "/api/v1/tenant/2"], )
def test_auth_ssl(self, mock_post): client = ContainerPlatformClient(username='******', password='******', api_host='127.0.0.1', api_port=8080, use_ssl=True) client.create_session()
def get_client(): client = ContainerPlatformClient( username='******', password='******', api_host='127.0.0.1', api_port=8080, use_ssl=True) client.create_session() return client
def test_auth_ssl_with_error(self, mock_post): client = ContainerPlatformClient(username='******', password='******', api_host='127.0.0.1', api_port=8080, use_ssl=True) with self.assertRaises(requests.exceptions.HTTPError): client.create_session()
def get_client(): client = ContainerPlatformClient( username="******", password="******", api_host="127.0.0.1", api_port=8080, use_ssl=True, ) client.create_session() return client
def test_auth_ssl(self, mock_post): client = ContainerPlatformClient( username="******", password="******", api_host="127.0.0.1", api_port=8080, use_ssl=True, ) client.create_session()
def test_create_session(self, mock_post): client = ContainerPlatformClient(username='******', password='******', api_host='127.0.0.1', api_port=8080, use_ssl=False) self.assertIsInstance(client.create_session(), ContainerPlatformClient)
print(80 * "*") print("ERROR: Can't parse: './generated/output.json'") print(80 * "*") sys.exit(1) controller_public_ip = j["controller_public_ip"]["value"] ad_server_private_ip = j["ad_server_private_ip"]["value"] client = ContainerPlatformClient(username='******', password='******', api_host=controller_public_ip, api_port=8080, use_ssl=True, verify_ssl=False) client.create_session() print("*" * 80) print("Current License:\n" + str(client.license.get_license())) print("*" * 80) print("Platform ID: " + client.license.get_platform_id()) print("*" * 80) lic = input("Paste License Text: ") with open('./generated/LICENSE', 'w') as out_file: out_file.write(lic) import subprocess subprocess.run([ "scp", "-i", "./generated/controller.prv_key", "./generated/LICENSE", "centos@{}:/srv/bluedata/license/LICENSE".format(controller_public_ip)
import time import os, sys import urllib3 os.environ["LOG_LEVEL"] = "INFO" # Disable the SSL warnings - don't do this on productions! urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) hpeclient = ContainerPlatformClient(username='******', password='******', api_host='127.0.0.1', api_port=8080, use_ssl=True, verify_ssl='/certs/hpecp-ca-cert.pem') hpeclient.create_session() print("\nHPE Container Platform K8S Clusters:\n") for c in hpeclient.k8s_cluster.list(): print("{:>12} {:>12} {:>12}".format(c.id, c.name, c.k)) cluster_list = hpeclient.k8s_cluster.list() if len(cluster_list) == 0: print("No clusters found. Aborting.") sys.exit(1) else: # get the kube admin config for the first cluster admin_kube_config = cluster_list[0].admin_kube_config # write it to a temporary file with tempfile.NamedTemporaryFile(mode="w") as fp: