def do_image_create(gc, args):
    """Create a new image."""
    schema = gc.schemas.get("image")
    _args = [(x[0].replace('-', '_'), x[1]) for x in vars(args).items()]
    fields = dict(filter(lambda x: x[1] is not None and
                         (x[0] == 'property' or
                          schema.is_core_property(x[0])),
                         _args))

    raw_properties = fields.pop('property', [])
    for datum in raw_properties:
        key, value = datum.split('=', 1)
        fields[key] = value

    file_name = fields.pop('file', None)
    if file_name is not None and os.access(file_name, os.R_OK) is False:
        utils.exit("File %s does not exist or user does not have read "
                   "privileges to it" % file_name)
    image = gc.images.create(**fields)
    try:
        if utils.get_data_file(args) is not None:
            args.id = image['id']
            args.size = None
            do_image_upload(gc, args)
            image = gc.images.get(args.id)
    finally:
        utils.print_image(image)
Example #2
0
def do_image_create(gc, args):
    """Create a new image."""
    schema = gc.schemas.get("image")
    _args = [(x[0].replace('-', '_'), x[1]) for x in vars(args).items()]
    fields = dict(filter(lambda x: x[1] is not None and
                         (x[0] == 'property' or
                          schema.is_core_property(x[0])),
                         _args))

    raw_properties = fields.pop('property', [])
    for datum in raw_properties:
        key, value = datum.split('=', 1)
        fields[key] = value

    file_name = fields.pop('file', None)
    if file_name is not None and os.access(file_name, os.R_OK) is False:
        utils.exit("File %s does not exist or user does not have read "
                   "privileges to it" % file_name)
    image = gc.images.create(**fields)
    try:
        if utils.get_data_file(args) is not None:
            args.id = image['id']
            args.size = None
            do_image_upload(gc, args)
            image = gc.images.get(args.id)
    finally:
        utils.print_image(image)
def do_image_create_via_import(gc, args):
    """EXPERIMENTAL: Create a new image via image import."""
    schema = gc.schemas.get("image")
    _args = [(x[0].replace('-', '_'), x[1]) for x in vars(args).items()]
    fields = dict(
        filter(
            lambda x: x[1] is not None and
            (x[0] == 'property' or schema.is_core_property(x[0])), _args))

    raw_properties = fields.pop('property', [])
    for datum in raw_properties:
        key, value = datum.split('=', 1)
        fields[key] = value

    file_name = fields.pop('file', None)
    if file_name is not None and os.access(file_name, os.R_OK) is False:
        utils.exit("File %s does not exist or user does not have read "
                   "privileges to it" % file_name)
    import_methods = gc.images.get_import_info().get('import-methods')
    if file_name and (not import_methods
                      or 'glance-direct' not in import_methods.get('value')):
        utils.exit("No suitable import method available for direct upload, "
                   "please use image-create instead.")
    image = gc.images.create(**fields)
    try:
        if utils.get_data_file(args) is not None:
            args.id = image['id']
            args.size = None
            do_image_stage(gc, args)
            args.from_create = True
            do_image_import(gc, args)
            image = gc.images.get(args.id)
    finally:
        utils.print_image(image)
def do_image_import(gc, args):
    """Initiate the image import taskflow."""
    try:
        gc.images.image_import(args.id, args.import_method)
    except exc.HTTPNotFound:
        utils.exit('Target Glance does not support Image Import workflow')
    else:
        if not getattr(args, 'from_create', False):
            image = gc.images.get(args.id)
            utils.print_image(image)
Example #5
0
def do_image_create(gc, args):
    """Create a new image."""
    schema = gc.schemas.get("image")
    _args = [(x[0].replace('-', '_'), x[1]) for x in vars(args).items()]
    fields = dict(
        filter(
            lambda x: x[1] is not None and
            (x[0] == 'property' or schema.is_core_property(x[0])), _args))

    raw_properties = fields.pop('property', [])
    for datum in raw_properties:
        key, value = datum.split('=', 1)
        fields[key] = value

    image = gc.images.create(**fields)
    utils.print_image(image)
