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


Python config.Config类代码示例

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


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

示例1: test_upload_previous_checksum

def test_upload_previous_checksum(server, tmpdir):

    content = ''.join(['a' for _ in range(0, 1025)])

    with open(str(tmpdir / "test"), "w+") as f:
        f.write(content)
    body = aiohttp.FormData()
    body.add_field("type", "QEMU")
    body.add_field("file", open(str(tmpdir / "test"), "rb"), content_type="application/iou", filename="test2")

    Config.instance().set("Server", "images_path", str(tmpdir))

    os.makedirs(str(tmpdir / "QEMU"))

    with open(str(tmpdir / "QEMU" / "test2.md5sum"), 'w+') as f:
        f.write("FAKE checksum")

    response = server.post('/upload', api_version=None, body=body, raw=True)

    assert "test2" in response.body.decode("utf-8")

    with open(str(tmpdir / "QEMU" / "test2")) as f:
        assert f.read() == content

    with open(str(tmpdir / "QEMU" / "test2.md5sum")) as f:
        checksum = f.read()
        assert checksum == "ae187e1febee2a150b64849c32d566ca"
开发者ID:lykinsbd,项目名称:gns3-server,代码行数:27,代码来源:test_upload.py

示例2: test_backup_projects

def test_backup_projects(server, tmpdir, loop):
    Config.instance().set('Server', 'projects_path', str(tmpdir))

    os.makedirs(str(tmpdir / 'a'))
    with open(str(tmpdir / 'a' / 'a.gns3'), 'w+') as f:
        f.write('hello')
    os.makedirs(str(tmpdir / 'b'))
    with open(str(tmpdir / 'b' / 'b.gns3'), 'w+') as f:
        f.write('world')

    response = server.get('/backup/projects.tar', api_version=None, raw=True)
    assert response.status == 200
    assert response.headers['CONTENT-TYPE'] == 'application/x-gtar'

    with open(str(tmpdir / 'projects.tar'), 'wb+') as f:
        print(len(response.body))
        f.write(response.body)

    tar = tarfile.open(str(tmpdir / 'projects.tar'), 'r')
    os.makedirs(str(tmpdir / 'extract'))
    os.chdir(str(tmpdir / 'extract'))
    # Extract to current working directory
    tar.extractall()
    tar.close()

    assert os.path.exists(os.path.join('a', 'a.gns3'))
    assert open(os.path.join('a', 'a.gns3')).read() == 'hello'

    assert os.path.exists(os.path.join('b', 'b.gns3'))
    assert open(os.path.join('b', 'b.gns3')).read() == 'world'
开发者ID:DenerThiago21,项目名称:gns3-server,代码行数:30,代码来源:test_upload.py

示例3: test_upload_projects_backup

def test_upload_projects_backup(server, tmpdir):
    Config.instance().set("Server", "projects_path", str(tmpdir / 'projects'))
    os.makedirs(str(tmpdir / 'projects' / 'b'))
    # An old b image that we need to replace
    with open(str(tmpdir / 'projects' / 'b' / 'b.img'), 'w+') as f:
        f.write('bad')

    os.makedirs(str(tmpdir / 'old' / 'a'))
    with open(str(tmpdir / 'old' / 'a' / 'a.img'), 'w+') as f:
        f.write('hello')
    os.makedirs(str(tmpdir / 'old' / 'b'))
    with open(str(tmpdir / 'old' / 'b' / 'b.img'), 'w+') as f:
        f.write('world')

    os.chdir(str(tmpdir / 'old'))
    with tarfile.open(str(tmpdir / 'test.tar'), 'w') as tar:
        tar.add('.', recursive=True)

    body = aiohttp.FormData()
    body.add_field('type', 'PROJECTS')
    body.add_field('file', open(str(tmpdir / 'test.tar'), 'rb'), content_type='application/x-gtar', filename='test.tar')
    response = server.post('/upload', api_version=None, body=body, raw=True)
    assert response.status == 200

    with open(str(tmpdir / 'projects' / 'a' / 'a.img')) as f:
        assert f.read() == 'hello'
    with open(str(tmpdir / 'projects' / 'b' / 'b.img')) as f:
        assert f.read() == 'world'

    assert 'a.img' not in response.body.decode('utf-8')
    assert 'b.img' not in response.body.decode('utf-8')
    assert not os.path.exists(str(tmpdir / 'projects' / 'archive.tar'))
