Exemplo n.º 1
0
def do_update(gc, args):
    """DEPRECATED! Use image-update instead."""
    try:
        fields = get_image_fields_from_args(args.fields)
    except RuntimeError as e:
        print(e)
        return FAILURE

    image_meta = {}

    # Strip any args that are not supported
    nonmodifiable_fields = ["created_at", "deleted_at", "deleted", "updated_at", "size", "status"]
    for field in nonmodifiable_fields:
        if field in fields.keys():
            print("Found non-modifiable field %s. Removing." % field)
            fields.pop(field)

    base_image_fields = [
        "disk_format",
        "container_format",
        "name",
        "min_disk",
        "min_ram",
        "location",
        "owner",
        "copy_from",
    ]
    for field in base_image_fields:
        fvalue = fields.pop(field, None)
        if fvalue is not None:
            image_meta[field] = fvalue

    # Have to handle "boolean" values specially...
    if "is_public" in fields:
        image_meta["is_public"] = utils.string_to_bool(fields.pop("is_public"))
    if "protected" in fields:
        image_meta["protected"] = utils.string_to_bool(fields.pop("protected"))

    # Add custom attributes, which are all the arguments remaining
    image_meta["properties"] = fields

    if not args.dry_run:
        image = gc.images.update(args.id, **image_meta)
        print("Updated image %s" % args.id)

        if args.verbose:
            print("Updated image metadata for image %s:" % args.id)
            print_image_formatted(gc, image)
    else:

        def _dump(dict):
            for k, v in sorted(dict.items()):
                print(" %(k)30s => %(v)s" % {"k": k, "v": v})

        print("Dry run. We would have done the following:")
        print("Update existing image with metadata:")
        _dump(image_meta)

    return SUCCESS
Exemplo n.º 2
0
def do_update(gc, args):
    """DEPRECATED! Use image-update instead."""
    try:
        fields = get_image_fields_from_args(args.fields)
    except RuntimeError as e:
        print e
        return FAILURE

    image_meta = {}

    # Strip any args that are not supported
    nonmodifiable_fields = [
        'created_at', 'deleted_at', 'deleted', 'updated_at', 'size', 'status'
    ]
    for field in nonmodifiable_fields:
        if field in fields.keys():
            print 'Found non-modifiable field %s. Removing.' % field
            fields.pop(field)

    base_image_fields = [
        'disk_format', 'container_format', 'name', 'min_disk', 'min_ram',
        'location', 'owner', 'copy_from'
    ]
    for field in base_image_fields:
        fvalue = fields.pop(field, None)
        if fvalue is not None:
            image_meta[field] = fvalue

    # Have to handle "boolean" values specially...
    if 'is_public' in fields:
        image_meta['is_public'] = utils.string_to_bool(fields.pop('is_public'))
    if 'protected' in fields:
        image_meta['protected'] = utils.string_to_bool(fields.pop('protected'))

    # Add custom attributes, which are all the arguments remaining
    image_meta['properties'] = fields

    if not args.dry_run:
        image = gc.images.update(args.id, **image_meta)
        print "Updated image %s" % args.id

        if args.verbose:
            print "Updated image metadata for image %s:" % args.id
            print_image_formatted(gc, image)
    else:

        def _dump(dict):
            for k, v in sorted(dict.items()):
                print " %(k)30s => %(v)s" % locals()

        print "Dry run. We would have done the following:"
        print "Update existing image with metadata:"
        _dump(image_meta)

    return SUCCESS
