當前位置: 首頁>>代碼示例>>Python>>正文


Python napalm.get_network_driver方法代碼示例

本文整理匯總了Python中napalm.get_network_driver方法的典型用法代碼示例。如果您正苦於以下問題:Python napalm.get_network_driver方法的具體用法?Python napalm.get_network_driver怎麽用?Python napalm.get_network_driver使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在napalm的用法示例。


在下文中一共展示了napalm.get_network_driver方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: import napalm [as 別名]
# 或者: from napalm import get_network_driver [as 別名]
def __init__(self):
        """Initialise new instance."""
        if not isinstance(self.driver_class, NetworkDriver):
            if type(self).name:
                self.driver_class = napalm.get_network_driver(type(self).name)
            else:
                raise ValueError 
開發者ID:wolcomm,項目名稱:djangolg,代碼行數:9,代碼來源:base.py

示例2: napalm_cli

# 需要導入模塊: import napalm [as 別名]
# 或者: from napalm import get_network_driver [as 別名]
def napalm_cli(task, commands, timeout=60, optional_args=None):
    """
    Run commands on remote devices using napalm

    Arguments:
        commands (list): list of commands to execute on the device
        timeout (int, optional): defaults to 60
        optional_args (dict, optional): defaults to ``{"port": task.host["napalm_port"]}``


    Returns:
        :obj:`brigade.core.task.Result`:
          * result (``dict``): dictionary with the result of the commands
    """
    parameters = {
        "hostname": task.host.host,
        "username": task.host.username,
        "password": task.host.password,
        "timeout": timeout,
        "optional_args": optional_args or {},
    }
    if "port" not in parameters["optional_args"] and task.host.network_api_port:
        parameters["optional_args"]["port"] = task.host.network_api_port
    network_driver = get_network_driver(task.host.nos)

    with network_driver(**parameters) as device:
        result = device.cli(commands)
    return Result(host=task.host, result=result) 
開發者ID:napalm-automation,項目名稱:brigade,代碼行數:30,代碼來源:napalm_cli.py

示例3: napalm_configure

# 需要導入模塊: import napalm [as 別名]
# 或者: from napalm import get_network_driver [as 別名]
def napalm_configure(task, configuration, replace=False, timeout=60, optional_args=None):
    """
    Loads configuration into a network devices using napalm

    Arguments:
        configuration (str): configuration to load into the device
        replace (bool): whether to replace or merge the configuration
        timeout (int, optional): defaults to 60
        optional_args (dict, optional): defaults to ``{"port": task.host["napalm_port"]}``


    Returns:
        :obj:`brigade.core.task.Result`:
          * changed (``bool``): whether if the task is changing the system or not
          * diff (``string``): change in the system
    """
    parameters = {
        "hostname": task.host.host,
        "username": task.host.username,
        "password": task.host.password,
        "timeout": timeout,
        "optional_args": optional_args or {},
    }
    if "port" not in parameters["optional_args"] and task.host.network_api_port:
        parameters["optional_args"]["port"] = task.host.network_api_port
    network_driver = get_network_driver(task.host.nos)

    with network_driver(**parameters) as device:
        if replace:
            device.load_replace_candidate(config=configuration)
        else:
            device.load_merge_candidate(config=configuration)
        diff = device.compare_config()

        if task.dry_run:
            device.discard_config()
        else:
            device.commit_config()
    return Result(host=task.host, diff=diff, changed=len(diff) > 0) 
開發者ID:napalm-automation,項目名稱:brigade,代碼行數:41,代碼來源:napalm_configure.py

示例4: napalm_get

# 需要導入模塊: import napalm [as 別名]
# 或者: from napalm import get_network_driver [as 別名]
def napalm_get(task, getters, timeout=60, optional_args=None):
    """
    Gather information from network devices using napalm

    Arguments:
        getters (list of str): getters to use
        hostname (string, optional): defaults to ``brigade_ip``
        username (string, optional): defaults to ``brigade_username``
        password (string, optional): defaults to ``brigade_password``
        driver (string, optional): defaults to ``nos``
        timeout (int, optional): defaults to 60
        optional_args (dict, optional): defaults to ``{"port": task.host["napalm_port"]}``


    Returns:
        :obj:`brigade.core.task.Result`:
          * result (``dict``): dictionary with the result of the getter
    """
    parameters = {
        "hostname": task.host.host,
        "username": task.host.username,
        "password": task.host.password,
        "timeout": timeout,
        "optional_args": optional_args or {},
    }
    if "port" not in parameters["optional_args"] and task.host.network_api_port:
        parameters["optional_args"]["port"] = task.host.network_api_port
    network_driver = get_network_driver(task.host.nos)

    if not isinstance(getters, list):
        getters = [getters]

    with network_driver(**parameters) as device:
        result = {}
        for g in getters:
            if not g.startswith("get_"):
                getter = "get_{}".format(g)
            method = getattr(device, getter)
            result[g] = method()
    return Result(host=task.host, result=result) 
