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


Python IOSXR.close方法代码示例

本文整理汇总了Python中pyIOSXR.IOSXR.close方法的典型用法代码示例。如果您正苦于以下问题:Python IOSXR.close方法的具体用法?Python IOSXR.close怎么用?Python IOSXR.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyIOSXR.IOSXR的用法示例。


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

示例1: test_lock_raises_LockError

# 需要导入模块: from pyIOSXR import IOSXR [as 别名]
# 或者: from pyIOSXR.IOSXR import close [as 别名]
    def test_lock_raises_LockError(self):

        """Tests if DB already locked raises LockError"""

        if self.MOCK:
            self.assertRaises(
                LockError,
                self.device.lock
            )
            self.assertFalse(self.device.locked)
        else:
            self.device.unlock()  # make sure the config is not locked
            same_device = IOSXR(self.HOSTNAME,
                            self.USERNAME,
                            self.PASSWORD,
                            port=self.PORT,
                            lock=self.LOCK,
                            logfile=self.LOG,
                            timeout=self.TIMEOUT)
            same_device.open()
            same_device.lock()
            # the other instance locks the config DB

            try:
                # trying to acquire the config DB
                self.device.lock()
            except LockError:
                self.assertFalse(self.device.locked)
            else:
                self.assertTrue(self.device.locked)

            same_device.close()
开发者ID:courtsmith,项目名称:pyiosxr,代码行数:34,代码来源:test.py

示例2: IOSXRDriver

# 需要导入模块: from pyIOSXR import IOSXR [as 别名]
# 或者: from pyIOSXR.IOSXR import close [as 别名]
class IOSXRDriver(NetworkDriver):
    def __init__(self, hostname, username, password):
        self.hostname = hostname
        self.username = username
        self.password = password
        self.device = IOSXR(hostname, username, password)
        self.pending_changes = False

    def open(self):
        self.device.open()

    def close(self):
        self.device.close()

    def load_replace_candidate(self, filename=None, config=None):
        self.pending_changes = True
        self.replace = True

        try:
            self.device.load_candidate_config(filename=filename, config=config)
        except InvalidInputError as e:
            self.pending_changes = False
            self.replace = False
            raise ReplaceConfigException(e.message)

    def load_merge_candidate(self, filename=None, config=None):
        self.pending_changes = True
        self.replace = False

        try:
            self.device.load_candidate_config(filename=filename, config=config)
        except InvalidInputError as e:
            self.pending_changes = False
            self.replace = False
            raise MergeConfigException(e.message)

    def compare_config(self):
        if not self.pending_changes:
            return ""
        elif self.replace:
            return self.device.compare_replace_config()
        else:
            return self.device.compare_config()

    def commit_config(self):
        if self.replace:
            self.device.commit_replace_config()
        else:
            self.device.commit_config()
        self.pending_changes = False

    def discard_config(self):
        self.device.discard_config()
        self.pending_changes = False

    def rollback(self):
        self.device.rollback()
开发者ID:irom77,项目名称:napalm,代码行数:59,代码来源:iosxr.py

示例3: test_close

# 需要导入模块: from pyIOSXR import IOSXR [as 别名]
# 或者: from pyIOSXR.IOSXR import close [as 别名]
 def test_close(self, mock_close, mock_sendline, mock_expect, mock_spawn):
     '''
     Test pyiosxr class close
     Should return None
     '''
     device = IOSXR(hostname='hostname', username='ejasinska', password='passwd', port=22, timeout=60, logfile=None, lock=False)
     mock_spawn.return_value = None
     device.open()
     self.assertIsNone(device.close())
开发者ID:mygoda,项目名称:pyiosxr,代码行数:11,代码来源:test.py

示例4: test_commit_after_other_session_commit

# 需要导入模块: from pyIOSXR import IOSXR [as 别名]
# 或者: from pyIOSXR.IOSXR import close [as 别名]
    def test_commit_after_other_session_commit(self):

        """Testing if trying to commit after another process commited does not raise CommitError"""

        if self.MOCK:
            # mock data contains the error message we are looking for
            self.assertIsNone(self.device.commit_config(comment="parallel"))
        else:
            # to test this will neet to apply changes to the same device
            # through a different SSH session
            same_device = IOSXR(self.HOSTNAME,
                                self.USERNAME,
                                self.PASSWORD,
                                port=self.PORT,
                                lock=self.LOCK,
                                logfile=self.LOG,
                                timeout=self.TIMEOUT)
            same_device.open()
            # loading something
            same_device.load_candidate_config(
                config='interface MgmtEth0/RP0/CPU0/0 description testing parallel commits'
            )
            # committing
            same_device.commit_config(comment='pyIOSXR-test_parallel_commits')

            # trying to load something from the test instance
            self.device.load_candidate_config(config='interface MgmtEth0/RP0/CPU0/0 description this wont work')
            # and will fail because of the commit above
            self.assertIsNone(self.device.commit_config(comment="parallel"))

            # let's rollback the committed changes
            same_device.rollback()
            # and close the auxiliary connection
            same_device.close()

            # because this error was raised
            self.device.close()
            self.device.open()
