def _create_netconf_creds(self, context, body, protocol): """Create a new NETCONF Credential.""" name = body.get('name') netconf_cred = db.get_netconf_cred_by_name(context, name) if netconf_cred: raise webob.exc.HTTPConflict( _("NETCONF Credential with %s name already present") % name) access_parameters = body.pop(protocol) netconf_cred_dict = self._create_netconf_cred_dict() for key, value in access_parameters.iteritems(): body[key] = value body['proto_type'] = protocol netconf_cred = self._update_dict(body, netconf_cred_dict) db_netconf_cred = db.add_bnp_netconf_cred(context, netconf_cred) return db_netconf_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 test_get_netconf_cred_by_name(self): """Test get_netconf_cred_by_name method.""" netconf_cred_dict = self._get_netconf_cred_dict() retval = [db.add_bnp_netconf_cred(self.ctx, netconf_cred_dict)] cred_val = db.get_netconf_cred_by_name(self.ctx, 'CRED1') self.assertEqual(retval, cred_val)