Revision 672238f1
b/kamaki/cli/commands/astakos.py | ||
---|---|---|
177 | 177 |
|
178 | 178 |
def _print_quotas(self, quotas, *args, **kwargs): |
179 | 179 |
if not self['bytes']: |
180 |
for category in quotas.values():
|
|
181 |
for service in self._to_format.intersection(category):
|
|
182 |
for attr, v in category[service].items():
|
|
183 |
category[service][attr] = format_size(v)
|
|
180 |
for project_id, resources in quotas.items():
|
|
181 |
for r in self._to_format.intersection(resources):
|
|
182 |
resources[r] = dict(
|
|
183 |
[(k, format_size(v)) for k, v in resources[r].items()])
|
|
184 | 184 |
self.print_dict(quotas, *args, **kwargs) |
185 | 185 |
|
186 | 186 |
|
187 | 187 |
@command(quota_commands) |
188 | 188 |
class quota_info(_quota): |
189 |
"""Get quota for a service (cyclades, pithos, astakos)""" |
|
189 |
"""Get quota information""" |
|
190 |
|
|
191 |
arguments = dict( |
|
192 |
resource=ValueArgument('Quota for this resource', '--resource'), |
|
193 |
project_id=ValueArgument('Quota for this project', '--project-id'), |
|
194 |
bytes=FlagArgument('Show data size in bytes', '--bytes') |
|
195 |
) |
|
196 |
required = ['resource', 'project_id'] |
|
190 | 197 |
|
191 | 198 |
@errors.generic.all |
192 | 199 |
@errors.user.astakosclient |
193 |
def _run(self, service): |
|
194 |
r = dict() |
|
195 |
for k, v in self.client.get_quotas()['system'].items(): |
|
196 |
if (k.startswith(service)): |
|
197 |
r[k] = v |
|
198 |
self._print({'%s*' % service: r}, self._print_quotas) |
|
199 |
|
|
200 |
def main(self, service): |
|
200 |
def _run(self): |
|
201 |
quotas = self.client.get_quotas() |
|
202 |
if self['project_id']: |
|
203 |
quotas = {self['project_id']: quotas.get(self['project_id'])} |
|
204 |
if self['resource']: |
|
205 |
d = dict() |
|
206 |
for project_id, resources in quotas.items(): |
|
207 |
r = dict() |
|
208 |
for resource, value in resources.items(): |
|
209 |
if (resource.startswith(self['resource'])): |
|
210 |
r[resource] = value |
|
211 |
if r: |
|
212 |
d[project_id] = r |
|
213 |
quotas = d |
|
214 |
self._print(quotas, self._print_quotas) |
|
215 |
|
|
216 |
def main(self): |
|
201 | 217 |
super(self.__class__, self)._run() |
202 |
self._run(service)
|
|
218 |
self._run() |
|
203 | 219 |
|
204 | 220 |
|
205 | 221 |
@command(quota_commands) |
Also available in: Unified diff