当前位置: 首页>>代码示例>>Python>>正文


Python SoftLayer.DNSManager类代码示例

本文整理汇总了Python中SoftLayer.DNSManager的典型用法代码示例。如果您正苦于以下问题:Python DNSManager类的具体用法?Python DNSManager怎么用?Python DNSManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了DNSManager类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: execute

 def execute(self, args):
     manager = DNSManager(self.client)
     zone_id = resolve_id(manager.resolve_ids, args['<zone>'], name='zone')
     try:
         return manager.dump_zone(zone_id)
     except DNSZoneNotFound:
         raise CLIAbort("No zone found matching: %s" % args['<zone>'])
开发者ID:anil-kumbhar,项目名称:softlayer-python,代码行数:7,代码来源:dns.py

示例2: list_zone

    def list_zone(client, zone, args):
        manager = DNSManager(client)
        t = Table([
            "record",
            "type",
            "ttl",
            "value",
        ])

        t.align['ttl'] = 'l'
        t.align['record'] = 'r'
        t.align['value'] = 'l'

        zone_id = resolve_id(manager.resolve_ids, args['<zone>'], name='zone')

        try:
            records = manager.get_records(
                zone_id,
                type=args.get('--type'),
                host=args.get('--record'),
                ttl=args.get('--ttl'),
                data=args.get('--data'),
            )
        except DNSZoneNotFound:
            raise CLIAbort("No zone found matching: %s" % args['<zone>'])

        for rr in records:
            t.add_row([
                rr['host'],
                rr['type'].upper(),
                rr['ttl'],
                rr['data']
            ])

        return t
开发者ID:loles,项目名称:softlayer-api-python-client,代码行数:35,代码来源:dns.py

示例3: execute

    def execute(client, args):
        manager = DNSManager(client)

        zone_id = resolve_id(manager.resolve_ids, args['<zone>'], name='zone')
        args['--ttl'] = args['--ttl'] or DNSManager.DEFAULT_TTL

        manager.create_record(
            zone_id,
            args['<record>'],
            args['<type>'],
            args['<data>'],
            ttl=args['--ttl'])
开发者ID:loles,项目名称:softlayer-api-python-client,代码行数:12,代码来源:dns.py

示例4: on_delete

    def on_delete(self, req, resp, tenant_id, domain, entry):
        client = req.env['sl_client']
        mgr = DNSManager(client)

        domain = unquote_plus(domain)

        zone_id = mgr._get_zone_id_from_name(domain)[0]

        record = mgr.get_records(zone_id, host=entry)[0]

        mgr.delete_record(record['id'])

        resp.status = 204
开发者ID:BillArnold,项目名称:barnoldjg,代码行数:13,代码来源:dns.py

示例5: on_get

    def on_get(self, req, resp, tenant_id, domain, entry=None):
        client = req.env['sl_client']
        mgr = DNSManager(client)

        domain = unquote_plus(domain)

        zone_id = mgr._get_zone_id_from_name(domain)[0]

        if entry:
            record = mgr.get_records(zone_id, host=entry)[0]

        result = get_dns_entry_dict(domain, record['host'], record['data'],
                                    record['type'], entry_id=record['id'])

        resp.body = {'dns_entry': result}
开发者ID:BillArnold,项目名称:barnoldjg,代码行数:15,代码来源:dns.py

示例6: on_put

    def on_put(self, req, resp, tenant_id, domain, entry):
        client = req.env['sl_client']
        mgr = DNSManager(client)

        body = json.loads(req.stream.read().decode())
        ip = lookup(body, 'dns_entry', 'ip')
        record_type = lookup(body, 'dns_entry', 'type')
        if not record_type:
            record_type = 'A'

        domain = unquote_plus(domain)
        zone_id = mgr._get_zone_id_from_name(domain)[0]
        mgr.create_record(zone_id=zone_id, record=entry,
                          record_type=record_type, data=ip)
        new_record = mgr.get_records(zone_id, host=entry)[0]
        result = get_dns_entry_dict(domain, entry, ip, record_type,
                                    entry_id=new_record['id'])

        resp.body = {'dns_entry': result}
开发者ID:BillArnold,项目名称:barnoldjg,代码行数:19,代码来源:dns.py

示例7: list_all_zones

    def list_all_zones(self):
        manager = DNSManager(self.client)
        zones = manager.list_zones()
        t = Table([
            "id",
            "zone",
            "serial",
            "updated",
        ])
        t.align['serial'] = 'c'
        t.align['updated'] = 'c'

        for z in zones:
            t.add_row([
                z['id'],
                z['name'],
                z['serial'],
                z['updateDate'],
            ])

        return t
