예제 #1
0
def get_vmdk_size_and_properties(context, image, instance):
    """
    Get size of the vmdk file that is to be downloaded for attach in spawn.
    Need this to create the dummy virtual disk for the meta-data file. The
    geometry of the disk created depends on the size.
    """

    LOG.debug(_("Getting image size for the image %s") % image)
    (tank_client, image_id) = tank.get_tank_client(context, image)
    meta_data = tank_client.get_image_meta(image_id)
    size, properties = meta_data["size"], meta_data["properties"]
    LOG.debug(_("Got image size of %(size)s for the image %(image)s") %
              locals())
    return size, properties
예제 #2
0
def fetch_image(context, image, instance, **kwargs):
    """Download image from the tank image server."""
    LOG.debug(_("Downloading image %s from tank image server") % image)
    (tank_client, image_id) = tank.get_tank_client(context, image)
    metadata, read_iter = tank_client.get_image(image_id)
    read_file_handle = read_write_util.TankFileRead(read_iter)
    file_size = int(metadata['size'])
    write_file_handle = read_write_util.VMWareHTTPWriteFile(
                                kwargs.get("host"),
                                kwargs.get("data_center_name"),
                                kwargs.get("datastore_name"),
                                kwargs.get("cookies"),
                                kwargs.get("file_path"),
                                file_size)
    start_transfer(read_file_handle, file_size,
                   write_file_handle=write_file_handle)
    LOG.debug(_("Downloaded image %s from tank image server") % image)
예제 #3
0
def get_image_service(context, image_href):
    """Get the proper image_service and id for the given image_href.

    The image_href param can be an href of the form
    http://mytankserver:9292/images/42, or just an int such as 42. If the
    image_href is an int, then the default image service is returned.

    :param image_href: image ref/id for an image
    :returns: a tuple of the form (image_service, image_id)

    """
    # check if this is not a uri
    if '/' not in str(image_href):
        return (get_default_image_service(), image_href)

    else:
        (tank_client, image_id) = tank.get_tank_client(context, image_href)
        image_service = engine.image.tank.TankImageService(tank_client)
        return (image_service, image_id)
예제 #4
0
def get_image_service(context, image_href):
    """Get the proper image_service and id for the given image_href.

    The image_href param can be an href of the form
    http://mytankserver:9292/images/42, or just an int such as 42. If the
    image_href is an int, then the default image service is returned.

    :param image_href: image ref/id for an image
    :returns: a tuple of the form (image_service, image_id)

    """
    # check if this is not a uri
    if '/' not in str(image_href):
        return (get_default_image_service(), image_href)

    else:
        (tank_client, image_id) = tank.get_tank_client(context,
                                                             image_href)
        image_service = engine.image.tank.TankImageService(tank_client)
        return (image_service, image_id)
예제 #5
0
def upload_image(context, image, instance, **kwargs):
    """Upload the snapshotted vm disk file to Tank image server."""
    LOG.debug(_("Uploading image %s to the Tank image server") % image)
    read_file_handle = read_write_util.VmWareHTTPReadFile(
                                kwargs.get("host"),
                                kwargs.get("data_center_name"),
                                kwargs.get("datastore_name"),
                                kwargs.get("cookies"),
                                kwargs.get("file_path"))
    file_size = read_file_handle.get_size()
    (tank_client, image_id) = tank.get_tank_client(context, image)
    # The properties and other fields that we need to set for the image.
    image_metadata = {"is_public": True,
                      "disk_format": "vmdk",
                      "container_format": "bare",
                      "type": "vmdk",
                      "properties": {"vmware_adaptertype":
                                            kwargs.get("adapter_type"),
                                     "vmware_ostype": kwargs.get("os_type"),
                                     "vmware_image_version":
                                            kwargs.get("image_version")}}
    start_transfer(read_file_handle, file_size, tank_client=tank_client,
                        image_id=image_id, image_meta=image_metadata)
    LOG.debug(_("Uploaded image %s to the Tank image server") % image)
예제 #6
0
 def test_tank_client_image_ref(self):
     fixture = self._make_fixture(name='test image')
     image_id = self.service.create(self.context, fixture)['id']
     image_url = 'http://foo/%s' % image_id
     client, same_id = tank.get_tank_client(self.context, image_url)
     self.assertEquals(same_id, image_id)
예제 #7
0
 def test_tank_client_image_id(self):
     fixture = self._make_fixture(name='test image')
     image_id = self.service.create(self.context, fixture)['id']
     client, same_id = tank.get_tank_client(self.context, image_id)
     self.assertEquals(same_id, image_id)
예제 #8
0
 def test_tank_client_image_ref(self):
     fixture = self._make_fixture(name='test image')
     image_id = self.service.create(self.context, fixture)['id']
     image_url = 'http://foo/%s' % image_id
     client, same_id = tank.get_tank_client(self.context, image_url)
     self.assertEquals(same_id, image_id)
예제 #9
0
 def test_tank_client_image_id(self):
     fixture = self._make_fixture(name='test image')
     image_id = self.service.create(self.context, fixture)['id']
     client, same_id = tank.get_tank_client(self.context, image_id)
     self.assertEquals(same_id, image_id)