Revision 415a7304 lib/rpc.py

b/lib/rpc.py
438 438

  
439 439

  
440 440
class RpcRunner(_generated_rpc.RpcClientDefault,
441
                _generated_rpc.RpcClientBootstrap):
441
                _generated_rpc.RpcClientBootstrap,
442
                _generated_rpc.RpcClientConfig):
442 443
  """RPC runner class.
443 444

  
444 445
  """
......
453 454
    # <http://www.logilab.org/ticket/36586> and
454 455
    # <http://www.logilab.org/ticket/35642>
455 456
    # pylint: disable=W0233
457
    _generated_rpc.RpcClientConfig.__init__(self)
456 458
    _generated_rpc.RpcClientBootstrap.__init__(self)
457 459
    _generated_rpc.RpcClientDefault.__init__(self)
458 460

  
......
639 641

  
640 642
    return ieioargs
641 643

  
642
  #
643
  # Begin RPC calls
644
  #
645

  
646
  @classmethod
647
  @_RpcTimeout(_TMO_NORMAL)
648
  def call_upload_file(cls, node_list, file_name, address_list=None):
649
    """Upload a file.
650

  
651
    The node will refuse the operation in case the file is not on the
652
    approved file list.
653

  
654
    This is a multi-node call.
655

  
656
    @type node_list: list
657
    @param node_list: the list of node names to upload to
658
    @type file_name: str
659
    @param file_name: the filename to upload
660
    @type address_list: list or None
661
    @keyword address_list: an optional list of node addresses, in order
662
        to optimize the RPC speed
644
  @staticmethod
645
  def _PrepareFileUpload(filename):
646
    """Loads a file and prepares it for an upload to nodes.
663 647

  
664 648
    """
665
    file_contents = utils.ReadFile(file_name)
666
    data = _Compress(file_contents)
667
    st = os.stat(file_name)
649
    data = _Compress(utils.ReadFile(filename))
650
    st = os.stat(filename)
668 651
    getents = runtime.GetEnts()
669
    params = [file_name, data, st.st_mode, getents.LookupUid(st.st_uid),
670
              getents.LookupGid(st.st_gid), st.st_atime, st.st_mtime]
671
    return cls._StaticMultiNodeCall(node_list, "upload_file", params,
672
                                    address_list=address_list)
673

  
674
  @classmethod
675
  @_RpcTimeout(_TMO_NORMAL)
676
  def call_write_ssconf_files(cls, node_list, values):
677
    """Write ssconf files.
678

  
679
    This is a multi-node call.
652
    return [filename, data, st.st_mode, getents.LookupUid(st.st_uid),
653
            getents.LookupGid(st.st_gid), st.st_atime, st.st_mtime]
680 654

  
681
    """
682
    return cls._StaticMultiNodeCall(node_list, "write_ssconf_files", [values])
655
  #
656
  # Begin RPC calls
657
  #
683 658

  
684 659
  def call_test_delay(self, node_list, duration, read_timeout=None):
685 660
    """Sleep for a fixed time on given node(s).
......
743 718
    body = serializer.DumpJson(args, indent=False)
744 719

  
745 720
    return self._proc(node_list, procedure, body, read_timeout=timeout)
721

  
722

  
723
class ConfigRunner(_generated_rpc.RpcClientConfig):
724
  """RPC wrappers for L{config}.
725

  
726
  """
727
  _PrepareFileUpload = \
728
    staticmethod(RpcRunner._PrepareFileUpload) # pylint: disable=W0212
729

  
730
  def __init__(self, address_list):
731
    """Initializes this class.
732

  
733
    """
734
    _generated_rpc.RpcClientConfig.__init__(self)
735

  
736
    if address_list is None:
737
      resolver = _SsconfResolver
738
    else:
739
      # Caller provided an address list
740
      resolver = _StaticResolver(address_list)
741

  
742
    self._proc = _RpcProcessor(resolver,
743
                               netutils.GetDaemonPort(constants.NODED))
744

  
745
  def _Call(self, node_list, procedure, timeout, args):
746
    """Entry point for automatically generated RPC wrappers.
747

  
748
    """
749
    body = serializer.DumpJson(args, indent=False)
750

  
751
    return self._proc(node_list, procedure, body, read_timeout=timeout)

Also available in: Unified diff