开发者ID:anil-kumbhar,项目名称:softlayer-python,代码行数:21,代码来源:dns.py

示例8: list_all_zones

    def list_all_zones(self):
        """ List all zones """
        manager = DNSManager(self.client)
        zones = manager.list_zones()
        table = Table([
            "id",
            "zone",
            "serial",
            "updated",
        ])
        table.align['serial'] = 'c'
        table.align['updated'] = 'c'

        for zone in zones:
            table.add_row([
                zone['id'],
                zone['name'],
                zone['serial'],
                zone['updateDate'],
            ])

        return table
开发者ID:MayaY2014,项目名称:softlayer-python,代码行数:22,代码来源:dns.py

示例9: list_zone

    def list_zone(self, args):
        """ list records for a particular zone """
        manager = DNSManager(self.client)
        table = Table([
            "id",
            "record",
            "type",
            "ttl",
            "value",
        ])

        table.align['ttl'] = 'l'
        table.align['record'] = 'r'
        table.align['value'] = 'l'

        zone_id = resolve_id(manager.resolve_ids, args['<zone>'], name='zone')

        try:
            records = manager.get_records(
                zone_id,
                record_type=args.get('--type'),
                host=args.get('--record'),
                ttl=args.get('--ttl'),
                data=args.get('--data'),
            )
        except DNSZoneNotFound:
            raise CLIAbort("No zone found matching: %s" % args['<zone>'])

        for record in records:
            table.add_row([
                record['id'],
                record['host'],
                record['type'].upper(),
                record['ttl'],
                record['data']
            ])

        return table
开发者ID:MayaY2014,项目名称:softlayer-python,代码行数:38,代码来源:dns.py

示例10: DNSTests