Example #6
0
def do_image_create(gc, args):
    """Create a new image."""
    schema = gc.schemas.get("image")
    _args = [(x[0].replace('-', '_'), x[1]) for x in vars(args).items()]
    fields = dict(filter(lambda x: x[1] is not None and
                         (x[0] == 'property' or
                          schema.is_core_property(x[0])),
                         _args))

    raw_properties = fields.pop('property', [])
    for datum in raw_properties:
        key, value = datum.split('=', 1)
        fields[key] = value

    image = gc.images.create(**fields)
    utils.print_image(image)
    def test_print_image_virtual_size_not_available(self):
        image = {'id': '42', 'virtual_size': None}
        saved_stdout = sys.stdout
        try:
            sys.stdout = output_list = six.StringIO()
            utils.print_image(image)
        finally:
            sys.stdout = saved_stdout

        self.assertEqual(
            '''\
+--------------+---------------+
| Property     | Value         |
+--------------+---------------+
| id           | 42            |
| virtual_size | Not available |
+--------------+---------------+
''', output_list.getvalue())
    def test_print_image_virtual_size_not_available(self):
        image = {'id': '42', 'virtual_size': None}
        saved_stdout = sys.stdout
        try:
            sys.stdout = output_list = six.StringIO()
            utils.print_image(image)
        finally:
            sys.stdout = saved_stdout

        self.assertEqual('''\
+--------------+---------------+
| Property     | Value         |
+--------------+---------------+
| id           | 42            |
| virtual_size | Not available |
+--------------+---------------+
''',
                         output_list.getvalue())
def do_image_update(gc, args):
    """Update an existing image."""
    schema = gc.schemas.get("image")
    _args = [(x[0].replace('-', '_'), x[1]) for x in vars(args).items()]
    fields = dict(filter(lambda x: x[1] is not None and
                         (x[0] in ['property', 'remove_property'] or
                          schema.is_core_property(x[0])),
                         _args))

    raw_properties = fields.pop('property', [])
    for datum in raw_properties:
        key, value = datum.split('=', 1)
        fields[key] = value

    remove_properties = fields.pop('remove_property', None)

    image_id = fields.pop('id')
    image = gc.images.update(image_id, remove_properties, **fields)
    utils.print_image(image)
Example #10
0
def do_image_update(gc, args):
    """Update an existing image."""
    schema = gc.schemas.get("image")
    _args = [(x[0].replace('-', '_'), x[1]) for x in vars(args).items()]
    fields = dict(filter(lambda x: x[1] is not None and
                         (x[0] in ['property', 'remove_property'] or
                          schema.is_core_property(x[0])),
                         _args))

    raw_properties = fields.pop('property', [])
    for datum in raw_properties:
        key, value = datum.split('=', 1)
        fields[key] = value

    remove_properties = fields.pop('remove_property', None)

    image_id = fields.pop('id')
    image = gc.images.update(image_id, remove_properties, **fields)
    utils.print_image(image)
def do_image_create(gc, args):
    """Create a new image."""
    schema = gc.schemas.get("image")
    _args = [(x[0].replace('-', '_'), x[1]) for x in vars(args).items()]
    fields = dict(
        filter(
            lambda x: x[1] is not None and
            (x[0] == 'property' or x[0] == 'cache_raw' or x[0] == 'wait' or
             schema.is_core_property(x[0])), _args))

    raw_properties = fields.pop('property', [])
    cache_raw = fields.pop('cache_raw', False)
    cache_raw_wait = fields.pop('wait', None)

    if cache_raw is not False:
        raw_properties += ['cache_raw=True']
    for datum in raw_properties:
        key, value = datum.split('=', 1)
        fields[key] = value

    file_name = fields.pop('file', None)
    if file_name is not None and os.access(file_name, os.R_OK) is False:
        utils.exit("File %s does not exist or user does not have read "
                   "privileges to it" % file_name)
    image = gc.images.create(**fields)
    try:
        image_data = utils.get_data_file(args)
        if image_data is not None:
            args.id = image['id']
            args.size = utils.get_file_size(image_data)
            do_image_upload(gc, args)
            # If cache_raw and wait options were chosen, wait until
            # image is cached.
            if cache_raw is not False and cache_raw_wait is not None:
                utils.wait_for_caching(cache_raw_wait, gc, args.id)
            image = gc.images.get(args.id)
    finally:
        utils.print_image(image)
Example #12
0
def do_image_show(gc, args):
    """Describe a specific image."""
    image = gc.images.get(args.id)
    utils.print_image(image, args.human_readable, int(args.max_column_width))
Example #13
0
def do_image_show(gc, args):
    """Describe a specific image."""
    image = gc.images.get(args.id)
    utils.print_image(image, int(args.max_column_width))