-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathEGI_AppDB.py
101 lines (90 loc) · 3.33 KB
/
EGI_AppDB.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/usr/bin/env python
#
# Copyright 2016 EGI Foundation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#
import sys
import httplib
import xmltodict
from urlparse import urlparse
__copyright__ = "Copyright (c) 2016 EGI Foundation"
__license__ = "Apache Licence v2.0"
def get_vo_list():
vos = []
data = appdb_call('/rest/1.0/vos')
for vo in data['appdb:appdb']['vo:vo']:
vos.append(vo['@name'])
return vos
def check_supported_VOs(data, vo):
"""
Check if there are an image of the supported VO
"""
if 'provider:image' in data['appdb:appdb']['virtualization:provider']:
for os_tpl in data['appdb:appdb']['virtualization:provider']['provider:image']:
if '@voname' in os_tpl and vo in os_tpl['@voname']:
return True
return False
def appdb_call(c):
conn = httplib.HTTPSConnection('appdb.egi.eu')
conn.request("GET", c)
data = conn.getresponse().read()
conn.close()
data.replace('\n', '')
return xmltodict.parse(data)
def get_sites(vo):
data = appdb_call('/rest/1.0/sites?flt=%%2B%%3Dvo.name:%s&%%2B%%3Dsite.supports:1' % vo)
providersID = []
if 'appdb:site' in data['appdb:appdb']:
if isinstance(data['appdb:appdb']['appdb:site'], list):
sites = data['appdb:appdb']['appdb:site']
else:
sites = [data['appdb:appdb']['appdb:site']]
for site in sites:
if isinstance(site['site:service'], list):
for service in site['site:service']:
providersID.append(service['@id'])
else:
providersID.append(site['site:service']['@id'])
# Get provider metadata
endpoints = []
for ID in providersID:
data = appdb_call('/rest/1.0/va_providers/%s' % ID)
if check_supported_VOs(data, vo):
if ('provider:url' in data['appdb:appdb']['virtualization:provider'] and
data['appdb:appdb']['virtualization:provider']['@service_type'] == 'org.openstack.nova'):
provider_name = data['appdb:appdb']['virtualization:provider']['provider:name']
provider_endpoint_url = data['appdb:appdb']['virtualization:provider']['provider:url']
url = urlparse(provider_endpoint_url)
endpoints.append(provider_name + ";" + "%s://%s" % url[0:2])
return endpoints
if __name__ == "__main__":
vo = "fedcloud.egi.eu"
option = "vos"
if len(sys.argv) > 2:
vo = sys.argv[2]
option = sys.argv[1]
elif len(sys.argv) > 1:
option = sys.argv[1]
if option == "vos":
for vo in get_vo_list():
print(vo)
elif option == "sites":
for site in get_sites(vo):
if site.endswith("/"):
print(site[:-1])
else:
print(site)
else:
print("Incorrect Option.")