Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
Args:
commands (list): The ordered list of commands to send to the
device using the transport
encoding (str): The encoding method to use for the request and
excpected response.
send_enable (bool): If True the enable command will be
prepended to the command list automatically.
**kwargs: Additional keyword arguments for expanded eAPI
functionality. Only supported eAPI params are used in building
the request
Returns:
This method will return the raw response from the connection
which is a Python dictionary object.
"""
commands = make_iterable(commands)
# Some commands are multiline commands. These are banner commands and
# SSL commands. So with this two lines we
# can support those by passing commands by doing:
# banner login MULTILINE: This is my banner.\nAnd I even support
# multiple lines.
# Why this? To be able to read a configuration from a file, split it
# into lines and pass it as it is
# to pyeapi without caring about multiline commands.
commands = [{'cmd': c.split('MULTILINE:')[0],
'input': '%s\n' % (c.split('MULTILINE:')[1].strip())}
if 'MULTILINE:' in c else c for c in commands]
if send_enable:
if self._enablepwd:
commands.insert(0, {'cmd': 'enable', 'input': self._enablepwd})
A dict object that includes the response for each command along
with the encoding
Raises:
TypeError:
This method does not support sending configure
commands and will raise a TypeError if configuration commands
are found in the list of commands provided
This method will also raise a TypeError if the specified
encoding is not one of 'json' or 'text'
CommandError: This method will raise a CommandError if any one
of the commands fails.
"""
commands = make_iterable(commands)
if 'configure' in commands:
raise TypeError('config mode commands not supported')
results = list()
# IMPORTANT: There are two keys (response, result) that both
# return the same value. 'response' was originally placed
# there in error and both are now present to avoid breaking
# existing scripts. 'response' will be removed in a future release.
if strict:
responses = self.run_commands(commands, encoding, send_enable,
**kwargs)
for index, response in enumerate(responses):
results.append(dict(command=commands[index],
result=response,
response=response,
vrf_name (str): The VRF name to configure
default (bool): Configures ipv6 unicast routing for the vrf value
to default if this value is true
disable (bool): Negates the ipv6 unicast routing for the vrf if set
to true
Returns:
True if the operation was successful otherwise False
"""
cmd = 'ipv6 unicast-routing vrf %s' % vrf_name
if default:
cmd = 'default %s' % cmd
elif disable:
cmd = 'no %s' % cmd
cmd = make_iterable(cmd)
return self.configure(cmd)
def configure_ospf(self, cmd):
"""Allows for a list of OSPF subcommands to be configured"
Args:
cmd: (list or str): Subcommand to be entered
Returns:
bool: True if all the commands completed successfully
"""
config = self.get()
cmds = ['router ospf {}'.format(config['ospf_process_id'])]
cmds.extend(make_iterable(cmd))
return super(Ospf, self).configure(cmds)
def configure_bgp(self, cmd):
config = self.get()
cmds = ['router bgp {}'.format(config['bgp_as'])]
cmds.extend(make_iterable(cmd))
return super(Bgp, self).configure(cmds)
Args:
commands (list): A list of commands to include in the eAPI
request object
encoding (string): The encoding method passed as the `format`
parameter in the eAPI request
reqid (string): A custom value to assign to the request ID
field. This value is automatically generated if not passed
**kwargs: Additional keyword arguments for expanded eAPI
functionality. Only supported eAPI params are used in building
the request
Returns:
A JSON encoding request structure that can be send over eAPI
"""
commands = make_iterable(commands)
reqid = id(self) if reqid is None else reqid
params = {'version': 1, 'cmds': commands, 'format': encoding}
if 'autoComplete' in kwargs:
params['autoComplete'] = kwargs['autoComplete']
if 'expandAliases' in kwargs:
params['expandAliases'] = kwargs['expandAliases']
return json.dumps({'jsonrpc': '2.0', 'method': 'runCmds',
'params': params, 'id': str(reqid)})
def configure_vlan(self, vid, commands):
""" Configures the specified Vlan using commands
Args:
vid (str): The VLAN ID to configure
commands: The list of commands to configure
Returns:
True if the commands completed successfully
"""
commands = make_iterable(commands)
commands.insert(0, 'vlan %s' % vid)
return self.configure(commands)
def configure_vrf(self, vrf_name, commands):
""" Configures the specified VRF using commands
Args:
vrf_name (str): The VRF name to configure
commands: The list of commands to configure
Returns:
True if the commands completed successfully
"""
commands = make_iterable(commands)
commands.insert(0, 'vrf definition %s' % vrf_name)
return self.configure(commands)