Skip to content

Commit

Permalink
Merge pull request #1450 from grycap/vmimage_by_name
Browse files Browse the repository at this point in the history
Implements #1449
  • Loading branch information
micafer authored Jan 10, 2023
2 parents 9fa4bc2 + 66b9a73 commit 350b3d0
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 16 deletions.
34 changes: 26 additions & 8 deletions IM/InfrastructureManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
from IM.VirtualMachine import VirtualMachine

from radl import radl_parse
from radl.radl import Feature, RADL
from radl.radl import Feature, RADL, system
from radl.radl_json import dump_radl as dump_radl_json

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

return concrete_system, score

@staticmethod
def search_vm(inf, radl_sys, auth):
# If an images is already set do not search
if radl_sys.getValue("disk.0.image.url"):
return []

dist = radl_sys.getValue('disk.0.os.flavour')
version = radl_sys.getValue('disk.0.os.version')
res = []
for c in CloudInfo.get_cloud_list(auth):
cloud_site = c.getCloudConnector(inf)
for image in cloud_site.list_images(auth):
if ((dist is None or dist.lower() in image["name"].lower()) and
(version is None or version.lower() in image["name"].lower())):
new_sys = system(radl_sys.name)
new_sys.setValue("disk.0.image.url", image["uri"])
res.append(new_sys)
break
return res

@staticmethod
def systems_with_iis(sel_inf, radl, auth):
"""
Expand All @@ -412,9 +432,6 @@ def systems_with_iis(sel_inf, radl, auth):
for system_id in set([d.id for d in radl.deploys if d.vm_number > 0]):
s = radl.get_system_by_name(system_id)

if not s.getValue("disk.0.image.url") and len(vmrc_list + appdbis_list) == 0:
raise Exception("No correct VMRC or AppDBIS auth data provided nor image URL")

if Config.SINGLE_SITE:
image_id = os.path.basename(s.getValue("disk.0.image.url"))
url_prefix = Config.SINGLE_SITE_IMAGE_URL_PREFIX
Expand All @@ -436,13 +453,14 @@ def systems_with_iis(sel_inf, radl, auth):

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

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

return systems_with_vmrc
Expand Down
2 changes: 1 addition & 1 deletion IM/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
'InfrastructureInfo', 'InfrastructureManager', 'recipe', 'request', 'REST', 'retry',
'ServiceRequests', 'SSH', 'SSHRetry', 'timedcall', 'UnixHTTPAdapter',
'VirtualMachine', 'VMRC', 'xmlobject']
__version__ = '1.13.0'
__version__ = '1.13.1'
__author__ = 'Miguel Caballer'


Expand Down
6 changes: 6 additions & 0 deletions changelog
Original file line number Diff line number Diff line change
Expand Up @@ -720,3 +720,9 @@ IM 1.13.0:
* Add an admin user.
* Add additional_dns_names field.
* Enable to delete nodes using TOSCA without remove_list.

IM 1.13.1:
* Enable to delete FaaS functions using TOSCA.
* Enable to create public router in openstack.
* Enable to define dependencies in OSCAR conn.
* Search VM Images in sites using name.
2 changes: 1 addition & 1 deletion codemeta.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"@type": "SoftwareSourceCode",
"identifier": "im",
"name": "Infrastructure Manager",
"version": "1.13.0",
"version": "1.13.1",
"description": "IM is a tool that deploys complex and customized virtual infrastructures on IaaS Cloud deployments",
"license": "GNU General Public License v3.0",
"author": [
Expand Down
2 changes: 1 addition & 1 deletion contextualization/conf-ansible.yml
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@
pip:
name:
- pyOpenSSL>20.0,<22.1.0
- cryptography
- cryptography<39.0.0
- wheel
- pyyaml
- paramiko>=2.9.5
Expand Down
3 changes: 2 additions & 1 deletion docker-devel/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Dockerfile to create a container with the IM service
FROM ubuntu:22.04
ARG BRANCH=devel
LABEL maintainer="Miguel Caballer <micafer1@upv.es>"
LABEL version="1.13.0"
LABEL version="1.13.1"
LABEL description="Container image to run the IM service. (http://www.grycap.upv.es/im)"
EXPOSE 8899 8800

Expand Down
4 changes: 2 additions & 2 deletions docker-py3/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Dockerfile to create a container with the IM service
FROM ubuntu:22.04
LABEL maintainer="Miguel Caballer <micafer1@upv.es>"
LABEL version="1.13.0"
LABEL version="1.13.1"
LABEL description="Container image to run the IM service. (http://www.grycap.upv.es/im)"
EXPOSE 8899 8800

Expand All @@ -13,7 +13,7 @@ RUN apt-get update && apt-get install --no-install-recommends -y python3 python3
RUN apt-get update && apt-get install --no-install-recommends -y python3-setuptools python3-pip git && \
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 && \
pip3 install pyOpenSSL cheroot xmltodict pymongo ansible==6.4.0&& \
pip3 install IM==1.13.0 && \
pip3 install IM==1.13.1 && \
apt-get purge -y python3-pip git && \
apt-get autoremove -y && apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* && rm -rf ~/.cache/

Expand Down
4 changes: 2 additions & 2 deletions docker-py3/Dockerfile.alp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Dockerfile to create a container with the IM service
FROM alpine:3.16
LABEL maintainer="Miguel Caballer <micafer1@upv.es>"
LABEL version="1.13.0"
LABEL version="1.13.1"
LABEL description="Container image to run the IM service. (http://www.grycap.upv.es/im)"
EXPOSE 8899 8800

Expand Down Expand Up @@ -34,7 +34,7 @@ RUN pip3 install pyOpenSSL \
RUN pip3 install ansible==6.4.0

RUN apk add --no-cache git &&\
pip3 install IM==1.13.0 &&\
pip3 install IM==1.13.1 &&\
apk del git

# Copy a ansible.cfg with correct minimum values
Expand Down
19 changes: 19 additions & 0 deletions test/unit/test_im_logic.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -1472,6 +1472,25 @@ def test_change_inf_auth(self):
self.assertEqual(str(ex.exception), ("Invalid new infrastructure data provided: No credentials"
" provided for the InfrastructureManager."))

@patch("IM.connectors.Dummy.DummyCloudConnector")
def test_search_vm(self, dummycc):
auth = self.getAuth([0], [], [("Dummy", 0), ("Dummy", 0)])
radl_sys = system("s0", [Feature("disk.0.os.flavour", "=", "Ubuntu"),
Feature("disk.0.os.version", "=", "20.04")])
inf = MagicMock()
dummy = MagicMock(["list_images"])
dummycc.return_value = dummy
dummy.list_images.side_effect = [[{"name": "ubuntu-20.04-raw", "uri": "imageuri"}],
[{"name": "ubuntu-22.04-raw", "uri": "imageuri2"},
{"name": "ubuntu-20.04-raw", "uri": "imageuri3"},
{"name": "ubuntu-20.04-raw", "uri": "imageuri4"}]]
res = IM.search_vm(inf, radl_sys, auth)
self.assertEqual(len(res), 2)
self.assertEqual(res[0].name, "s0")
self.assertEqual(res[0].getValue("disk.0.image.url"), "imageuri")
self.assertEqual(res[1].name, "s0")
self.assertEqual(res[1].getValue("disk.0.image.url"), "imageuri3")

@patch('IM.InfrastructureManager.AppDB')
def test_translate_egi_to_ost(self, appdb):
appdb.get_site_id.return_value = 'site_id'
Expand Down

0 comments on commit 350b3d0

Please sign in to comment.