Skip to content

[DOCS] salt-cloud and register_image function #60679

Closed as not planned
Closed as not planned

Description

@vladaurosh

Description
Hello. I am relatively new to saltstack and salt-cloud.
I am trying to use salt-cloud function register_image
https://docs.saltproject.io/en/latest/ref/clouds/all/salt.cloud.clouds.ec2.html#salt.cloud.clouds.ec2.register_image

Current documentation has one CLI example but you can't see what parameters can be passed to this function.

While CLI example works fine, it creates AMI with one block device. So I was trying to create AMI with 2 block devices, and that option is not documented. But it exists. I've looked into source code (ec2.py) and there's argument block_device_mapping.
Now, I do not know what to pass as block_device_mapping.

I've played around a bit and added this line:
block_device_mapping = {'DeviceName': '/dev/xvda','Ebs': {'SnapshotId': 'snap-111111111','VolumeType': 'gp2'}}, {'DeviceName': '/dev/sdb','Ebs': {'SnapshotId': 'snap-222222222','VolumeType': 'gp2'}}
just before
params.update(_param_from_config('BlockDeviceMapping', block_device_mapping))

And with this I was able to create AMI with 2 block devices.

Now, the issue here is that I can't pass this in CLI:
salt-cloud -f register_image my-ec2-config ami_name=new_AMI description="new ami" architecture=x86_64 root_device_name=/dev/xvda block_device_mapping={'DeviceName': '/dev/xvda','Ebs': {'SnapshotId': 'snap-111111111','VolumeType': 'gp2'}}, {'DeviceName': '/dev/sdb','Ebs': {'SnapshotId': 'snap-222222222','VolumeType': 'gp2'}}

I've tried with double/single quotes but thad didn't work as python didn't interpret this correctly.

Does anybody know why to pass block_device_mapping to salt-cloud -f register_image ?

Suggested Fix
List of parameters that can be passed to function with examples how to use them.

Type of documentation

  • Salt documentation
  • Salt modules
  • Man pages (which get autogenerated from the docs, such as salt.1 and salt.7)

Location or format of documentation
https://docs.saltproject.io/en/latest/ref/clouds/all/salt.cloud.clouds.ec2.html#salt.cloud.clouds.ec2.register_image

Additional context
Add any other context or screenshots about the feature request here.