开发者ID:DenerThiago21,项目名称:gns3-server,代码行数:32,代码来源:test_upload.py

示例4: __init__

    def __init__(self, name, *args, **kwargs):
        config = Config.instance()

        # a new process start when calling IModule
        IModule.__init__(self, name, *args, **kwargs)
        self._host = kwargs["host"]
        self._projects_dir = kwargs["projects_dir"]
        self._tempdir = kwargs["temp_dir"]
        self._working_dir = self._projects_dir
        self._heartbeat_file = "%s/heartbeat_file_for_gnsdms" % (
            self._tempdir)

        if 'heartbeat_file' in kwargs:
            self._heartbeat_file = kwargs['heartbeat_file']

        self._is_enabled = False
        try:
            cloud_config = Config.instance().get_section_config("CLOUD_SERVER")
            instance_id = cloud_config["instance_id"]
            cloud_user_name = cloud_config["cloud_user_name"]
            cloud_api_key = cloud_config["cloud_api_key"]
            self._is_enabled = True
        except KeyError:
            log.critical("Missing cloud.conf - disabling Deadman Switch")

        self._deadman_process = None
        self.heartbeat()
        self.start()
开发者ID:planctechnologies,项目名称:gns3-server,代码行数:28,代码来源:__init__.py

示例5: main

def main():
    """
    Entry point for GNS3 server
    """

    level = logging.INFO
    args = parse_arguments(sys.argv[1:], Config.instance().get_section_config("Server"))
    if args.debug:
        level = logging.DEBUG

    user_log = init_logger(level, logfile=args.log, quiet=args.quiet)
    user_log.info("GNS3 server version {}".format(__version__))
    current_year = datetime.date.today().year
    user_log.info("Copyright (c) 2007-{} GNS3 Technologies Inc.".format(current_year))

    for config_file in Config.instance().get_config_files():
        user_log.info("Config file {} loaded".format(config_file))

    set_config(args)
    server_config = Config.instance().get_section_config("Server")
    if server_config.getboolean("local"):
        log.warning("Local mode is enabled. Beware, clients will have full control on your filesystem")

    # we only support Python 3 version >= 3.3
    if sys.version_info < (3, 3):
        raise RuntimeError("Python 3.3 or higher is required")

    user_log.info("Running with Python {major}.{minor}.{micro} and has PID {pid}".format(
                  major=sys.version_info[0], minor=sys.version_info[1],
                  micro=sys.version_info[2], pid=os.getpid()))

    # check for the correct locale (UNIX/Linux only)
    locale_check()

    try:
        os.getcwd()
    except FileNotFoundError:
        log.critical("The current working directory doesn't exist")
        return

    Project.clean_project_directory()

    CrashReport.instance()
    host = server_config["host"]
    port = int(server_config["port"])
    server = Server.instance(host, port)
    try:
        server.run()
    except OSError as e:
        # This is to ignore OSError: [WinError 0] The operation completed successfully exception on Windows.
        if not sys.platform.startswith("win") and not e.winerror == 0:
            raise
    except Exception as e:
        log.critical("Critical error while running the server: {}".format(e), exc_info=1)
        CrashReport.instance().capture_exception()
        return
开发者ID:AshokVardhn,项目名称:gns3-server,代码行数:56,代码来源:main.py

示例6: parse_arguments

