def delete(self, request, vimid="", tenantid="", subnetid=""): logger.debug("Subnets--delete::> %s" % request.data) try: # prepare request resource to vim instance req_resouce = "v2.0/subnets" if subnetid: req_resouce += "/%s" % subnetid query = VimDriverUtils.get_query_part(request) if query: req_resouce += "?%s" % query vim = VimDriverUtils.get_vim_info(vimid) sess = VimDriverUtils.get_session(vim, tenantid) resp = sess.delete(req_resouce, endpoint_filter=self.service) return Response(status=resp.status_code) except VimDriverKiloException as e: return Response(data={'error': e.content}, status=e.status_code) except HttpError as e: logger.error("HttpError: status:%s, response:%s" % (e.http_status, e.response.json())) return Response(data=e.response.json(), status=e.http_status) except Exception as e: logger.error(traceback.format_exc()) return Response(data={'error': str(e)}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) pass
def get(self, request, vimid="", tenantid="", subnetid=""): logger.debug("Subnets--get::> %s" % request.data) try: # prepare request resource to vim instance query = VimDriverUtils.get_query_part(request) content, status_code = self.get_subnets(query, vimid, tenantid, subnetid) return Response(data=content, status=status_code) except VimDriverKiloException as e: return Response(data={'error': e.content}, status=e.status_code) except HttpError as e: logger.error("HttpError: status:%s, response:%s" % (e.http_status, e.response.json())) return Response(data=e.response.json(), status=e.http_status) except Exception as e: logger.error(traceback.format_exc()) return Response(data={'error': str(e)}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
def get(self, request, vimid=""): logger.debug("Tenants--get::> %s" % request.data) try: #prepare request resource to vim instance query = VimDriverUtils.get_query_part(request) vim = VimDriverUtils.get_vim_info(vimid) if '/v2' in vim["url"]: req_resouce = "/v2.0/tenants" elif '/v3' in vim["url"]: req_resouce = "/projects" else: req_resouce = "/projects" sess = VimDriverUtils.get_session(vim) resp = sess.get(req_resouce, endpoint_filter=self.service) content = resp.json() vim_dict = { "vimName": vim["name"], "vimId": vim["vimId"], } content.update(vim_dict) VimDriverUtils.replace_key_by_mapping(content, self.keys_mapping) if query: _, tenantname = query.split('=') if tenantname: tmp = content["tenants"] content["tenants"] = [] # convert the key naming in hosts for tenant in tmp: if tenantname == tenant['name']: content["tenants"].append(tenant) return Response(data=content, status=resp.status_code) except VimDriverNewtonException as e: return Response(data={'error': e.content}, status=e.status_code) except HttpError as e: logger.error("HttpError: status:%s, response:%s" % (e.http_status, e.response.json())) return Response(data=e.response.json(), status=e.http_status) except Exception as e: logger.error(traceback.format_exc()) return Response(data={'error': str(e)}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
def get_flavor(self, sess, request, flavorid=""): logger.debug("Flavors--get basic") if not sess: return {} else: # prepare request resource to vim instance req_resouce = "/flavors" if flavorid: req_resouce += "/%s" % flavorid else: req_resouce += "/detail" query = VimDriverUtils.get_query_part(request) if query: req_resouce += "?%s" % query resp = sess.get(req_resouce, endpoint_filter=self.service) return resp pass
def get(self, request, vimid="", tenantid="", flavorid=""): logger.debug("Flavors--get::> %s" % request.data) try: # prepare request resource to vim instance query = VimDriverUtils.get_query_part(request) vim = VimDriverUtils.get_vim_info(vimid) sess = VimDriverUtils.get_session(vim, tenantid) resp = self.get_flavor(sess, request, flavorid) content = resp.json() if flavorid: flavor = content.pop("flavor", None) extraResp = self.get_flavor_extra_specs(sess, flavor["id"]) extraContent = extraResp.json() if extraContent["extra_specs"]: extraSpecs = [] self.convertExtraSpecs(extraSpecs, extraContent["extra_specs"], True) flavor["extraSpecs"] = extraSpecs VimDriverUtils.replace_key_by_mapping(flavor, self.keys_mapping) content.update(flavor) else: wanted = None #check if query contains name="flavorname" if query: for queryone in query.split('&'): k, v = queryone.split('=') if k == "name": wanted = v break pass if wanted: oldFlavors = content.pop("flavors", None) content["flavors"] = [] for flavor in oldFlavors: if wanted == flavor["name"]: content["flavors"].append(flavor) pass #iterate each flavor to get extra_specs for flavor in content["flavors"]: extraResp = self.get_flavor_extra_specs(sess, flavor["id"]) extraContent = extraResp.json() if extraContent["extra_specs"]: extraSpecs = [] self.convertExtraSpecs(extraSpecs, extraContent["extra_specs"], True) flavor["extraSpecs"] = extraSpecs VimDriverUtils.replace_key_by_mapping( flavor, self.keys_mapping) #add extra keys vim_dict = { "vimName": vim["name"], "vimId": vim["vimId"], "tenantId": tenantid, } content.update(vim_dict) return Response(data=content, status=resp.status_code) except VimDriverKiloException as e: return Response(data={'error': e.content}, status=e.status_code) except HttpError as e: logger.error("HttpError: status:%s, response:%s" % (e.http_status, e.response.json())) return Response(data=e.response.json(), status=e.http_status) except Exception as e: logger.error(traceback.format_exc()) return Response(data={'error': str(e)}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) pass