Skip to content

Commit

Permalink
Support image name in CAPI (#219)
Browse files Browse the repository at this point in the history
* Support image name in CAPI openstackMachine

* Fix test errors

* Update unit test

---------

Co-authored-by: Mohammed Naser <[email protected]>
  • Loading branch information
okozachenko1203 and mnaser committed Oct 2, 2023
1 parent 5023a32 commit 963ce70
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
7 changes: 5 additions & 2 deletions magnum_cluster_api/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -1719,7 +1719,7 @@ def generate_machine_deployments_for_cluster(
},
{
"name": "imageUUID",
"value": ng.image_id,
"value": utils.get_image_uuid(ng.image_id, context),
},
],
},
Expand Down Expand Up @@ -1960,7 +1960,10 @@ def get_object(self) -> objects.Cluster:
},
{
"name": "imageUUID",
"value": self.cluster.default_ng_master.image_id,
"value": utils.get_image_uuid(
self.cluster.default_ng_master.image_id,
self.context,
),
},
{
"name": "nodeCidr",
Expand Down
3 changes: 3 additions & 0 deletions magnum_cluster_api/tests/unit/test_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ def test_generate_machine_deployments_for_cluster_with_deleting_node_group(
)
mock_get_default_boot_volume_type.return_value = "foo"

mock_get_image_uuid = mocker.patch("magnum_cluster_api.utils.get_image_uuid")
mock_get_image_uuid.return_value = "foo"

mds = resources.generate_machine_deployments_for_cluster(
context,
cluster,
Expand Down
11 changes: 11 additions & 0 deletions magnum_cluster_api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import shortuuid
import yaml
from magnum import objects as magnum_objects
from magnum.api import attr_validator
from magnum.common import context, exception, octavia
from magnum.common import utils as magnum_utils
from oslo_serialization import base64
Expand Down Expand Up @@ -326,3 +327,13 @@ def get_operating_system(cluster: magnum_objects.Cluster):
if cluster_distro.startswith(ops):
return ops
return None


def get_image_uuid(image_ref: str, ctx: context.RequestContext):
"""Get image uuid from image ref
:param image_ref: Image id or name
"""
osc = clients.get_openstack_api(ctx)
image_obj = attr_validator.validate_image(osc, image_ref)
return image_obj.get("id")

0 comments on commit 963ce70

Please sign in to comment.