def validate_network_mapping_list(network_mapping, check_vlan): """Validate network mapping list in connection.""" if network_mapping.get('segmentation_id'): if check_vlan: raise exceptions.InvalidInput( error_message=_("default segmentation_id should not be" " provided when segmentation_id is assigned" " during l2gateway creation")) seg_id = network_mapping.get(constants.SEG_ID) is_valid_vlan_id(seg_id) if not network_mapping.get('segmentation_id'): if check_vlan is False: raise exceptions.InvalidInput( error_message=_("Segmentation id must be specified in create " "l2gateway connections")) network_id = network_mapping.get(constants.NETWORK_ID) if not network_id: raise exceptions.InvalidInput( error_message=_("A valid network identifier must be specified " "when connecting a network to a network " "gateway. Unable to complete operation")) connection_attrs = set(network_mapping.keys()) if not connection_attrs.issubset(ALLOWED_CONNECTION_ATTRIBUTES): raise exceptions.InvalidInput( error_message=(_("Invalid keys found among the ones provided " "in request : %(connection_attrs)s."), connection_attrs)) return network_id
def is_valid_vlan_id(seg_id): try: int_seg_id = int(seg_id) except ValueError: msg = _("Segmentation id must be a valid integer") raise exceptions.InvalidInput(error_message=msg) if int_seg_id < 0 or int_seg_id >= 4095: msg = _("Segmentation id is out of range") raise exceptions.InvalidInput(error_message=msg)
def _process_port_list(self, context, device, gw_connection, method, gw_connection_ovsdb_set=None): port_dicts = [] port_dict = {} logical_switch_uuid = None seg_id = gw_connection.get('segmentation_id', None) interfaces = self.service_plugin.get_l2gateway_interfaces_by_device_id( context, device['id']) LOG.debug("L2gwRpcDriver._process_port_list: ints=%s", interfaces) for interface in interfaces: interface_name = interface.get('interface_name') LOG.debug("L2gwRpcDriver._process_port_list: int_name=%s", interface_name) physical_switch = db.get_physical_switch_by_name( context, device.get('device_name')) if not physical_switch: msg = _('The PHYSICAL SWITCH data not found in the server') raise Exception(msg) ovsdb_identifier = physical_switch.get('ovsdb_identifier') pp_dict = { 'interface_name': interface_name, 'ovsdb_identifier': ovsdb_identifier, 'physical_switch_id': physical_switch.get('uuid'), 'logical_switch_name': gw_connection.get('network_id') } logical_switch = db.get_logical_switch_by_name(context, pp_dict) if method == "DELETE": if not logical_switch: msg = _('The LOGICAL SWITCH data not found in the server') raise Exception(msg) if not (ovsdb_identifier in list(gw_connection_ovsdb_set)): continue if logical_switch: logical_switch_uuid = logical_switch.get('uuid') ps_port = db.get_physical_port_by_name_and_ps(context, pp_dict) if not ps_port: msg = _('The PHYSICAL PORT data not found in the server') raise Exception(msg) pp_dict['uuid'] = ps_port.get('uuid') pp_dict['name'] = ps_port.get('name') LOG.debug("L2gwRpcDriver._process_port_list: pp_dict.name=%s", pp_dict['name']) port_dict = self._generate_port_list(context, method, seg_id, interface, pp_dict, logical_switch_uuid, gw_connection) port_dicts.append(port_dict) return ovsdb_identifier, logical_switch, port_dicts
def _process_port_list(self, context, device, gw_connection, method, gw_connection_ovsdb_set=None): port_dicts = [] port_dict = {} logical_switch_uuid = None seg_id = gw_connection.get('segmentation_id', None) interfaces = self.service_plugin.get_l2gateway_interfaces_by_device_id( context, device['id']) LOG.debug("L2gwRpcDriver._process_port_list: ints=%s", interfaces) for interface in interfaces: interface_name = interface.get('interface_name') LOG.debug("L2gwRpcDriver._process_port_list: int_name=%s", interface_name) physical_switch = db.get_physical_switch_by_name( context, device.get('device_name')) if not physical_switch: msg = _('The PHYSICAL SWITCH data not found in the server') raise Exception(msg) ovsdb_identifier = physical_switch.get('ovsdb_identifier') pp_dict = {'interface_name': interface_name, 'ovsdb_identifier': ovsdb_identifier, 'physical_switch_id': physical_switch.get('uuid'), 'logical_switch_name': gw_connection.get( 'network_id')} logical_switch = db.get_logical_switch_by_name( context, pp_dict) if method == "DELETE": if not logical_switch: msg = _('The LOGICAL SWITCH data not found in the server') raise Exception(msg) if not (ovsdb_identifier in list(gw_connection_ovsdb_set)): continue if logical_switch: logical_switch_uuid = logical_switch.get('uuid') ps_port = db.get_physical_port_by_name_and_ps(context, pp_dict) if not ps_port: msg = _('The PHYSICAL PORT data not found in the server') raise Exception(msg) pp_dict['uuid'] = ps_port.get('uuid') pp_dict['name'] = ps_port.get('name') LOG.debug("L2gwRpcDriver._process_port_list: pp_dict.name=%s", pp_dict['name']) port_dict = self._generate_port_list( context, method, seg_id, interface, pp_dict, logical_switch_uuid, gw_connection) port_dicts.append(port_dict) return ovsdb_identifier, logical_switch, port_dicts
def get_parser(self, parser): parser = super(l2gatewayV20.CreateCommand, self).get_parser(parser) parser.add_argument( 'gateway_name', metavar='<GATEWAY-NAME/UUID>', help=_('Descriptive name for logical gateway.')) parser.add_argument( 'network', metavar='<NETWORK-NAME/UUID>', help=_('Network name or uuid.')) parser.add_argument( '--default-segmentation-id', dest='seg_id', help=_('default segmentation-id that will ' 'be applied to the interfaces for which ' 'segmentation id was not specified ' 'in l2-gateway-create command.')) return parser
def _generate_port_list(self, context, method, seg_id, interface, pp_dict, logical_switch_uuid, gw_connection=None): port_list = [] vlan_bindings = db.get_all_vlan_bindings_by_physical_port( context, pp_dict) if method == "CREATE": if not seg_id: vlan_id = interface.get('segmentation_id') else: vlan_id = int(seg_id) vlan_dict = { 'vlan': vlan_id, 'logical_switch_uuid': logical_switch_uuid } port_list.append(vlan_dict) for vlan_binding in vlan_bindings: if vlan_binding.get('vlan') == vlan_id: msg = _('Duplicate segmentation ID for the interface ' 'name=%(name)s uuid=%(uuid)s') % { 'name': pp_dict['name'], 'uuid': pp_dict['uuid'] } raise l2gw_exc.L2GatewayDuplicateSegmentationID( message=msg) physical_port = self._get_dict( ovsdb_schema.PhysicalPort( uuid=pp_dict.get('uuid'), name=pp_dict.get('interface_name'), phys_switch_id=pp_dict.get('physical_switch_id'), vlan_binding_dicts=None, port_fault_status=None)) physical_port['vlan_bindings'] = port_list else: vlan_id = gw_connection.get('segmentation_id') if not vlan_id: vlan_id = interface.get('segmentation_id') vlan_dict = { 'vlan': vlan_id, 'logical_switch_uuid': logical_switch_uuid } port_list.append(vlan_dict) physical_port = self._get_dict( ovsdb_schema.PhysicalPort( uuid=pp_dict.get('uuid'), name=pp_dict.get('interface_name'), phys_switch_id=pp_dict.get('physical_switch_id'), vlan_binding_dicts=None, port_fault_status=None)) physical_port['vlan_bindings'] = port_list return physical_port
def add_known_arguments(self, parser): parser.add_argument( '--device', metavar='name=name,interface_names=INTERFACE-DETAILS', action='append', dest='devices', type=utils.str2dict, help=_('Device name and Interface-names of l2gateway. ' 'INTERFACE-DETAILS is of form ' '\"<interface_name1>;[<interface_name2>]' '[|<seg_id1>[#<seg_id2>]]\" ' '(--device option can be repeated)'))
def validate_gwdevice_list(data, valid_values=None): """Validate the list of devices.""" if not data: # Devices must be provided msg = _("Cannot create a gateway with an empty device list") return msg try: for device in data: interface_data = device.get(constants.IFACE_NAME_ATTR) device_name = device.get(constants.DEVICE_ID_ATTR) if not device_name: msg = _("Cannot create a gateway with an empty device_name") return msg if not interface_data: msg = _("Cannot create a gateway with an empty interfaces") return msg if not isinstance(interface_data, list): msg = _("interfaces format is not a type list of dicts") return msg for int_dict in interface_data: if not isinstance(int_dict, dict): msg = _("interfaces format is not a type dict") return msg err_msg = validators.validate_dict(int_dict, None) if not int_dict.get('name'): msg = _("Cannot create a gateway with an empty " "interface name") return msg if constants.SEG_ID in int_dict: seg_id_list = int_dict.get(constants.SEG_ID) if seg_id_list and type(seg_id_list) is not list: msg = _("segmentation_id type should be of list type ") return msg if not seg_id_list: msg = _("segmentation_id_list should not be empty") return msg for seg_id in seg_id_list: is_valid_vlan_id(seg_id) if err_msg: return err_msg except TypeError: return (_("%s: provided data are not iterable") % validate_gwdevice_list.__name__)
def _get_identifer_list(self, context, gw_connection): identifier_list = [] l2gateway_devices = ( self.service_plugin.get_l2gateway_devices_by_gateway_id( context, gw_connection.get('l2_gateway_id'))) for device in l2gateway_devices: physical_switch = db.get_physical_switch_by_name( context, device.get('device_name')) if not physical_switch: msg = _('The PHYSICAL SWITCH data not found in the server') raise Exception(msg) ovsdb_identifier = physical_switch.get('ovsdb_identifier') identifier_list.append(ovsdb_identifier) return set(identifier_list)
def _get_identifer_list(self, context, gw_connection): identifier_list = [] l2gateway_devices = ( self.service_plugin.get_l2gateway_devices_by_gateway_id( context, gw_connection.get('l2_gateway_id'))) for device in l2gateway_devices: physical_switch = db.get_physical_switch_by_name( context, device.get('device_name')) if not physical_switch: msg = _('The PHYSICAL SWITCH data not found in the server') raise Exception(msg) ovsdb_identifier = physical_switch.get('ovsdb_identifier') identifier_list.append(ovsdb_identifier) return set(identifier_list)
def _generate_port_list(self, context, method, seg_id, interface, pp_dict, logical_switch_uuid, gw_connection=None): port_list = [] vlan_bindings = db.get_all_vlan_bindings_by_physical_port( context, pp_dict) if method == "CREATE": if not seg_id: vlan_id = interface.get('segmentation_id') else: vlan_id = int(seg_id) vlan_dict = {'vlan': vlan_id, 'logical_switch_uuid': logical_switch_uuid} port_list.append(vlan_dict) for vlan_binding in vlan_bindings: if vlan_binding.get('vlan') == vlan_id: msg = _('Duplicate segmentation ID for the interface ' 'name=%(name)s uuid=%(uuid)s' ) % {'name': pp_dict['name'], 'uuid': pp_dict['uuid']} raise l2gw_exc.L2GatewayDuplicateSegmentationID(message=msg ) physical_port = self._get_dict( ovsdb_schema.PhysicalPort( uuid=pp_dict.get('uuid'), name=pp_dict.get('interface_name'), phys_switch_id=pp_dict.get('physical_switch_id'), vlan_binding_dicts=None, port_fault_status=None)) physical_port['vlan_bindings'] = port_list else: vlan_id = gw_connection.get('segmentation_id') if not vlan_id: vlan_id = interface.get('segmentation_id') vlan_dict = {'vlan': vlan_id, 'logical_switch_uuid': logical_switch_uuid} port_list.append(vlan_dict) physical_port = self._get_dict( ovsdb_schema.PhysicalPort( uuid=pp_dict.get('uuid'), name=pp_dict.get('interface_name'), phys_switch_id=pp_dict.get('physical_switch_id'), vlan_binding_dicts=None, port_fault_status=None)) physical_port['vlan_bindings'] = port_list return physical_port
def update_connection_to_gateway(self, context, ovsdb_identifier, ls_dict, locator_list, mac_dict, port_dict, op_method): """RPC to update the connection to gateway.""" self._validate_request_op_method(context, op_method) cctxt = self.client.prepare() try: return cctxt.call(context, 'update_connection_to_gateway', ovsdb_identifier=ovsdb_identifier, logical_switch_dict=ls_dict, locator_dicts=locator_list, mac_dicts=mac_dict, port_dicts=port_dict, op_method=op_method) except messaging.MessagingTimeout: message = _("Communication error with the L2 gateway agent") raise l2gw_exc.OVSDBError(message=message) except Exception as ex: message = str(ex) msg_splits = message.split('\n') raise l2gw_exc.OVSDBError(message="Error on the OVSDB " "server: " + msg_splits[0])
def update_connection_to_gateway(self, context, ovsdb_identifier, ls_dict, locator_list, mac_dict, port_dict, op_method): """RPC to update the connection to gateway.""" self._validate_request_op_method(context, op_method) cctxt = self.client.prepare() try: return cctxt.call(context, 'update_connection_to_gateway', ovsdb_identifier=ovsdb_identifier, logical_switch_dict=ls_dict, locator_dicts=locator_list, mac_dicts=mac_dict, port_dicts=port_dict, op_method=op_method) except messaging.MessagingTimeout: message = _("Communication error with the L2 gateway agent") raise l2gw_exc.OVSDBError(message=message) except Exception as ex: message = str(ex) msg_splits = message.split('\n') raise l2gw_exc.OVSDBError(message="Error on the OVSDB " "server: " + msg_splits[0])
def add_known_arguments(self, parser): parser.add_argument( '--name', metavar='name', help=_('Descriptive name for logical gateway.')) add_known_arguments(self, parser)
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from neutron.common import config from oslo_config import cfg from networking_l2gw._i18n import _ OVSDB_OPTS = [ cfg.StrOpt('ovsdb_hosts', default='host1:127.0.0.1:6632', help=_("OVSDB server name:host/IP:port")), cfg.StrOpt('l2_gw_agent_priv_key_base_path', help=_('L2 gateway agent private key')), cfg.StrOpt('l2_gw_agent_cert_base_path', help=_('L2 gateway agent public certificate')), cfg.StrOpt('l2_gw_agent_ca_cert_base_path', help=_('Trusted issuer CA cert')), cfg.IntOpt('periodic_interval', default=20, help=_('Seconds between periodic task runs')), cfg.IntOpt('socket_timeout', default=30, help=_('Socket timeout in seconds. ' 'If there is no echo request on the socket for ' 'socket_timeout seconds, the agent can safely ' 'assume that the connection with the remote '