Пример #1
0
def download_file(
        read_handle, host, port, dc_name, ds_name, cookies,
        upload_file_path, file_size, cacerts, timeout_secs):
    """Download file to VMware server.

    :param read_handle: file read handle
    :param host: VMware server host name or IP address
    :param port: VMware server port number
    :param dc_name: name of the datacenter which contains the destination
                    datastore
    :param ds_name: name of the destination datastore
    :param cookies: cookies to build the cookie header while establishing
                    http connection with VMware server
    :param upload_file_path: destination datastore file path
    :param file_size: source file size
    :param cacerts: CA bundle file to use for SSL verification
    :param timeout_secs: timeout in seconds to wait for the download to
                         complete
    """
    write_handle = rw_handles.FileWriteHandle(host,
                                              port,
                                              dc_name,
                                              ds_name,
                                              cookies,
                                              upload_file_path,
                                              file_size,
                                              cacerts=cacerts)
    _start_transfer(read_handle, write_handle, timeout_secs)
Пример #2
0
def download_flat_image(context, timeout_secs, image_service, image_id,
                        **kwargs):
    """Download flat image from the image service to VMware server.

    :param context: image service write context
    :param timeout_secs: time in seconds to wait for the download to complete
    :param image_service: image service handle
    :param image_id: ID of the image to be downloaded
    :param kwargs: keyword arguments to configure the destination
                   file write handle
    :raises: VimConnectionException, ImageTransferException, ValueError
    """
    LOG.debug("Downloading image: %s from image service as a flat file.",
              image_id)

    # TODO(vbala) catch specific exceptions raised by download call
    read_iter = image_service.download(context, image_id)
    read_handle = rw_handles.ImageReadHandle(read_iter)
    file_size = int(kwargs.get('image_size'))
    write_handle = rw_handles.FileWriteHandle(kwargs.get('host'),
                                              kwargs.get('port'),
                                              kwargs.get('data_center_name'),
                                              kwargs.get('datastore_name'),
                                              kwargs.get('cookies'),
                                              kwargs.get('file_path'),
                                              file_size,
                                              cacerts=kwargs.get('cacerts'))
    _start_transfer(read_handle, write_handle, timeout_secs)
    LOG.debug("Downloaded image: %s from image service as a flat file.",
              image_id)
Пример #3
0
def fetch_image(context,
                instance,
                host,
                port,
                dc_name,
                ds_name,
                file_path,
                cookies=None):
    """Download image from the glance image server."""
    image_ref = instance.image_ref
    LOG.debug(
        "Downloading image file data %(image_ref)s to the "
        "data store %(data_store_name)s", {
            'image_ref': image_ref,
            'data_store_name': ds_name
        },
        instance=instance)

    metadata = IMAGE_API.get(context, image_ref)
    file_size = int(metadata['size'])
    read_iter = IMAGE_API.download(context, image_ref)
    read_file_handle = rw_handles.ImageReadHandle(read_iter)
    write_file_handle = rw_handles.FileWriteHandle(host, port, dc_name,
                                                   ds_name, cookies, file_path,
                                                   file_size)
    image_transfer(read_file_handle, write_file_handle)
    LOG.debug(
        "Downloaded image file data %(image_ref)s to "
        "%(upload_name)s on the data store "
        "%(data_store_name)s", {
            'image_ref': image_ref,
            'upload_name': 'n/a' if file_path is None else file_path,
            'data_store_name': 'n/a' if ds_name is None else ds_name
        },
        instance=instance)
Пример #4
0
 def _upload_vmdk(self, read_handle, host, port, dc_name, ds_name, cookies,
                  upload_file_path, file_size, cacerts, timeout_secs):
     write_handle = rw_handles.FileWriteHandle(host,
                                               port,
                                               dc_name,
                                               ds_name,
                                               cookies,
                                               upload_file_path,
                                               file_size,
                                               cacerts=cacerts)
     image_transfer._start_transfer(read_handle, write_handle, timeout_secs)
Пример #5
0
    def setUp(self):
        super(FileWriteHandleTest, self).setUp()

        vim_cookie = mock.Mock()
        vim_cookie.name = 'name'
        vim_cookie.value = 'value'

        self._conn = mock.Mock()
        patcher = mock.patch('urllib3.connection.HTTPConnection')
        self.addCleanup(patcher.stop)
        HTTPConnectionMock = patcher.start()
        HTTPConnectionMock.return_value = self._conn

        self.vmw_http_write_file = rw_handles.FileWriteHandle(
            '10.1.2.3', 443, 'dc-0', 'ds-0', [vim_cookie], '1.vmdk', 100,
            'http')
Пример #6
0
def upload_iso_to_datastore(iso_path, instance, **kwargs):
    LOG.debug("Uploading iso %s to datastore", iso_path, instance=instance)
    with open(iso_path, 'r') as iso_file:
        write_file_handle = rw_handles.FileWriteHandle(
            kwargs.get("host"), kwargs.get("port"),
            kwargs.get("data_center_name"), kwargs.get("datastore_name"),
            kwargs.get("cookies"), kwargs.get("file_path"),
            os.fstat(iso_file.fileno()).st_size)

        LOG.debug("Uploading iso of size : %s ",
                  os.fstat(iso_file.fileno()).st_size)
        block_size = 0x10000
        data = iso_file.read(block_size)
        while len(data) > 0:
            write_file_handle.write(data)
            data = iso_file.read(block_size)
        write_file_handle.close()

    LOG.debug("Uploaded iso %s to datastore", iso_path, instance=instance)