開發者ID:napalm-automation,項目名稱:brigade,代碼行數:42,代碼來源:napalm_get.py

示例5: get_napalm_device

# 需要導入模塊: import napalm [as 別名]
# 或者: from napalm import get_network_driver [as 別名]
def get_napalm_device(self):
        try:
            # Driver found, instanciate it
            driver = napalm.get_network_driver(self.platform)
            return driver(hostname=self.hostname,
                          username=settings.NAPALM_USERNAME,
                          password=settings.NAPALM_PASSWORD,
                          timeout=settings.NAPALM_TIMEOUT,
                          optional_args=settings.NAPALM_ARGS)
        except napalm.base.exceptions.ModuleImportError:
            # Unable to import proper driver from napalm
            # Most probably due to a broken install
            return None 
開發者ID:respawner,項目名稱:peering-manager,代碼行數:15,代碼來源:models.py

示例6: __init__

# 需要導入模塊: import napalm [as 別名]
# 或者: from napalm import get_network_driver [as 別名]
def __init__(self, hostname, os, ipaddress, username, password):
        self.hostname = hostname
        self.username = username
        self.password = password
        self.ipaddress = ipaddress
        self.os = os
        self.driver = napalm.get_network_driver(self.os)
        self.device = self.driver(hostname=ipaddress, username=username, password=password) 
開發者ID:as2518,項目名稱:napalm-scenario,代碼行數:10,代碼來源:router.py

示例7: bgp_neighbors

# 需要導入模塊: import napalm [as 別名]
# 或者: from napalm import get_network_driver [as 別名]
def bgp_neighbors(self):
        """Get BGP session info using napalm."""
        try:
            driver_name = self.device_driver
        except AttributeError:
            driver_name = settings.DEFAULT_DRIVER
        driver = napalm.get_network_driver(driver_name)
        with driver(hostname=self.hostname, username=settings.NAPALM_USERNAME,
                    password=settings.NAPALM_PASSWORD) as device:
            neighbors = device.get_bgp_neighbors()
        return neighbors 
開發者ID:wolcomm,項目名稱:prngmgr,代碼行數:13,代碼來源:models.py

示例8: _get_devices

# 需要導入模塊: import napalm [as 別名]
# 或者: from napalm import get_network_driver [as 別名]
def _get_devices(self):
        """Generate a dictionary of devices

        This used to be a fancy dictionary comprehension, but the way that most
        NAPALM drivers handle optional_args, this was difficult to maintain.
        We're doing it this way now so that optional_args is only provided when
        we are explicitly setting "port". Otherwise, we don't want to pass in
        "optional_args", so NAPALM can use its default value for port.
        """

        devices = {}
        for device in self._config['devices']:
            port = self._get_port(device)
            if port:
                devices[device['hostname']] = get_network_driver(device['driver'])(
                    hostname=device['hostname'],
                    username=self._get_creds(device['hostname'])['username'],
                    password=self._get_creds(device['hostname'])['password'],
                    optional_args={
                        'port': self._get_port(device)
                    }
                )
            else:
                devices[device['hostname']] = get_network_driver(device['driver'])(
                    hostname=device['hostname'],
                    username=self._get_creds(device['hostname'])['username'],
                    password=self._get_creds(device['hostname'])['password']
                )
        return devices 
開發者ID:StackStorm-Exchange,項目名稱:stackstorm-napalm,代碼行數:31,代碼來源:lldp_sensor.py

示例9: get_driver

# 需要導入模塊: import napalm [as 別名]
# 或者: from napalm import get_network_driver [as 別名]
def get_driver(self, **std_kwargs):
        """Centralizes some of the setup logic for each action

        This will allow each action to more or less focus solely on the logic specific
        to its task
        """

        # Hostname is required
        hostname = std_kwargs['hostname']

        # These are not required, so we can default to None
        credentials = std_kwargs.get('credentials')
        driver = std_kwargs.get('driver')
        port = std_kwargs.get('port')
        htmlout = std_kwargs.get('htmlout', False)

        # Look up the driver  and if it's not given from the configuration file
        # Also overides the hostname since we might have a partial host i.e. from
        # syslog such as host1 instead of host1.example.com
        found_device = self.find_device_from_config(hostname, driver, credentials, port)

        login = self.get_credentials(found_device['credentials'])

        if not found_device['port']:
            optional_args = None
        else:
            optional_args = {'port': int(found_device['port'])}

        # Some actions like to use these params in log messages, or commands, etc.
        # So we tie to instance for easy lookup
        self.hostname = found_device['hostname']
        self.driver = found_device['driver']
        self.htmlout = htmlout

        return get_network_driver(self.driver)(
            hostname=str(found_device['hostname']),
            username=login['username'],
            password=login['password'],
            optional_args=optional_args
        ) 
