def create(self, request, **kwargs): context = request.context self._check_admin(context) body = validators.validate_request(request) key_list = ['ip_address', 'vendor', 'access_protocol', 'access_parameters'] keys = body.keys() for key in key_list: if key not in keys: raise webob.exc.HTTPBadRequest( _("Key %s not found in request body") % key) validators.validate_attributes(keys, key_list) if body['vendor'] not in const.SUPPORTED_VENDORS: raise webob.exc.HTTPBadRequest( _("Switch with vendor %s is not supported") % body['vendor']) ip_address = body['ip_address'] bnp_switch = db.get_bnp_phys_switch_by_ip(context, ip_address) if bnp_switch: raise webob.exc.HTTPConflict( _("Switch with ip_address %s is already present") % ip_address) validators.validate_access_parameters(body) access_parameters = body.pop("access_parameters") switch_dict = self._create_switch_dict() for key, value in access_parameters.iteritems(): body[key] = value switch = self._update_dict(body, switch_dict) bnp_switch = self._discover_switch(switch) if bnp_switch.get('mac_address'): switch['mac_address'] = bnp_switch.get('mac_address') switch['status'] = const.SWITCH_STATUS['enable'] else: switch['status'] = const.SWITCH_STATUS['create'] db_switch = db.add_bnp_phys_switch(context, switch) if bnp_switch.get('ports'): self._add_physical_port(context, db_switch.get('id'), bnp_switch.get('ports')) return {const.BNP_SWITCH_RESOURCE_NAME: dict(db_switch)}
def create(self, request, **kwargs): """Create a new Credential""" context = request.context self._check_admin(context) body = validators.validate_request(request) key_list = ['name', 'snmpv1', 'snmpv2c', 'snmpv3', 'netconf-ssh', 'netconf-soap'] keys = body.keys() validators.validate_attributes(keys, key_list) protocol = validators.validate_access_parameters(body) if protocol in ['snmpv1', 'snmpv2c', 'snmpv3']: db_snmp_cred = self._create_snmp_creds(context, body, protocol) return {const.BNP_CREDENTIAL_RESOURCE_NAME: dict(db_snmp_cred)} else: db_netconf_cred = self._create_netconf_creds(context, body, protocol) return {const.BNP_CREDENTIAL_RESOURCE_NAME: dict(db_netconf_cred)}
def create(self, request, **kwargs): """Create a new Credential.""" context = request.context self._check_admin(context) body = validators.validate_request(request) key_list = ["name", "snmpv1", "snmpv2c", "snmpv3", "netconf_ssh", "netconf_soap"] keys = body.keys() validators.validate_attributes(keys, key_list) protocol = validators.validate_access_parameters(body) if protocol in ["snmpv1", "snmpv2c", "snmpv3"]: db_snmp_cred = self._create_snmp_creds(context, body, protocol) db_snmp_cred = self._creds_to_show(db_snmp_cred) return {const.BNP_CREDENTIAL_RESOURCE_NAME: dict(db_snmp_cred)} else: db_netconf_cred = self._create_netconf_creds(context, body, protocol) db_netconf_cred = self._creds_to_show(db_netconf_cred) return {const.BNP_CREDENTIAL_RESOURCE_NAME: dict(db_netconf_cred)}
def create(self, request, **kwargs): """Create a new Credential.""" context = request.context self._check_admin(context) body = validators.validate_request(request) key_list = [ 'name', 'snmpv1', 'snmpv2c', 'snmpv3', 'netconf_ssh', 'netconf_soap' ] keys = body.keys() validators.validate_attributes(keys, key_list) protocol = validators.validate_access_parameters(body) if protocol in ['snmpv1', 'snmpv2c', 'snmpv3']: db_snmp_cred = self._create_snmp_creds(context, body, protocol) db_snmp_cred = self._creds_to_show(db_snmp_cred) return {const.BNP_CREDENTIAL_RESOURCE_NAME: dict(db_snmp_cred)} else: db_netconf_cred = self._create_netconf_creds( context, body, protocol) db_netconf_cred = self._creds_to_show(db_netconf_cred) return {const.BNP_CREDENTIAL_RESOURCE_NAME: dict(db_netconf_cred)}
def create(self, request, **kwargs): """Create a new Credential.""" context = request.context self._check_admin(context) body = validators.validate_request(request) key_list = ['name', 'snmpv1', 'snmpv2c', 'snmpv3', 'netconf_ssh', 'netconf_soap'] keys = body.keys() validators.validate_attributes(keys, key_list) protocol = validators.validate_access_parameters(body) if protocol in ['snmpv1', 'snmpv2c', 'snmpv3']: db_snmp_cred = self._create_snmp_creds(context, body, protocol) db_snmp_cred = self._creds_to_show(db_snmp_cred) return {const.BNP_CREDENTIAL_RESOURCE_NAME: dict(db_snmp_cred)} else: if body[protocol].get('password'): body[protocol]['password'] = credential_manager.create_secret( body[protocol]['password']) db_netconf_cred = self._create_netconf_creds( context, body, protocol) db_netconf_cred = self._creds_to_show(db_netconf_cred) return {const.BNP_CREDENTIAL_RESOURCE_NAME: dict(db_netconf_cred)}