Ejemplo n.º 1
0
    def take_action(self, parsed_args):
        self.log.debug("take_action(%s)" % parsed_args)

        image_client = self.app.client_manager.image
        data = image_client.images.data(parsed_args.id)

        gc_utils.save_image(data, parsed_args.file)
Ejemplo n.º 2
0
    def take_action(self, parsed_args):
        self.log.debug("take_action(%s)" % parsed_args)

        image_client = self.app.client_manager.image
        data = image_client.images.data(parsed_args.id)

        gc_utils.save_image(data, parsed_args.file)
Ejemplo n.º 3
0
def do_image_download(gc, args):
    """Download a specific image."""
    image = utils.find_resource(gc.images, args.image)
    body = image.data()
    if args.progress:
        body = progressbar.VerboseIteratorWrapper(body, len(body))
    utils.save_image(body, args.file)
Ejemplo n.º 4
0
def do_image_download(gc, args):
    """Download a specific image."""
    image = utils.find_resource(gc.images, args.image)
    body = image.data()
    if args.progress:
        body = progressbar.VerboseIteratorWrapper(body, len(body))
    utils.save_image(body, args.file)
Ejemplo n.º 5
0
    def take_action(self, parsed_args):
        self.log.debug("take_action(%s)" % parsed_args)

        image_client = self.app.client_manager.image
        image = utils.find_resource(image_client.images, parsed_args.image)
        data = image_client.images.data(image)

        gc_utils.save_image(data, parsed_args.file)
Ejemplo n.º 6
0
    def take_action(self, parsed_args):
        image_client = self.app.client_manager.image
        image = utils.find_resource(
            image_client.images,
            parsed_args.image,
        )
        data = image_client.images.data(image.id)

        gc_utils.save_image(data, parsed_args.file)
Ejemplo n.º 7
0
    def take_action(self, parsed_args):
        image_client = self.app.client_manager.image
        image = utils.find_resource(
            image_client.images,
            parsed_args.image,
        )
        data = image_client.images.data(image.id)

        gc_utils.save_image(data, parsed_args.file)
Ejemplo n.º 8
0
def downloadImage(glance, snapshotId, imageName, path):
    try:
        print "Download snapshot of the instance %s" % (snapshotId)

        d = glance.images.data(snapshotId)
        utils.save_image(d, path + '/' + imageName + '.raw')
        print "Completed to download image\n"
    except Exception as e:
        #print(str(e))
        print "Completed to download image\n"
Ejemplo n.º 9
0
    def take_action(self, parsed_args):
        self.log.debug("take_action(%s)", parsed_args)

        image_client = self.app.client_manager.image
        image = utils.find_resource(
            image_client.images,
            parsed_args.image,
        )
        data = image_client.images.data(image)

        gc_utils.save_image(data, parsed_args.file)
Ejemplo n.º 10
0
def do_image_download(gc, args):
    """Download a specific image."""
    image = utils.find_resource(gc.images, args.image)
    body = image.data()
    if args.progress:
        body = progressbar.VerboseIteratorWrapper(body, len(body))
    if not (sys.stdout.isatty() and args.file is None):
        utils.save_image(body, args.file)
    else:
        print('No redirection or local file specified for downloaded image '
              'data. Please specify a local file with --file to save '
              'downloaded image or redirect output to another source.')
Ejemplo n.º 11
0
def do_image_download(gc, args):
    """Download a specific image."""
    body = gc.images.data(args.id)
    if args.progress:
        body = progressbar.VerboseIteratorWrapper(body, len(body))
    if not (sys.stdout.isatty() and args.file is None):
        utils.save_image(body, args.file)
    else:
        msg = ('No redirection or local file specified for downloaded image '
               'data. Please specify a local file with --file to save '
               'downloaded image or redirect output to another source.')
        utils.exit(msg)