开发者ID:courtsmith,项目名称:pyiosxr,代码行数:40,代码来源:test.py

示例5: IOSXRDriver

# 需要导入模块: from pyIOSXR import IOSXR [as 别名]
# 或者: from pyIOSXR.IOSXR import close [as 别名]
class IOSXRDriver(NetworkDriver):
    def __init__(self, hostname, username, password, timeout=60):
        self.hostname = hostname
        self.username = username
        self.password = password
        self.timeout = timeout
        self.device = IOSXR(hostname, username, password, timeout=timeout)
        self.pending_changes = False
        self.replace = False

    def open(self):
        self.device.open()

    def close(self):
        self.device.close()

    def load_replace_candidate(self, filename=None, config=None):
        self.pending_changes = True
        self.replace = True

        try:
            self.device.load_candidate_config(filename=filename, config=config)
        except InvalidInputError as e:
            self.pending_changes = False
            self.replace = False
            raise ReplaceConfigException(e.message)

    def load_merge_candidate(self, filename=None, config=None):
        self.pending_changes = True
        self.replace = False

        try:
            self.device.load_candidate_config(filename=filename, config=config)
        except InvalidInputError as e:
            self.pending_changes = False
            self.replace = False
            raise MergeConfigException(e.message)

    def compare_config(self):
        if not self.pending_changes:
            return ''
        elif self.replace:
            return self.device.compare_replace_config().strip()
        else:
            return self.device.compare_config().strip()

    def commit_config(self):
        if self.replace:
            self.device.commit_replace_config()
        else:
            self.device.commit_config()
        self.pending_changes = False

    def discard_config(self):
        self.device.discard_config()
        self.pending_changes = False

    def rollback(self):
        self.device.rollback()

    def get_facts(self):

        sh_ver = self.device.show_version()

        for line in sh_ver.splitlines():
            if 'Cisco IOS XR Software' in line:
                os_version = line.split()[-1]
            elif 'uptime' in line:
                uptime = string_parsers.convert_uptime_string_seconds(line)
                hostname = line.split()[0]
                fqdn = line.split()[0]
            elif 'Series' in line:
                model = ' '.join(line.split()[1:3])

        interface_list = list()

        for x in self.device.show_interface_description().splitlines()[3:-1]:
            if '.' not in x:
                interface_list.append(x.split()[0])

        result = {
            'vendor': u'Cisco',
            'os_version': unicode(os_version),
            'hostname': unicode(hostname),
            'uptime': uptime,
            'model': unicode(model),
            'serial_number': u'',
            'fqdn': unicode(fqdn),
            'interface_list': interface_list,
        }

        return result

    def get_interfaces(self):

        # init result dict
        result = {}

        # fetch show interface output
        sh_int = self.device.show_interfaces()
#.........这里部分代码省略.........
开发者ID:t2d,项目名称:napalm,代码行数:103,代码来源:iosxr.py

示例6: IOSXRDriver

# 需要导入模块: from pyIOSXR import IOSXR [as 别名]
# 或者: from pyIOSXR.IOSXR import close [as 别名]
class IOSXRDriver(NetworkDriver):
    def __init__(self, hostname, username, password, timeout=60):
        self.hostname = hostname
        self.username = username
        self.password = password
        self.timeout = timeout
        self.device = IOSXR(hostname, username, password, timeout=timeout)
        self.pending_changes = False
        self.replace = False

    def open(self):
        self.device.open()

    def close(self):
        self.device.close()

    def load_replace_candidate(self, filename=None, config=None):
        self.pending_changes = True
        self.replace = True

        try:
            self.device.load_candidate_config(filename=filename, config=config)
        except InvalidInputError as e:
            self.pending_changes = False
            self.replace = False
            raise ReplaceConfigException(e.message)

    def load_merge_candidate(self, filename=None, config=None):
        self.pending_changes = True
        self.replace = False

        try:
            self.device.load_candidate_config(filename=filename, config=config)
        except InvalidInputError as e:
            self.pending_changes = False
            self.replace = False
            raise MergeConfigException(e.message)

    def compare_config(self):
        if not self.pending_changes:
            return ""
        elif self.replace:
            return self.device.compare_replace_config().strip()
        else:
            return self.device.compare_config().strip()

    def commit_config(self):
        if self.replace:
            self.device.commit_replace_config()
        else:
            self.device.commit_config()
        self.pending_changes = False

    def discard_config(self):
        self.device.discard_config()
        self.pending_changes = False

    def rollback(self):
        self.device.rollback()

    def get_facts(self):

        sh_ver = self.device.show_version()

        for line in sh_ver.splitlines():
            if "Cisco IOS XR Software" in line:
                os_version = line.split()[-1]
            elif "uptime" in line:
                uptime = string_parsers.convert_uptime_string_seconds(line)
                hostname = line.split()[0]
                fqdn = line.split()[0]
            elif "Series" in line:
                model = " ".join(line.split()[1:3])

        interface_list = list()

        for x in self.device.show_interface_description().splitlines()[3:-1]:
            if "." not in x:
                interface_list.append(x.split()[0])

        result = {
            "vendor": u"Cisco",
            "os_version": unicode(os_version),
            "hostname": unicode(hostname),
            "uptime": uptime,
            "model": unicode(model),
            "serial_number": u"",
            "fqdn": unicode(fqdn),
            "interface_list": interface_list,
        }

        return result

    def get_interfaces(self):

        # init result dict
        result = {}

        # fetch show interface output
        sh_int = self.device.show_interfaces()