Activity

  1. added
    documentation
    on Aug 5, 2021
  2. welcome commented on Aug 5, 2021

    @welcome

    Hi there! Welcome to the Salt Community! Thank you for making your first contribution. We have a lengthy process for issues and PRs. Someone from the Core Team will follow up as soon as possible. In the meantime, here’s some information that may help as you continue your Salt journey.
    Please be sure to review our Code of Conduct. Also, check out some of our community resources including:

    There are lots of ways to get involved in our community. Every month, there are around a dozen opportunities to meet with other contributors and the Salt Core team and collaborate in real time. The best way to keep track is by subscribing to the Salt Community Events Calendar.
    If you have additional questions, email us at [email protected]. We’re glad you’ve joined our community and look forward to doing awesome things with you!

  3. bryceml commented on Aug 10, 2021

    @bryceml
    Contributor

    salt/salt/cloud/clouds/ec2.py

    Lines 4074 to 4154 in 76e5088

    def register_image(kwargs=None, call=None):
    """
    Create an ami from a snapshot
    CLI Example:
    .. code-block:: bash
    salt-cloud -f register_image my-ec2-config ami_name=my_ami description="my description"
    root_device_name=/dev/xvda snapshot_id=snap-xxxxxxxx
    """
    if call != "function":
    log.error("The create_volume function must be called with -f or --function.")
    return False
    if "ami_name" not in kwargs:
    log.error("ami_name must be specified to register an image.")
    return False
    block_device_mapping = kwargs.get("block_device_mapping", None)
    if not block_device_mapping:
    if "snapshot_id" not in kwargs:
    log.error(
    "snapshot_id or block_device_mapping must be specified to register an"
    " image."
    )
    return False
    if "root_device_name" not in kwargs:
    log.error(
    "root_device_name or block_device_mapping must be specified to register"
    " an image."
    )
    return False
    block_device_mapping = [
    {
    "DeviceName": kwargs["root_device_name"],
    "Ebs": {
    "VolumeType": kwargs.get("volume_type", "gp2"),
    "SnapshotId": kwargs["snapshot_id"],
    },
    }
    ]
    if not isinstance(block_device_mapping, list):
    block_device_mapping = [block_device_mapping]
    params = {"Action": "RegisterImage", "Name": kwargs["ami_name"]}
    params.update(_param_from_config("BlockDeviceMapping", block_device_mapping))
    if "root_device_name" in kwargs:
    params["RootDeviceName"] = kwargs["root_device_name"]
    if "description" in kwargs:
    params["Description"] = kwargs["description"]
    if "virtualization_type" in kwargs:
    params["VirtualizationType"] = kwargs["virtualization_type"]
    if "architecture" in kwargs:
    params["Architecture"] = kwargs["architecture"]
    log.debug(params)
    data = aws.query(
    params,
    return_url=True,
    return_root=True,
    location=get_location(),
    provider=get_provider(),
    opts=__opts__,
    sigver="4",
    )
    r_data = {}
    for d in data[0]:
    for k, v in d.items():
    r_data[k] = v
    return r_data

    is the code. You are right, the documentation is poor there.

    looks like you might be missing the []'s around block_device_mappings on the cli. Let me know if that fixes it.

    something like

    salt-cloud -f register_image my-ec2-config ami_name=new_AMI description="new ami" architecture=x86_64 root_device_name=/dev/xvda "block_device_mapping=[{'DeviceName': '/dev/xvda','Ebs': {'SnapshotId': 'snap-111111111','VolumeType': 'gp2'}}, {'DeviceName': '/dev/sdb','Ebs': {'SnapshotId': 'snap-222222222','VolumeType': 'gp2'}}]"
  4. garethgreenaway commented on Aug 24, 2021

    @garethgreenaway
    Contributor

    @vladaurosh Following up on this one, did the solution mentioned above resolve the issue for you? Thanks!

  5. vladaurosh commented on Aug 25, 2021

    @vladaurosh
    Author

    Hello @bryceml @garethgreenaway

    Sorry for late reply.

    I've tried what bryceml suggested but it didn't work:
    [ERROR ] AWS Response Status Code and Error: [400 400 Client Error: Bad Request for url: https://ec2.eu-west-1.amazonaws.com/?Action=RegisterImage&Architecture=x86_64....]
    {'Errors': {'Error': {'Code': 'InvalidRequest', 'Message': 'The request received was invalid.'}}, 'RequestID': '...........'}
    [ERROR ] There was an error running the function: 'str' object has no attribute 'items'

  6. added
    severity-medium
    and removed on Feb 28, 2022
  7. added this to the Sulphur v3006.26 milestone on Jun 25, 2026
  8. dwoz commented on Oct 15, 2026

    @dwoz
    Contributor

    Thanks for the original report. This issue has been open for more than three years without recent activity and carries a severity label below severity-high. As part of a backlog cleanup, we're closing older low- and medium-severity issues so triage can focus on reports against currently supported releases.

    Closing isn't a judgement that the problem wasn't real — only that the codebase has moved through several releases since this was filed, and much of the surrounding code has changed.

    If you — or anyone else — can still reproduce this on the 3008.x LTS release, please leave a comment with a reproduction and a maintainer will reopen. The original reporter can also reopen directly.

  9. dwoz commented on Oct 17, 2026

    @dwoz
    Contributor

    Reopening — there is an open PR tracking a fix for this: #69558.

  10. reopened this on Oct 17, 2026
  11. dwoz commented on Oct 28, 2026

    @dwoz
    Contributor

    Closing — consolidated into #70585. The checkbox for this item is in the appropriate theme section of that tracker. Please pick up the sub-item there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationseverity-mediumtime-estimate-sprint

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions