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


Python fs.FS类代码示例

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


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

示例1: facts_domain

def facts_domain(junos, facts):
    """
    The following facts are required:
        facts['hostname']

    The following facts are assigned:
        facts['domain']
        facts['fqdn']
    """

    try:
        domain_filter_xml = E('configuration', E('system', E('domain-name')))
        domain = junos.rpc.get_config(filter_xml=domain_filter_xml,
                                      options=INHERIT)
        domain_name = domain.xpath('.//domain-name')
        if len(domain_name) > 0:
            facts['domain'] = domain_name[0].text
            facts['fqdn'] = facts['hostname'] + '.' + facts['domain']
            return
    except RpcError:
        pass

    fs = FS(junos)
    file_content = fs.cat('/etc/resolv.conf') or fs.cat('/var/etc/resolv.conf')
    words = file_content.split() if file_content is not None else ''
    if 'domain' not in words:
        facts['domain'] = None
        facts['fqdn'] = facts['hostname']
    else:
        idx = words.index('domain') + 1
        facts['domain'] = words[idx]
        facts['fqdn'] = facts['hostname'] + '.' + facts['domain']
开发者ID:GIC-de,项目名称:py-junos-eznc,代码行数:32,代码来源:domain.py

示例2: inventory

 def inventory(self):
     """
     Returns dictionary of file listing information for current and rollback
     Junos install packages. This information comes from the /packages
     directory.
     """
     from jnpr.junos.utils.fs import FS
     fs = FS(self.dev)
     pkgs = fs.ls('/packages')
     return dict(current=pkgs['files'].get(
         'junos'), rollback=pkgs['files'].get('junos.old'))
开发者ID:dgjnpr,项目名称:py-junos-eznc,代码行数:11,代码来源:sw.py

示例3: inventory

    def inventory(self):
        """
        Returns dictionary of file listing information for current and rollback
        Junos install packages. This information comes from the /packages
        directory.

        .. warning:: Experimental method; may not work on all platforms.  If
                     you find this not working, please report issue.
        """
        from jnpr.junos.utils.fs import FS
        fs = FS(self.dev)
        pkgs = fs.ls('/packages')
        return dict(current=pkgs['files'].get(
            'junos'), rollback=pkgs['files'].get('junos.old'))
开发者ID:ARD92,项目名称:py-junos-eznc,代码行数:14,代码来源:sw.py

示例4: facts_domain

def facts_domain(junos, facts):
    """
    The following facts are required:
        facts['hostname']

    The following facts are assigned:
        facts['domain']
        facts['fqdn']
    """
    fs = FS(junos)
    words = fs.cat('/etc/resolv.conf').split()
    if 'domain' not in words:
        facts['domain'] = None
        facts['fqdn'] = facts['hostname']
    else:
        idx = words.index('domain') + 1
        facts['domain'] = words[idx]
        facts['fqdn'] = facts['hostname'] + '.' + facts['domain']
开发者ID:RobWC,项目名称:py-junos-eznc,代码行数:18,代码来源:domain.py

示例5: get_facts

def get_facts(device):
    """
    Gathers domain facts from the configuration or /etc/resolv.conf.
    """
    domain_config = """
        <configuration>
            <system>
                <domain-name/>
             </system>
        </configuration>
    """
    domain = None
    fqdn = None
    # Try to read the domain-name from the config.
    # This might fail due to lack of permissions.
    try:
        rsp = device.rpc.get_config(filter_xml=etree.XML(domain_config),
                                    options={'database': 'committed',
                                             'inherit': 'inherit',
                                             'commit-scripts': 'apply', })
        domain = rsp.findtext('.//domain-name')
    # Ignore if user can't view the configuration.
    except PermissionError:
        pass

    # Try to read the domain from the resolv.conf file. This only requires
    # view permissions.
    if domain is None:
        fs = FS(device)
        file_content = (fs.cat('/etc/resolv.conf') or
                        fs.cat('/var/etc/resolv.conf'))
        words = file_content.split() if file_content is not None else []
        if 'domain' in words:
            idx = words.index('domain') + 1
            domain = words[idx]

    # Set the fqdn
    fqdn = device.facts['hostname']
    if fqdn is not None and domain is not None:
        fqdn = fqdn + '.' + domain

    return {'domain': domain,
            'fqdn': fqdn, }
开发者ID:GIC-de,项目名称:py-junos-eznc,代码行数:43,代码来源:domain.py

