def show(self, req, id, *args, **kwargs): """get one dns zone info""" # get the context context = req.context try: if kwargs.get('device'): LOG.info(_(" args is %(args)s"), {"args": args}) # from rpc server get the zone in device zones = self.manager.get_zones(context) else: LOG.info(_(" args is %(args)s"), {"args": args}) # from rpc server get the zone in db zones = self.manager.get_zone_db_details(context, id) except Nca47Exception as e: self.response.status = e.code LOG.error(_LE('Error exception! error info: %' + e.message)) LOG.exception(e) return tools.ret_info(e.code, e.message) except RemoteError as exception: self.response.status = 500 message = exception.value return tools.ret_info(self.response.status, message) except Exception as exception: LOG.exception(exception) self.response.status = 500 return tools.ret_info(self.response.status, exception.message) return zones
def show(self, req, id, *args, **kwargs): """get one dns region info""" # get the context context = req.context try: if kwargs.get('device'): LOG.info(_(" args is %(args)s"), {"args": args}) # from rpc server get the region in device regions = self.manager.get_region(context) else: LOG.info(_(" args is %(args)s"), {"args": args}) # from rpc server get the region in db regions = self.manager.get_region_db_detail(context, id) regions_user = self.manager.get_members(context, regions.name) region_users = [] for key in regions_user: region_users.append(dict(key)) regions.region_user = region_users except Nca47Exception as e: self.response.status = e.code LOG.error(_LE('Error exception! error info: %' + e.message)) LOG.exception(e) return tools.ret_info(e.code, e.message) except RemoteError as exception: self.response.status = 500 message = exception.value return tools.ret_info(self.response.status, message) except Exception as exception: LOG.exception(exception) self.response.status = 500 return tools.ret_info(self.response.status, exception.message) return regions
def create(self, req, *args, **kwargs): """create the dns zone_record""" url = req.url try: if len(args) != 1: raise BadRequest(resource="record create", msg=url) list1 = ['name', 'type', 'rdata', "tenant_id"] list2 = ['ttl', 'current_user', "klass"] # get the body dic = json.loads(req.body) # validate the in values of the zone_record dic_body = tool.message_regrouping(dic, list1, list2) context = req.context LOG.info(_("req is %(json)s, args is %(args)s," "kwargs is %(kwargs)s"), {"json": req.body, "args": args, "kwargs": kwargs}) # from rpc server create the zone_record record = self.manager.create_record(context, dic_body, args[0]) except Nca47Exception as e: self.response.status = e.code LOG.error(_LE('Error exception! error info: %' + e.message)) LOG.exception(e) return tool.ret_info(e.code, e.message) except MessagingException as exception: self.response.status = 500 message = exception.value return tool.ret_info(self.response.status, message) except Exception as exception: LOG.exception(exception) self.response.status = 500 message = "the values of the body format error" return tool.ret_info(self.response.status, message) LOG.info(_("Return of create_zone_record JSON is %(record)s !"), {"record": record}) return record
def list(self, req, *args, **kwargs): """get the list of the dns zones""" # get the context context = req.context try: if 'device' in args: LOG.info(_(" args is %(args)s, kwargs is %(kwargs)s"), {"args": args, "kwargs": kwargs}) # from rpc server get the zones in device zones = self.manager.get_zones(context) else: LOG.info(_(" args is %(args)s, kwargs is %(kwargs)s"), {"args": args, "kwargs": kwargs}) # from rpc server get the zones in db zones = self.manager.get_all_db_zone(context) LOG.info(_("Return of get_all_db_zone JSON is %(zones)s !"), {"zones": zones}) except Nca47Exception as e: self.response.status = e.code LOG.error(_LE('Error exception! error info: %' + e.message)) LOG.exception(e) return tools.ret_info(e.code, e.message) except MessagingException as exception: self.response.status = 500 message = exception.value return tools.ret_info(self.response.status, message) LOG.info(_("Return of get_zones json is %(zones)s"), {"zones": zones}) return zones
def list(self, req, *args, **kwargs): """get the list of the dns members""" # get the context context = req.context try: # get the body values = {} values.update(kwargs) LOG.info(_(" args is %(args)s, kwargs is %(kwargs)s"), {"args": args, "kwargs": kwargs}) # check the in values valid_attributes = ['tenant_id'] recom_msg = self.validat_parms(values, valid_attributes) # from db server get the get_members in db members = self.manager.get_db_members(context, recom_msg) LOG.info(_("Return get_members JSON is %(members)s !"), {"members": members}) except Nca47Exception as e: self.response.status = e.code LOG.error(_LE('Error exception! error info: %' + e.message)) LOG.exception(e) return tools.ret_info(e.code, e.message) except RemoteError as exception: self.response.status = 500 message = exception.value return tools.ret_info(self.response.status, message) except Exception as exception: LOG.exception(exception) self.response.status = 500 return tools.ret_info(self.response.status, exception.message) return members
def remove(self, req, *args, **kwargs): """delete the dns zone_record""" url = req.url try: if len(args) != 2: raise BadRequest(resource="record remove", msg=url) list_ = ['current_user'] # get the body dic = json.loads(req.body) # validate the in values of the zone_record dic_body = tool.validat_parms(dic, list_) c = req.context LOG.info(_("server is %(json)s, args is %(args)s, " "kwargs is %(kwargs)s"), {"json": req.body, "args": args, "kwargs": kwargs}) """from rpc server delete the zone_record""" record = self.manager.delete_record(c, dic_body, args[0], args[1]) except Nca47Exception as e: self.response.status = e.code LOG.error(_LE('Error exception! error info: %' + e.message)) LOG.exception(e) return tool.ret_info(e.code, e.message) except MessagingException as exception: self.response.status = 500 message = exception.value return tool.ret_info(self.response.status, message) except Exception as exception: LOG.exception(exception) self.response.status = 500 message = "the values of the body format error" return tool.ret_info(self.response.status, message) LOG.info(_("Return of remove_record JSON is %(record)s !"), {"record": record}) return record
def remove(self, req, id, *args, **kwargs): """delete the dns zone_record""" url = req.url try: # if len(args) != 1: # raise BadRequest(resource="record remove", msg=url) dic = {} dic.update(kwargs) list_ = ["tenant_id", "id"] dic['id'] = id dic_body = self.validat_parms(dic, list_) # get the body # validate the in values of the zone_record c = req.context LOG.info(_("server is %(json)s, args is %(args)s, " "kwargs is %(kwargs)s"), {"json": req.body, "args": args, "kwargs": kwargs}) """from rpc server delete the zone_record""" record = self.manager.delete_record(c, dic_body) except Nca47Exception as e: self.response.status = e.code LOG.error(_LE('Error exception! error info: %' + e.message)) LOG.exception(e) return tool.ret_info(e.code, e.message) except RemoteError as exception: self.response.status = 500 message = exception.value return tool.ret_info(self.response.status, message) except Exception as exception: LOG.exception(exception) self.response.status = 500 return tool.ret_info(self.response.status, exception.message) LOG.info(_("Return of remove_record JSON is %(record)s !"), {"record": record}) return record
def clean_cache(self, *args, **kwargs): list_ = ['owners', 'domain_name', 'view_name'] req = pecan.request context = req.context try: # get the body values = json.loads(req.body) LOG.info(_("req is %(json)s, args is %(args)s," " kwargs is %(kwargs)s"), {"json": req.body, "args": args, "kwargs": kwargs}) self.validat_parms(values, list_) caches = self.manager.del_cache(context, values) LOG.info(_("Return of delete cache JSON is %(zones)s !"), {"zones": caches}) except Nca47Exception as e: self.response.status = e.code LOG.error(_LE('Error exception! error info: %' + e.message)) LOG.exception(e) return tool.ret_info(e.code, e.message) except RemoteError as exception: self.response.status = 500 message = exception.value return tools.ret_info(self.response.status, message) except Exception as exception: LOG.exception(exception) self.response.status = 500 return tools.ret_info(self.response.status, exception.message) return caches
def get(self, req, *args, **kwargs): """ # get info for one or more :param req: :param args: :param kwargs: :return: """ context = req.context try: LOG.info( _("args is %(args)s,kwargs is %(kwargs)s"), { 'args': args, "kwargs": kwargs}) syngroup = self.manager.get_syngroups(context) LOG.info(_("Retrun of get_all_db_zone JSON is %(syngroup)s !"), {"syngroup": syngroup}) except Nca47Exception as e: self.response.status = e.code LOG.error(_LE('Error exception! error info: %' + e.message)) LOG.exception(e) return tools.ret_info(e.code, e.message) except RemoteError as e: self.response.status = 500 message = e.value return tools.ret_info(self.response.status, message) except Exception as exception: LOG.exception(exception) self.response.status = 500 return tools.ret_info(self.response.status, exception.message) return syngroup
def create(self, req, *args, **kwargs): """create the dns hm_template""" try: LOG.info(_("create hm_template:body is %(json)s, args is %(args)s," "kwargs is %(kwargs)s"), {"json": req.body, "args": args, "kwargs": kwargs}) url = req.url # if len(args) != 0: # raise BadRequest(resource="hm_template create", msg=url) array1 = ["tenant_id", "name", "types"] array2 = ["check_interval", "timeout", "max_retries"] # get the body dic = json.loads(req.body) dic_body = self.message_regrouping(dic, array1, array2) context = req.context response = self.manager.create_hm_template(context, dic_body) LOG.info(_("Return of Created hm_template Json is %(response)s !"), {"response": response}) return response except Nca47Exception as e: LOG.error(_LE('Exception Message: %s !' % (e.message))) LOG.exception(e) self.response.status = e.code return tool.ret_info(e.code, e.message) except RemoteError as e: LOG.error(_LE('Exception Message: %s !' % (e.message))) LOG.exception(e) self.response.status = 500 return tool.ret_info(self.response.status, e.value) except Exception as e: LOG.error(_LE('Exception Message: %s !' % (e.message))) LOG.exception(e) self.response.status = 500 return tool.ret_info(self.response.status, e.message)
def update(self, req, id, *args, **kwargs): """update the dns hm template""" try: LOG.info(_("update hm template:body is %(json)s, args is %(args)s," "kwargs is %(kwargs)s"), {"json": req.body, "args": args, "kwargs": kwargs}) url = req.url # if len(args) != 1: # raise BadRequest(resource="hm template update", msg=url) dic = json.loads(req.body) dic['id'] = id c = req.context if not tool.is_not_nil(dic['id']): raise ParamNull(param_name="id") response = self.manager.update_hm_template(c, dic, dic['id']) LOG.info(_("Return of update hm template JSON is %(response)s !"), {"response": response}) return response except Nca47Exception as e: LOG.error(_LE('Exception Message: %s !' % (e.message))) LOG.exception(e) self.response.status = e.code return tool.ret_info(e.code, e.message) except RemoteError as e: LOG.error(_LE('Exception Message: %s !' % (e.message))) LOG.exception(e) self.response.status = 500 message = e.value return tool.ret_info(self.response.status, message) except Exception as e: LOG.error(_LE('Exception Message: %s !' % (e.message))) LOG.exception(e) self.response.status = 500 return tool.ret_info(self.response.status, e.message)
def show(self, req, id, *args, **kwargs): """get one of the dns hm template""" try: LOG.info(_("get a hm template: args is %(args)s, " "kwargs is %(kwargs)s"), {"args": args, "kwargs": kwargs}) url = req.url # if len(args) != 1: # raise BadRequest(resource="hm template query one ", msg=url) context = req.context response = self.manager.get_one_hm_template_db(context, id) LOG.info(_("Return of hm template JSON is %(response)s !"), {"response": response}) return response except Nca47Exception as e: LOG.error(_LE('Exception Message: %s !' % (e.message))) LOG.exception(e) self.response.status = e.code return tool.ret_info(e.code, e.message) except RemoteError as e: LOG.error(_LE('Exception Message: %s !' % (e.message))) LOG.exception(e) self.response.status = 500 message = e.value return tool.ret_info(self.response.status, message) except Exception as e: LOG.error(_LE('Exception Message: %s !' % (e.message))) LOG.exception(e) self.response.status = 500 return tool.ret_info(self.response.status, e.message)
def remove(self, req, *args, **kwargs): """delete the dns zones""" # get the context context = req.context # check the in values valid_attributes = ['current_user'] try: # get the url url = req.url if len(args) != 1: raise BadRequest(resource="zone delete", msg=url) # get the body values = json.loads(req.body) LOG.info(_("the in value body is %(body)s"), {"body": values}) LOG.info(_("the id is %(id)s"), {"id": args[0]}) # check the in values recom_msg = tools.validat_parms(values, valid_attributes) # from rpc server delete the zones in db and device zones = self.manager.delete_zone(context, recom_msg, args[0]) except Nca47Exception as e: self.response.status = e.code LOG.error(_LE('Error exception! error info: %' + e.message)) LOG.exception(e) return tools.ret_info(e.code, e.message) except MessagingException as exception: self.response.status = 500 message = exception.value return tools.ret_info(self.response.status, message) except Exception as exception: LOG.exception(exception) self.response.status = 500 message = "the values of the body format error" return tools.ret_info(self.response.status, message) return zones
def update(self, req, id, *args, **kwargs): """update the dns zone_record""" url = req.url try: # if len(args) != 1: # raise BadRequest(resource="record update", msg=url) dic = json.loads(req.body) dic['id'] = id list_ = ["tenant_id", "id"] if "ttl" not in dic.keys() and "rdata" not in dic.keys(): raise ParamIsNotHaveError(param_name="rdata or ttl") if "ttl" in dic.keys(): if tool.check_ttl(dic['ttl']): list_.append("ttl") else: raise ParamFormatError(param_name="ttl") if "rdata" in dic.keys(): if tool.check_rdata(dic['rdata']): list_.append("rdata") else: raise ParamFormatError(param_name="rdata") if len(list_) == 0: raise ParamValueError(param_name="JSON") # get the body # validate the in values of the zone_record dic_body = self.validat_parms(dic, list_) c = req.context LOG.info(_("req is %(json)s, args is %(args)s, " "kwargs is %(kwargs)s"), {"json": req.body, "args": args, "kwargs": kwargs}) # from rpc server update the zone_record record = self.manager.update_record(c, dic_body) except Nca47Exception as e: self.response.status = e.code LOG.error(_LE('Error exception! error info: %' + e.message)) LOG.exception(e) return tool.ret_info(e.code, e.message) except RemoteError as exception: self.response.status = 500 message = exception.value return tool.ret_info(self.response.status, message) except Exception as exception: LOG.exception(exception) self.response.status = 500 return tool.ret_info(self.response.status, exception.message) LOG.info(_("Return of update_record JSON is %(record)s !"), {"record": record}) return record
def start(self): super(Service, self).start() LOG.info(_('Starting %(name)s service (version: %(version)s)'), { 'name': self.service_name, 'version': 'nca47 v1.0' })
def get_one(self, req, id, *args, **kwargs): LOG.debug(_('id: %(id)s, args: %(args)s, kwargs: %(kwargs)s'), { "id": id, "args": args, "kwargs": kwargs }) return self._get_one(req, id, *args, **kwargs)
def create(self, req, *args, **kwargs): """create the addrobj""" url = req.url try: # get the right url if len(args) != 1: raise BadRequest(resource="addrobj operation", msg=url) # get the body json_body = req.body # get the context context = req.context values = json.loads(json_body) # check the in values valid_attributes = ['tenant_id', 'dc_name', 'network_zone', 'ip', 'name', 'vfwname'] # check the in values recom_msg = self.validat_values(values, valid_attributes) LOG.info(_("the in value body is %(body)s"), {"body": values}) # from rpc server create the addrobj in db and device addrobj = self.manager.add_addrobj(context, recom_msg) except Nca47Exception as e: self.response.status = e.code LOG.error(_LE('Error exception! error info: %' + e.message)) LOG.exception(e) return tools.ret_info(e.code, e.message) except RemoteError as exception: self.response.status = 500 message = exception.value return tools.ret_info(self.response.status, message) except Exception as e: LOG.exception(e) self.response.status = 500 return tools.ret_info(self.response.status, e.message) return addrobj
def create(self, req, *args, **kwargs): """ Create GMap method :param req: :param args: :param kwargs: :return: return http response """ context = req.context try: values = json.loads(req.body) url = req.url valid_attrbutes = [ 'tenant_id', 'name', ] # recom_msg = self.validat_create(values, valid_attrbutes) self.check_create(valid_attrbutes, values) LOG.info(_('the in value body is %(body)s'), {'body': values}) gmaps = self.manager.create_gmap(context, values) except Nca47Exception as e: self.response.status = e.code LOG.error(_LE("Error exception ! error info:%" + e.message)) LOG.exception(e) return tools.ret_info(self.response.status, e.message) except RemoteError as e: self.response.status = 500 message = e.value[3:] return tools.ret_info(self.response.status, message) except Exception as e: LOG.exception(e) self.response.status = 500 return tools.ret_info(self.response.status, e.message) return gmaps
def update(self, req, id, *args, **kwargs): """ update GPool method :param req: :param args: :param kwargs: :return: """ context = req.context try: values = json.loads(req.body) values['id'] = id url = req.url self.check_update(values) # recom_msg = self.validat_update(values, valid_attrbutes) LOG.info(_('the in value body is %(body)s'), {'body': values}) gpools = self.manager.update_gpool(context, values) except Nca47Exception as e: self.response.status = e.code LOG.error(_LE("Error exception ! error info:%" + e.message)) LOG.exception(e) return tools.ret_info(self.response.status, e.message) except RemoteError as e: self.response.status = 500 message = e.value return tools.ret_info(self.response.status, e.message) except Exception as e: LOG.exception(e) self.response.status = 500 return tools.ret_info(self.response.status, e.message) return gpools
def show(self, req, id, *args, **kwargs): """ get syngroup by id :param req: :param id: :param args: :param kwargs: :return: return http response """ context = req.context try: LOG.info(_("args is %(args)s"), {"args": args}) syngroup = self.manager.get_syngroup(context, id) except Nca47Exception as e: self.response.status = e.code LOG.error(_LE('Error exception! error info: %' + e.message)) LOG.exception(e) return tools.ret_info(e.code, e.message) except RemoteError as exception: self.response.status = 500 message = exception.value return tools.ret_info(self.response.status, message) except Exception as exception: LOG.exception(exception) self.response.status = 500 return tools.ret_info(self.response.status, exception.message) return syngroup
def update(self, req, id, *args, **kwargs): """ update Syngroup method :param req: :param args: :param kwargs: :return: """ context = req.context try: url = req.url values = json.loads(req.body) values['id'] = id LOG.info(_("the in value body if %(body)s"), {'body': values}) self.check_update(values) syngroups = self.manager.update_syngroup( context, values) # args[0] is id except Nca47Exception as e: self.response.status = e.code LOG.error(_LE("Error exception! error info: %" + e.message)) LOG.exception(e) return tools.ret_info(e.code, e.message) except RemoteError as exception: self.reponse.status = 500 message = exception.value return tools.ret_info(self.reponse.status, message) except Exception as exception: LOG.exception(exception) self.response.status = 500 return tools.ret_info(self.response.status, exception.message) return syngroups
def create(self, req, *args, **kwargs): """ Create syngorup method :param req: :param args: :param kwargs: :return: """ context = req.context try: values = json.loads(req.body) url = req.url valid_attributes = [ "tenant_id", "name", ] self.check_create(valid_attributes, values) LOG.info(_('the in value body is %(body)s'), {'body': values}) syngroups = self.manager.create_syngroup(context, values) except Nca47Exception as e: self.response.status = e.code LOG.error(_LE("Error exception ! error info:%" + e.message)) LOG.exception(e) return tools.ret_info(self.response.status, e.message) except RemoteError as e: self.response.status = 500 message = e.value return tools.ret_info(self.response.status, message) except Exception as e: LOG.exception(e) self.response.status = 500 return tools.ret_info(self.response.status, e.message) return syngroups
def remove(self, req, *args, **kwargs): """del the snataddrpool""" url = req.url try: # get the right url if len(args) != 1: raise BadRequest(resource="AddrPool operation", msg=url) # get the body json_body = req.body # get the context context = req.context values = json.loads(json_body) # check the in values valid_attributes = ['tenant_id', 'dc_name', 'id', 'network_zone', 'vfwname'] # check the in values recom_msg = self.validat_values(values, valid_attributes) LOG.info(_("the in value body is %(body)s"), {"body": values}) # from rpc server delete the snataddrpool in db and device snataddrpool = self.manager.del_snataddrpool(context, recom_msg) except Nca47Exception as e: self.response.status = e.code LOG.error(_LE('Error exception! error info: %' + e.message)) LOG.exception(e) return tools.ret_info(e.code, e.message) except MessagingException as exception: self.response.status = 500 message = exception.value return tools.ret_info(self.response.status, message) except Exception as exception: LOG.exception(exception) self.response.status = 500 message = "the values of the body format error" return tools.ret_info(self.response.status, message) return snataddrpool
def show(self, req, *args, **kwargs): """get the one addrobj""" url = req.url try: # get the right url if len(args) != 1: raise BadRequest(resource="addrobj operation", msg=url) # get the body json_body = req.body # get the context context = req.context values = json.loads(json_body) # check the in values valid_attributes = ['id'] # check the in values recom_msg = self.validat_values(values, valid_attributes) LOG.info(_("the in value body is %(body)s"), {"body": values}) # from rpc server get the addrobj in db and device addrobj = self.manager.get_addrobj(context, recom_msg) except Nca47Exception as e: self.response.status = e.code LOG.error(_LE('Error exception! error info: %' + e.message)) LOG.exception(e) return tools.ret_info(e.code, e.message) except MessagingException as exception: self.response.status = 500 message = exception.value return tools.ret_info(self.response.status, message) except Exception as exception: LOG.exception(exception) self.response.status = 500 message = "the values of the body format error" return tools.ret_info(self.response.status, message) return addrobj
def create(self, req, *args, **kwargs): """create the dns proximitys""" # get the context context = req.context try: # get the body values = json.loads(req.body) # get the url url = req.url # if len(args) != 1: # raise BadRequest(resource="proximity create", msg=url) # check the in values valid_attributes = ['tenant_id', 'priority', 'src_type', 'src_logic', 'src_data1', 'dst_type', 'dst_logic', 'dst_data1'] # check the in values recom_msg = self.validat_parms(values, valid_attributes) LOG.info(_("the in value body is %(body)s"), {"body": values}) # from rpc server create the proximitys in db and device proximitys = self.manager.create_sp_policy(context, recom_msg) except Nca47Exception as e: self.response.status = e.code LOG.error(_LE('Error exception! error info: %' + e.message)) LOG.exception(e) return tools.ret_info(e.code, e.message) except RemoteError as e: self.response.status = 500 message = e.value return tools.ret_info(self.response.status, message) except Exception as exception: LOG.exception(exception) self.response.status = 500 return tools.ret_info(self.response.status, exception.message) return proximitys
def post(self, req, *args, **kwargs): LOG.debug(_('args: %(args)s, kwargs: %(kwargs)s'), {"args": args, "kwargs": kwargs}) """ operation = args[0] req = pecan.request if operation == 'add': return self.create(req, *args, **kwargs) elif operation == 'del': return self.remove(req, *args, **kwargs) elif operation == 'upd': return self.update(req, *args, **kwargs) elif operation == 'get': return self.show(req, *args, **kwargs) elif operation == 'getall': return self.list(req, *args, **kwargs) elif operation == 'addif': return self.addif(req, *args, **kwargs) elif operation == 'delif': return self.delif(req, *args, **kwargs) else: pecan.abort(404) """ try: operation = args[0] req = pecan.request if operation == 'addif': return self.addif(req, *args, **kwargs) elif operation == 'delif': return self.delif(req, *args, **kwargs) except Exception as e: pass return self.create(req, *args, **kwargs)
def create(self, req, *args, **kwargs): LOG.debug( _("server is %(server)s, args is %(args)s, kwargs is %(kwargs)s"), {"server": 'server', "args": args, "kwargs": kwargs}) dns_server = self.db_api.create(DnsServer, json.loads(req.body)) return dns_server
def update(self, req, id, *args, **kwargs): """update the dns proximitys by currentUser/owners""" # get the context context = req.context try: # get the url url = req.url # if len(args) != 1: # raise BadRequest(resource="proximity update", msg=url) # get the body values = json.loads(req.body) values['id'] = id LOG.info(_("the in value body is %(body)s"), {"body": values}) # check the in values valid_attributes = ['new_priority', 'tenant_id', 'id'] recom_msg = self.validat_parms(values, valid_attributes) # from rpc server update the proximitys in db and device proximitys = self.manager.update_sp_policy(context, recom_msg, recom_msg['id']) except Nca47Exception as e: self.response.status = e.code LOG.error(_LE('Error exception! error info: %' + e.message)) LOG.exception(e) return tools.ret_info(e.code, e.message) except RemoteError as exception: self.response.status = 500 message = exception.value return tools.ret_info(self.response.status, message) except Exception as exception: LOG.exception(exception) self.response.status = 500 return tools.ret_info(self.response.status, exception.message) return proximitys
def validate_filters(cls, **kwargs): bad_filters = [key for key in kwargs if key not in cls.fields or key in cls.synthetic_fields] if bad_filters: bad_filters = ', '.join(bad_filters) msg = _("'%s' is not supported for filtering") % bad_filters raise exception.Invalid(error_message=msg)
def remove(self, req, id, *args, **kwargs): """delete the dns zones""" # get the context context = req.context try: # get the url url = req.url # if len(args) != 1: # raise BadRequest(resource="zone delete", msg=url) # get the body values = {} values.update(kwargs) values['id'] = id LOG.info(_("the in value body is %(body)s"), {"body": values}) # check the in values valid_attributes = ['tenant_id', 'id'] recom_msg = self.validat_parms(values, valid_attributes) # from rpc server delete the zones in db and device zones = self.manager.delete_zone(context, recom_msg['id']) except Nca47Exception as e: LOG.error(_LE('Error exception! error info: %' + e.message)) LOG.exception(e) self.response.status = e.code return tools.ret_info(e.code, e.message) except RemoteError as exception: self.response.status = 500 message = exception.value return tools.ret_info(self.response.status, message) except Exception as exception: LOG.exception(exception) self.response.status = 500 return tools.ret_info(self.response.status, exception.message) return zones
def remove(self, req, id, *args, **kwargs): """ delete the syngroup method :param req: :param id: :param args: :param kwargs: :return: """ context = req.context try: values = json.loads(req.body) values['id'] = id self.check_remove(values) LOG.info(_('the in value body is %(body)s'), {'body': values}) syngroup = self.manager.delete_syngroup(context, values) except Nca47Exception as e: LOG.error(_LE('Error exception! error info: %' + e.message)) LOG.exception(e) self.response.status = e.code return tools.ret_info(e.code, e.message) except RemoteError as exception: self.response.status = 500 message = exception.value return tools.ret_info(self.response.status, message) except Exception as exception: LOG.exception(exception) self.response.status = 500 return tools.ret_info(self.response.status, exception.message) return syngroup
def remove(self, req, id, *args, **kwargs): """ delete GPool method :param req: :param id: :param args: :param kwargs: :return: return http response """ context = req.context try: url = req.url values = {} values.update(kwargs) values['id'] = id self.check_update(values) LOG.info(_('the in value body is %(body)s'), {'body': values}) recom_msg = {} gmap = self.manager.delete_gpool(context, values) except Nca47Exception as e: LOG.error(_LE('Error exception! error info: %' + e.message)) LOG.exception(e) self.response.status = e.code return tools.ret_info(e.code, e.message) except RemoteError as exception: self.response.status = 500 message = exception.value return tools.ret_info(self.response.status, message) except Exception as exception: LOG.exception(exception) self.response.status = 500 return tools.ret_info(self.response.status, exception.message) return gmap
class DuplicateEntry(exception.Conflict): _msg_fmt = _("Failed to create a duplicate %(object_type)s: " "for attribute(s) %(attributes)s with value(s) %(values)s") def __init__(self, object_class, db_exception): super(DuplicateEntry, self).__init__( object_type=reflection.get_class_name(object_class, fully_qualified=False), attributes=db_exception.columns, values=db_exception.value)
def _post(self, req, server, *args, **kwargs): LOG.debug( _("server is %(server)s, args is %(args)s, kwargs is %(kwargs)s"), { "server": server, "args": args, "kwargs": kwargs }) dns_server = self.db_api.create(DnsServer, server) return dns_server
def __init__(self, name, use_ssl=False): """Initialize, but do not start the WSGi server. :param name: The name of the WSGi server given to the loader. :param use_ssl: Wraps the socket in an SSL context if True. :returns: None """ self.name = name self.app = app.setup_app() self.workers = (CONF.api.api_workers or processutils.get_worker_count()) if self.workers and self.workers < 1: raise exception.ConfigInvalid( _("api_workers value of %d is invalid, " "must be greater than 0.") % self.workers) self.server = wsgi.Server(CONF, name, self.app, host=CONF.api.host_ip, port=CONF.api.port, use_ssl=use_ssl, logger_name=name)
class NotAuthorized(Nca47Exception): _msg_fmt = _("Not authorized.") code = http_client.FORBIDDEN
class ObjectUpdateForbidden(exception.Nca47Exception): _msg_fmt = _("Unable to update the following object fields: %(fields)s")
def post(self, req, *args, **kwargs): LOG.debug(_('args: %(args)s, kwargs: %(kwargs)s'), { "args": args, "kwargs": kwargs }) return self._post(req, *args, **kwargs)
class Nca47Exception(Exception): """ Base Ironic Exception To correctly use this class, inherit from it and define a '_msg_fmt' property. That message will get printf'd with the keyword arguments provided to the constructor. If you need to access the message from an exception you should use six.text_type(exc) """ _msg_fmt = _("An unknown exception occurred.") code = http_client.INTERNAL_SERVER_ERROR headers = {} safe = False def __init__(self, message=None, **kwargs): self.kwargs = kwargs if 'code' not in self.kwargs: try: self.kwargs['code'] = self.code except AttributeError: pass if not message: # Check if class is using deprecated 'message' attribute. if (hasattr(self, 'message') and self.message): LOG.warning( _LW("Exception class: %s Using the 'message' " "attribute in an exception has been " "deprecated. The exception class should be " "modified to use the '_msg_fmt' " "attribute."), self.__class__.__name__) self._msg_fmt = self.message try: message = self._msg_fmt % kwargs except Exception as e: # kwargs doesn't match a variable in self._msg_fmt # log the issue and the kwargs LOG.exception(_LE('Exception in string format operation')) for name, value in kwargs.items(): LOG.error("%s: %s" % (name, value)) if CONF.fatal_exception_format_errors: raise e else: # at least get the core self._msg_fmt out if something # happened message = self._msg_fmt super(Nca47Exception, self).__init__(message) def __str__(self): """Encode to utf-8 then wsme api can consume it as well.""" if not six.PY3: return unicode(self.args[0]).encode('utf-8') return self.args[0] def __unicode__(self): """Return a unicode representation of the exception message.""" return unicode(self.args[0])
class BadRequest(Nca47Exception): _msg_fmt = _('Bad %(resource)s request: %(msg)s.')
class Invalid(Nca47Exception): _msg_fmt = _("Unacceptable parameters.") code = http_client.BAD_REQUEST
def get_all(self, req, *args, **kwargs): LOG.debug(_('args: %(args)s, kwargs: %(kwargs)s'), { "args": args, "kwargs": kwargs }) return self._get_all(req, *args, **kwargs)
import oslo_messaging as messaging from oslo_service import service from oslo_service import wsgi from nca47.api import app from nca47.common import config from nca47.common import exception from nca47.common.i18n import _ from nca47.common.i18n import _LE from nca47.common.i18n import _LI from nca47.common import rpc service_opts = [ cfg.IntOpt('periodic_interval', default=60, help=_('Seconds between running periodic tasks.')), cfg.StrOpt('host', default=socket.getfqdn(), help=_('Name of this node. This can be an opaque identifier. ' 'It is not necessarily a hostname, FQDN, or IP address. ' 'However, the node name must be valid within ' 'an AMQP key, and if using ZeroMQ, a valid ' 'hostname, FQDN, or IP address.')), ] CONF = cfg.CONF LOG = log.getLogger(__name__) CONF.register_opts(service_opts)
from oslo_config import cfg from oslo_log import log as logging import six from six.moves import http_client from nca47.common.i18n import _ from nca47.common.i18n import _LE from nca47.common.i18n import _LW LOG = logging.getLogger(__name__) exc_log_opts = [ cfg.BoolOpt('fatal_exception_format_errors', default=False, help=_('Used if there is a formatting error when generating ' 'an exception message (a programming error). If True, ' 'raise an exception; if False, use the unformatted ' 'message.')), ] CONF = cfg.CONF CONF.register_opts(exc_log_opts) class Nca47Exception(Exception): """ Base Ironic Exception To correctly use this class, inherit from it and define a '_msg_fmt' property. That message will get printf'd with the keyword arguments provided to the constructor.
def stop(self): LOG.info(_('Stopping %(name)s service'), {'name': self.service_name}) super(Service, self).stop()
from oslo_config import cfg from nca47.common.i18n import _ API_SERVICE_OPTS = [ cfg.StrOpt('host_ip', default='0.0.0.0', help=_('The IP address on which nca47-api listens.')), cfg.PortOpt('port', default=8080, help=_('The TCP port on which nca47-api listens.')), cfg.IntOpt('max_limit', default=1000, help=_('The maximum number of items returned in a single ' 'response from a collection resource.')), cfg.StrOpt('public_endpoint', default=None, help=_("Public URL to use when building the links to the API " "resources (for example, \"https://nca47.rocks:6384\")." " If None the links will be built using the request's " "host URL. If the API is operating behind a proxy, you " "will want to change this to represent the proxy's URL. " "Defaults to None.")), cfg.IntOpt('api_workers', help=_('Number of workers for OpenStack nca47 API service. ' 'The default is equal to the number of CPUs available ' 'if that can be determined, else a default worker ' 'count of 1 is returned.')), cfg.BoolOpt('enable_ssl_api', default=False, help=_("Enable the integrated stand-alone API to service "
class OperationNotPermitted(NotAuthorized): _msg_fmt = _("Operation not permitted.")