|
4 | 4 | import datetime |
5 | 5 |
|
6 | 6 | from common.interface.siteinfo import SiteInfoSourceInterface |
| 7 | +from common.interface.userinfo import UserInfoSourceInterface |
7 | 8 | from common.interface.webservice import RESTService, GET, POST |
8 | 9 | from common.dataformat import Site |
9 | 10 | import common.configuration as config |
10 | 11 |
|
11 | 12 | logger = logging.getLogger(__name__) |
12 | 13 |
|
13 | | -class SiteDB(SiteInfoSourceInterface): |
| 14 | +class SiteDB(SiteInfoSourceInterface, UserInfoSourceInterface): |
14 | 15 | def __init__(self): |
15 | 16 | self._interface = RESTService(config.sitedb.url_base) |
16 | 17 |
|
17 | | - def get_site_list(self, sites, filt = '*'): #override |
| 18 | + def get_site_list(self, sites, filt = '*'): #override (SiteInfoSourceInterface) |
18 | 19 | """ |
19 | 20 | Fill the list of sites with sites that match the wildcard name. |
20 | 21 | Arguments: |
@@ -81,6 +82,30 @@ def get_site_list(self, sites, filt = '*'): #override |
81 | 82 |
|
82 | 83 | sites[name] = site |
83 | 84 |
|
| 85 | + def get_user(self, name): #override (UserInfoSourceInterface) |
| 86 | + result = self._interface.make_request('people', ['match=%s' % name]) |
| 87 | + |
| 88 | + if len(result) == 0: |
| 89 | + return None |
| 90 | + else: |
| 91 | + user_info = result[0] |
| 92 | + name = user_info[0] |
| 93 | + email = user_info[1] |
| 94 | + dn = user_info[4] |
| 95 | + |
| 96 | + return (name, email, dn) |
| 97 | + |
| 98 | + def get_user_list(self, users, filt = '*'): #override (UserInfoSourceInterface) |
| 99 | + result = self._interface.make_request('people') |
| 100 | + |
| 101 | + for user in users: |
| 102 | + user_info = result[0] |
| 103 | + name = user_info[0] |
| 104 | + email = user_info[1] |
| 105 | + dn = user_info[4] |
| 106 | + |
| 107 | + users[name] = (name, email, dn) |
| 108 | + |
84 | 109 | def _make_request(self, resource, options = []): |
85 | 110 | """ |
86 | 111 | Make a single API call to SiteDB, strip the "header" and return the body JSON. |
@@ -118,3 +143,8 @@ def _make_request(self, resource, options = []): |
118 | 143 | continue |
119 | 144 |
|
120 | 145 | out.write('UPDATE `sites` SET storage = %f, cpu = %f WHERE `name` LIKE \'%s\';\n' % (site.storage, site.cpu, site.name)) |
| 146 | + |
| 147 | + elif args.command == 'api': |
| 148 | + result = interface._make_request(args.options[0], args.options[1:]) |
| 149 | + |
| 150 | + pprint.pprint(result) |
0 commit comments