示例#1
0
 def handle_sync(self):
     connect()
     for c in Collection.iter_collections():
         try:
             c.sync()
         except ValueError as e:
             self.die(str(e))
示例#2
0
    def handle_export(self, list_collection=False, 
                      export_path=None, export_collections=None, 
                      export_model_names=None, export_model_uuids=None):
        MODELS = {}
        for c in COLLECTIONS:
            cm = get_model(c)
            cn = cm._meta["json_collection"]
            MODELS[cn] = cm
        if list_collection is not None:
            if list_collection is True:
                for c in Collection.iter_collections():
                    print("%s" % c.name, file=self.stdout)
            else:
                if list_collection not in MODELS:
                    print("Collection not found", file=self.stdout)
                    return
                objs = MODELS[list_collection].objects.all().order_by('name')
                for o in objs:
                    print("uuid:%s name:\"%s\"" % (o.uuid, o.name),
                          file=self.stdout)
        else:
            if not export_path or not export_collections:
                return
            if not os.path.isdir(export_path):
                self.die("Path not found: %s" % export_path)

            for ecname in export_collections:
                if ecname not in MODELS:
                    print("Collection not found", file=self.stdout)
                    continue
                kwargs = {}
                if export_model_names:
                    kwargs['name__in'] = export_model_names
                elif export_model_uuids:
                    kwargs['uuid__in'] = export_model_uuids
                objs = MODELS[ecname].objects.filter(**kwargs).order_by('name')
                for o in objs:
                    path = os.path.join(
                        export_path,
                        ecname,
                        o.get_json_path()
                    )
                    print("export \"%s\" to %s" % (o.name, path),
                          file=self.stdout)
                    safe_rewrite(
                        path,
                        o.to_json(),
                        mode=0o644
                    )
示例#3
0
# Copyright (C) 2007-2019 The NOC Project
# See LICENSE for details
# ----------------------------------------------------------------------

# NOC modules
import operator
import os

# Third-party modules
import pytest

# NOC modules
from noc.core.collection.base import Collection


@pytest.fixture(params=list(Collection.iter_collections()), ids=operator.attrgetter("name"))
def collection(request):
    return request.param


@pytest.mark.xfail
def test_collection_path(collection):
    assert any(os.path.isdir(p) for p in collection.get_path())


@pytest.mark.usefixtures("database")
def test_collection_load(database, collection):
    """
    Load collection
    :param database:
    :return:
示例#4
0
# Copyright (C) 2007-2019 The NOC Project
# See LICENSE for details
# ----------------------------------------------------------------------

# NOC modules
import operator
import os

# Third-party modules
import pytest

# NOC modules
from noc.core.collection.base import Collection


@pytest.fixture(params=list(Collection.iter_collections()),
                ids=operator.attrgetter("name"))
def collection(request):
    return request.param


@pytest.mark.xfail
def test_collection_path(collection):
    assert any(os.path.isdir(p) for p in collection.get_path())


@pytest.mark.usefixtures("database")
def test_collection_load(database, collection):
    """
    Load collection
    :param database: