Ejemplo n.º 1
0
    def _check_port_fault_status_and_switch_fault_status(self, context,
                                                         l2_gateway_id):
        l2gw = self.get_l2_gateway(context, l2_gateway_id)
        if not l2gw:
            raise l2gw_exc.L2GatewayNotFound(gateway_id=l2_gateway_id)
        devices = l2gw['devices']
        rec_dict = {}
        for device in devices:
            device_name = device['device_name']
            dev_db = db.get_physical_switch_by_name(context, device_name)
            if not dev_db:
                raise l2gw_exc.L2GatewayDeviceNotFound(device_id=device_name)
            rec_dict['physical_switch_id'] = dev_db['uuid']
            rec_dict['ovsdb_identifier'] = dev_db['ovsdb_identifier']
            status = dev_db.get('switch_fault_status')
            if status and status != constants.SWITCH_FAULT_STATUS_UP:
                raise l2gw_exc.L2GatewayPhysicalSwitchFaultStatus(
                    device_name=device_name, fault_status=status)
            for interface_list in device['interfaces']:
                int_name = interface_list.get('name')
                rec_dict['interface_name'] = int_name
                port_db = db.get_physical_port_by_name_and_ps(context,
                                                              rec_dict)
                if not port_db:
                    raise l2gw_exc.L2GatewayInterfaceNotFound(
                        interface_id=int_name)

                port_status = port_db['port_fault_status']
                if (port_status and port_status !=
                        constants.PORT_FAULT_STATUS_UP):
                    raise l2gw_exc.L2GatewayPhysicalPortFaultStatus(
                        int_name=int_name, device_name=device_name,
                        fault_status=port_status)
Ejemplo n.º 2
0
    def _validate_gateway_for_update(self, context, gw):
        LOG.debug("L2gwRpcDriver._validate_gateway_for_update gw=%s",
                  gw)
        devices = gw.get('l2_gateway').get('devices')

        for device in devices:
            interfaces = device.get('interfaces')
            device_name = device.get("device_name")
            for interface in interfaces:
                interface_name = interface.get('name')
                physical_switch = db.get_physical_switch_by_name(
                    context, device.get('device_name'))
                if not physical_switch:
                    raise l2gw_exc.L2GatewayDeviceNotFound(
                        device_id=device_name)
                ovsdb_identifier = physical_switch.get('ovsdb_identifier')
                pp_dict = {'interface_name': interface_name,
                           'ovsdb_identifier': ovsdb_identifier,
                           'physical_switch_id': physical_switch.get('uuid')}

                ps_port = db.get_physical_port_by_name_and_ps(context, pp_dict)
                if not ps_port:
                    raise l2gw_exc.L2GatewayPhysicalPortNotFound(
                        int_name=interface_name,
                        device_name=device_name)
Ejemplo n.º 3
0
 def test_get_physical_switch_by_name(self):
     record_dict = self._get_physical_switch_dict()
     with self.ctx.session.begin(subtransactions=True):
         entry = self._create_physical_switch(record_dict,
                                              'physical_switch2')
     result = lib.get_physical_switch_by_name(self.ctx, 'physical_switch2')
     self.assertEqual(entry, result)
Ejemplo n.º 4
0
    def _validate_gateway_for_update(self, context, gw):
        LOG.debug("L2gwRpcDriver._validate_gateway_for_update gw=%s", gw)
        devices = gw.get('l2_gateway').get('devices')

        for device in devices:
            interfaces = device.get('interfaces')
            device_name = device.get("device_name")
            for interface in interfaces:
                interface_name = interface.get('name')
                physical_switch = db.get_physical_switch_by_name(
                    context, device.get('device_name'))
                if not physical_switch:
                    raise l2gw_exc.L2GatewayDeviceNotFound(
                        device_id=device_name)
                ovsdb_identifier = physical_switch.get('ovsdb_identifier')
                pp_dict = {
                    'interface_name': interface_name,
                    'ovsdb_identifier': ovsdb_identifier,
                    'physical_switch_id': physical_switch.get('uuid')
                }

                ps_port = db.get_physical_port_by_name_and_ps(context, pp_dict)
                if not ps_port:
                    raise l2gw_exc.L2GatewayPhysicalPortNotFound(
                        int_name=interface_name, device_name=device_name)
Ejemplo n.º 5
0
 def test_get_physical_switch_by_name(self):
     record_dict = self._get_physical_switch_dict()
     with self.ctx.session.begin(subtransactions=True):
         entry = self._create_physical_switch(record_dict,
                                              'physical_switch2')
     result = lib.get_physical_switch_by_name(self.ctx,
                                              'physical_switch2')
     self.assertEqual(entry, result)
Ejemplo n.º 6
0
 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
Ejemplo n.º 7
0
 def _get_identifer_list(self, context, gw_connection):
     identifier_list = []
     l2gateway_devices = self.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)
Ejemplo n.º 8
0
 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