3 # jose.lausuch@ericsson.com
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
14 from six.moves.urllib.parse import urlparse
16 from functest.ci import check_deployment
17 from functest.utils.constants import CONST
20 class OpenStack(object):
23 self.os_auth_url = CONST.__getattribute__('OS_AUTH_URL')
24 self.endpoint_ip = None
25 self.endpoint_port = None
26 self.openstack_creds = CONST.__getattribute__('openstack_creds')
28 self.endpoint_ip = urlparse(self.os_auth_url).hostname
29 self.endpoint_port = urlparse(self.os_auth_url).port
31 def ping_endpoint(self):
32 if self.os_auth_url is None:
33 click.echo("Source the OpenStack credentials first '. $creds'")
35 response = os.system("ping -c 1 " + self.endpoint_ip + ">/dev/null")
39 click.echo("Cannot talk to the endpoint %s\n" % self.endpoint_ip)
43 def show_credentials():
45 for key, value in os.environ.items():
46 if key.startswith('OS_'):
47 dic_credentials.update({key: value})
48 return dic_credentials
52 deployment = check_deployment.CheckDeployment()
53 deployment.check_all()
56 class CliOpenStack(OpenStack):
59 super(CliOpenStack, self).__init__()
62 def show_credentials():
63 dic_credentials = OpenStack.show_credentials()
64 for key, value in dic_credentials.items():
65 if key.startswith('OS_'):
66 click.echo("{}={}".format(key, value))