- # Fix here unless we have plugin registry
- json_file = os.path.join(os.path.dirname(__file__),
- '../pub/config/provider-plugin.json')
- with open(json_file, "r") as f:
- plugins = json.load(f)
- data = {"vim_types": plugins}
- return Response(data=data, status=status.HTTP_200_OK)
+ return Response(data=syscomm.getVIMTypes(), status=status.HTTP_200_OK)
+
+
+class CheckCapacity(BaseServer):
+
+ def post(self, request):
+ try:
+ body = json.loads(request.body)
+ except ValueError as e:
+ return Response(
+ data={'error': 'Invalidate request body %s.' % e},
+ status=status.HTTP_400_BAD_REQUEST)
+
+ ret = {"VIMs": []}
+ newbody = {
+ "vCPU": body.get("vCPU", 0),
+ "Memory": body.get("Memory", 0),
+ "Storage": body.get("Storage", 0)
+ }
+ for vim in body.get("VIMs", []):
+ url = request.get_full_path().replace(
+ "check_vim_capacity", "%s/capacity_check" % vim)
+ resp = self.send(vim, url, json.dumps(newbody), "POST")
+ if int(resp.status_code) != status.HTTP_200_OK:
+ continue
+ try:
+ resp_body = json.loads(resp.content)
+ except ValueError:
+ continue
+ if not resp_body.get("result", False):
+ continue
+ ret['VIMs'].append(vim)
+ return Response(data=ret, status=status.HTTP_200_OK)