Exemplo n.º 3
0
def do_update(gc, args):
    """DEPRECATED! Use image-update instead."""
    try:
        fields = get_image_fields_from_args(args.fields)
    except RuntimeError as e:
        print e
        return FAILURE

    image_meta = {}

    # Strip any args that are not supported
    nonmodifiable_fields = ['created_at', 'deleted_at', 'deleted',
                            'updated_at', 'size', 'status']
    for field in nonmodifiable_fields:
        if field in fields.keys():
            print 'Found non-modifiable field %s. Removing.' % field
            fields.pop(field)

    base_image_fields = ['disk_format', 'container_format', 'name',
                         'min_disk', 'min_ram', 'location', 'owner',
                         'copy_from']
    for field in base_image_fields:
        fvalue = fields.pop(field, None)
        if fvalue is not None:
            image_meta[field] = fvalue

    # Have to handle "boolean" values specially...
    if 'is_public' in fields:
        image_meta['is_public'] = utils.string_to_bool(fields.pop('is_public'))
    if 'protected' in fields:
        image_meta['protected'] = utils.string_to_bool(fields.pop('protected'))

    # Add custom attributes, which are all the arguments remaining
    image_meta['properties'] = fields

    if not args.dry_run:
        image = gc.images.update(args.id, **image_meta)
        print "Updated image %s" % args.id

        if args.verbose:
            print "Updated image metadata for image %s:" % args.id
            print_image_formatted(gc, image)
    else:
        def _dump(dict):
            for k, v in sorted(dict.items()):
                print " %(k)30s => %(v)s" % locals()

        print "Dry run. We would have done the following:"
        print "Update existing image with metadata:"
        _dump(image_meta)

    return SUCCESS
Exemplo n.º 4
0
    def _image_meta_from_headers(self, headers):
        meta = {'properties': {}}
        for key, value in headers.iteritems():
            if key.startswith('x-image-meta-property-'):
                _key = key[22:]
                meta['properties'][_key] = value
            elif key.startswith('x-image-meta-'):
                _key = key[13:]
                meta[_key] = value

        for key in ['is_public', 'protected', 'deleted']:
            if key in meta:
                meta[key] = utils.string_to_bool(meta[key])

        return self._format_image_meta_for_user(meta)
Exemplo n.º 5
0
    def _image_meta_from_headers(self, headers):
        meta = {'properties': {}}
        for key, value in headers.iteritems():
            if key.startswith('x-image-meta-property-'):
                _key = key[22:]
                meta['properties'][_key] = value
            elif key.startswith('x-image-meta-'):
                _key = key[13:]
                meta[_key] = value

        for key in ['is_public', 'protected', 'deleted']:
            if key in meta:
                meta[key] = utils.string_to_bool(meta[key])

        return self._format_image_meta_for_user(meta)
Exemplo n.º 6
0
    def _image_meta_from_headers(self, headers):
        meta = {"properties": {}}
        for key, value in headers.iteritems():
            if key.startswith("x-image-meta-property-"):
                _key = key[22:]
                meta["properties"][_key] = value
            elif key.startswith("x-image-meta-"):
                _key = key[13:]
                meta[_key] = value

        for key in ["is_public", "protected", "deleted"]:
            if key in meta:
                meta[key] = utils.string_to_bool(meta[key])

        return self._format_image_meta_for_user(meta)
Exemplo n.º 7
0
    def _image_meta_from_headers(self, headers):
        meta = {'properties': {}}
        safe_decode = strutils.safe_decode
        for key, value in six.iteritems(headers):
            value = safe_decode(value, incoming='utf-8')
            if key.startswith('x-image-meta-property-'):
                _key = safe_decode(key[22:], incoming='utf-8')
                meta['properties'][_key] = value
            elif key.startswith('x-image-meta-'):
                _key = safe_decode(key[13:], incoming='utf-8')
                meta[_key] = value

        for key in ['is_public', 'protected', 'deleted']:
            if key in meta:
                meta[key] = utils.string_to_bool(meta[key])

        return self._format_image_meta_for_user(meta)