Ejemplo n.º 12
0
    def take_action(self, parsed_args):
        image_client = self.app.client_manager.image
        image = utils.find_resource(
            image_client.images,
            parsed_args.image,
        )
        data = image_client.images.data(image.id)

        if data.wrapped is None:
            msg = _('Image %s has no data.') % image.id
            LOG.error(msg)
            self.app.stdout.write(msg + '\n')
            raise SystemExit

        gc_utils.save_image(data, parsed_args.file)
Ejemplo n.º 13
0
    def take_action(self, parsed_args):
        image_client = self.app.client_manager.image
        image = utils.find_resource(
            image_client.images,
            parsed_args.image,
        )
        data = image_client.images.data(image.id)

        if data.wrapped is None:
            msg = _('Image %s has no data.') % image.id
            LOG.error(msg)
            self.app.stdout.write(msg + '\n')
            raise SystemExit

        gc_utils.save_image(data, parsed_args.file)
Ejemplo n.º 14
0
def do_image_download(gc, args):
    """Download a specific image."""
    body = gc.images.data(args.id)
    if body is None:
        msg = ('Image %s has no data.' % args.id)
        utils.exit(msg)

    if args.progress:
        body = progressbar.VerboseIteratorWrapper(body, len(body))
    if not (sys.stdout.isatty() and args.file is None):
        utils.save_image(body, args.file)
    else:
        msg = ('No redirection or local file specified for downloaded image '
               'data. Please specify a local file with --file to save '
               'downloaded image or redirect output to another source.')
        utils.exit(msg)
Ejemplo n.º 15
0
def download_image(username, course, image_name):
    print('inside download_image')
    gl = setup_glanceclient()

    for image in gl.images.list():
        if hasattr(image, 'owner') and hasattr(image, 'image_type'):
            if image.name == image_name and image.owner == list(
                    get_projects(course)['instructors'].values())[0]:
                img_info = image

    img_data = gl.images.data(img_info.id)
    file_name = "downloads/%s-%s-%s.qcow2" % (calendar.timegm(
        time.gmtime()), course, img_info.name)
    utils.save_image(img_data, file_name)

    print('leaving download_image')
    send_image_download_link(username, file_name)
Ejemplo n.º 16
0
def do_image_download(gc, args):
    """Download a specific image."""
    try:
        body = gc.images.data(args.id)
    except (exc.HTTPForbidden, exc.HTTPException) as e:
        msg = "Unable to download image '%s'. (%s)" % (args.id, e)
        utils.exit(msg)

    if body is None:
        msg = ('Image %s has no data.' % args.id)
        utils.exit(msg)

    if args.progress:
        body = progressbar.VerboseIteratorWrapper(body, len(body))
    if not (sys.stdout.isatty() and args.file is None):
        utils.save_image(body, args.file)
    else:
        msg = ('No redirection or local file specified for downloaded image '
               'data. Please specify a local file with --file to save '
               'downloaded image or redirect output to another source.')
        utils.exit(msg)
Ejemplo n.º 17
0
def do_image_download(gc, args):
    """Download a specific image."""
    if sys.stdout.isatty() and (args.file is None):
        msg = ('No redirection or local file specified for downloaded image '
               'data. Please specify a local file with --file to save '
               'downloaded image or redirect output to another source.')
        utils.exit(msg)

    try:
        body = gc.images.data(args.id)
    except (exc.HTTPForbidden, exc.HTTPException) as e:
        msg = "Unable to download image '%s'. (%s)" % (args.id, e)
        utils.exit(msg)

    if body is None:
        msg = ('Image %s has no data.' % args.id)
        utils.exit(msg)

    if args.progress:
        body = progressbar.VerboseIteratorWrapper(body, len(body))

    utils.save_image(body, args.file)
Ejemplo n.º 18
0
def do_image_download(gc, args):
    """Download a specific image."""
    body = gc.images.data(args.id)
    utils.save_image(body, args.file)
	while notActive:
		image = glance.images.get(snapshotId)
		if image.status == 'active':
			notActive = False
	print "Snapshot created\n"

