Пример #1
0
    def handle(self, *args, **options):
        if settings.RELEASE_ENV != "dev" and not settings.TUTORIAL_MODE:
            self.stdout.write(
                "Command can only be run on dev instances and instances "
                "with tutorial mode enabled")
            return

        if not options.get("commit"):
            self.stdout.write(
                "This will sync data from {url} to this instance, and will take "
                "roughly 20 minutes to complete on a fresh db. "
                "Run the command with `--commit` if you are sure you want "
                "to do this.".format(**options))
            return

        # settings.USE_TZ = True
        db_settings = settings.DATABASES.get("default")

        config = {
            "sync": {
                "url": options.get("url")
            },
            "orm": {
                "secret_key": settings.SECRET_KEY,
                "backend": "peeringdb_server",
                "migrate": False,
                "database": {k.lower(): v
                             for k, v in db_settings.items()},
            },
        }

        apply_defaults(ClientSchema(), config)

        pre_save.disconnect(signals.addressmodel_save,
                            sender=pdb_models.Facility)

        djpdb_models.all_models = [
            pdb_models.Organization,
            pdb_models.Facility,
            pdb_models.Network,
            pdb_models.InternetExchange,
            pdb_models.InternetExchangeFacility,
            pdb_models.IXLan,
            pdb_models.IXLanPrefix,
            pdb_models.NetworkContact,
            pdb_models.NetworkFacility,
            pdb_models.NetworkIXLan,
        ]

        SUPPORTED_BACKENDS[
            "peeringdb_server"] = "peeringdb_server.client_adaptor"

        client = Client(config)
        client.update_all(resource.all_resources(), since=None)
Пример #2
0
    def handle(config, poids, output_format, depth, remote, **_):
        client = Client(config)
        for poid in poids:
            (tag, pk) = util.split_ref(poid)
            res = resource.get_resource(tag)
            B = peeringdb.get_backend()
            try:
                obj = client.get(res, pk)
            except B.object_missing_error(B.get_concrete(res)):
                if remote:
                    obj = client.fetch(res, pk, depth)[0]
                else:
                    print(f"Not found: {tag}-{pk}", file=sys.stderr)
                    return 1

            dump(obj, depth, sys.stdout)
Пример #3
0
    def handle(config, verbose, quiet, init, **kwargs):
        rs = resource.all_resources()
        # if only: rs = [resource.get_resource(tag) for tag in only]

        loglvl = 1 + (verbose or 0) - (quiet or 0)
        if loglvl > 1:
            peeringdb._config_logs(logging.DEBUG)
        if loglvl < 1:
            peeringdb._config_logs(logging.WARNING)

        client = Client(config, **kwargs)
        # todo verify table schema
        if init: return

        if loglvl >= 0:
            print("Syncing to", config['sync']['url'])

        client.update_all(rs)
Пример #4
0
def test_dry_run(client_empty):
    client = Client(helper.CONFIG, dry_run=True)
    rs = all_resources()
    client.update_all(rs)
    # still empty?
    with pytest.raises(peeringdb.get_backend().object_missing_error()):
        client.get(Network, FIRST_NET)
Пример #5
0
    def sync(self):
        self.log_info(f"Syncing from {self.pdburl}")
        settings.USE_TZ = False
        config = {
            "sync": {
                "url": self.pdburl,
                "user": self.username,
                "password": self.password,
                "strip_tz": 1,
                "timeout": 0,
                "only": [],
            },
            "orm": {
                "database": settings.DATABASES["default"],
                "backend": "django_peeringdb",
                "migrate": True,
            },
        }

        initialize_backend("django_peeringdb", **config["orm"])

        client = Client(config, **config)
        client.update_all(resource.all_resources())
Пример #6
0
def test_auth(client_empty):

    with pytest.raises(ValueError):
        config = helper.CONFIG
        config["sync"]["user"] = "******"
        config["sync"]["password"] = "******"
        config["sync"]["api_key"] = "test"
        client = Client(config, dry_run=True)
        rs = all_resources()
        client.update_all(rs)
        client.get(Network, FIRST_NET)
Пример #7
0
    def handle(config, poids, **_):
        client = Client(config)

        def get(res, **kwargs):
            objs = client.fetch_all(res, depth=2, **kwargs)
            if not objs:
                raise peeringdb.sync.NotFoundException
            return objs

        fmt = WhoisFormat()
        for poid in poids:
            (tag, key) = util.split_ref(poid)
            try:
                data = _lookup_tag(tag, key, get)
            except peeringdb.sync.NotFoundException:
                print(f"Not found: resource for {tag}={key}", file=sys.stderr)
                return 1
            fmt.display(tag, data[0])
Пример #8
0
 def handle(config, **_):
     Client(config)
     B = peeringdb.get_backend()
     B.delete_all()
Пример #9
0
def get_pclient():
    c = Client(helper.CONFIG)
    c._updater._ContextClass = _PartialEnabledContext
    return c
Пример #10
0
def get_client():
    return Client(helper.CONFIG)