Esempio n. 1
0
    def _create_or_associate_extension(self, line, extension):
        existing_extension = self._get_first_existing_extension(extension)

        if not existing_extension:
            existing_extension = confd.extensions.create(extension)

        if existing_extension:
            confd.lines(line).add_extension(existing_extension)
Esempio n. 2
0
    def _delete_user_associations(self, user):
        if user.get('voicemail'):
            confd.users(user['uuid']).remove_voicemail()

        lines = user.get('lines', [])
        for line in lines:
            device_id = confd.lines.get(line['id'])['device_id']
            if device_id:
                confd.lines(line['id']).remove_device(device_id)
            confd.lines.delete(line)
 def create(self, resource):
     resource_created = super(LineService, self).create(resource)
     resource['id'] = resource_created['id']
     if resource.get('endpoint_sip'):
         endpoint_sip = confd.endpoints_sip.create(resource['endpoint_sip'])
         confd.lines(resource['id']).add_endpoint_sip(endpoint_sip['id'])
     if resource.get('endpoint_custom'):
         endpoint_custom = confd.endpoints_custom.create(
             resource['endpoint_custom'])
         confd.lines(resource['id']).add_endpoint_custom(
             endpoint_custom['id'])
Esempio n. 4
0
    def _update_line_and_associations(self, line):
        if line.get('endpoint_sip'):
            # If we move from SIP to WEBRTC
            if 'options' in line['endpoint_sip']:
                self._update_endoint_sip_webrtc(line['endpoint_sip'])
            confd.endpoints_sip.update(line['endpoint_sip'])

        extensions = line.get('extensions', [])
        if extensions and extensions[0].get('id'):
            existing_extension = confd.extensions.get(extensions[0])
            if self._is_extension_has_changed(extensions[0], existing_extension):
                if self._is_extension_associated_with_other_lines(existing_extension):
                    confd.lines(line).remove_extension(extensions[0])
                    extension_created = confd.extensions.create(extensions[0])
                    confd.lines(line).add_extension(extension_created)
                else:
                    confd.extensions.update(extensions[0])

        elif extensions:
            self._create_or_associate_extension(line, extensions[0])

        else:
            existing_extensions = confd.lines.get(line['id']).get('extensions')
            if existing_extensions:
                confd.lines(line).remove_extension(existing_extensions[0])
                confd.extensions.delete(existing_extensions[0])

        confd.lines.update(line)
Esempio n. 5
0
    def _update_device_association(self, line_id, device_id):
        existing_device_id = confd.lines.get(line_id)['device_id']

        if not device_id and not existing_device_id:
            return
        if device_id == existing_device_id:
            return

        if not device_id and existing_device_id:
            confd.lines(line_id).remove_device(existing_device_id)
        elif device_id and not existing_device_id:
            confd.lines(line_id).add_device(device_id)
        elif device_id != existing_device_id:
            confd.lines(line_id).remove_device(existing_device_id)
            confd.lines(line_id).add_device(device_id)
Esempio n. 6
0
    def _update_user_lines(self, existing_user, user):
        lines = user.get('lines', [])
        line_ids = set([l.get('id') for l in lines])
        existing_lines = existing_user['lines']
        existing_line_ids = set([l['id'] for l in existing_lines])

        line_ids_to_remove = existing_line_ids - line_ids
        for line_id in line_ids_to_remove:
            device_id = confd.lines.get(line_id)['device_id']
            if device_id:
                confd.lines(line_id).remove_device(device_id)
            confd.lines.delete(line_id)

        for line in lines:
            if line.get('id'):
                self._update_line_and_associations(line)
                self._update_device_association(line['id'], line.get('device_id'))
            else:
                line = self._create_line_and_associations(line)
                if line.get('device_id'):
                    confd.lines(line).add_device(line['device_id'])

        if line_ids != existing_line_ids or self._get_first_line_id(lines) != self._get_first_line_id(existing_lines):
            confd.users(user).update_lines(lines)
Esempio n. 7
0
    def _create_line_and_associations(self, line):
        line['id'] = confd.lines.create(line)['id']

        if 'endpoint_sip' in line:
            endpoint_sip = confd.endpoints_sip.create(line['endpoint_sip'])
            if endpoint_sip:
                confd.lines(line).add_endpoint_sip(endpoint_sip)
        elif 'endpoint_sccp' in line:
            endpoint_sccp = confd.endpoints_sccp.create(line['endpoint_sccp'])
            if endpoint_sccp:
                confd.lines(line).add_endpoint_sccp(endpoint_sccp)
        elif 'endpoint_custom' in line:
            endpoint_custom = confd.endpoints_custom.create(line['endpoint_custom'])
            if endpoint_custom:
                confd.lines(line).add_endpoint_custom(endpoint_custom)
        else:
            logger.debug('No endpoint found for line: %s', line)
            return line

        if line.get('extensions'):
            self._create_or_associate_extension(line, line['extensions'][0])

        return line