예제 #1
0
    def generate_trunks(self, output):
        writer = AsteriskFileWriter(output)
        endpoints = asterisk_conf_dao.find_sip_trunk_settings()
        for endpoint in endpoints:
            name = endpoint['name']
            label = endpoint.get('label')
            endpoint_section_options = endpoint.get('endpoint_section_options',
                                                    [])
            registration_section_options = endpoint.get(
                'registration_section_options', [])
            writer.write_section(name, comment=label)
            writer.write_options(endpoint_section_options)
            sections = {
                'identify_section_options': name,
                'registration_section_options': name,
            }
            for key, value in endpoint_section_options:
                if key == 'auth':
                    sections['auth_section_options'] = value
                elif key == 'aors':
                    sections['aor_section_options'] = value
                elif key == 'outbound_auth':
                    sections['outbound_auth_section_options'] = value
            for key, value in registration_section_options:
                if key == 'outbound_auth':
                    sections[
                        'registration_outbound_auth_section_options'] = value

            for key in sorted(sections):
                options = endpoint.get(key)
                if not options:
                    continue

                writer.write_section(sections[key])
                writer.write_options(options)
예제 #2
0
 def generate_transports(self, output):
     writer = AsteriskFileWriter(output)
     transports = transport_dao.search()
     for transport in transports.items:
         writer.write_section(transport.name)
         writer.write_option('type', 'transport')
         writer.write_options(transport.options)
예제 #3
0
 def setUp(self):
     self.output = StringIO.StringIO()
     self.ast_file = AsteriskFileWriter(self.output)
예제 #4
0
class TestAsteriskFileWriter(unittest.TestCase):
    def setUp(self):
        self.output = StringIO.StringIO()
        self.ast_file = AsteriskFileWriter(self.output)

    def test_write_section(self):
        self.ast_file.write_section('foobar')

        assert_that(self.output.getvalue(), equal_to('[foobar]\n'))

    def test_write_section_tpl(self):
        self.ast_file.write_section_tpl('foobar')

        assert_that(self.output.getvalue(), equal_to('[foobar](!)\n'))

    def test_write_section_using_tpl(self):
        self.ast_file.write_section_using_tpl('foobar', 'base')

        assert_that(self.output.getvalue(), equal_to('[foobar](base)\n'))

    def test_write_option(self):
        self.ast_file.write_option('foo', 'bar')

        assert_that(self.output.getvalue(), equal_to('foo = bar\n'))

    def test_write_options(self):
        self.ast_file.write_options([('foo', 'bar'), ('pow', 'bang')])

        assert_that(self.output.getvalue(),
                    equal_to('foo = bar\npow = bang\n'))

    def test_write_object_option(self):
        self.ast_file.write_object_option('foo', 'bar')

        assert_that(self.output.getvalue(), equal_to('foo => bar\n'))
예제 #5
0
 def generate(self, output):
     ast_file = AsteriskFileWriter(output)
     self._generate_general(ast_file)
     self._generate_default_parking_lot(ast_file)
     self._generate_parking_lots(ast_file)
예제 #6
0
 def generate(self, output):
     ast_file = AsteriskFileWriter(output)
     self._generate_general(ast_file)
     self._generate_featuremap(ast_file)
     self._generate_applicationmap(ast_file)
예제 #7
0
    def generate(self, output):
        queue_penalty_settings = asterisk_conf_dao.find_queue_penalty_settings()
        penalties = dict((itm['id'], itm['name']) for itm in queue_penalty_settings)

        writer = AsteriskFileWriter(output)

        writer.write_section('general')
        for item in asterisk_conf_dao.find_queue_general_settings():
            writer.write_option(item['var_name'], item['var_val'])

        for q in asterisk_conf_dao.find_queue_settings():
            writer.write_section(q['name'], comment=q['label'])

            for k, v in q.iteritems():
                if k in self._ignored_keys:
                    continue
                if v is None or (isinstance(v, basestring) and not v):
                    continue

                if k == 'defaultrule':
                    if int(v) not in penalties:
                        continue
                    v = penalties[int(v)]

                writer.write_option(k, v)

            queuemember_settings = asterisk_conf_dao.find_queue_members_settings(q['name'])
            for values in queuemember_settings:
                writer.write_option('member', ','.join(values))
예제 #8
0
 def generate_meeting_guests(self, output):
     writer = AsteriskFileWriter(output)
     endpoints = asterisk_conf_dao.find_sip_meeting_guests_settings()
     for endpoint in endpoints:
         self._write_simple_endpoint(writer, endpoint)