Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_connect_ssh_with_hostkey_ed25519(self, mock_ssh):
hostkey = 'AAAAC3NzaC1lZDI1NTE5AAAAIIiHpGSf8fla6tCwLpwshvMGmUK+B/0v5CsRu+5v4uT7'
manager.connect(host='host', hostkey=hostkey)
mock_ssh.assert_called_once_with(host='host', hostkey=hostkey)
def main():
"""
Main method that prints netconf capabilities of remote device.
"""
for device in DEVICES:
with manager.connect(host=device, port=PORT, username=USER,
password=PASS, hostkey_verify=False,
device_params={'name': 'nexus'},
look_for_keys=False, allow_agent=False) as m:
# print all NETCONF capabilities
print('\n***Remote Devices Capabilities for device {} {}***\n'.format(DEVICE_NAMES[device], device))
for capability in m.server_capabilities:
print(capability.split('?')[0])
router = {"ip": "10.10.20.48",
"port": 830,
"user": "developer",
"pass": "C1sco12345"}
netconf_filter = """
"""
m = manager.connect(host=router["ip"],
port=router["port"],
username=router["user"],
password=router["pass"],
hostkey_verify=False)
interface_netconf = m.get_config("running", netconf_filter)
interface_python = xmltodict.parse(interface_netconf.xml)["rpc-reply"]["data"]
pprint(interface_python["interfaces"]["interface"]["name"]["#text"])
def connect(host, port, user, password):
conn = manager.connect(host=host,
port=port,
username=user,
password=password,
timeout=60,
device_params={'name': 'junos'},
hostkey_verify=False)
conn.lock()
# configuration as a text string
host_name = """
system {
host-name foo-bar;
}
"""
def connect(host, port, user, password):
conn = manager.connect(host=host,
port=port,
username=user,
password=password,
timeout=60,
device_params={'name': 'junos'},
hostkey_verify=False)
rpc = """
"""
result = conn.rpc(rpc)
logging.info('Chassis serial-number: %s', result.xpath('//chassis-inventory/chassis/serial-number')[0].text)
def connect(self, session_config):
assert session_config.transportMode == _SessionTransportMode.SSH
if self.use_native_client:
self.ydk_client = YdkClient(
username=session_config.username,
password=session_config.password,
host=session_config.hostname,
port=session_config.port)
self.ydk_client.connect()
return self.ydk_client
else:
self._nc_manager = manager.connect(
host=session_config.hostname,
port=session_config.port,
username=session_config.username,
password=session_config.password,
look_for_keys=False,
allow_agent=False,
hostkey_verify=False)
return self._nc_manager
def get_netconf(xml_filter):
"""
Main method that retrieves information via NETCONF get.
"""
with manager.connect(host=HOST, port=PORT, username=USER,
password=PASS, hostkey_verify=False,
device_params={'name': 'default'},
allow_agent=False, look_for_keys=False) as m:
with open(xml_filter) as f:
# MISSION: Replace XXX with the correct NETCONF operation
return(m.get(f.read()))
# Input parameters
parser.add_argument('--host', type=str, required=True,
help="The device IP or DN")
parser.add_argument('-u', '--username', type=str, default='cisco',
help="Go on, guess!")
parser.add_argument('-p', '--password', type=str, default='cisco',
help="Yep, this one too! ;-)")
parser.add_argument('--port', type=int, default=830,
help="Specify non-default port for NETCONF")
args = parser.parse_args()
global m
m = manager.connect(host=args.host,
port=args.port,
username=args.username,
password=args.password,
device_params={'name':"iosxe"})
prompt = QoSPolicy()
prompt.prompt = 'QoSPolicy> '
prompt.cmdloop('Starting QoSPolicy prompt...')