diff --git a/app/__init__.py b/app/__init__.py index 76f71acb8..949d47826 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -44,7 +44,7 @@ from functools import wraps from urllib.parse import urlparse from radl import radl_parse -from radl.radl import deploy, description +from radl.radl import deploy, description, Feature from flask_apscheduler import APScheduler from flask_wtf.csrf import CSRFProtect, CSRFError from toscaparser.tosca_template import ToscaTemplate @@ -394,11 +394,20 @@ def managevm(op=None, infid=None, vmid=None): form_data = request.form.to_dict() cpu = int(form_data['cpu']) memory = int(form_data['memory']) - system_name = form_data['system_name'] - radl = "system %s (cpu.count >= %d and memory.size >= %dg and instance_type = '')" % (system_name, - cpu, memory) - response = im.resize_vm(infid, vmid, radl, auth_data) + vminforesp = im.get_vm_info(infid, vmid, auth_data, "text/plain") + if vminforesp.ok: + vminfo = radl_parse.parse_radl(vminforesp.text) + vminfo.systems[0].delValue("instance_type") + vminfo.systems[0].delValue("cpu.count") + vminfo.systems[0].addFeature(Feature("cpu.count", ">=", cpu), + conflict="other", missing="other") + vminfo.systems[0].delValue("memory.size") + vminfo.systems[0].addFeature(Feature("memory.size", ">=", memory, "GB"), + conflict="other", missing="other") + response = im.resize_vm(infid, vmid, str(vminfo), auth_data) + else: + raise Exception("Error getting VM info: %s" % vminforesp.text) else: response = im.manage_vm(op, infid, vmid, auth_data) except Exception as ex: diff --git a/app/im.py b/app/im.py index 2f2e4fc96..1ae534eaf 100644 --- a/app/im.py +++ b/app/im.py @@ -64,8 +64,8 @@ def get_inf_state(self, infid, auth_data): inf_state = response.json() return inf_state['state'] - def get_vm_info(self, infid, vmid, auth_data): - headers = {"Authorization": auth_data, "Accept": "application/json"} + def get_vm_info(self, infid, vmid, auth_data, accept="application/json"): + headers = {"Authorization": auth_data, "Accept": accept} url = "%s/infrastructures/%s/vms/%s" % (self.im_url, infid, vmid) return requests.get(url, headers=headers, timeout=self.timeout) diff --git a/app/templates/vminfo.html b/app/templates/vminfo.html index 90d8c9b50..e2bfb33a2 100644 --- a/app/templates/vminfo.html +++ b/app/templates/vminfo.html @@ -318,7 +318,6 @@