-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathonetts.py
48 lines (41 loc) · 1.39 KB
/
onetts.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
'''
Created on 16 de jun. de 2016
@author: micafer
'''
try:
from urlparse import urlparse
except ImportError:
from urllib.parse import urlparse
from IM.tts.tts import TTSClient
class ONETTSClient():
"""
Class to interact get user/password credentials to OpenNebula using the TTS
"""
@staticmethod
def get_auth_from_tts(tts_url, one_server, token, verify_ssl=False):
"""
Get username and password from the TTS service
"""
tts_uri = urlparse(tts_url)
scheme = tts_uri[0]
host = tts_uri[1]
port = None
if host.find(":") != -1:
parts = host.split(":")
host = parts[0]
port = int(parts[1])
ttsc = TTSClient(token, host, port, scheme, verify_ssl)
success, svc = ttsc.find_service(one_server)
if not success:
raise Exception("Error getting credentials from TTS: %s" % svc)
succes, cred = ttsc.request_credential(svc["id"])
if succes:
username = password = None
for elem in cred['credential']['entries']:
if elem['name'] == 'Username':
username = elem['value']
elif elem['name'] == 'Password':
password = elem['value']
return username, password
else:
raise Exception("Error getting credentials from TTS: %s" % cred)