Exemplo n.º 8
0
def do_add(gc, args):
    """DEPRECATED! Use image-create instead."""
    try:
        fields = get_image_fields_from_args(args.fields)
    except RuntimeError as e:
        print(e)
        return FAILURE

    image_meta = {
        "is_public": utils.string_to_bool(fields.pop("is_public", "False")),
        "protected": utils.string_to_bool(fields.pop("protected", "False")),
        "min_disk": fields.pop("min_disk", 0),
        "min_ram": fields.pop("min_ram", 0),
    }

    # NOTE(bcwaldon): Use certain properties only if they are explicitly set
    optional = ["id", "name", "disk_format", "container_format"]
    for field in optional:
        if field in fields:
            image_meta[field] = fields.pop(field)

    # Strip any args that are not supported
    unsupported_fields = ["status", "size"]
    for field in unsupported_fields:
        if field in fields.keys():
            print("Found non-settable field %s. Removing." % field)
            fields.pop(field)

    # We need either a location or image data/stream to add...
    image_data = None
    if "location" in fields.keys():
        image_meta["location"] = fields.pop("location")
        if "checksum" in fields.keys():
            image_meta["checksum"] = fields.pop("checksum")
    elif "copy_from" in fields.keys():
        image_meta["copy_from"] = fields.pop("copy_from")
    else:
        # Grab the image data stream from stdin or redirect,
        # otherwise error out
        image_data = sys.stdin

    image_meta["data"] = image_data

    # allow owner to be set when image is created
    if "owner" in fields.keys():
        image_meta["owner"] = fields.pop("owner")

    # Add custom attributes, which are all the arguments remaining
    image_meta["properties"] = fields

    if not args.dry_run:
        image = gc.images.create(**image_meta)
        print("Added new image with ID: %s" % image.id)
        if args.verbose:
            print("Returned the following metadata for the new image:")
            for k, v in sorted(image.to_dict().items()):
                print(" %(k)30s => %(v)s" % {"k": k, "v": v})
    else:
        print("Dry run. We would have done the following:")

        def _dump(dict):
            for k, v in sorted(dict.items()):
                print(" %(k)30s => %(v)s" % {"k": k, "v": v})

        print("Add new image with metadata:")
        _dump(image_meta)

    return SUCCESS
Exemplo n.º 9
0
        print "Updated at: %s" % image.updated_at


@utils.arg('--silent-upload', action="store_true",
           help="DEPRECATED! Animations are always off.")
@utils.arg('fields', default=[], nargs='*', help=argparse.SUPPRESS)
def do_add(gc, args):
    """DEPRECATED! Use image-create instead."""
    try:
        fields = get_image_fields_from_args(args.fields)
    except RuntimeError, e:
        print e
        return FAILURE

    image_meta = {
        'is_public': utils.string_to_bool(
            fields.pop('is_public', 'False')),
        'protected': utils.string_to_bool(
            fields.pop('protected', 'False')),
        'min_disk': fields.pop('min_disk', 0),
        'min_ram': fields.pop('min_ram', 0),
    }

    #NOTE(bcwaldon): Use certain properties only if they are explicitly set
    optional = ['id', 'name', 'disk_format', 'container_format', 'copy_from']
    for field in optional:
        if field in fields:
            image_meta[field] = fields.pop(field)

    # Strip any args that are not supported
    unsupported_fields = ['status', 'size']
    for field in unsupported_fields:
Exemplo n.º 10
0

@utils.arg('--silent-upload',
           action="store_true",
           help="DEPRECATED! Animations are always off.")
@utils.arg('fields', default=[], nargs='*', help=argparse.SUPPRESS)
def do_add(gc, args):
    """DEPRECATED! Use image-create instead."""
    try:
        fields = get_image_fields_from_args(args.fields)
    except RuntimeError, e:
        print e
        return FAILURE

    image_meta = {
        'is_public': utils.string_to_bool(fields.pop('is_public', 'False')),
        'protected': utils.string_to_bool(fields.pop('protected', 'False')),
        'min_disk': fields.pop('min_disk', 0),
        'min_ram': fields.pop('min_ram', 0),
    }

    #NOTE(bcwaldon): Use certain properties only if they are explicitly set
    optional = ['id', 'name', 'disk_format', 'container_format', 'copy_from']
    for field in optional:
        if field in fields:
            image_meta[field] = fields.pop(field)

    # Strip any args that are not supported
    unsupported_fields = ['status', 'size']
    for field in unsupported_fields:
        if field in fields.keys():