#.........这里部分代码省略.........
开发者ID:jmay00,项目名称:napalm,代码行数:103,代码来源:iosxr.py

示例7: open

# 需要导入模块: from pyIOSXR import IOSXR [as 别名]
# 或者: from pyIOSXR.IOSXR import close [as 别名]
        with open(os.path.join(xr_filename), 'r') as f:
            ipaddress = str(xr_filename[10:-11])
            pprint('***Processing %s port %s ***' % (ipaddress, port))
            xr_device = IOSXR(hostname='172.16.2.10',username='dipsingh',password='cisco123')
            xr_device.open()

            try:
                xr_device.load_candidate_config(filename=xr_filename)
            except Exception as err:
                print ('Error occured while loading candidate configs',err)
                continue

            if args.confirm is True:
                pprint("Confirmation bypassed")
                xr_device.commit_config()
                xr_device.close()
                continue
            else:
                pprint("The following configs will be applied ")
                diff = xr_device.compare_config()
                commit_config = ''
                while commit_config != 'YES' and commit_config != 'NO':
                    commit_config = raw_input('Apply configuration (YES/NO)')
                    if commit_config == 'YES':
                        pprint("Commiting")
                        rsp = xr_device.commit_config()
                        if rsp is True:
                            pprint ("Commit successful")
                            xr_device.close()
                    elif commit_config == 'NO' :
                        pprint("Rolling back")
开发者ID:Dipsingh,项目名称:l3vpnIOSXR_JunOS,代码行数:33,代码来源:l3vpn_config_push.py

示例8: IOSXRDriver

# 需要导入模块: from pyIOSXR import IOSXR [as 别名]
# 或者: from pyIOSXR.IOSXR import close [as 别名]
class IOSXRDriver(NetworkDriver):
    def __init__(self, hostname, username, password, timeout=60):
        self.hostname = hostname
        self.username = username
        self.password = password
        self.timeout = timeout
        self.device = IOSXR(hostname, username, password, timeout=timeout)
        self.pending_changes = False
        self.replace = False

    def open(self):
        self.device.open()

    def close(self):
        self.device.close()

    def load_replace_candidate(self, filename=None, config=None):
        self.pending_changes = True
        self.replace = True

        try:
            self.device.load_candidate_config(filename=filename, config=config)
        except InvalidInputError as e:
            self.pending_changes = False
            self.replace = False
            raise ReplaceConfigException(e.message)

    def load_merge_candidate(self, filename=None, config=None):
        self.pending_changes = True
        self.replace = False

        try:
            self.device.load_candidate_config(filename=filename, config=config)
        except InvalidInputError as e:
            self.pending_changes = False
            self.replace = False
            raise MergeConfigException(e.message)

    def compare_config(self):
        if not self.pending_changes:
            return ''
        elif self.replace:
            return self.device.compare_replace_config().strip()
        else:
            return self.device.compare_config().strip()

    def commit_config(self):
        if self.replace:
            self.device.commit_replace_config()
        else:
            self.device.commit_config()
        self.pending_changes = False

    def discard_config(self):
        self.device.discard_config()
        self.pending_changes = False

    def rollback(self):
        self.device.rollback()

    def get_facts(self):

        sh_ver = self.device.show_version()

        for line in sh_ver.splitlines():
            if 'Cisco IOS XR Software' in line:
                os_version = line.split()[-1]
            elif 'uptime' in line:
                uptime = string_parsers.convert_uptime_string_seconds(line)
                hostname = line.split()[0]
                fqdn = line.split()[0]
            elif 'Series' in line:
                model = ' '.join(line.split()[1:3])

        interface_list = list()

        for x in self.device.show_interface_description().splitlines()[3:-1]:
            if '.' not in x:
                interface_list.append(x.split()[0])

        result = {
            'vendor': u'Cisco',
            'os_version': unicode(os_version),
            'hostname': unicode(hostname),
            'uptime': uptime,
            'model': unicode(model),
            'serial_number': u'',
            'fqdn': unicode(fqdn),
            'interface_list': interface_list,
        }

        return result

    def get_interfaces(self):

        # init result dict
        result = {}

        # fetch show interface output
        sh_int = self.device.show_interfaces()
#.........这里部分代码省略.........
开发者ID:mileswdavis,项目名称:napalm,代码行数:103,代码来源:iosxr.py


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