def parse_arguments(argv):
    """
    Parse command line arguments and override local configuration

    :params args: Array of command line arguments
    """

    parser = argparse.ArgumentParser(description="GNS3 server version {}".format(__version__))
    parser.add_argument("-v", "--version", help="show the version", action="version", version=__version__)
    parser.add_argument("--host", help="run on the given host/IP address")
    parser.add_argument("--port", help="run on the given port", type=int)
    parser.add_argument("--ssl", action="store_true", help="run in SSL mode")
    parser.add_argument("--controller", action="store_true", help="start as a GNS3 controller")
    parser.add_argument("--config", help="Configuration file")
    parser.add_argument("--certfile", help="SSL cert file")
    parser.add_argument("--certkey", help="SSL key file")
    parser.add_argument("--record", help="save curl requests into a file (for developers)")
    parser.add_argument("-L", "--local", action="store_true", help="local mode (allows some insecure operations)")
    parser.add_argument("-A", "--allow", action="store_true", help="allow remote connections to local console ports")
    parser.add_argument("-q", "--quiet", action="store_true", help="do not show logs on stdout")
    parser.add_argument("-d", "--debug", action="store_true", help="show debug logs")
    parser.add_argument("--live", action="store_true", help="enable code live reload")
    parser.add_argument("--shell", action="store_true", help="start a shell inside the server (debugging purpose only you need to install ptpython before)")
    parser.add_argument("--log", help="send output to logfile instead of console")
    parser.add_argument("--daemon", action="store_true", help="start as a daemon")
    parser.add_argument("--pid", help="store process pid")

    args = parser.parse_args(argv)
    if args.config:
        Config.instance(files=[args.config])

    config = Config.instance().get_section_config("Server")
    defaults = {
        "host": config.get("host", "0.0.0.0"),
        "port": config.get("port", 3080),
        "ssl": config.getboolean("ssl", False),
        "certfile": config.get("certfile", ""),
        "certkey": config.get("certkey", ""),
        "record": config.get("record", ""),
        "local": config.getboolean("local", False),
        "controller": config.getboolean("controller", False),
        "allow": config.getboolean("allow_remote_console", False),
        "quiet": config.getboolean("quiet", False),
        "debug": config.getboolean("debug", False),
        "live": config.getboolean("live", False),
        "logfile": config.getboolean("logfile", ""),
    }

    parser.set_defaults(**defaults)
    return parser.parse_args(argv)
开发者ID:ravirajsdeshmukh,项目名称:gns3-server,代码行数:50,代码来源:run.py

示例7: test_upload

def test_upload(server, tmpdir):

    with open(str(tmpdir / "test"), "w+") as f:
        f.write("TEST")
    body = aiohttp.FormData()
    body.add_field("type", "QEMU")
    body.add_field("file", open(str(tmpdir / "test"), "rb"), content_type="application/iou", filename="test2")

    Config.instance().set("Server", "images_path", str(tmpdir))
    response = server.post('/upload', api_version=None, body=body, raw=True)

    with open(str(tmpdir / "QEMU" / "test2")) as f:
        assert f.read() == "TEST"

    assert "test2" in response.body.decode("utf-8")
开发者ID:DenerThiago21,项目名称:gns3-server,代码行数:15,代码来源:test_upload.py

示例8: __init__

    def __init__(self, path, working_dir, host='127.0.0.1', console_host='0.0.0.0'):

        self._hypervisors = []
        self._path = path
        self._working_dir = working_dir
        self._console_host = console_host
        self._host = console_host  # FIXME: Dynamips must be patched to bind on a different address than the one used by the hypervisor.

        config = Config.instance()
        dynamips_config = config.get_section_config("DYNAMIPS")
        self._hypervisor_start_port_range = dynamips_config.get("hypervisor_start_port_range", 7200)
        self._hypervisor_end_port_range = dynamips_config.get("hypervisor_end_port_range", 7700)
        self._console_start_port_range = dynamips_config.get("console_start_port_range", 2001)
        self._console_end_port_range = dynamips_config.get("console_end_port_range", 2500)
        self._aux_start_port_range = dynamips_config.get("aux_start_port_range", 2501)
        self._aux_end_port_range = dynamips_config.get("aux_end_port_range", 3000)
        self._udp_start_port_range = dynamips_config.get("udp_start_port_range", 10001)
        self._udp_end_port_range = dynamips_config.get("udp_end_port_range", 20000)
        self._ghost_ios_support = dynamips_config.get("ghost_ios_support", True)
        self._mmap_support = dynamips_config.get("mmap_support", True)
        self._jit_sharing_support = dynamips_config.get("jit_sharing_support", False)
        self._sparse_memory_support = dynamips_config.get("sparse_memory_support", True)
        self._allocate_hypervisor_per_device = dynamips_config.get("allocate_hypervisor_per_device", True)
        self._memory_usage_limit_per_hypervisor = dynamips_config.get("memory_usage_limit_per_hypervisor", 1024)
        self._allocate_hypervisor_per_ios_image = dynamips_config.get("allocate_hypervisor_per_ios_image", True)
