Skip to content

Commit 350b3d0

Browse files
authored
Merge pull request #1450 from grycap/vmimage_by_name
Implements #1449
2 parents 9fa4bc2 + 66b9a73 commit 350b3d0

9 files changed

Lines changed: 60 additions & 16 deletions

File tree

IM/InfrastructureManager.py

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
from IM.VirtualMachine import VirtualMachine
3737

3838
from radl import radl_parse
39-
from radl.radl import Feature, RADL
39+
from radl.radl import Feature, RADL, system
4040
from radl.radl_json import dump_radl as dump_radl_json
4141

4242
from IM.openid.JWT import JWT
@@ -387,6 +387,26 @@ def _compute_score(system_score, requested_radl):
387387

388388
return concrete_system, score
389389

390+
@staticmethod
391+
def search_vm(inf, radl_sys, auth):
392+
# If an images is already set do not search
393+
if radl_sys.getValue("disk.0.image.url"):
394+
return []
395+
396+
dist = radl_sys.getValue('disk.0.os.flavour')
397+
version = radl_sys.getValue('disk.0.os.version')
398+
res = []
399+
for c in CloudInfo.get_cloud_list(auth):
400+
cloud_site = c.getCloudConnector(inf)
401+
for image in cloud_site.list_images(auth):
402+
if ((dist is None or dist.lower() in image["name"].lower()) and
403+
(version is None or version.lower() in image["name"].lower())):
404+
new_sys = system(radl_sys.name)
405+
new_sys.setValue("disk.0.image.url", image["uri"])
406+
res.append(new_sys)
407+
break
408+
return res
409+
390410
@staticmethod
391411
def systems_with_iis(sel_inf, radl, auth):
392412
"""
@@ -412,9 +432,6 @@ def systems_with_iis(sel_inf, radl, auth):
412432
for system_id in set([d.id for d in radl.deploys if d.vm_number > 0]):
413433
s = radl.get_system_by_name(system_id)
414434

415-
if not s.getValue("disk.0.image.url") and len(vmrc_list + appdbis_list) == 0:
416-
raise Exception("No correct VMRC or AppDBIS auth data provided nor image URL")
417-
418435
if Config.SINGLE_SITE:
419436
image_id = os.path.basename(s.getValue("disk.0.image.url"))
420437
url_prefix = Config.SINGLE_SITE_IMAGE_URL_PREFIX
@@ -436,13 +453,14 @@ def systems_with_iis(sel_inf, radl, auth):
436453

437454
vmrc_res = [s0 for vmrc in vmrc_list for s0 in vmrc.search_vm(s)]
438455
appdbis_res = [s0 for appdbis in appdbis_list for s0 in appdbis.search_vm(s)]
456+
local_res = InfrastructureManager.search_vm(sel_inf, s, auth)
439457
# Check that now the image URL is in the RADL
440-
if not s.getValue("disk.0.image.url") and not vmrc_res and not appdbis_res:
441-
sel_inf.add_cont_msg("No VMI obtained from VMRC nor AppDBIS to system: " + system_id)
442-
raise Exception("No VMI obtained from VMRC nor AppDBIS to system: " + system_id)
458+
if not s.getValue("disk.0.image.url") and not vmrc_res and not appdbis_res and not local_res:
459+
sel_inf.add_cont_msg("No VMI obtained from VMRC nor AppDBIS nor Sites to system: " + system_id)
460+
raise Exception("No VMI obtained from VMRC nor AppDBIS not Sites to system: " + system_id)
443461

444462
n = [s_without_apps.clone().applyFeatures(s0, conflict="other", missing="other")
445-
for s0 in (vmrc_res + appdbis_res)]
463+
for s0 in (vmrc_res + appdbis_res + local_res)]
446464
systems_with_vmrc[system_id] = n if n else [s_without_apps]
447465

448466
return systems_with_vmrc

IM/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
'InfrastructureInfo', 'InfrastructureManager', 'recipe', 'request', 'REST', 'retry',
2020
'ServiceRequests', 'SSH', 'SSHRetry', 'timedcall', 'UnixHTTPAdapter',
2121
'VirtualMachine', 'VMRC', 'xmlobject']
22-
__version__ = '1.13.0'
22+
__version__ = '1.13.1'
2323
__author__ = 'Miguel Caballer'
2424

2525

changelog

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -720,3 +720,9 @@ IM 1.13.0:
720720
* Add an admin user.
721721
* Add additional_dns_names field.
722722
* Enable to delete nodes using TOSCA without remove_list.
723+
724+
IM 1.13.1:
725+
* Enable to delete FaaS functions using TOSCA.
726+
* Enable to create public router in openstack.
727+
* Enable to define dependencies in OSCAR conn.
728+
* Search VM Images in sites using name.

codemeta.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"@type": "SoftwareSourceCode",
77
"identifier": "im",
88
"name": "Infrastructure Manager",
9-
"version": "1.13.0",
9+
"version": "1.13.1",
1010
"description": "IM is a tool that deploys complex and customized virtual infrastructures on IaaS Cloud deployments",
1111
"license": "GNU General Public License v3.0",
1212
"author": [

contextualization/conf-ansible.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@
140140
pip:
141141
name:
142142
- pyOpenSSL>20.0,<22.1.0
143-
- cryptography
143+
- cryptography<39.0.0
144144
- wheel
145145
- pyyaml
146146
- paramiko>=2.9.5

docker-devel/Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# Dockerfile to create a container with the IM service
22
FROM ubuntu:22.04
3+
ARG BRANCH=devel
34
LABEL maintainer="Miguel Caballer <micafer1@upv.es>"
4-
LABEL version="1.13.0"
5+
LABEL version="1.13.1"
56
LABEL description="Container image to run the IM service. (http://www.grycap.upv.es/im)"
67
EXPOSE 8899 8800
78

docker-py3/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Dockerfile to create a container with the IM service
22
FROM ubuntu:22.04
33
LABEL maintainer="Miguel Caballer <micafer1@upv.es>"
4-
LABEL version="1.13.0"
4+
LABEL version="1.13.1"
55
LABEL description="Container image to run the IM service. (http://www.grycap.upv.es/im)"
66
EXPOSE 8899 8800
77

@@ -13,7 +13,7 @@ RUN apt-get update && apt-get install --no-install-recommends -y python3 python3
1313
RUN apt-get update && apt-get install --no-install-recommends -y python3-setuptools python3-pip git && \
1414
pip3 install msrest msrestazure azure-common azure-mgmt-storage azure-mgmt-compute azure-mgmt-network azure-mgmt-resource azure-mgmt-dns azure-identity==1.8.0 && \
1515
pip3 install pyOpenSSL cheroot xmltodict pymongo ansible==6.4.0&& \
16-
pip3 install IM==1.13.0 && \
16+
pip3 install IM==1.13.1 && \
1717
apt-get purge -y python3-pip git && \
1818
apt-get autoremove -y && apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* && rm -rf ~/.cache/
1919

docker-py3/Dockerfile.alp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Dockerfile to create a container with the IM service
22
FROM alpine:3.16
33
LABEL maintainer="Miguel Caballer <micafer1@upv.es>"
4-
LABEL version="1.13.0"
4+
LABEL version="1.13.1"
55
LABEL description="Container image to run the IM service. (http://www.grycap.upv.es/im)"
66
EXPOSE 8899 8800
77

@@ -34,7 +34,7 @@ RUN pip3 install pyOpenSSL \
3434
RUN pip3 install ansible==6.4.0
3535

3636
RUN apk add --no-cache git &&\
37-
pip3 install IM==1.13.0 &&\
37+
pip3 install IM==1.13.1 &&\
3838
apk del git
3939

4040
# Copy a ansible.cfg with correct minimum values

test/unit/test_im_logic.py

100755100644
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1472,6 +1472,25 @@ def test_change_inf_auth(self):
14721472
self.assertEqual(str(ex.exception), ("Invalid new infrastructure data provided: No credentials"
14731473
" provided for the InfrastructureManager."))
14741474

1475+
@patch("IM.connectors.Dummy.DummyCloudConnector")
1476+
def test_search_vm(self, dummycc):
1477+
auth = self.getAuth([0], [], [("Dummy", 0), ("Dummy", 0)])
1478+
radl_sys = system("s0", [Feature("disk.0.os.flavour", "=", "Ubuntu"),
1479+
Feature("disk.0.os.version", "=", "20.04")])
1480+
inf = MagicMock()
1481+
dummy = MagicMock(["list_images"])
1482+
dummycc.return_value = dummy
1483+
dummy.list_images.side_effect = [[{"name": "ubuntu-20.04-raw", "uri": "imageuri"}],
1484+
[{"name": "ubuntu-22.04-raw", "uri": "imageuri2"},
1485+
{"name": "ubuntu-20.04-raw", "uri": "imageuri3"},
1486+
{"name": "ubuntu-20.04-raw", "uri": "imageuri4"}]]
1487+
res = IM.search_vm(inf, radl_sys, auth)
1488+
self.assertEqual(len(res), 2)
1489+
self.assertEqual(res[0].name, "s0")
1490+
self.assertEqual(res[0].getValue("disk.0.image.url"), "imageuri")
1491+
self.assertEqual(res[1].name, "s0")
1492+
self.assertEqual(res[1].getValue("disk.0.image.url"), "imageuri3")
1493+
14751494
@patch('IM.InfrastructureManager.AppDB')
14761495
def test_translate_egi_to_ost(self, appdb):
14771496
appdb.get_site_id.return_value = 'site_id'

0 commit comments

Comments
 (0)