Exemplo n.º 11
0
def do_add(gc, args):
    """DEPRECATED! Use image-create instead."""
    try:
        fields = get_image_fields_from_args(args.fields)
    except RuntimeError as e:
        print e
        return FAILURE

    image_meta = {
        'is_public': utils.string_to_bool(
            fields.pop('is_public', 'False')),
        'protected': utils.string_to_bool(
            fields.pop('protected', 'False')),
        'min_disk': fields.pop('min_disk', 0),
        'min_ram': fields.pop('min_ram', 0),
    }

    #NOTE(bcwaldon): Use certain properties only if they are explicitly set
    optional = ['id', 'name', 'disk_format', 'container_format']
    for field in optional:
        if field in fields:
            image_meta[field] = fields.pop(field)

    # Strip any args that are not supported
    unsupported_fields = ['status', 'size']
    for field in unsupported_fields:
        if field in fields.keys():
            print 'Found non-settable field %s. Removing.' % field
            fields.pop(field)

    # We need either a location or image data/stream to add...
    image_data = None
    if 'location' in fields.keys():
        image_meta['location'] = fields.pop('location')
        if 'checksum' in fields.keys():
            image_meta['checksum'] = fields.pop('checksum')
    elif 'copy_from' in fields.keys():
        image_meta['copy_from'] = fields.pop('copy_from')
    else:
        # Grab the image data stream from stdin or redirect,
        # otherwise error out
        image_data = sys.stdin

    image_meta['data'] = image_data

    # allow owner to be set when image is created
    if 'owner' in fields.keys():
        image_meta['owner'] = fields.pop('owner')

    # Add custom attributes, which are all the arguments remaining
    image_meta['properties'] = fields

    if not args.dry_run:
        image = gc.images.create(**image_meta)
        print "Added new image with ID: %s" % image.id
        if args.verbose:
            print "Returned the following metadata for the new image:"
            for k, v in sorted(image.to_dict().items()):
                print " %(k)30s => %(v)s" % locals()
    else:
        print "Dry run. We would have done the following:"

        def _dump(dict):
            for k, v in sorted(dict.items()):
                print " %(k)30s => %(v)s" % locals()

        print "Add new image with metadata:"
        _dump(image_meta)

    return SUCCESS
Exemplo n.º 12
0
def do_add(gc, args):
    """DEPRECATED! Use image-create instead."""
    try:
        fields = get_image_fields_from_args(args.fields)
    except RuntimeError as e:
        print e
        return FAILURE

    image_meta = {
        'is_public': utils.string_to_bool(fields.pop('is_public', 'False')),
        'protected': utils.string_to_bool(fields.pop('protected', 'False')),
        'min_disk': fields.pop('min_disk', 0),
        'min_ram': fields.pop('min_ram', 0),
    }

    #NOTE(bcwaldon): Use certain properties only if they are explicitly set
    optional = ['id', 'name', 'disk_format', 'container_format']
    for field in optional:
        if field in fields:
            image_meta[field] = fields.pop(field)

    # Strip any args that are not supported
    unsupported_fields = ['status', 'size']
    for field in unsupported_fields:
        if field in fields.keys():
            print 'Found non-settable field %s. Removing.' % field
            fields.pop(field)

    # We need either a location or image data/stream to add...
    image_data = None
    if 'location' in fields.keys():
        image_meta['location'] = fields.pop('location')
        if 'checksum' in fields.keys():
            image_meta['checksum'] = fields.pop('checksum')
    elif 'copy_from' in fields.keys():
        image_meta['copy_from'] = fields.pop('copy_from')
    else:
        # Grab the image data stream from stdin or redirect,
        # otherwise error out
        image_data = sys.stdin

    image_meta['data'] = image_data

    # allow owner to be set when image is created
    if 'owner' in fields.keys():
        image_meta['owner'] = fields.pop('owner')

    # Add custom attributes, which are all the arguments remaining
    image_meta['properties'] = fields

    if not args.dry_run:
        image = gc.images.create(**image_meta)
        print "Added new image with ID: %s" % image.id
        if args.verbose:
            print "Returned the following metadata for the new image:"
            for k, v in sorted(image.to_dict().items()):
                print " %(k)30s => %(v)s" % locals()
    else:
        print "Dry run. We would have done the following:"

        def _dump(dict):
            for k, v in sorted(dict.items()):
                print " %(k)30s => %(v)s" % locals()

        print "Add new image with metadata:"
        _dump(image_meta)

    return SUCCESS