Пример #1
0
    def __init__(self, **kwargs):
        """

        """
        self.base = kwargs.pop('base')
        self._conn = kwargs.pop('conn')
        self.host = self._conn[0]
        self._auth = kwargs.pop('auth', (None, None))
        if 'auth_snmp' in kwargs:
            auth_snmp = kwargs.pop('auth_snmp', (None, None, None, None))
            self._auth = (auth_snmp[0], auth_snmp[1])
        self._callback = kwargs.pop('callback', None)
        self.os_type_val = None
        self._rest_proto = None
        self.platform_type_val = None

        if len(self._conn) >= 3:
            self._rest_proto = self._conn[2]

        if self._callback is None:
            self._callback = self._callback_main

        self._mgr = None
        self._cli = None

        self.reconnect()

        fullver = self.firmware_version
        thismodule = sys.modules[__name__]
        os_table = getattr(thismodule, '%s_VERSIONS' %
                           str(self.os_type).upper())

        if fullver in os_table:
            ver = fullver
        else:
            ver = util.get_two_tuple_version(fullver)

        for nos_attr in NOS_ATTRS:
            if nos_attr in os_table[ver]:
                """
                  utils class should be considered as
                  special as it can execute CLI commands
                  wherever REST is not supported. Hence
                  we need to pass the host and auth parameters.
                """
                if nos_attr == 'utils':
                    setattr(
                        self.base,
                        nos_attr,
                        os_table[ver][nos_attr](
                            self._callback, self.host, self._auth))
                else:
                    setattr(
                        self.base,
                        nos_attr,
                        os_table[ver][nos_attr](
                            self._callback))

        setattr(self, 'asset', self._mgr)
Пример #2
0
    def __init__(self, **kwargs):
        """
        Args:
            conn (tuple): IP/Hostname and port of the VDX device you
                intend to connect to. Ex. ('10.0.0.1', '22')
            auth (tuple): Username and password of the VDX device you
                intend to connect to. Ex. ('admin', 'password')
            hostkey_verify (bool): True to verify hostkey, False to bypass
                verify.
            auth_method (string): ```key``` if using ssh-key auth.
                ```userpass``` if using username/password auth.
            auth_key (string): Location of ssh key to use for authentication.
        Returns:
            Instance of the device object.
        Examples:
            >>> from pprint import pprint
            >>> import pyswitch.rawdevice1
            >>> conn = ('10.24.39.211', '22')
            >>> auth = ('admin', 'password')
            >>> dev = pyswitch.rawdevice1.Device(conn=conn, auth=auth)
            >>> dev.connection
            True
            >>> del dev
            >>> with pyswitch.rawdevice1.Device(conn=conn, auth=auth) as dev:
            ...     pprint(dev.mac_table) # doctest: +ELLIPSIS
            [{'interface'...'mac_address'...'state'...'type'...'vlan'...}]
            >>> dev.connection
            False
        """
        self.base = kwargs.pop('base')
        self._conn = kwargs.pop('conn')
        self._auth = kwargs.pop('auth', (None, None))
        if 'auth_snmp' in kwargs:
            auth_snmp = kwargs.pop('auth_snmp', (None, None, None, None))
            self._auth = (auth_snmp[0], auth_snmp[1])
        self._hostkey_verify = kwargs.pop('hostkey_verify', None)
        self._auth_method = kwargs.pop('auth_method', 'userpass')
        self._auth_key = kwargs.pop('auth_key', None)
        self._test = kwargs.pop('test', False)
        self._callback = kwargs.pop('callback', None)
        if self._callback is None:
            self._callback = self._callback_main

        self._mgr = None

        self.reconnect()
        self._fetch_firmware_version()
        self.platform_type_val = None

        self.fullver = self.firmware_version

        thismodule = sys.modules[__name__]

        self.os_table = getattr(thismodule,
                                '%s_VERSIONS' % str(self.os_type).upper())

        if self.fullver in self.os_table:
            self.ver = self.fullver
        else:
            self.ver = util.get_two_tuple_version(self.fullver)

        for nos_attr in NOS_ATTRS:
            if nos_attr in self.os_table[self.ver]:
                setattr(self.base, nos_attr,
                        self.os_table[self.ver][nos_attr](self._callback_main))
Пример #3
0
    def __init__(self, sysobj, **kwargs):
        """

        """
        self.base = kwargs.pop('base')
        self._conn = kwargs.pop('conn')
        self.host = self._conn[0]
        auth_snmp = kwargs.pop('auth_snmp', (None, None, None, None))
        self._auth = (auth_snmp[0], auth_snmp[1])
        self._test = kwargs.pop('test', False)
        self._callback = kwargs.pop('callback', None)
        self._enablepass = auth_snmp[2]
        snmpconfig = auth_snmp[3]
        self._snmpversion = snmpconfig['version']
        self._snmpport = snmpconfig['snmpport']
        self._snmpv2c = snmpconfig['snmpv2c']
        self._v3user = snmpconfig['v3user']
        self._v3auth = snmpconfig['v3auth']
        self._v3priv = snmpconfig['v3priv']
        self._authpass = snmpconfig['authpass']
        self._privpass = snmpconfig['privpass']
        self._sysobj = sysobj
        self._proxied = None
        ns_daemon_dict = ConfigFileUtil().read(
            filename=pyswitchlib_ns_daemon_file)

        if pyswitchlib_daemon in ns_daemon_dict:
            uri = ns_daemon_dict[pyswitchlib_daemon]
            with Pyro4.Proxy(uri) as pyro_proxy:
                pyro_proxy._pyroBind()
                self._proxied = pyro_proxy

        if self._callback is None:
            self._callback = self._callback_main

        self._mgr = {}

        self.reconnect()

        # self._os_type = version_list[0][2]
        devicemap = SNMPUtils.SNMP_DEVICE_MAP[sysobj]
        self.platform_type_val = devicemap[0]
        self._os_type = devicemap[1]
        self.fullver = self.firmware_version
        # self.fullver = version_list[0][1]

        thismodule = sys.modules[__name__]
        os_table = getattr(thismodule,
                           '%s_VERSIONS' % str(self.os_type).upper())

        if self.fullver in os_table:
            ver = self.fullver
        else:
            ver = util.get_two_tuple_version(self.fullver)

        for router_attr in ROUTER_ATTRS:
            if router_attr in os_table[ver]:
                setattr(self.base, router_attr,
                        os_table[ver][router_attr](self._callback))
        # setattr(self.base, 'snmp', NI_VERSIONS['6.1.0T163']['snmp'](self._callback))

        setattr(self, 'asset', self._mgr)