'Rebuild -- shut down and then re-image -- a server.
:param server: The :class:`Server` (or its ID) to share onto.
:param image: the :class:`Image` (or its ID) to re-image with.
:param password: string to set as password on the rebuilt server.
:param disk_config: partitioning mode to use on the rebuilt server.
Valid values are \'AUTO\' or \'MANUAL\'
:param preserve_ephemeral: If True, request that any ephemeral device
be preserved when rebuilding the instance. Defaults to False.
:param name: Something to name the server.
:param meta: A dict of arbitrary key/value metadata to store for this
server. Both keys and values must be <=255 characters.
:param files: A dict of files to overwrite on the server upon boot.
Keys are file names (i.e. ``/etc/passwd``) and values
are the file contents (either as a string or as a
file-like object). A maximum of five entries is allowed,
and each file must be 10k or less.
:param description: optional description of the server (allowed since
microversion 2.19)
:returns: :class:`Server`'

def rebuild(self, server, image, password=None, disk_config=None, preserve_ephemeral=False, name=None, meta=None, files=None, **kwargs):

    descr_microversion = api_versions.APIVersion('2.19')
    if (('description' in kwargs) and (self.api_version < descr_microversion)):
        raise exceptions.UnsupportedAttribute('description', '2.19')
    body = {'imageRef': base.getid(image)}
    if (password is not None):
        body['adminPass'] = password
    if (disk_config is not None):
        body['OS-DCF:diskConfig'] = disk_config
    if (preserve_ephemeral is not False):
        body['preserve_ephemeral'] = True
    if (name is not None):
        body['name'] = name
    if ('description' in kwargs):
        body['description'] = kwargs['description']
    if meta:
        body['metadata'] = meta
    if files:
        personality = body['personality'] = []
        for (filepath, file_or_string) in sorted(files.items(), key=(lambda x: x[0])):
            if hasattr(file_or_string, 'read'):
                data = file_or_string.read()
            else:
                data = file_or_string
            cont = base64.b64encode(data.encode('utf-8')).decode('utf-8')
            personality.append({'path': filepath, 'contents': cont})
    (resp, body) = self._action_return_resp_and_body('rebuild', server, body, **kwargs)
    return Server(self, body['server'], resp=resp)