class DNSTests(unittest.TestCase):

    def setUp(self):
        self.client = MagicMock()
        self.dns_client = DNSManager(self.client)

    def test_init_exercise(self):
        self.assertTrue(hasattr(self.dns_client, 'service'))
        self.assertTrue(hasattr(self.dns_client, 'record'))

    def test_list_zones(self):
        zone_list = ['test']
        self.client['Account'].getDomains.return_value = zone_list
        zones = self.dns_client.list_zones()
        self.assertEqual(zones, zone_list)

    def test_get_zone(self):
        zone_list = [
            {'id': 98765, 'name': 'test-example.com'},
            {'id': 12345, 'name': 'example.com', "resourceRecords": ["test"]},
        ]

        # match, with defaults
        self.client['Account'].getObject.return_value = zone_list[1]
        res = self.dns_client.get_zone(12345)
        self.assertEqual(res, zone_list[1])
        self.client['Account'].getObject.assert_called_once_with(
            id=12345,
            mask='resourceRecords')

        # No records masked in
        self.client['Account'].getObject.reset_mock()
        self.client['Account'].getObject.return_value = [zone_list[1]]
        self.dns_client.get_zone(12345, records=False)
        self.client['Account'].getObject.assert_called_once_with(
            id=12345,
            mask=None)

    def test_resolve_zone_name(self):
        zone_list = [{'name': 'example.com', 'id': 12345}]
        # matching domain
        self.client['Account'].getDomains.return_value = zone_list
        res = self.dns_client._get_zone_id_from_name('example.com')
        self.assertEqual([12345], res)
        self.client['Account'].getDomains.assert_called_once_with(
            filter={"domains": {"name": {"operation": "_= example.com"}}})

        # no matches
        self.client['Account'].getDomains.reset_mock()
        self.client['Account'].getDomains.return_value = []
        res = self.dns_client._get_zone_id_from_name('example.com')
        self.assertEqual([], res)
        self.client['Account'].getDomains.assert_called_once_with(
            filter={"domains": {"name": {"operation": "_= example.com"}}})

    def test_create_zone(self):
        call = self.client['Dns_Domain'].createObject
        call.return_value = {'name': 'example.com'}

        res = self.dns_client.create_zone('example.com')

        call.assert_called_once_with({
            'name': 'example.com', "resourceRecords": {}, "serial": ANY
        })

        self.assertEqual(res, {'name': 'example.com'})

    def test_delete_zone(self):
        self.dns_client.delete_zone(1)
        self.client['Dns_Domain'].deleteObject.assert_called_once_with(id=1)

    def test_edit_zone(self):
        self.dns_client.edit_zone('example.com')
        self.client['Dns_Domain'].editObject.assert_called_once_with(
            'example.com')

    def test_create_record(self):
        self.dns_client.create_record(1, 'test', 'TXT', 'testing', ttl=1200)

        f = self.client['Dns_Domain_ResourceRecord'].createObject
        f.assert_called_once_with(
            {
                'domainId': 1,
                'ttl': 1200,
                'host': 'test',
                'type': 'TXT',
                'data': 'testing'
            })

    def test_delete_record(self):
        self.dns_client.delete_record(1)
        f = self.client['Dns_Domain_ResourceRecord'].deleteObject
        f.assert_called_once_with(id=1)

    def test_edit_record(self):
        self.dns_client.edit_record({'id': 1, 'name': 'test', 'ttl': '1800'})
        f = self.client['Dns_Domain_ResourceRecord'].editObject
        f.assert_called_once_with(
            {'id': 1, 'name': 'test', 'ttl': '1800'},
            id=1
#.........这里部分代码省略.........
开发者ID:loles,项目名称:softlayer-api-python-client,代码行数:101,代码来源:dns_tests.py

示例11: setUp

 def setUp(self):
     self.client = MagicMock()
     self.dns_client = DNSManager(self.client)
开发者ID:loles,项目名称:softlayer-api-python-client,代码行数:3,代码来源:dns_tests.py

示例12: dns_sync

    def dns_sync(self, args):
        """ Sync DNS records to match the FQDN of the CCI """
        dns = DNSManager(self.client)
        cci = CCIManager(self.client)

        cci_id = resolve_id(cci.resolve_ids, args.get('<identifier>'), 'CCI')
        instance = cci.get_instance(cci_id)
        zone_id = resolve_id(dns.resolve_ids, instance['domain'], name='zone')

        def sync_a_record():
            """ Sync A record """
            records = dns.get_records(
                zone_id,
                host=instance['hostname'],
            )

            if not records:
                # don't have a record, lets add one to the base zone
                dns.create_record(
                    zone['id'],
                    instance['hostname'],
                    'a',
                    instance['primaryIpAddress'],
                    ttl=args['--ttl'])
            else:
                recs = [x for x in records if x['type'].lower() == 'a']
                if len(recs) != 1:
                    raise CLIAbort("Aborting A record sync, found %d "
                                   "A record exists!" % len(recs))
                rec = recs[0]
                rec['data'] = instance['primaryIpAddress']
                rec['ttl'] = args['--ttl']
                dns.edit_record(rec)

        def sync_ptr_record():
            """ Sync PTR record """
            host_rec = instance['primaryIpAddress'].split('.')[-1]
            ptr_domains = self.client['Virtual_Guest'].\
                getReverseDomainRecords(id=instance['id'])[0]
            edit_ptr = None
            for ptr in ptr_domains['resourceRecords']:
                if ptr['host'] == host_rec:
                    ptr['ttl'] = args['--ttl']
                    edit_ptr = ptr
                    break

            if edit_ptr:
                edit_ptr['data'] = instance['fullyQualifiedDomainName']
                dns.edit_record(edit_ptr)
            else:
                dns.create_record(
                    ptr_domains['id'],
                    host_rec,
                    'ptr',
                    instance['fullyQualifiedDomainName'],
                    ttl=args['--ttl'])

        if not instance['primaryIpAddress']:
            raise CLIAbort('No primary IP address associated with this CCI')

        try:
            zone = dns.get_zone(zone_id)
        except DNSZoneNotFound:
            raise CLIAbort("Unable to create A record, "
                           "no zone found matching: %s" % instance['domain'])

        go_for_it = args['--really'] or confirm(
            "Attempt to update DNS records for %s"
            % instance['fullyQualifiedDomainName'])

        if not go_for_it:
            raise CLIAbort("Aborting DNS sync")

        both = False
        if not args['--ptr'] and not args['-a']:
            both = True

        if both or args['-a']:
            sync_a_record()

        if both or args['--ptr']:
            sync_ptr_record()
开发者ID:TimurNurlygayanov,项目名称:softlayer-python,代码行数:82,代码来源:cci.py

示例13: setUp

 def setUp(self):
     self.client = FixtureClient()
     self.dns_client = DNSManager(self.client)
开发者ID:MayaY2014,项目名称:softlayer-python,代码行数:3,代码来源:dns_tests.py


注:本文中的SoftLayer.DNSManager类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。