def get_by_name(self, req): """ Get one vsm setting by name """ context = req.environ['vsm.context'] search_opts = {} search_opts.update(req.GET) LOG.debug('search options %s' % search_opts) vsm_name = search_opts.pop('name', None) if not vsm_name: raise exc.HTTPBadRequest( explanation=_('Invalid request: vsm name is required.')) try: utils.check_string_length(vsm_name, 'name', min_length=1, max_length=255) setting = db.vsm_settings_get_by_name(context, vsm_name) except db_exc.DBError as e: raise exc.HTTPServerError(explanation=e.message) except exception.InvalidInput as e: raise exc.HTTPBadRequest(explanation=e.message) if not setting: raise exc.HTTPNotFound( explanation=_('The vsm setting(%s) does not exists.' % vsm_name)) return self._view_builder.basic(req, setting)
def update(contxt, appnode_id, ssh_status=None, log_info=None, ip=None): """update app node ssh status, log info or deleted""" if contxt is None: contxt = context.get_admin_context() id = utils.int_from_str(appnode_id) LOG.debug('app node id: %s ' % id) kargs = {} if ip: kargs['ip'] = ip if ssh_status: utils.check_string_length(ssh_status, 'ssh_status', 1, 50) kargs['ssh_status'] = ssh_status if log_info: utils.check_string_length(log_info, 'log_info', 1, 65535) kargs['log_info'] = log_info if kargs: try: return db.appnodes_update(contxt, id, kargs) except db_exc.DBError as e: LOG.exception(_("DB Error on updating Appnodes %s" % e)) raise exception.AppNodeFailure()
def _validate_body(self, setting_dict): if not isinstance(setting_dict, dict): raise exc.HTTPBadRequest(explanation=_('Invalid request body.')) if not 'name' in setting_dict.keys(): LOG.debug('dict keys %s %s' % (setting_dict, setting_dict.keys())) msg = _("vsm setting name is not defined in vsm setting request.") raise exc.HTTPBadRequest(explanation=msg) name = setting_dict.get('name') value = setting_dict.get('value') default_value = setting_dict.get('default_value') try: if name: utils.check_string_length(name, 'name', min_length=1, max_length=255) else: msg = _('key name cannot be null or empty.') raise exc.HTTPBadRequest(explanation=msg) if value: utils.check_string_length(value, 'value', max_length=255) if default_value: utils.check_string_length(default_value, 'default value', max_length=255) except exception.InvalidInput as e: raise exc.HTTPBadRequest(explanation=e.message)
def get_by_name(self, req): """ Get one vsm setting by name """ context = req.environ['vsm.context'] search_opts = {} search_opts.update(req.GET) LOG.debug('search options %s' % search_opts) vsm_name = search_opts.pop('name', None) if not vsm_name: raise exc.HTTPBadRequest(explanation=_('Invalid request: vsm name is required.')) try: utils.check_string_length(vsm_name, 'name', min_length=1, max_length=255) setting = db.vsm_settings_get_by_name(context, vsm_name) except db_exc.DBError as e: raise exc.HTTPServerError(explanation=e.message) except exception.InvalidInput as e: raise exc.HTTPBadRequest(explanation=e.message) if not setting: raise exc.HTTPNotFound(explanation=_('The vsm setting(%s) does not exists.' % vsm_name)) return self._view_builder.basic(req, setting)