def _get_access_param(self, context, proto, creds): if not uuidutils.is_uuid_like(creds): access_parameters = db.get_snmp_cred_by_name(context, creds) else: access_parameters = db.get_snmp_cred_by_id(context, creds) if not access_parameters: raise webob.exc.HTTPNotFound( _("Invalid disc_creds %s") % creds) if access_parameters and access_parameters.proto_type == proto: return access_parameters if access_parameters and access_parameters.proto_type != proto: raise webob.exc.HTTPBadRequest( _("Invalid disc_proto %s") % proto)
def _create_snmp_creds(self, context, body, protocol): """Create a new SNMP Credential.""" name = body.get('name') snmp_cred = db.get_snmp_cred_by_name(context, name) if snmp_cred: raise webob.exc.HTTPConflict( _("SNMP Credential with %s name already present") % name) access_parameters = body.pop(protocol) snmp_cred_dict = self._create_snmp_cred_dict() for key, value in access_parameters.iteritems(): body[key] = value body['proto_type'] = protocol snmp_cred = self._update_dict(body, snmp_cred_dict) db_snmp_cred = db.add_bnp_snmp_cred(context, snmp_cred) return db_snmp_cred
def _get_credentials_dict(self, bnp_switch, func_name): if not bnp_switch: self._raise_ml2_error(wexc.HTTPNotFound, func_name) db_context = neutron_context.get_admin_context() creds_dict = {} creds_dict["ip_address"] = bnp_switch.ip_address prov_creds = bnp_switch.credentials prov_protocol = bnp_switch.management_protocol if hp_const.PROTOCOL_SNMP in prov_protocol: if not uuidutils.is_uuid_like(prov_creds): snmp_cred = db.get_snmp_cred_by_name(db_context, prov_creds) snmp_cred = snmp_cred[0] else: snmp_cred = db.get_snmp_cred_by_id(db_context, prov_creds) if not snmp_cred: LOG.error(_LE("Credentials does not match")) self._raise_ml2_error(wexc.HTTPNotFound, "") creds_dict["write_community"] = snmp_cred.write_community creds_dict["security_name"] = snmp_cred.security_name creds_dict["security_level"] = snmp_cred.security_level creds_dict["auth_protocol"] = snmp_cred.auth_protocol creds_dict["management_protocol"] = prov_protocol creds_dict["auth_key"] = snmp_cred.auth_key creds_dict["priv_protocol"] = snmp_cred.priv_protocol creds_dict["priv_key"] = snmp_cred.priv_key else: if not uuidutils.is_uuid_like(prov_creds): netconf_cred = db.get_netconf_cred_by_name(db_context, prov_creds) if netconf_cred.get("password"): password = credential_manager.retrieve_secret(netconf_cred["password"]) netconf_cred["password"] = password else: netconf_cred = db.get_netconf_cred_by_id(db_context, prov_creds) if netconf_cred.get("password"): password = credential_manager.retrieve_secret(netconf_cred["password"]) netconf_cred["password"] = password if not netconf_cred: LOG.error(_LE("Credentials does not match")) self._raise_ml2_error(wexc.HTTPNotFound, "") creds_dict["user_name"] = netconf_cred.write_community creds_dict["password"] = netconf_cred.security_name creds_dict["key_path"] = netconf_cred.security_level return creds_dict
def _get_credentials_dict(self, bnp_switch, func_name): if not bnp_switch: self._raise_ml2_error(wexc.HTTPNotFound, func_name) db_context = neutron_context.get_admin_context() creds_dict = {} creds_dict['ip_address'] = bnp_switch.ip_address prov_creds = bnp_switch.credentials prov_protocol = bnp_switch.management_protocol if hp_const.PROTOCOL_SNMP in prov_protocol: if not uuidutils.is_uuid_like(prov_creds): snmp_cred = db.get_snmp_cred_by_name(db_context, prov_creds) snmp_cred = snmp_cred[0] else: snmp_cred = db.get_snmp_cred_by_id(db_context, prov_creds) if not snmp_cred: LOG.error(_LE("Credentials does not match")) self._raise_ml2_error(wexc.HTTPNotFound, '') creds_dict['write_community'] = snmp_cred.write_community creds_dict['security_name'] = snmp_cred.security_name creds_dict['security_level'] = snmp_cred.security_level creds_dict['auth_protocol'] = snmp_cred.auth_protocol creds_dict['management_protocol'] = prov_protocol creds_dict['auth_key'] = snmp_cred.auth_key creds_dict['priv_protocol'] = snmp_cred.priv_protocol creds_dict['priv_key'] = snmp_cred.priv_key else: if not uuidutils.is_uuid_like(prov_creds): netconf_cred = db.get_netconf_cred_by_name(db_context, prov_creds) else: netconf_cred = db.get_netconf_cred_by_id(db_context, prov_creds) if not netconf_cred: LOG.error(_LE("Credentials does not match")) self._raise_ml2_error(wexc.HTTPNotFound, '') creds_dict['user_name'] = netconf_cred.write_community creds_dict['password'] = netconf_cred.security_name creds_dict['key_path'] = netconf_cred.security_level return creds_dict
def _get_credentials_dict(self, bnp_switch, func_name): if not bnp_switch: self._raise_ml2_error(wexc.HTTPNotFound, func_name) db_context = neutron_context.get_admin_context() creds_dict = {} creds_dict['ip_address'] = bnp_switch.ip_address prov_creds = bnp_switch.credentials prov_protocol = bnp_switch.management_protocol if hp_const.PROTOCOL_SNMP in prov_protocol: if not uuidutils.is_uuid_like(prov_creds): snmp_cred = db.get_snmp_cred_by_name(db_context, prov_creds) snmp_cred = snmp_cred[0] else: snmp_cred = db.get_snmp_cred_by_id(db_context, prov_creds) if not snmp_cred: LOG.error(_LE("Credentials does not match")) self._raise_ml2_error(wexc.HTTPNotFound, '') creds_dict['write_community'] = snmp_cred.write_community creds_dict['security_name'] = snmp_cred.security_name creds_dict['security_level'] = snmp_cred.security_level creds_dict['auth_protocol'] = snmp_cred.auth_protocol creds_dict['management_protocol'] = prov_protocol creds_dict['auth_key'] = snmp_cred.auth_key creds_dict['priv_protocol'] = snmp_cred.priv_protocol creds_dict['priv_key'] = snmp_cred.priv_key else: if not uuidutils.is_uuid_like(prov_creds): netconf_cred = db.get_netconf_cred_by_name(db_context, prov_creds) else: netconf_cred = db.get_netconf_cred_by_id(db_context, prov_creds) if not netconf_cred: LOG.error(_LE("Credentials does not match")) self._raise_ml2_error(wexc.HTTPNotFound, '') creds_dict['user_name'] = netconf_cred.write_community creds_dict['password'] = netconf_cred.security_name creds_dict['key_path'] = netconf_cred.security_level return creds_dict
def _get_access_param(self, context, proto, creds): access_parameters = db.get_snmp_cred_by_name(context, creds) return access_parameters
def test_get_snmp_cred_by_name(self): """Test get_snmp_cred_by_name method.""" snmp_cred_dict = self._get_snmp_cred_dict() retval = [db.add_bnp_snmp_cred(self.ctx, snmp_cred_dict)] cred_val = db.get_snmp_cred_by_name(self.ctx, 'CRED1') self.assertEqual(retval, cred_val)