开发者ID:planctechnologies,项目名称:gns3-server,代码行数:25,代码来源:hypervisor_manager.py

示例9: test_index_upload

def test_index_upload(server, tmpdir):

    Config.instance().set("Server", "images_path", str(tmpdir))

    open(str(tmpdir / "alpha"), "w+").close()
    open(str(tmpdir / "alpha.md5sum"), "w+").close()
    open(str(tmpdir / ".beta"), "w+").close()

    response = server.get('/upload', api_version=None)
    assert response.status == 200
    html = response.html
    assert "GNS3 Server" in html
    assert "Select & Upload" in html
    assert "alpha" in html
    assert ".beta" not in html
    assert "alpha.md5sum" not in html
开发者ID:lykinsbd,项目名称:gns3-server,代码行数:16,代码来源:test_upload.py

示例10: import_project

    def import_project(request, response):

        controller = Controller.instance()

        if request.get("path"):
            config = Config.instance()
            if config.get_section_config("Server").getboolean("local", False) is False:
                response.set_status(403)
                return
        path = request.json.get("path")
        name = request.json.get("name")

        # We write the content to a temporary location and after we extract it all.
        # It could be more optimal to stream this but it is not implemented in Python.
        # Spooled means the file is temporary kept in memory until max_size is reached
        try:
            with tempfile.SpooledTemporaryFile(max_size=10000) as temp:
                while True:
                    packet = yield from request.content.read(512)
                    if not packet:
                        break
                    temp.write(packet)
                project = yield from import_project(controller, request.match_info["project_id"], temp, location=path, name=name)
        except OSError as e:
            raise aiohttp.web.HTTPInternalServerError(text="Could not import the project: {}".format(e))

        response.json(project)
        response.set_status(201)
开发者ID:AJNOURI,项目名称:gns3-server,代码行数:28,代码来源:project_handler.py

示例11: import_project

    async def import_project(request, response):

        controller = Controller.instance()

        if request.get("path"):
            config = Config.instance()
            if config.get_section_config("Server").getboolean("local", False) is False:
                response.set_status(403)
                return
        path = request.json.get("path")
        name = request.json.get("name")

        # We write the content to a temporary location and after we extract it all.
        # It could be more optimal to stream this but it is not implemented in Python.
        try:
            begin = time.time()
            with tempfile.TemporaryDirectory() as tmpdir:
                temp_project_path = os.path.join(tmpdir, "project.zip")
                async with aiofiles.open(temp_project_path, 'wb') as f:
                    while True:
                        chunk = await request.content.read(CHUNK_SIZE)
                        if not chunk:
                            break
                        await f.write(chunk)

                with open(temp_project_path, "rb") as f:
                    project = await import_project(controller, request.match_info["project_id"], f, location=path, name=name)

            log.info("Project '{}' imported in {:.4f} seconds".format(project.name, time.time() - begin))
        except OSError as e:
            raise aiohttp.web.HTTPInternalServerError(text="Could not import the project: {}".format(e))
        response.json(project)
        response.set_status(201)
开发者ID:GNS3,项目名称:gns3-server,代码行数:33,代码来源:project_handler.py