<<<<<<< HEAD
	print "Downloading snapshot, id: %s" %(snapshotId)
        #d = glance.images.data(snapshotId) 
        os.system("glance image-download --file "+path+imageName+".raw "+snapshotId)
        print "completed check point"
        #utilsGlance.save_image(d, path+imageName+'.raw')
=======
	print "Download snapshot of the instance %s" %(snapshotId)
        d = glance.images.data(snapshotId) 
        utilsGlance.save_image(d, path+imageName+'.raw' )
>>>>>>> 20d128af4b6809f5a311e57da1a2b8835663a8dd
        print "Completed to download image\n"
    except Exception as e:
        #print(str(e))
        print "Completed to download image\n"

def deleteImage(glance, snapshotId):
    try:
        print "Delete image : %s" %(snapshotId)
        glance.images.delete(snapshotId)
        print "Image Deleted\n"
    except Exception as e:
        print str(e)

Ejemplo n.º 20
0
def do_image_download(gc, args):
    """Download a specific image."""
    body = gc.images.data(args.id)
    utils.save_image(body, args.file)
Ejemplo n.º 21
0
 def download_image(self, image, path):
     temp_path = path + '.tmp'
     body = self.glance.images.data(image['id'])
     glance_utils.save_image(body, temp_path)
     os.rename(temp_path, path)
Ejemplo n.º 22
0
 def download_image(self, image, path):
     temp_path = path + '.tmp'
     body = self.glance.images.data(image['id'])
     glance_utils.save_image(body, temp_path)
     os.rename(temp_path, path)
Ejemplo n.º 23
0
def do_image_download(gc, args):
    """Download a specific image."""
    body = gc.images.data(args.id)
    if args.progress:
        body = progressbar.VerboseIteratorWrapper(body, len(body))
    utils.save_image(body, args.file)
Ejemplo n.º 24
0
def do_image_download(gc, args):
    """Download a specific image."""
    image = utils.find_resource(gc.images, args.image)
    body = image.data()
    utils.save_image(body, args.file)
Ejemplo n.º 25
0
def do_image_download(gc, args):
    """Download a specific image."""
    body = gc.images.data(args.id)
    if args.progress:
        body = progressbar.VerboseIteratorWrapper(body, len(body))
    utils.save_image(body, args.file)
Ejemplo n.º 26
0
def do_image_download(gc, args):
    """Download a specific image."""
    image = utils.find_resource(gc.images, args.image)
    body = image.data()
    utils.save_image(body, args.file)
def migrate_image(glanceclient, image_id):
    """
    Download an image and create a new one with the same properties
    (except UUID)
    Delete the original image at the orginal location
    Update the location of the original image to the location of the new image
    Protect both images to prevent them from being deleted and orphaned
    Prior to running this, the Glance backend should already be changed to the
    new one.
    """
    # Retrieve image object
    LOG.info("Retrieving properties for {0}".format(image_id))
    image = utils.find_resource(
        glanceclient.images,
        image_id,
    )
    image_description = "{0} ({1})".format(image.name, image.id)

    # Download the image locally
    file_path = TMPDIR + image.id
    LOG.info("Downloading {0} to {1}".format(image_description, file_path))
    data = glanceclient.images.data(image.id)
    gc_utils.save_image(data, file_path)

    # Save the properties we want to keep from the current image
    kwargs = {}
    # Note: Owner may not be preserved with Glance API v2 because of
    # https://bugs.launchpad.net/glance/+bug/1420008
    # Otherwise, we'd put "owner" in copy_attrs
    # properties is the custom properties that you have for your images
    properties = ['architecture', 'build_version']
    copy_attrs = ['name', 'container_format', 'disk_format', 'min_disk',
                  'min_ram', 'visibility'] + properties
    for attr in copy_attrs:
        if hasattr(image, attr):
            val = getattr(image, attr, None)
            if val:
                kwargs[attr] = val

    # Create a new image with the same properties except the UUID
    try:
        LOG.info("Creating new image based on {0}".format(image_description))
        new_image = glanceclient.images.create(**kwargs)
        data = io.open(file_path, "rb")
        glanceclient.images.upload(new_image.id, data, None)
    finally:
        # Clean up open file
        if hasattr(data, 'close'):
            data.close()

    # Fetch all properties of the new image
    new_image = utils.find_resource(
        glanceclient.images,
        new_image.id,
    )
    new_image_description = "{0} ({1})".format(new_image.name, new_image.id)
    LOG.info("New image created: {0}".format(new_image_description))

    # Delete the file based location for the original image and
    # set the location to be the new one
    LOG.info("Deleting original image location and setting the new one...")
    glanceclient.images.delete_locations(image.id,
                                         set([image.locations[0]["url"]]))
    glanceclient.images.add_location(image.id,
                                     new_image.locations[0]["url"], {})

    # Protect both images to prevent them from being deleted/orphaned
    LOG.info("Protecting both images to prevent them from being deleted...")
    kwargs = {}
    kwargs['protected'] = True
    glanceclient.images.update(image.id, **kwargs)
    glanceclient.images.update(new_image.id, **kwargs)

    # Delete the local temporary original image file once everything is done
    LOG.info("Deleting temporary image file at {0}".format(file_path))
    os.remove(file_path)

    return
