Example #1
0
def register(instance_name, *device_names):
    """Register device with a SDPSubarray device server instance.

    If the device is already registered, do nothing.

    :param instance_name: Instance name SDPSubarray device server
    :param device_names: Subarray device names to register

    """
    # pylint: disable=protected-access
    try:
        tango_db = Database()
        class_name = 'SDPSubarray'
        server_name = '{}/{}'.format(class_name, instance_name)
        devices = list(tango_db.get_device_name(server_name, class_name))
        device_info = DbDevInfo()
        device_info._class = class_name
        device_info.server = server_name
        for device_name in device_names:
            device_info.name = device_name
            if device_name in devices:
                LOG.debug("Device '%s' already registered", device_name)
                continue
            LOG.info('Registering device: %s (server: %s, class: %s)',
                     device_info.name, server_name, class_name)
            tango_db.add_device(device_info)
    except ConnectionFailed:
        pass
def register_master():
    """Register the SDP Master device."""
    tango_db = Database()
    device = "sip_sdp/elt/master"
    device_info = DbDevInfo()
    device_info._class = "SDPMasterDevice"
    device_info.server = "sdp_master_ds/1"
    device_info.name = device
    devices = tango_db.get_device_name(device_info.server, device_info._class)
    if device not in devices:
        LOG.info('Registering device "%s" with device server "%s"',
                 device_info.name, device_info.server)
        tango_db.add_device(device_info)
def register_master():
    """Register the SDP Master device."""
    tango_db = Database()
    device = "sip_sdp/elt/master"
    device_info = DbDevInfo()
    device_info._class = "SDPMasterDevice"
    device_info.server = "sdp_master_ds/1"
    device_info.name = device
    devices = tango_db.get_device_name(device_info.server, device_info._class)
    if device not in devices:
        LOG.info('Registering device "%s" with device server "%s"',
                 device_info.name, device_info.server)
        tango_db.add_device(device_info)
    def configure(self, value):
        """Schedule an offline only SBI with SDP."""

        # Only accept new SBIs if the SDP is on.
        if self._sdp_state.current_state != 'on':
            raise RuntimeWarning('Unable to configure SBIs unless SDP is '
                                 '\'on\'.')

        # Check that the new SBI is not already registered.
        sbi_config_dict = json.loads(value)
        sbi_list = SchedulingBlockInstanceList()
        LOG.info('SBIs before: %s', sbi_list.active)
        if sbi_config_dict.get('id') in sbi_list.active:
            raise RuntimeWarning(
                'Unable to add SBI with ID {}, an SBI with '
                'this ID is already registered with SDP!'.format(
                    sbi_config_dict.get('id')))

        # Add the SBI to the dictionary.
        LOG.info('Scheduling offline SBI! Config:\n%s', value)
        sbi = SchedulingBlockInstance.from_config(sbi_config_dict)
        LOG.info('SBIs after: %s', sbi_list.active)

        sbi_pb_ids = sbi.processing_block_ids
        LOG.info('SBI "%s" contains PBs: %s', sbi.id, sbi_pb_ids)
        # pb_list = ProcessingBlockList()
        # LOG.info('Active PBs: %s', pb_list.active)

        # Get the list and number of Tango PB devices
        tango_db = Database()
        pb_device_class = "ProcessingBlockDevice"
        pb_device_server_instance = "processing_block_ds/1"
        pb_devices = tango_db.get_device_name(pb_device_server_instance,
                                              pb_device_class)
        LOG.info('Number of PB devices in the pool = %d', len(pb_devices))

        # Get a PB device which has not been assigned.
        for pb_id in sbi_pb_ids:
            for pb_device_name in pb_devices:
                device = DeviceProxy(pb_device_name)

                if not device.pb_id:
                    LOG.info('Assigning PB device = %s to PB id = %s',
                             pb_device_name, pb_id)
                    # Set the device attribute 'pb_id' to the processing block
                    # id it is tracking.
                    device.pb_id = pb_id
                    break
    def configure(self, value):
        """Schedule an offline only SBI with SDP."""

        # Only accept new SBIs if the SDP is on.
        if self._sdp_state.current_state != 'on':
            raise RuntimeWarning('Unable to configure SBIs unless SDP is '
                                 '\'on\'.')

        # Check that the new SBI is not already registered.
        sbi_config_dict = json.loads(value)
        sbi_list = SchedulingBlockInstanceList()
        LOG.info('SBIs before: %s', sbi_list.active)
        if sbi_config_dict.get('id') in sbi_list.active:
            raise RuntimeWarning('Unable to add SBI with ID {}, an SBI with '
                                 'this ID is already registered with SDP!'
                                 .format(sbi_config_dict.get('id')))

        # Add the SBI to the dictionary.
        LOG.info('Scheduling offline SBI! Config:\n%s', value)
        sbi = SchedulingBlockInstance.from_config(sbi_config_dict)
        LOG.info('SBIs after: %s', sbi_list.active)

        sbi_pb_ids = sbi.processing_block_ids
        LOG.info('SBI "%s" contains PBs: %s', sbi.id, sbi_pb_ids)
        # pb_list = ProcessingBlockList()
        # LOG.info('Active PBs: %s', pb_list.active)

        # Get the list and number of Tango PB devices
        tango_db = Database()
        pb_device_class = "ProcessingBlockDevice"
        pb_device_server_instance = "processing_block_ds/1"
        pb_devices = tango_db.get_device_name(pb_device_server_instance,
                                              pb_device_class)
        LOG.info('Number of PB devices in the pool = %d', len(pb_devices))

        # Get a PB device which has not been assigned.
        for pb_id in sbi_pb_ids:
            for pb_device_name in pb_devices:
                device = DeviceProxy(pb_device_name)

                if not device.pb_id:
                    LOG.info('Assigning PB device = %s to PB id = %s',
                             pb_device_name, pb_id)
                    # Set the device attribute 'pb_id' to the processing block
                    # id it is tracking.
                    device.pb_id = pb_id
                    break
    def processing_block_devices(self):
        """Get list of processing block devices."""
        # Get the list and number of Tango PB devices
        tango_db = Database()
        pb_device_class = "ProcessingBlockDevice"
        pb_device_server_instance = "processing_block_ds/1"
        pb_devices = tango_db.get_device_name(pb_device_server_instance,
                                              pb_device_class)
        LOG.info('Number of PB devices in the pool = %d', len(pb_devices))

        pb_device_map = []
        for pb_device_name in pb_devices:
            device = DeviceProxy(pb_device_name)
            if device.pb_id:
                LOG.info('%s %s', pb_device_name, device.pb_id)
                pb_device_map.append((pb_device_name, device.pb_id))

        return str(pb_device_map)
    def processing_block_devices(self):
        """Get list of processing block devices."""
        # Get the list and number of Tango PB devices
        tango_db = Database()
        pb_device_class = "ProcessingBlockDevice"
        pb_device_server_instance = "processing_block_ds/1"
        pb_devices = tango_db.get_device_name(pb_device_server_instance,
                                              pb_device_class)
        LOG.info('Number of PB devices in the pool = %d', len(pb_devices))

        pb_device_map = []
        for pb_device_name in pb_devices:
            device = DeviceProxy(pb_device_name)
            if device.pb_id:
                LOG.info('%s %s', pb_device_name, device.pb_id)
                pb_device_map.append((pb_device_name, device.pb_id))

        return str(pb_device_map)