def _create_port(self, port): switchports = port['port']['switchports'] LOG.debug(_LE("_create_port switch: %s"), port) network_id = port['port']['network_id'] db_context = neutron_context.get_admin_context() subnets = db.get_subnets_by_network(db_context, network_id) if not subnets: LOG.error("Subnet not found for the network") self._raise_ml2_error(wexc.HTTPNotFound, 'create_port') for switchport in switchports: switch_mac_id = switchport['switch_id'] port_id = switchport['port_id'] bnp_switch = db.get_bnp_phys_switch_by_mac(db_context, switch_mac_id) # check for port and switch level existence if not bnp_switch: LOG.error(_LE("No physical switch found '%s' "), switch_mac_id) self._raise_ml2_error(wexc.HTTPNotFound, 'create_port') phys_port = db.get_bnp_phys_port(db_context, bnp_switch.id, port_id) if not phys_port: LOG.error(_LE("No physical port found for '%s' "), phys_port) self._raise_ml2_error(wexc.HTTPNotFound, 'create_port') if bnp_switch.port_prov != hp_const.SWITCH_STATUS['enable']: LOG.error(_LE("Physical switch is not Enabled '%s' "), bnp_switch.port_prov) self._raise_ml2_error(wexc.HTTPBadRequest, 'create_port')
def bind_port_to_segment(self, port): """bind_port_to_segment .""" db_context = neutron_context.get_admin_context() LOG.info(_LI('bind_port_to_segment called from back-end mech driver')) switchports = port['port']['switchports'] for switchport in switchports: switch_id = switchport['switch_id'] bnp_switch = db.get_bnp_phys_switch_by_mac(db_context, switch_id) port_name = switchport['port_id'] if not bnp_switch: self._raise_ml2_error(wexc.HTTPNotFound, 'create_port') phys_port = db.get_bnp_phys_port(db_context, bnp_switch.id, port_name) if not phys_port: self._raise_ml2_error(wexc.HTTPNotFound, 'create_port') switchport['ifindex'] = phys_port.ifindex credentials_dict = port.get('port') cred_dict = self._get_credentials_dict(bnp_switch, 'create_port') credentials_dict['credentials'] = cred_dict try: prov_protocol = bnp_switch.prov_proto vendor = bnp_switch.vendor family = bnp_switch.family prov_driver = self._provisioning_driver(prov_protocol, vendor, family) if not prov_driver: LOG.error(_LE("No suitable provisioning driver found" )) self._raise_ml2_error(wexc.HTTPNotFound, 'create_port') prov_driver.obj.set_isolation(port) port_id = port['port']['id'] segmentation_id = port['port']['segmentation_id'] mapping_dict = {'neutron_port_id': port_id, 'switch_port_id': phys_port.id, 'switch_id': bnp_switch.id, 'lag_id': None, 'access_type': hp_const.ACCESS, 'segmentation_id': int(segmentation_id), 'bind_status': 0 } db.add_bnp_switch_port_map(db_context, mapping_dict) db.add_bnp_neutron_port(db_context, mapping_dict) return hp_const.BIND_SUCCESS except Exception as e: LOG.error(_LE("Exception in configuring VLAN '%s' "), e) return hp_const.BIND_FAILURE
def bind_port_to_segment(self, port): """bind_port_to_segment .""" LOG.info(_LI('bind_port_to_segment called from back-end mech driver')) switchports = port['port']['switchports'] for switchport in switchports: switch_id = switchport['switch_id'] bnp_switch = db.get_bnp_phys_switch_by_mac(self.context, switch_id) port_name = switchport['port_id'] if not bnp_switch: self._raise_ml2_error(wexc.HTTPNotFound, 'create_port') phys_port = db.get_bnp_phys_port(self.context, bnp_switch.id, port_name) if not phys_port: self._raise_ml2_error(wexc.HTTPNotFound, 'create_port') # port_maps = db.get_all_bnp_swport_mappings(self.context) # for port_map in port_maps: # if phys_port.id == port_map.switch_port_id: # self._raise_ml2_error(wexc.HTTPConflict, 'create_port') switchport['ifindex'] = phys_port.ifindex credentials_dict = port.get('port') cred_dict = self._get_credentials_dict(bnp_switch, 'create_port') credentials_dict['credentials'] = cred_dict try: self.protocol_driver.set_isolation(port) port_id = port['port']['id'] segmentation_id = port['port']['segmentation_id'] mapping_dict = {'neutron_port_id': port_id, 'switch_port_id': phys_port.id, 'switch_id': bnp_switch.id, 'lag_id': None, 'access_type': constants.ACCESS, 'segmentation_id': int(segmentation_id), 'bind_status': 0 } db.add_bnp_switch_port_map(self.context, mapping_dict) db.add_bnp_neutron_port(self.context, mapping_dict) return constants.BIND_SUCCESS except Exception as e: LOG.error(_LE("Exception in configuring VLAN '%s' "), e) return constants.BIND_FAILURE
def _create_port(self, port): switchports = port["port"]["switchports"] LOG.debug(_LE("_create_port switch: %s"), port) network_id = port["port"]["network_id"] subnets = db.get_subnets_by_network(self.context, network_id) if not subnets: LOG.error("Subnet not found for the network") self._raise_ml2_error(wexc.HTTPNotFound, "create_port") for switchport in switchports: switch_mac_id = switchport["switch_id"] port_id = switchport["port_id"] bnp_switch = db.get_bnp_phys_switch_by_mac(self.context, switch_mac_id) # check for port and switch level existence if not bnp_switch: LOG.error(_LE("No physical switch found '%s' "), switch_mac_id) self._raise_ml2_error(wexc.HTTPNotFound, "create_port") phys_port = db.get_bnp_phys_port(self.context, bnp_switch.id, port_id) if not phys_port: LOG.error(_LE("No physical port found for '%s' "), phys_port) self._raise_ml2_error(wexc.HTTPNotFound, "create_port") if bnp_switch.status != constants.SWITCH_STATUS["enable"]: LOG.error(_LE("Physical switch is not Enabled '%s' "), bnp_switch.status) self._raise_ml2_error(wexc.HTTPBadRequest, "create_port")
def bind_port_to_segment(self, port): """bind_port_to_segment .""" LOG.info(_LI("bind_port_to_segment called from back-end mech driver")) switchports = port["port"]["switchports"] for switchport in switchports: switch_id = switchport["switch_id"] bnp_switch = db.get_bnp_phys_switch_by_mac(self.context, switch_id) port_name = switchport["port_id"] if not bnp_switch: self._raise_ml2_error(wexc.HTTPNotFound, "create_port") phys_port = db.get_bnp_phys_port(self.context, bnp_switch.id, port_name) if not phys_port: self._raise_ml2_error(wexc.HTTPNotFound, "create_port") switchport["ifindex"] = phys_port.ifindex credentials_dict = port.get("port") cred_dict = self._get_credentials_dict(bnp_switch, "create_port") credentials_dict["credentials"] = cred_dict try: self.protocol_driver.set_isolation(port) port_id = port["port"]["id"] segmentation_id = port["port"]["segmentation_id"] mapping_dict = { "neutron_port_id": port_id, "switch_port_id": phys_port.id, "switch_id": bnp_switch.id, "lag_id": None, "access_type": constants.ACCESS, "segmentation_id": int(segmentation_id), "bind_status": 0, } db.add_bnp_switch_port_map(self.context, mapping_dict) db.add_bnp_neutron_port(self.context, mapping_dict) return constants.BIND_SUCCESS except Exception as e: LOG.error(_LE("Exception in configuring VLAN '%s' "), e) return constants.BIND_FAILURE