Ejemplo n.º 28
0
def replate_images_from_region(args, other_endpoint, local_endpoint):
    # method to handle a single region
    token = get_fresh_token(args).service_catalog.catalog.get('token')
    token_id = token.get('id')
    token_tenant_id = token['tenant']['id']
    remote_images = glanceclient(other_endpoint.get(ENDPOINT_TYPE),
                                 token_id).images.list()
    for remote_image in remote_images:
        if not image_for_me(remote_image):
            continue
        if remote_image.status != 'active':
            logging.warn("Ignoring the image %s (%s) as it is not in an active"
                         " state yet" % (remote_image.name, remote_image.id))
            global image_not_ready_state_count
            image_not_ready_state_count += 1
            continue
        if image_exists(remote_image, local_endpoint,
                        get_fresh_token_id(args)):
            logging.info("The image %s (%s) is already replicated locally"
                         % (remote_image.name, remote_image.id))
            continue
        logging.info("We need to replicate the image %s (%s) to the region"
                     " %s" % (remote_image.name, remote_image.id,
                              other_endpoint.get('region')))
        # download the image
        try:
            body = glanceclient(other_endpoint.get(ENDPOINT_TYPE),
                                token_id).images.data(remote_image.id)
        except (exc.HTTPForbidden, exc.HTTPException) as e:
            msg = "Unable to download image '%s'. (%s)" % (args.id, e)
            utils.exit(msg)
        temp = tempfile.NamedTemporaryFile()
        temp_file_name = temp.name
        temp.close()
        try:
            logging.info("The image %s is downloading to %s"
                         % (remote_image.id, temp_file_name))
            utils.save_image(body, temp_file_name)
            glance_cmd = ["glance", "--os-image-api-version", "1",
                          "image-create", "--file", temp_file_name]
            # this code takes the properties on the source image, and uses them
            # for the target image
            for cli_param, glance_name in CREATE_ARGS.iteritems():
                if glance_name in remote_image:
                    value = remote_image[glance_name]
                    if " " in str(value):
                        value = "\"%s\"" % value
                    glance_cmd.extend(["--%s" % cli_param, str(value)])
            for xtra_prop in EXTRA_PROPS:
                if xtra_prop in remote_image and remote_image[xtra_prop]:
                    value = remote_image[xtra_prop]
                    if " " in str(value):
                        value = "\"%s\"" % value
                    glance_cmd.extend(["--property", "%s=%s" % (xtra_prop, value)])

            call_glance_image_create(args, glance_cmd,
                                     local_endpoint.get('region'),
                                     token_tenant_id)
        finally:
            os.remove(temp_file_name)
    logging.info('Completed processing images for the region %s' %
                 other_endpoint.get('region'))