示例6: __init__

    def __init__(self, host, username, password, *args, **kwargs):
        super(JunosDevice, self).__init__(host,
                                          username,
                                          password,
                                          *args,
                                          vendor='juniper',
                                          device_type=JNPR_DEVICE_TYPE,
                                          **kwargs)

        self.native = JunosNativeDevice(*args, host=host, user=username, passwd=password, **kwargs)
        self.open()

        self.cu = JunosNativeConfig(self.native)
        self.fs = JunosNativeFS(self.native)
        self.sw = JunosNativdSW(self.native)
开发者ID:ogenstad,项目名称:pyntc,代码行数:15,代码来源:jnpr_device.py

示例7: setUp

 def setUp(self, mock_connect):
     mock_connect.side_effect = self._mock_manager
     self.dev = Device(host="1.1.1.1", user="rick", password="password123", gather_facts=False)
     self.dev.open()
     self.fs = FS(self.dev)
开发者ID:pklimai,项目名称:py-junos-eznc,代码行数:5,代码来源:test_fs.py

示例8: TestFS

class TestFS(unittest.TestCase):
    @patch("ncclient.manager.connect")
    def setUp(self, mock_connect):
        mock_connect.side_effect = self._mock_manager
        self.dev = Device(host="1.1.1.1", user="rick", password="password123", gather_facts=False)
        self.dev.open()
        self.fs = FS(self.dev)

    def test_cat_wrong_path_return_none(self):
        path = "test/report"
        self.assertEqual(self.fs.cat(path), None)

    def test_cat(self):
        self.fs._dev.rpc.file_show = MagicMock(side_effect=self._mock_manager)
        path = "test/cat.txt"
        self.assertTrue("testing cat functionality" in self.fs.cat(path))
        self.fs._dev.rpc.file_show.assert_called_with(filename="test/cat.txt")

    def test_cwd(self):
        self.fs._dev.rpc.set_cli_working_directory = MagicMock(side_effect=self._mock_manager)
        folder = "change/directory"
        self.assertEqual("change/directory", self.fs.cwd(folder))
        self.fs._dev.rpc.set_cli_working_directory.assert_called_with(directory="change/directory")

    @patch("jnpr.junos.Device.execute")
    def test_pwd(self, mock_execute):
        mock_execute.side_effect = MagicMock(side_effect=self._mock_manager)
        self.fs.pwd()
        self.assertEqual(self.fs.pwd(), "/cf/var/home/rick")

    def test_checksum_return_none(self):
        path = "test/report"
        self.assertEqual(self.fs.checksum(path), None)

    def test_checksum_unknown_calc(self):
        path = "test/report"
        self.assertRaises(ValueError, self.fs.checksum, path=path, calc="abc")

    def test_checksum_return_rsp(self):
        self.fs.dev.rpc.get_sha256_checksum_information = MagicMock(side_effect=self._mock_manager)
        path = "test/checksum"
        self.assertEqual(self.fs.checksum(path, "sha256"), "xxxx")
        self.fs.dev.rpc.get_sha256_checksum_information.assert_called_with(path="test/checksum")

    def test_stat_calling___decode_file(self):
        path = "test/stat/decode_file"
        self.fs.dev.rpc.file_list = MagicMock(side_effect=self._mock_manager)
        self.assertEqual(
            self.fs.stat(path),
            {
                "owner": "pqr",
                "path": "/var/abc.sh",
                "permissions": 755,
                "permissions_text": "-rwxr-xr-x",
                "size": 2,
                "ts_date": "Mar 13 06:54",
                "ts_epoc": "1394693680",
                "type": "file",
            },
        )

    def test_stat_calling___decode_dir(self):
        path = "test/stat/decode_dir"
        self.fs.dev.rpc.file_list = MagicMock(side_effect=self._mock_manager)
        self.assertEqual(self.fs.stat(path), {"path": "/var", "type": "dir", "file_count": 1, "size": 2})

    def test_stat_return_none(self):
        path = "test/abc"
        self.fs.dev.rpc.file_list = MagicMock()
        self.fs.dev.rpc.file_list.find.return_value = "output"
        self.assertEqual(self.fs.stat(path), None)

    def test_ls_calling___decode_file(self):
        path = "test/stat/decode_file"
        self.fs.dev.rpc.file_list = MagicMock(side_effect=self._mock_manager)
        self.assertEqual(
            self.fs.ls(path),
            {
                "owner": "pqr",
                "path": "/var/abc.sh",
                "permissions": 755,
                "permissions_text": "-rwxr-xr-x",
                "size": 2,
                "ts_date": "Mar 13 06:54",
                "ts_epoc": "1394693680",
                "type": "file",
            },
        )

    def test_ls_calling___decode_dir(self):
        path = "test/stat/decode_dir"
        self.fs.dev.rpc.file_list = MagicMock(side_effect=self._mock_manager)
        self.assertEqual(
            self.fs.ls(path),
            {
                "files": {
                    "abc": {
                        "permissions_text": "drwxr-xr-x",
                        "ts_date": "Feb 17 15:30",
                        "ts_epoc": "1392651039",
#.........这里部分代码省略.........
开发者ID:pklimai,项目名称:py-junos-eznc,代码行数:101,代码来源:test_fs.py

示例9: setUp

 def setUp(self, mock_connect):
     mock_connect.side_effect = self._mock_manager
     self.dev = Device(host='1.1.1.1', user='rick', password='password123',
                       gather_facts=False)
     self.dev.open()
     self.fs = FS(self.dev)
开发者ID:ydnath,项目名称:py-junos-eznc,代码行数:6,代码来源:test_fs.py

示例10: TestFS

class TestFS(unittest.TestCase):

    @patch('ncclient.manager.connect')
    def setUp(self, mock_connect):
        mock_connect.side_effect = self._mock_manager
        self.dev = Device(host='1.1.1.1', user='rick', password='password123',
                          gather_facts=False)
        self.dev.open()
        self.fs = FS(self.dev)

    @patch('jnpr.junos.device.warnings')
    def test_cat_wrong_path_return_none(self, mock_warnings):
        path = 'test/report'
        self.assertEqual(self.fs.cat(path), None)

    def test_cat(self):
        self.fs._dev.rpc.file_show = MagicMock(side_effect=self._mock_manager)
        path = 'test/cat.txt'
        self.assertTrue('testing cat functionality' in self.fs.cat(path))
        self.fs._dev.rpc.file_show.assert_called_with(filename='test/cat.txt')

    def test_cwd(self):
        self.fs._dev.rpc.set_cli_working_directory = MagicMock(
            side_effect=self._mock_manager)
        folder = 'change/directory'
        self.assertEqual('change/directory', self.fs.cwd(folder))
        self.fs._dev.rpc.set_cli_working_directory.\
            assert_called_with(directory='change/directory')

    @patch('jnpr.junos.Device.execute')
    def test_pwd(self, mock_execute):
        mock_execute.side_effect = MagicMock(side_effect=self._mock_manager)
        self.fs.pwd()
        self.assertEqual(self.fs.pwd(), '/cf/var/home/rick')

    @patch('jnpr.junos.device.warnings')
    def test_checksum_return_none(self, mock_warnings):
        path = 'test/report'
        self.assertEqual(self.fs.checksum(path), None)

    def test_checksum_unknown_calc(self):
        path = 'test/report'
        self.assertRaises(ValueError, self.fs.checksum, path=path, calc='abc')

    def test_checksum_return_rsp(self):
        self.fs.dev.rpc.get_sha256_checksum_information = \
            MagicMock(side_effect=self._mock_manager)
        path = 'test/checksum'
        self.assertEqual(self.fs.checksum(path, 'sha256'), 'xxxx')
        self.fs.dev.rpc.get_sha256_checksum_information.\
            assert_called_with(path='test/checksum')

    def test_stat_calling___decode_file(self):
        path = 'test/stat/decode_file'
        self.fs.dev.rpc.file_list = \
            MagicMock(side_effect=self._mock_manager)
        self.assertEqual(self.fs.stat(path),
                         {'owner': 'pqr', 'path': '/var/abc.sh',
                          'permissions': 755,
                          'permissions_text': '-rwxr-xr-x', 'size': 2,
                          'ts_date': 'Mar 13 06:54',
                          'ts_epoc': '1394693680',
                          'type': 'file'})

    def test_stat_calling___decode_dir(self):
        path = 'test/stat/decode_dir'
        self.fs.dev.rpc.file_list = \
            MagicMock(side_effect=self._mock_manager)
        self.assertEqual(self.fs.stat(path),
                         {'path': '/var', 'type': 'dir', 'file_count': 1,
                          'size': 2})

    def test_stat_return_none(self):
        path = 'test/abc'
        self.fs.dev.rpc.file_list = MagicMock()
        self.fs.dev.rpc.file_list.find.return_value = 'output'
        self.assertEqual(self.fs.stat(path), None)

    def test_ls_calling___decode_file(self):
        path = 'test/stat/decode_file'
        self.fs.dev.rpc.file_list = \
            MagicMock(side_effect=self._mock_manager)
        self.assertEqual(self.fs.ls(path),
                         {'owner': 'pqr', 'path': '/var/abc.sh',
                          'permissions': 755,
                          'permissions_text': '-rwxr-xr-x', 'size': 2,
                          'ts_date': 'Mar 13 06:54',
                          'ts_epoc': '1394693680',
                          'type': 'file'})

    def test_ls_calling___decode_dir(self):
        path = 'test/stat/decode_dir'
        self.fs.dev.rpc.file_list = \
            MagicMock(side_effect=self._mock_manager)
        self.assertEqual(self.fs.ls(path),
                         {'files':
                          {'abc': {'permissions_text': 'drwxr-xr-x',
                                   'ts_date': 'Feb 17 15:30',
                                   'ts_epoc': '1392651039',
                                   'owner': 'root', 'path': 'abc',
#.........这里部分代码省略.........
开发者ID:ydnath,项目名称:py-junos-eznc,代码行数:101,代码来源:test_fs.py

示例11: Device

from jnpr.junos import Device
from jnpr.junos.utils.config import Config
from jnpr.junos.utils.fs import FS
from pprint import pprint
import sys


dev = Device('host', user='user', password='pwd')

dev.open()

fs = FS(dev)

pprint (fs.ls(path="/var/tmp/", brief=True))

print fs.pwd()
开发者ID:insqur,项目名称:PyEZ,代码行数:16,代码来源:FsClass.py

示例12: JunosDevice

class JunosDevice(BaseDevice):

    def __init__(self, host, username, password, *args, **kwargs):
        super(JunosDevice, self).__init__(host,
                                          username,
                                          password,
                                          *args,
                                          vendor='juniper',
                                          device_type=JNPR_DEVICE_TYPE,
                                          **kwargs)

        self.native = JunosNativeDevice(*args, host=host, user=username, passwd=password, **kwargs)
        self.connected = False
        self.open()

        self.cu = JunosNativeConfig(self.native)
        self.fs = JunosNativeFS(self.native)
        self.sw = JunosNativdSW(self.native)

    def open(self):
        if not self.connected:
            self.native.open()
            self.connected = True

    def close(self):
        if self.connected:
            self.native.close()
            self.connected = False

    def show(self, command, raw_text=True):
        if not raw_text:
            raise ValueError('Juniper only supports raw text output. \
                Append " | display xml" to your commands for a structured string.')

        if not command.startswith('show'):
            raise CommandError(command, 'Juniper "show" commands must begin with "show".')


        return self.native.cli(command, warning=False)


    def show_list(self, commands, raw_text=True):
        responses = []
        for command in commands:
            responses.append(self.show(command, raw_text=raw_text))

        return responses

    def backup_running_config(self, filename):
        with open(filename, 'w') as f:
            f.write(self.running_config)

    def config(self, command, format='set'):
        try:
            self.cu.load(command, format=format)
            self.cu.commit()
        except ConfigLoadError as e:
            raise CommandError(command, e.message)

    def config_list(self, commands, format='set'):
        try:
            for command in commands:
                self.cu.load(command, format=format)

            self.cu.commit()
        except ConfigLoadError as e:
            raise CommandListError(commands, command, e.message)


    def _uptime_components(self, uptime_full_string):
        match_days = re.search(r'(\d+) days?', uptime_full_string)
        match_hours = re.search(r'(\d+) hours?', uptime_full_string)
        match_minutes = re.search(r'(\d+) minutes?', uptime_full_string)
        match_seconds = re.search(r'(\d+) seconds?', uptime_full_string)

        days = int(match_days.group(1)) if match_days else 0
        hours = int(match_hours.group(1)) if match_hours else 0
        minutes = int(match_minutes.group(1)) if match_minutes else 0
        seconds = int(match_seconds.group(1)) if match_seconds else 0

        return days, hours, minutes, seconds

    def _uptime_to_string(self, uptime_full_string):
        days, hours, minutes, seconds = self._uptime_components(uptime_full_string)
        return '%02d:%02d:%02d:%02d' % (days, hours, minutes, seconds)

    def _uptime_to_seconds(self, uptime_full_string):
        days, hours, minutes, seconds = self._uptime_components(uptime_full_string)

        seconds += days * 24 * 60 * 60
        seconds += hours * 60 * 60
        seconds += minutes * 60

        return seconds

    def _get_interfaces(self):
        eth_ifaces = EthPortTable(self.native)
        eth_ifaces.get()

        loop_ifaces = LoopbackTable(self.native)
#.........这里部分代码省略.........
开发者ID:ktbyers,项目名称:pyntc,代码行数:101,代码来源:jnpr_device.py

示例13: Device

from jnpr.junos.utils.fs import FS
from jnpr.junos import Device

dev = Device(host='xxxx', user='demo', password='demo123')
dev.open()

fs = FS(dev)
pprint(fs.ls('/var/tmp'))

dev.close()
开发者ID:insqur,项目名称:PyEZ,代码行数:10,代码来源:11_file_system.py


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