Revision 94bedc5b

b/Changelog
34 34
- Add enumeration to all listing commands, make it optional [#3739]
35 35
- Add a download_to_string method in pithos client [#3608]
36 36
- Add an upload_from_string method in pithos client [#3608]
37
- Add pithos client method create_container [#3756]
38
- Add output for file methods [#3756, #3732]:
39
    mkdir, touch, create
37 40

  
b/kamaki/cli/commands/pithos.py
432 432
class file_mkdir(_file_container_command):
433 433
    """Create a directory"""
434 434

  
435
    arguments = dict(
436
        with_output=FlagArgument('show response headers', ('--with-output')),
437
        json_output=FlagArgument('show headers in json', ('-j', '--json'))
438
    )
439

  
435 440
    __doc__ += '\n. '.join([
436 441
        'Kamaki hanldes directories the same way as OOS Storage and Pithos+:',
437 442
        'A   directory  is   an  object  with  type  "application/directory"',
......
443 448
    @errors.pithos.connection
444 449
    @errors.pithos.container
445 450
    def _run(self):
446
        self.client.create_directory(self.path)
451
        r = self.client.create_directory(self.path)
452
        if self['json_output']:
453
            print_json(r)
454
        elif self['with_output']:
455
            print_dict(r)
447 456

  
448 457
    def main(self, container___directory):
449 458
        super(self.__class__, self)._run(
......
462 471
        content_type=ValueArgument(
463 472
            'Set content type (default: application/octet-stream)',
464 473
            '--content-type',
465
            default='application/octet-stream')
474
            default='application/octet-stream'),
475
        with_output=FlagArgument('show response headers', ('--with-output')),
476
        json_output=FlagArgument('show headers in json', ('-j', '--json'))
466 477
    )
467 478

  
468 479
    @errors.generic.all
469 480
    @errors.pithos.connection
470 481
    @errors.pithos.container
471 482
    def _run(self):
472
        self.client.create_object(self.path, self['content_type'])
483
        r = self.client.create_object(self.path, self['content_type'])
484
        if self['json_output']:
485
            print_json(r)
486
        elif self['with_output']:
487
            print_dict(r)
473 488

  
474 489
    def main(self, container___path):
475 490
        super(file_touch, self)._run(
......
489 504
        limit=IntArgument('set default container limit', '--limit'),
490 505
        meta=KeyValueArgument(
491 506
            'set container metadata (can be repeated)',
492
            '--meta')
507
            '--meta'),
508
        with_output=FlagArgument('show request headers', ('--with-output')),
509
        json_output=FlagArgument('show headers in json', ('-j', '--json'))
493 510
    )
494 511

  
495 512
    @errors.generic.all
496 513
    @errors.pithos.connection
497 514
    @errors.pithos.container
498
    def _run(self):
499
        self.client.container_put(
500
            limit=self['limit'],
515
    def _run(self, container):
516
        r = self.client.create_container(
517
            container=container,
518
            sizelimit=self['limit'],
501 519
            versioning=self['versioning'],
502 520
            metadata=self['meta'])
521
        if self['json_output']:
522
            print_json(r)
523
        elif self['with_output']:
524
            print_dict(r)
503 525

  
504 526
    def main(self, container=None):
505 527
        super(self.__class__, self)._run(container)
......
507 529
            raiseCLIError('Invalid container name %s' % container, details=[
508 530
                'Did you mean "%s" ?' % self.container,
509 531
                'Use --container for names containing :'])
510
        self._run()
532
        self._run(container)
511 533

  
512 534

  
513 535
class _source_destination_command(_file_container_command):
b/kamaki/clients/pithos/__init__.py
71 71
    def __init__(self, base_url, token, account=None, container=None):
72 72
        super(PithosClient, self).__init__(base_url, token, account, container)
73 73

  
74
    def create_container(
75
            self,
76
            container=None, sizelimit=None, versioning=None, metadata=None):
77
        """
78
        :param container: (str) if not given, self.container is used instead
79

  
80
        :param sizelimit: (int) container total size limit in bytes
81

  
82
        :param versioning: (str) can be auto or whatever supported by server
83

  
84
        :param metadata: (dict) Custom user-defined metadata of the form
85
            { 'name1': 'value1', 'name2': 'value2', ... }
86

  
87
        :returns: (dict) response headers
88
        """
89
        cnt_back_up = self.container
90
        try:
91
            self.container = container or cnt_back_up
92
            r = self.container_put(
93
                quota=sizelimit, versioning=versioning, metadata=metadata)
94
            return r.headers
95
        finally:
96
            self.container = cnt_back_up
97

  
74 98
    def purge_container(self, container=None):
75 99
        """Delete an empty container and destroy associated blocks
76 100
        """
b/kamaki/clients/storage/__init__.py
161 161
            content_type='application/octet-stream', content_length=0):
162 162
        """
163 163
        :param obj: (str) directory-object name
164

  
164 165
        :param content_type: (str) explicitly set content_type
166

  
165 167
        :param content_length: (int) explicitly set content length
168

  
169
        :returns: (dict) object creation headers
166 170
        """
167 171
        self._assert_container()
168 172
        path = path4url(self.account, self.container, obj)
169 173
        self.set_header('Content-Type', content_type)
170 174
        self.set_header('Content-length', str(content_length))
171
        self.put(path, success=201)
175
        r = self.put(path, success=201)
176
        return r.headers
172 177

  
173 178
    def create_directory(self, obj):
174 179
        """
175 180
        :param obj: (str) directory-object name
181

  
182
        :returns: (dict) request headers
176 183
        """
177 184
        self._assert_container()
178 185
        path = path4url(self.account, self.container, obj)
179 186
        self.set_header('Content-Type', 'application/directory')
180 187
        self.set_header('Content-length', '0')
181
        self.put(path, success=201)
188
        r = self.put(path, success=201)
189
        return r.headers
182 190

  
183 191
    def get_object_info(self, obj):
184 192
        """

Also available in: Unified diff