Revision 00b1248e kamaki/cli/commands/cyclades.py

b/kamaki/cli/commands/cyclades.py
479 479
            '--firewall'),
480 480
        metadata_to_set=KeyValueArgument(
481 481
            'Set metadata in key=value form (can be repeated)',
482
            '--set-metadata'),
482
            '--metadata-set'),
483 483
        metadata_to_delete=RepeatableArgument(
484
            'Delete metadata by key (can be repeated)', '--del-metadata')
484
            'Delete metadata by key (can be repeated)', '--metadata-del')
485 485
    )
486 486
    required = [
487 487
        'server_name', 'flavor_id', 'firewall_profile', 'metadata_to_set',
488
        'metadata_to_del']
488
        'metadata_to_delete']
489 489

  
490 490
    @errors.generic.all
491 491
    @errors.cyclades.connection
......
698 698

  
699 699

  
700 700
@command(server_cmds)
701
class server_metadata_list(_init_cyclades, _optional_json):
702
    """Get server metadata"""
703

  
704
    @errors.generic.all
705
    @errors.cyclades.connection
706
    @errors.cyclades.server_id
707
    @errors.cyclades.metadata
708
    def _run(self, server_id, key=''):
709
        self._print(
710
            self.client.get_server_metadata(int(server_id), key),
711
            self.print_dict)
712

  
713
    def main(self, server_id, key=''):
714
        super(self.__class__, self)._run()
715
        self._run(server_id=server_id, key=key)
716

  
717

  
718
@command(server_cmds)
719
class server_metadata_set(_init_cyclades, _optional_json):
720
    """Set / update virtual server metadata
721
    Metadata should be given in key/value pairs in key=value format
722
    For example: /server metadata set <server id> key1=value1 key2=value2
723
    Old, unreferenced metadata will remain intact
724
    """
725

  
726
    @errors.generic.all
727
    @errors.cyclades.connection
728
    @errors.cyclades.server_id
729
    def _run(self, server_id, keyvals):
730
        assert keyvals, 'Please, add some metadata ( key=value)'
731
        metadata = dict()
732
        for keyval in keyvals:
733
            k, sep, v = keyval.partition('=')
734
            if sep and k:
735
                metadata[k] = v
736
            else:
737
                raiseCLIError(
738
                    'Invalid piece of metadata %s' % keyval,
739
                    importance=2, details=[
740
                        'Correct metadata format: key=val',
741
                        'For example:',
742
                        '/server metadata set <server id>'
743
                        'key1=value1 key2=value2'])
744
        self._print(
745
            self.client.update_server_metadata(int(server_id), **metadata),
746
            self.print_dict)
747

  
748
    def main(self, server_id, *key_equals_val):
749
        super(self.__class__, self)._run()
750
        self._run(server_id=server_id, keyvals=key_equals_val)
751

  
752

  
753
@command(server_cmds)
754
class server_metadata_delete(_init_cyclades, _optional_output_cmd):
755
    """Delete virtual server metadata"""
756

  
757
    @errors.generic.all
758
    @errors.cyclades.connection
759
    @errors.cyclades.server_id
760
    @errors.cyclades.metadata
761
    def _run(self, server_id, key):
762
        self._optional_output(
763
            self.client.delete_server_metadata(int(server_id), key))
764

  
765
    def main(self, server_id, key):
766
        super(self.__class__, self)._run()
767
        self._run(server_id=server_id, key=key)
768

  
769

  
770
@command(server_cmds)
771 701
class server_stats(_init_cyclades, _optional_json):
772 702
    """Get virtual server statistics"""
773 703

  

Also available in: Unified diff