示例12: __init__

    def __init__(self, name, *args, **kwargs):

        # get the VPCS location
        config = Config.instance()
        vpcs_config = config.get_section_config(name.upper())
        self._vpcs = vpcs_config.get("vpcs_path")
        if not self._vpcs or not os.path.isfile(self._vpcs):
            paths = [os.getcwd()] + os.environ["PATH"].split(os.pathsep)
            # look for VPCS in the current working directory and $PATH
            for path in paths:
                try:
                    if "vpcs" in os.listdir(path) and os.access(os.path.join(path, "vpcs"), os.X_OK):
                        self._vpcs = os.path.join(path, "vpcs")
                        break
                except OSError:
                    continue

        if not self._vpcs:
            log.warning("VPCS binary couldn't be found!")
        elif not os.access(self._vpcs, os.X_OK):
            log.warning("VPCS is not executable")

        # a new process start when calling IModule
        IModule.__init__(self, name, *args, **kwargs)
        self._vpcs_instances = {}
        self._console_start_port_range = vpcs_config.get("console_start_port_range", 4501)
        self._console_end_port_range = vpcs_config.get("console_end_port_range", 5000)
        self._allocated_udp_ports = []
        self._udp_start_port_range = vpcs_config.get("udp_start_port_range", 20501)
        self._udp_end_port_range = vpcs_config.get("udp_end_port_range", 21000)
        self._host = vpcs_config.get("host", kwargs["host"])
        self._console_host = vpcs_config.get("console_host", kwargs["console_host"])
        self._projects_dir = kwargs["projects_dir"]
        self._tempdir = kwargs["temp_dir"]
        self._working_dir = self._projects_dir
开发者ID:shaneutt,项目名称:gns3-server,代码行数:35,代码来源:__init__.py

示例13: run_around_tests

def run_around_tests(monkeypatch, port_manager):
    """
    This setup a temporay project file environnement around tests
    """

    tmppath = tempfile.mkdtemp()

    port_manager._instance = port_manager
    config = Config.instance()
    config.clear()
    os.makedirs(os.path.join(tmppath, 'projects'))
    config.set("Server", "project_directory", os.path.join(tmppath, 'projects'))
    config.set("Server", "images_path", os.path.join(tmppath, 'images'))
    config.set("Server", "auth", False)

    # Prevent executions of the VM if we forgot to mock something
    config.set("VirtualBox", "vboxmanage_path", tmppath)
    config.set("VPCS", "vpcs_path", tmppath)
    config.set("VMware", "vmrun_path", tmppath)

    # Force turn off KVM because it's not available on CI
    config.set("Qemu", "enable_kvm", False)

    monkeypatch.setattr("gns3server.modules.project.Project._get_default_project_directory", lambda *args: os.path.join(tmppath, 'projects'))

    # Force sys.platform to the original value. Because it seem not be restore correctly at each tests
    sys.platform = sys.original_platform

    yield

    # An helper should not raise Exception
    try:
        shutil.rmtree(tmppath)
    except:
        pass
开发者ID:Francisco1000,项目名称:gns3-server,代码行数:35,代码来源:conftest.py

示例14: run_around_tests

def run_around_tests(monkeypatch):
    """
    This setup a temporay project file environnement around tests
    """

    tmppath = tempfile.mkdtemp()

    config = Config.instance()
    config.clear()
    config.set("Server", "project_directory", tmppath)
    config.set("Server", "auth", False)

    # Prevent exectuions of the VM if we forgot to mock something
    config.set("VirtualBox", "vboxmanage_path", tmppath)
    config.set("VPCS", "vpcs_path", tmppath)

    monkeypatch.setattr("gns3server.modules.project.Project._get_default_project_directory", lambda *args: tmppath)

    yield

    # An helper should not raise Exception
    try:
        shutil.rmtree(tmppath)
    except:
        pass
开发者ID:astoffel,项目名称:gns3-server,代码行数:25,代码来源:conftest.py

示例15: test_node_working_directory

def test_node_working_directory(tmpdir, node):
    directory = Config.instance().get_section_config("Server").get("projects_path")

    with patch("gns3server.compute.project.Project.is_local", return_value=True):
        p = Project(project_id=str(uuid4()))
        assert p.node_working_directory(node) == os.path.join(directory, p.id, 'project-files', node.module_name, node.id)
        assert os.path.exists(p.node_working_directory(node))
开发者ID:athmane,项目名称:gns3-server,代码行数:7,代码来源:test_project.py


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