開發者ID:StackStorm-Exchange,項目名稱:stackstorm-napalm,代碼行數:42,代碼來源:action.py

示例10: parse_from_device

# 需要導入模塊: import napalm [as 別名]
# 或者: from napalm import get_network_driver [as 別名]
def parse_from_device(module, os_choices):
    update_module_provider_data(module)

    hostname = module.params['hostname']
    username = module.params['username']
    password = module.params['password']
    timeout = module.params['timeout']
    models = module.params['models']
    mode = module.params['mode']
    profiles = module.params['profiles']

    dev_os = module.params['dev_os']
    argument_check = {'hostname': hostname, 'username': username,
                      'dev_os': dev_os, 'password': password}
    for key, val in argument_check.items():
        if val is None:
            module.fail_json(msg=str(key) + " is required")

    # use checks outside of ansible defined checks, since params come can come
    # from provider
    dev_os = module.params['dev_os']
    if dev_os not in os_choices:
        module.fail_json(msg="dev_os is not set to " + str(os_choices))

    if module.params['optional_args'] is None:
        optional_args = {}
    else:
        optional_args = module.params['optional_args']

    try:
        network_driver = get_network_driver(dev_os)
        device = network_driver(hostname=hostname,
                                username=username,
                                password=password,
                                timeout=timeout,
                                optional_args=optional_args)
        device.open()
    except Exception as e:
        module.fail_json(msg="cannot connect to device: {}".format(e))

    root = get_root_object(models)

    if mode in ["config", "both"]:
        root.parse_config(device=device, profile=profiles or device.profile)

    if mode in ["state", "both"]:
        root.parse_state(device=device, profile=profiles or device.profile)

    # close device connection
    try:
        device.close()
    except Exception as e:
        module.fail_json(msg="cannot close device connection: {}".format(e))

    return root 
開發者ID:napalm-automation,項目名稱:napalm-ansible,代碼行數:57,代碼來源:napalm_parse_yang.py

示例11: get_device_instance

# 需要導入模塊: import napalm [as 別名]
# 或者: from napalm import get_network_driver [as 別名]
def get_device_instance(module, os_choices):

    provider = module.params['provider'] or {}

    no_log = ['password', 'secret']
    for param in no_log:
        if provider.get(param):
            module.no_log_values.update(return_values(provider[param]))
        if provider.get('optional_args') and provider['optional_args'].get(param):
            module.no_log_values.update(return_values(provider['optional_args'].get(param)))
        if module.params.get('optional_args') and module.params['optional_args'].get(param):
            module.no_log_values.update(return_values(module.params['optional_args'].get(param)))

    # allow host or hostname
    provider['hostname'] = provider.get('hostname', None) \
        or provider.get('host', None)
    # allow local params to override provider
    for param, pvalue in provider.items():
        if module.params.get(param) is not False:
            module.params[param] = module.params.get(param) or pvalue

    hostname = module.params['hostname']
    username = module.params['username']
    dev_os = module.params['dev_os']
    password = module.params['password']
    timeout = module.params['timeout']

    argument_check = {'hostname': hostname, 'username': username,
                      'dev_os': dev_os, 'password': password}
    for key, val in argument_check.items():
        if val is None:
            module.fail_json(msg=str(key) + " is required")

    # use checks outside of ansible defined checks,
    # since params come can come from provider
    if dev_os not in os_choices:
        module.fail_json(msg="dev_os is not set to " + str(os_choices))

    optional_args = module.params['optional_args'] or {}
    try:
        network_driver = get_network_driver(dev_os)
        device = network_driver(hostname=hostname,
                                username=username,
                                password=password,
                                timeout=timeout,
                                optional_args=optional_args)
        device.open()
    except Exception as err:
        module.fail_json(msg="cannot connect to device: {0}".format(str(err)))
    return device 
開發者ID:napalm-automation,項目名稱:napalm-ansible,代碼行數:52,代碼來源:napalm_validate.py

示例12: testOpen

# 需要導入模塊: import napalm [as 別名]
# 或者: from napalm import get_network_driver [as 別名]
def testOpen(self):
        hostname = '172.16.123.3'
        username = 'tog'
        password = 'tog'

        #optional_args = {'port': 830, }
        driver = get_network_driver('ios')
        self.device = driver(hostname,username,password)

        self.device.open() 
開發者ID:mundofer,項目名稱:napalm-sros,代碼行數:12,代碼來源:test-ios.py


注:本文中的napalm.get_network_driver方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。