Revision 44443c24 kamaki/cli/commands/image.py
b/kamaki/cli/commands/image.py | ||
---|---|---|
373 | 373 |
|
374 | 374 |
|
375 | 375 |
class PithosLocationArgument(ValueArgument): |
376 |
"""Resolve pithos url, return in the form pithos://uuid/container/path""" |
|
376 |
"""Resolve pithos URI, return in the form pithos://uuid/container[/path] |
|
377 |
|
|
378 |
UPDATE: URLs without a path are also resolvable. Therefore, caller methods |
|
379 |
should check if there is a path or not |
|
380 |
""" |
|
377 | 381 |
|
378 | 382 |
def __init__( |
379 | 383 |
self, help=None, parsed_name=None, default=None, user_uuid=None): |
... | ... | |
387 | 391 |
|
388 | 392 |
@property |
389 | 393 |
def value(self): |
390 |
return 'pithos://%s/%s/%s' % (self.uuid, self.container, self.path) |
|
394 |
path = ('/%s' % self.path) if self.path else '' |
|
395 |
return 'pithos://%s/%s%s' % (self.uuid, self.container, path) |
|
391 | 396 |
|
392 | 397 |
@value.setter |
393 | 398 |
def value(self, location): |
... | ... | |
397 | 402 |
uuid, self.container, self.path = pc._resolve_pithos_url( |
398 | 403 |
location) |
399 | 404 |
self.uuid = uuid or self.uuid |
400 |
for term in ('container', 'path'): |
|
401 |
assert getattr(self, term, None), 'No %s' % term |
|
405 |
assert self.container, 'No container in pithos URI' |
|
402 | 406 |
except Exception as e: |
403 | 407 |
raise CLIInvalidArgument( |
404 | 408 |
'Invalid Pithos+ location %s (%s)' % (location, e), |
405 | 409 |
details=[ |
406 | 410 |
'The image location must be a valid Pithos+', |
407 | 411 |
'location. There are two valid formats:', |
408 |
' pithos://USER_UUID/CONTAINER/PATH',
|
|
412 |
' pithos://USER_UUID/CONTAINER[/PATH]',
|
|
409 | 413 |
'OR', |
410 |
' /CONTAINER/PATH',
|
|
414 |
' /CONTAINER[/PATH]',
|
|
411 | 415 |
'To see all containers:', |
412 | 416 |
' [kamaki] container list', |
413 | 417 |
'To list the contents of a container:', |
... | ... | |
536 | 540 |
|
537 | 541 |
@errors.generic.all |
538 | 542 |
@errors.plankton.connection |
539 |
def _run(self, name, location):
|
|
540 |
locator, pithos = self.arguments['pithos_location'], None
|
|
543 |
def _run(self, name, locator):
|
|
544 |
location, pithos = locator.value, None
|
|
541 | 545 |
if self['local_image_path']: |
542 | 546 |
with open(self['local_image_path']) as f: |
543 | 547 |
pithos = self._get_pithos_client(locator) |
... | ... | |
603 | 607 |
|
604 | 608 |
def main(self): |
605 | 609 |
super(self.__class__, self)._run() |
610 |
|
|
611 |
locator, pithos = self.arguments['pithos_location'], None |
|
612 |
locator.setdefault('uuid', self.auth_base.user_term('id')) |
|
613 |
locator.path = locator.path or path.basename( |
|
614 |
self['local_image_path'] or '') |
|
615 |
if not locator.path: |
|
616 |
raise CLIInvalidArgument( |
|
617 |
'Missing the image file or object', details=[ |
|
618 |
'Pithos+ URI %s does not point to a physical image' % ( |
|
619 |
locator.value), |
|
620 |
'A physical image is necessary.', |
|
621 |
'It can be a remote Pithos+ object or a local file.', |
|
622 |
'To specify a remote image object:', |
|
623 |
' %s [pithos://UUID]/CONTAINER/PATH' % locator.lvalue, |
|
624 |
'To specify a local file:', |
|
625 |
' %s [pithos://UUID]/CONTAINER[/PATH] %s LOCAL_PATH' % ( |
|
626 |
locator.lvalue, |
|
627 |
self.arguments['local_image_path'].lvalue) |
|
628 |
]) |
|
606 | 629 |
self.arguments['pithos_location'].setdefault( |
607 | 630 |
'uuid', self.auth_base.user_term('id')) |
608 |
self._run(self['name'], self['pithos_location'])
|
|
631 |
self._run(self['name'], locator)
|
|
609 | 632 |
|
610 | 633 |
|
611 | 634 |
@command(image_cmds) |
Also available in: Unified diff