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


Python pyeapi.config_for函数代码示例

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


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

示例1: connect

    def connect(self):
        if self.config is not None:
            pyeapi.load_config(self.config)

        config = dict()

        if self.connection is not None:
            config = pyeapi.config_for(self.connection)
            if not config:
                msg = 'Connection name "{}" not found'.format(self.connection)

        for key in self.__attributes__:
            if getattr(self, key) is not None:
                config[key] = getattr(self, key)

        if 'transport' not in config:
            raise ValueError('Connection must define a transport')

        connection = pyeapi.client.make_connection(**config)
        node = pyeapi.client.Node(connection, **config)

        try:
            node.enable('show version')
        except (pyeapi.eapilib.ConnectionError, pyeapi.eapilib.CommandError):
            raise ValueError('unable to connect to {}'.format(node))
        return node
开发者ID:RichardBotham,项目名称:ansible-eos,代码行数:26,代码来源:eos_stp_interface.py

示例2: connect

    def connect(self):
        if self.params["config"]:
            pyeapi.load_config(self.params["config"])

        config = dict()

        if self.params["connection"]:
            config = pyeapi.config_for(self.params["connection"])
            if not config:
                msg = 'Connection name "%s" not found' % self.params["connection"]
                self.fail(msg)

        if self.params["username"]:
            config["username"] = self.params["username"]

        if self.params["password"]:
            config["password"] = self.params["password"]

        if self.params["transport"]:
            config["transport"] = self.params["transport"]

        if self.params["port"]:
            config["port"] = self.params["port"]

        if self.params["host"]:
            config["host"] = self.params["host"]

        if "transport" not in config:
            self.fail("Connection must define a transport")

        connection = pyeapi.client.make_connection(**config)
        self.log("Creating connection with autorefresh=%s" % self._autorefresh)
        node = pyeapi.client.Node(connection, autorefresh=self._autorefresh, **config)

        try:
            resp = node.enable("show version")
            self.debug("eos_version", resp[0]["result"]["version"])
            self.debug("eos_model", resp[0]["result"]["modelName"])
        except (pyeapi.eapilib.ConnectionError, pyeapi.eapilib.CommandError):
            self.fail("unable to connect to %s" % node)
        else:
            self.log("Connected to node %s" % node)
            self.debug("node", str(node))

        return node
开发者ID:RichardBotham,项目名称:ansible-eos,代码行数:45,代码来源:eos_varp_interface.py

示例3: connect

    def connect(self):
        if self.params['config']:
            pyeapi.load_config(self.params['config'])

        config = dict()

        if self.params['connection']:
            config = pyeapi.config_for(self.params['connection'])
            if not config:
                msg = 'Connection name "%s" not found' % self.params['connection']
                self.fail(msg)

        if self.params['username']:
            config['username'] = self.params['username']

        if self.params['password']:
            config['password'] = self.params['password']

        if self.params['transport']:
            config['transport'] = self.params['transport']

        if self.params['port']:
            config['port'] = self.params['port']

        if self.params['host']:
            config['host'] = self.params['host']

        if 'transport' not in config:
            self.fail('Connection must define a transport')

        connection = pyeapi.client.make_connection(**config)
        node = pyeapi.client.Node(connection)

        try:
            node.enable('show version')
        except (pyeapi.eapilib.ConnectionError, pyeapi.eapilib.CommandError):
            self.fail('unable to connect to %s' % node)
        else:
            self.log('Connected to node %s' % node)
            self.debug('node', str(node))

        return node
开发者ID:rodecker,项目名称:ansible-eos,代码行数:42,代码来源:eos_ethernet.py


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