Ejemplo n.º 1
0
 def __init__(self,
              get_url,
              part_index,
              chunk_size=None,
              digest_algorithm='MD5',
              digest=None,
              logger=None):
     self.get_url = str(get_url)
     self.part_index = part_index
     self.chunk_size = chunk_size or stages._chunk_size
     self.digest_algorithm = digest_algorithm
     self.digest = digest
     self.log = logger or stages.get_logger()
     self.written_digest = None
     self.bytes_written = 0
Ejemplo n.º 2
0
 def __init__(self,
              get_url,
              part_index,
              chunk_size=None,
              digest_algorithm='MD5',
              digest=None,
              max_buffer_size=None,
              logger=None):
     self.get_url = str(get_url)
     self.debug_url = str(self.get_url).split('?')[0] # rem sensitive info
     self.part_index = part_index
     self.chunk_size = chunk_size or stages._chunk_size
     self.digest_algorithm = digest_algorithm
     self.digest = digest
     self.log = logger or stages.get_logger()
     self.max_buffer_size = max_buffer_size or stages._max_part_buffer_size
     self.written_digest = None
     self.bytes_written = 0
Ejemplo n.º 3
0
 def __init__(self,
              get_url,
              part_index,
              chunk_size=None,
              digest_algorithm='MD5',
              digest=None,
              max_buffer_size=None,
              logger=None):
     self.get_url = str(get_url)
     self.debug_url = str(self.get_url).split('?')[0]  # rem sensitive info
     self.part_index = part_index
     self.chunk_size = chunk_size or stages._chunk_size
     self.digest_algorithm = digest_algorithm
     self.digest = digest
     self.log = logger or stages.get_logger()
     self.max_buffer_size = max_buffer_size or stages._max_part_buffer_size
     self.written_digest = None
     self.bytes_written = 0
Ejemplo n.º 4
0
 def __init__(self, loglevel=None):
     #self._log = logging.getLogger(stages._logger_name)
     self.version = None
     self.file_format = None
     self.key_filename = None
     self.sig_key_filename = None
     self.enc_key = None
     self.enc_iv = None
     self.download_image_size = None
     self.unbundled_image_size = None
     self.expected_size = None
     self.part_count = None
     self.image_parts = []
     self.signature = None
     self.signature_algorithm = None
     self.computed_signature = None
     self.log = get_logger()
     self._chunk_size = stages._chunk_size
Ejemplo n.º 5
0
 def __init__(self, loglevel=None):
     #self._log = logging.getLogger(stages._logger_name)
     self.version = None
     self.file_format = None
     self.key_filename = None
     self.sig_key_filename = None
     self.enc_key = None
     self.enc_iv = None
     self.download_image_size = None
     self.unbundled_image_size = None
     self.expected_size = None
     self.part_count = None
     self.image_parts = []
     self.signature = None
     self.signature_algorithm = None
     self.computed_signature = None
     self.log = get_logger()
     self._chunk_size = stages._chunk_size
Ejemplo n.º 6
0
    def __init__(self, dest_file=None, **kwargs):
        parser = argparse.ArgumentParser(description=
                                         "Download parts from manifest")
        parser.add_argument('-m', '--manifest', dest='manifest', required=True,
                            help='''Path to 'download-manifest. Use '-' to read
                            manifest from stdin''')
        parser.add_argument('-d', '--dest', dest='destination',
                            help='''Destination path to write image to.
                            Use '-' for stdout.''')
        parser.add_argument('-k', '--privatekey', dest='privatekey',
                            help='''file containing the private key to decrypt
                            the bundle with.''')
        parser.add_argument('-c', '--cloudcert', dest='cloudcert',
                            required=True,
                            help='''file containing the cloud cert used
                            to verify manifest signature.''')
        parser.add_argument('-x', '--xsd', dest='xsd', default=None,
                            help='''Path to 'download-manifest xsd used
                            to validate manfiest xml.''')
        parser.add_argument('--toolspath', dest='toolspath', default=None,
                            help='''Local path to euca2ools.''')
        parser.add_argument('--debug', dest='debug', default=False,
                            action='store_true',
                            help='''Enable debug to a log file''')
        parser.add_argument('--logfile', dest='logfile', default=None,
                            help='''log file path to write to''')
        parser.add_argument('--loglevel', dest='loglevel', default='INFO',
                            help='''log level for output''')
        parser.add_argument('--dumpmanifest', dest='dumpmanifest',
                            action='store_true', default=False,
                            help='''Get and show manifest then exit''')
        parser.add_argument('--reportprogress', dest='reportprogress',
                            default=False, action='store_true',
                            help='''Output progress information to stderr''')
        parser.add_argument('--destispipe', dest='destispipe',
                            default=False, action='store_true',
                            help='''Indicate that destination is a pipe''')
        parser.add_argument('--skip-size-validation', dest='skipsizevalidation',
                            default=False, action='store_true',
                            help='''Skip downloaded file size validation (use carefully)''')


        #Set any kwargs from init to default values for parsed args
        #Handle the cli arguments...
        if not kwargs:
            arg_list = sys.argv[1:]
        else:
            arg_list = []
        self.parser = parser
        #Handle any kwargs at __init__  assign to argparse...
        for kwarg in kwargs:
            for key in parser._option_string_actions:
                if parser._option_string_actions[key].dest == str(kwarg):
                    option = parser._option_string_actions[key]
                    arg_value = [option.option_strings[0]]
                    #Is there a better way to handle this for consts?
                    if not option.const:
                        arg_value.append(kwargs[kwarg])
                    arg_list.extend(arg_value)
        self.args = parser.parse_args(arg_list)
        if dest_file is not None:
            self.args.destination = dest_file
        if self.args.destination == "-":
            force_stderr = True
        else:
            force_stderr = False
        self.log = stages.get_logger(self.args.loglevel,
                                     logfile=self.args.logfile,
                                     force_stderr=force_stderr,
                                     debug=self.args.debug)
        self.log.debug('Parsed Args: ' + str(self.args))
        self._setup()