Skip to content

Commit

Permalink
Fix #534
Browse files Browse the repository at this point in the history
  • Loading branch information
micafer committed Apr 23, 2024
1 parent 6196e1f commit 3ffe654
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
19 changes: 14 additions & 5 deletions app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions app/im.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
1 change: 0 additions & 1 deletion app/templates/vminfo.html
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,6 @@ <h5 class="modal-title" id="managevm_resize_label">VM resize</h5>
</div>
<form id="resizeVM" action="{{ url_for('managevm', op='resize', infid=infid, vmid=vmid) }}" method="post">
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}"/>
<input type="hidden" name="system_name" value="{{ system_name }}"/>
<div class="modal-body">

<div class="row form-group">
Expand Down

0 comments on commit 3ffe654

Please sign in to comment.