Пример #1
0
 def _get_or_create_cdn(cls, cdn_id, create=True):
     try:
         return CDN.get(CDN.id == cdn_id), False
     except DoesNotExist:
         if create:
             return CDN.create(id=cdn_id), True
         return None, None
Пример #2
0
 def _get_or_create_cdn(cls, cdn_id, create=True):
     try:
         return CDN.get(CDN.id == cdn_id), False
     except DoesNotExist:
         if create:
             return CDN.create(id=cdn_id), True
         return None, None
Пример #3
0
def get_cdns(context, request):
    page = request.params.get('page', 0)
    num_per_page = request.params.get('num_per_page', 5)

    if num_per_page <= 0:
        result = CDN.select()
    else:
        result = CDN.select().paginate(page, num_per_page)
    cdns = [serialize_cdn(cdn) for cdn in result]

    request.reply(cdns)
Пример #4
0
 def _get_or_bootstrap_cdn(self, cdn_id):
     try:
         return CDN.get(CDN.id == cdn_id)
     except DoesNotExist:
         try:
             cdn_data = self.bootstrapper.lookup_cdn(id)
             cdn = CDN(**cdn_data)
             cdn.save(force_insert=True)
             return cdn
         except BootstrapError:
             raise DoesNotExist
Пример #5
0
def get_cdns(context, request):
    page = request.params.get('page', 0)
    num_per_page = request.params.get('num_per_page', 5)

    if num_per_page <= 0:
        result = CDN.select()
    else:
        result = CDN.select().paginate(page, num_per_page)
    cdns = [serialize_cdn(cdn) for cdn in result]

    request.reply(cdns)
Пример #6
0
 def cdn_list(self):
     """
     List CDNs registered with CacheBrowser
     """
     cdns = CDN.select()
     for cdn in cdns:
         self.send_line("%*s:  %s" % (15, cdn.id, ' '.join(cdn.addresses)))
Пример #7
0
 def cdn_list(self):
     """
     List CDNs registered with CacheBrowser
     """
     cdns = CDN.select()
     for cdn in cdns:
         self.send_line("%*s:  %s" % (15, cdn.id, ' '.join(cdn.addresses)))
Пример #8
0
    def test_database(self):
        initialize_database(":memory:", reset=True)

        cdn1 = CDN.create(id="cdn1", name="Sample CDN", edge_server="1.2.3.4")
        cdn2 = CDN.create(id="cdn2", name="Sample CDN2", edge_server="1.2.3.5")
        host1 = Host.create(hostname="first.host", cdn=cdn1)
        host2 = Host.create(hostname="second.host", cdn=cdn2)
        host3 = Host.create(hostname="third.host", cdn=cdn1)

        self.assertEqual([host1, host2, host3], list(Host.select()))
        self.assertEqual([host1, host3], Host.select().where(Host.cdn == cdn1))
        self.assertEqual([host1, host3], Host.select().join(CDN).where(CDN.id == 'cdn1'))
        self.assertEqual(host2, Host.get(Host.cdn == cdn2))

        self.assertEqual([], CDN.select().where(CDN.id == "doesntexist"))
        with self.assertRaises(DoesNotExist):
            CDN.get(CDN.id == "doesntexist")
Пример #9
0
def add_cdn(context, request):
    cdn = CDN()
    cdn.id = request.params.get('id', '')
    cdn.name = request.params.get('name', '')
    cdn.edge_server = request.params.get('edge_server', True)

    cdn.save(force_insert=True)
    request.reply()
Пример #10
0
def add_cdn(context, request):
    cdn = CDN()
    cdn.id = request.params.get('id', '')
    cdn.name = request.params.get('name', '')
    cdn.edge_server = request.params.get('edge_server', True)

    cdn.save(force_insert=True)
    request.reply()
Пример #11
0
    def _get_or_bootstrap_host(self, hostname):
        try:
            return Host.get(Host.hostname == hostname)
        except DoesNotExist:
            try:
                host_data = self.bootstrapper.lookup_host(hostname)
            except BootstrapError:
                raise DoesNotExist

            host = Host(**host_data)

            try:
                host.cdn = self._get_or_bootstrap_cdn(host.cdn_id)
            except DoesNotExist:
                host.cdn = CDN.create(id=host.cdn_id, valid=False)

            host.save(force_insert=True)

            return host
Пример #12
0
    def test_bootstrap(self):
        self.bootstrapper.bootstrap('the.host')

        self.assertTrue(Host.select().where(Host.hostname == 'the.host').exists())
        self.assertTrue(CDN.select().where(CDN.id == 'thecdn').exists())
Пример #13
0
 def test_unavailable_host__host_in_db__available_cdn__cdn_in_db_with_no_edge(self):
     cdn = CDN.create(id="thecdn")
     Host.create(hostname="host.db", cdn=cdn)
     self.bootstrapper.bootstrap('host.db')
Пример #14
0
    def test_unavailable_host__host_in_db__unavailable_cdn__cdn_in_db_with_no_edge(self):
        cdn = CDN.create(id="missingcdn")
        Host.create(hostname="host.db", cdn=cdn)

        with self.assertRaises(CDNNotAvailableError):
            self.bootstrapper.bootstrap('missingcdn.host')