X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=src%2Femuvim%2Fapi%2Frest%2Fcompute.py;h=f0c89540ec2d43e23990026f4e58fcb063a320d2;hb=9cc7360bf2c0dacb869d8ed0674d9d9e269a1082;hp=78b49e309ffab5d046b43b1975b6e170567518a1;hpb=a9dd901a96789fea8b1f4dd6a11b6fdcc01da830;p=osm%2Fvim-emu.git diff --git a/src/emuvim/api/rest/compute.py b/src/emuvim/api/rest/compute.py index 78b49e3..f0c8954 100755 --- a/src/emuvim/api/rest/compute.py +++ b/src/emuvim/api/rest/compute.py @@ -48,8 +48,13 @@ class Compute(Resource): """ global dcs - def put(self, dc_label, compute_name): + def put(self, dc_label, compute_name, resource=None, value=None): + # check if resource update + if resource and value: + c = self._update_resource(dc_label, compute_name, resource, value) + return c.getStatus(), 200 + # deploy new container # check if json data is a dict data = request.json if data is None: @@ -72,6 +77,20 @@ class Compute(Resource): logging.exception("API error.") return ex.message, 500 + def _update_resource(self, dc_label, compute_name, resource, value): + #check if container exists + d = dcs.get(dc_label).net.getNodeByName(compute_name) + if resource == 'cpu': + cpu_period = int(dcs.get(dc_label).net.cpu_period) + cpu_quota = int(cpu_period * float(value)) + #put default values back + if float(value) <= 0: + cpu_period = 100000 + cpu_quota = -1 + d.updateCpuLimit(cpu_period=cpu_period, cpu_quota=cpu_quota) + return d + + def get(self, dc_label, compute_name): logging.debug("API CALL: compute status") @@ -113,10 +132,10 @@ class Compute(Resource): class ComputeList(Resource): global dcs - def get(self, dc_label): + def get(self, dc_label=None): logging.debug("API CALL: compute list") try: - if dc_label == 'None': + if dc_label is None or dc_label == 'None': # return list with all compute nodes in all DCs all_containers = [] for dc in dcs.itervalues():