Doc string changes

This commit is contained in:
rajvidhimar 2017-01-27 16:44:28 +05:30
parent 410f131a36
commit 8fa99775b8
2 changed files with 206 additions and 98 deletions

View File

@ -137,7 +137,7 @@ def rpc(cmd=None, dest=None, format='xml', **kwargs):
The format in which the rpc reply must be stored in file specified in the dest
(used only when dest is specified) (default = xml)
* kwargs: keyworded arguments taken by rpc call like-
* timeout:
* dev_timeout:
Set NETCONF RPC timeout. Can be used for commands which
take a while to execute. (default= 30 seconds)
* filter:
@ -171,10 +171,6 @@ def rpc(cmd=None, dest=None, format='xml', **kwargs):
'Format ignored as it is only used for \
output which is dumped in the file.')
if 'timeout' in op:
conn.timeout = op['timeout']
del op['timeout']
write_response = ''
try:
if cmd in ['get-config', 'get_config']:
@ -247,7 +243,7 @@ def set_hostname(hostname=None, **kwargs):
* hostname: The name to be set. (default = None)
Optional
* kwargs: Keyworded arguments which can be provided like-
* timeout:
* dev_timeout:
Set NETCONF RPC timeout. Can be used for commands
which take a while to execute. (default = 30 seconds)
* comment:
@ -273,10 +269,6 @@ def set_hostname(hostname=None, **kwargs):
else:
op.update(kwargs)
if 'timeout' in op:
conn.timeout = op['timeout']
del op['timeout']
# Added to recent versions of JunOs
# Use text format instead
set_string = 'set system host-name {0}'.format(hostname)
@ -324,15 +316,15 @@ def commit(**kwargs):
salt 'device_name' junos.commit comment='Commiting via saltstack' detail=True
salt 'device_name' junos.commit timeout=60 confirm=10
salt 'device_name' junos.commit dev_timeout=60 confirm=10
salt 'device_name' junos.commit sync=True timeout=90
salt 'device_name' junos.commit sync=True dev_timeout=90
Parameters:
Optional
* kwargs: Keyworded arguments which can be provided like-
* timeout:
* dev_timeout:
Set NETCONF RPC timeout. Can be used for commands which take a \
while to execute. (default = 30 seconds)
* comment:
@ -368,10 +360,6 @@ def commit(**kwargs):
else:
op.update(kwargs)
if 'timeout' in op:
conn.timeout = op['timeout']
del op['timeout']
detail = False
if 'detail' in op and op['detail']:
detail = True
@ -424,7 +412,7 @@ def rollback(id=0, **kwargs):
* id:
The rollback id value [0-49]. (default = 0)
* kwargs: Keyworded arguments which can be provided like-
* timeout:
* dev_timeout:
Set NETCONF RPC timeout. Can be used for commands which
take a while to execute. (default = 30 seconds)
* comment:
@ -449,10 +437,6 @@ def rollback(id=0, **kwargs):
else:
op.update(kwargs)
if 'timeout' in op:
conn.timeout = op['timeout']
del op['timeout']
try:
ret['out'] = conn.cu.rollback(id)
except Exception as exception:
@ -548,7 +532,7 @@ def ping(dest_ip=None, **kwargs):
The IP which is to be pinged. (default = None)
Optional
* kwargs: Keyworded arguments which can be provided like-
* timeout:
* dev_timeout:
Set NETCONF RPC timeout. Can be used for commands which
take a while to execute. (default = 30 seconds)
* rapid:
@ -581,10 +565,6 @@ def ping(dest_ip=None, **kwargs):
else:
op.update(kwargs)
if 'timeout' in op:
conn.timeout = op['timeout']
del op['timeout']
if 'count' in op:
op['count'] = str(op['count'])
else:
@ -612,7 +592,7 @@ def cli(command=None, format='text', **kwargs):
salt 'device_name' junos.cli command='show system commit'
salt 'device_name' junos.cli command='show version' timeout=40
salt 'device_name' junos.cli command='show version' dev_timeout=40
salt 'device_name' junos.cli command='show system alarms' format='xml' dest=/home/user/cli_output.txt
@ -626,7 +606,7 @@ def cli(command=None, format='text', **kwargs):
Format in which to get the CLI output. (text or xml, \
default = 'text')
* kwargs: Keyworded arguments which can be provided like-
* timeout:
* dev_timeout:
Set NETCONF RPC timeout. Can be used for commands which
take a while to execute. (default = 30 seconds)
* dest:
@ -650,10 +630,6 @@ def cli(command=None, format='text', **kwargs):
else:
op.update(kwargs)
if 'timeout' in op:
conn.timeout = op['timeout']
del op['timeout']
try:
result = conn.cli(command, format)
except Exception as exception:
@ -718,10 +694,6 @@ def shutdown(**kwargs):
else:
op.update(kwargs)
if 'timeout' in op:
conn.timeout = op['timeout']
del op['timeout']
try:
if 'reboot' in op and op['reboot']:
shut = sw.reboot
@ -752,11 +724,11 @@ def install_config(path=None, **kwargs):
.. code-block:: bash
salt 'device_name' junos.install_config path='/home/user/config.set' timeout=60
salt 'device_name' junos.install_config path='/home/user/config.set'
salt 'device_name' junos.install_config path='/home/user/replace_config.conf' replace=True comment='Committed via SaltStack'
salt 'device_name' junos.install_config path='/home/user/my_new_configuration.conf' timeout=300 diffs_file='/salt/confs/old_config.conf' overwrite=True
salt 'device_name' junos.install_config path='/home/user/my_new_configuration.conf' dev_timeout=300 diffs_file='/salt/confs/old_config.conf' overwrite=True
Parameters:
@ -771,7 +743,7 @@ def install_config(path=None, **kwargs):
the content is treated as Junos OS 'set' commands.(default = None)
Optional
* kwargs: Keyworded arguments which can be provided like-
* timeout:
* dev_timeout:
Set NETCONF RPC timeout. Can be used for commands which
take a while to execute. (default = 30 seconds)
* overwrite:
@ -842,10 +814,6 @@ def install_config(path=None, **kwargs):
else:
op = {'path': path}
if 'timeout' in op:
conn.timeout = op['timeout']
del op['timeout']
if 'replace' in op and op['replace']:
op['merge'] = False
del op['replace']
@ -942,7 +910,7 @@ def install_os(path=None, **kwargs):
salt 'device_name' junos.install_os path='/home/user/junos_image.tgz' reboot=True
salt 'device_name' junos.install_os path='/home/user/junos_16_1.tgz' timeout=300
salt 'device_name' junos.install_os path='/home/user/junos_16_1.tgz' dev_timeout=300
Parameters:
@ -950,8 +918,8 @@ def install_os(path=None, **kwargs):
* path:
Path where the image file is present on the proxy minion.
Optional
* kwargs: keyworded arguments to be given such as timeout, reboot etc
* timeout:
* kwargs: keyworded arguments to be given such as dev_timeout, reboot etc
* dev_timeout:
Set NETCONF RPC timeout. Can be used to RPCs which
take a while to execute. (default = 30 seconds)
* reboot:
@ -984,10 +952,6 @@ def install_os(path=None, **kwargs):
else:
op.update(kwargs)
if 'timeout' in op:
conn.timeout = op['timeout']
del op['timeout']
try:
install = conn.sw.install(path, progress=True)
ret['message'] = 'Installed the os.'
@ -1058,9 +1022,6 @@ def file_copy(src=None, dest=None, **kwargs):
op.update(kwargs['__pub_arg'][-1])
else:
op.update(kwargs)
if 'timeout' in op:
conn.timeout = op['timeout']
del op['timeout']
try:
with SCP(conn, progress=True) as scp:

View File

@ -3,8 +3,8 @@
State modules to interact with Junos devices.
==============================================
These modules call the corresponding execution modules.
Refer to :mod:`junos <salt.modules.junos>` for further information.
State module to connect the junos devices connected via a junos proxy.
Refer to :mod:`junos <salt.proxy.junos>` for information on connecting to junos proxy.
'''
from __future__ import absolute_import
import logging
@ -25,11 +25,27 @@ def rpc(name, dest=None, format='xml', args=None, **kwargs):
- dest: /home/user/rpc.log
- interface_name: lo0
name: the rpc to be executed.
args: other arguments as taken by rpc call of PyEZ
kwargs: keyworded arguments taken by rpc call of PyEZ
Parameters:
Required
* cmd:
The rpc to be executed. (default = None)
Optional
* dest:
Destination file where the rpc ouput is stored. (default = None)
* format:
The format in which the rpc reply must be stored in file specified in the dest
(used only when dest is specified) (default = xml)
* kwargs: keyworded arguments taken by rpc call like-
* timeout:
Set NETCONF RPC timeout. Can be used for commands which
take a while to execute. (default= 30 seconds)
* filter:
Only to be used with 'get-config' rpc to get specific configuration.
* terse:
Amount of information you want.
* interface_name:
Name of the interface whose information you want.
'''
ret = {'name': name, 'changes': {}, 'result': True, 'comment': ''}
@ -45,91 +61,170 @@ kwargs: keyworded arguments taken by rpc call of PyEZ
return ret
def set_hostname(name, commit_changes=True):
def set_hostname(name, **kwargs):
'''
Changes the hostname of the device.
.. code-block:: yaml
device name:
device_name:
junos:
- set_hostname
- commit_changes: False
- comment: "Host-name set via saltstack."
name: the name to be given to the device
commit_changes: whether to commit the changes
Parameters:
Required
* hostname: The name to be set. (default = None)
Optional
* kwargs: Keyworded arguments which can be provided like-
* timeout:
Set NETCONF RPC timeout. Can be used for commands
which take a while to execute. (default = 30 seconds)
* comment:
Provide a comment to the commit. (default = None)
* confirm:
Provide time in minutes for commit confirmation. \
If this option is specified, the commit will be rollbacked in \
the given time unless the commit is confirmed.
'''
ret = {'name': name, 'changes': {}, 'result': True, 'comment': ''}
ret['changes'] = __salt__['junos.set_hostname'](name, commit_changes)
ret['changes'] = __salt__['junos.set_hostname'](name, **kwargs)
return ret
def commit(name):
def commit(name, **kwargs):
'''
Commits the changes loaded into the candidate configuration.
.. code-block:: yaml
commit the changes:
junos.commit
junos:
- commit
- confirm: 10
name: can be anything
Parameters:
Optional
* kwargs: Keyworded arguments which can be provided like-
* timeout:
Set NETCONF RPC timeout. Can be used for commands which take a \
while to execute. (default = 30 seconds)
* comment:
Provide a comment to the commit. (default = None)
* confirm:
Provide time in minutes for commit confirmation. If this option \
is specified, the commit will be rollbacked in the given time \
unless the commit is confirmed.
* sync:
On dual control plane systems, requests that the candidate\
configuration on one control plane be copied to the other \
control plane,checked for correct syntax, and committed on \
both Routing Engines. (default = False)
* force_sync:
On dual control plane systems, force the candidate configuration
on one control plane to be copied to the other control plane.
* full:
When set to True requires all the daemons to check and evaluate \
the new configuration.
* detail:
When true return commit detail.
'''
ret = {'name': name, 'changes': {}, 'result': True, 'comment': ''}
ret['changes'] = __salt__['junos.commit']()
ret['changes'] = __salt__['junos.commit'](**kwargs)
return ret
def rollback(name):
def rollback(name, id, **kwargs):
'''
Rollbacks the committed changes.
.. code-block:: yaml
rollback the changes:
junos.rollback
junos:
- rollback
- id: 5
Parameters:
Optional
* id:
The rollback id value [0-49]. (default = 0)
* kwargs: Keyworded arguments which can be provided like-
* timeout:
Set NETCONF RPC timeout. Can be used for commands which
take a while to execute. (default = 30 seconds)
* comment:
Provide a comment to the commit. (default = None)
* confirm:
Provide time in minutes for commit confirmation. If this option \
is specified, the commit will be rollbacked in the given time \
unless the commit is confirmed.
* diffs_file:
Path to the file where any diffs will be written. (default = None)
name: can be anything
'''
ret = {'name': name, 'changes': {}, 'result': True, 'comment': ''}
ret['changes'] = __salt__['junos.rollback']()
ret['changes'] = __salt__['junos.rollback'](id, **kwargs)
return ret
def diff(name):
def diff(name, d_id):
'''
Gets the difference between the candidate and the current configuration.
.. code-block:: yaml
get the diff:
junos.diff
junos:
- diff
- id: 10
name: can be anything
Parameters:
Optional
* id:
The rollback id value [0-49]. (default = 0)
'''
ret = {'name': name, 'changes': {}, 'result': True, 'comment': ''}
ret['changes'] = __salt__['junos.diff']()
ret['changes'] = __salt__['junos.diff'](d_id)
return ret
def cli(name):
def cli(name, format='text', **kwargs):
'''
Executes the CLI commands and reuturns the text output.
.. code-block:: yaml
show version:
junos.cli
junos:
- cli
- format: xml
name: the command to be executed on junos CLI.
Parameters:
Required
* command:
The command that need to be executed on Junos CLI. (default = None)
Optional
* format:
Format in which to get the CLI output. (text or xml, \
default = 'text')
* kwargs: Keyworded arguments which can be provided like-
* timeout:
Set NETCONF RPC timeout. Can be used for commands which
take a while to execute. (default = 30 seconds)
* dest:
The destination file where the CLI output can be stored.\
(default = None)
'''
ret = {'name': name, 'changes': {}, 'result': True, 'comment': ''}
ret['changes'] = __salt__['junos.cli'](name)
ret['changes'] = __salt__['junos.cli'](name, format, **kwargs)
return ret
def shutdown(name, time=0):
def shutdown(name, **kwargs):
'''
Shuts down the device.
@ -138,14 +233,20 @@ def shutdown(name, time=0):
shut the device:
junos:
- shutdown
- time: 10
- in_min: 10
name: can be anything
time: time after which the system should shutdown(in seconds, default=0)
Parameters:
Optional
* kwargs:
* reboot:
Whether to reboot instead of shutdown. (default=False)
* at:
Specify time for reboot. (To be used only if reboot=yes)
* in_min:
Specify delay in minutes for shutdown
'''
ret = {'name': name, 'changes': {}, 'result': True, 'comment': ''}
ret['changes'] = __salt__['junos.shutdown'](time)
ret['changes'] = __salt__['junos.shutdown'](**kwargs)
return ret
@ -159,10 +260,40 @@ def install_config(name, **kwargs):
junos:
- install_config
- timeout: 100
- diffs_file: 'home/user/diff'
name: path to the configuration file.
keyworded arguments taken by load fucntion of PyEZ
Parameters:
Required
* path:
Path where the configuration file is present. If the file has a \
'*.conf' extension,
the content is treated as text format. If the file has a '*.xml' \
extension,
the content is treated as XML format. If the file has a '*.set' \
extension,
the content is treated as Junos OS 'set' commands.(default = None)
Optional
* kwargs: Keyworded arguments which can be provided like-
* timeout:
Set NETCONF RPC timeout. Can be used for commands which
take a while to execute. (default = 30 seconds)
* overwrite:
Set to True if you want this file is to completely replace the\
configuration file. (default = False)
* replace:
Specify whether the configuration file uses "replace:" statements.
Those statements under the 'replace' tag will only be changed.\
(default = False)
* comment:
Provide a comment to the commit. (default = None)
* confirm:
Provide time in minutes for commit confirmation.
If this option is specified, the commit will be rollbacked in \
the given time unless the commit is confirmed.
* diffs_file:
Path to the file where the diff (difference in old configuration
and the newly commited configuration) will be stored.\
(default = None)
'''
ret = {'name': name, 'changes': {}, 'result': True, 'comment': ''}
ret['changes'] = __salt__['junos.install_config'](name, **kwargs)
@ -198,16 +329,29 @@ def install_os(name, **kwargs):
- timeout: 100
- reboot: True
name: path to the image file.
Parameters:
Required
* path:
Path where the image file is present on the pro\
xy minion.
Optional
* kwargs: keyworded arguments to be given such as timeout, reboot etc
* timeout:
Set NETCONF RPC timeout. Can be used to RPCs which
take a while to execute. (default = 30 seconds)
* reboot:
Whether to reboot after installation (default = False)
* no_copy:
When True the software package will not be SCPd to the device. \
(default = False)
kwargs: keyworded arguments to be given such as timeout, reboot etc
'''
ret = {'name': name, 'changes': {}, 'result': True, 'comment': ''}
ret['changes'] = __salt__['junos.install_os'](name, **kwargs)
return ret
def file_copy(name, dest=None):
def file_copy(name, dest=None, **kwargs):
'''
Copies the file from the local device to the junos device.
@ -218,10 +362,13 @@ def file_copy(name, dest=None):
- file_copy
- dest: info_copy.txt
name: source path of the file.
dest: destination path where the file will be placed.
Parameters:
Required
* src:
The sorce path where the file is kept.
* dest:
The destination path where the file will be copied.
'''
ret = {'name': name, 'changes': {}, 'result': True, 'comment': ''}
ret['changes'] = __salt__['junos.file_copy'](name, dest)
ret['changes'] = __salt__['junos.file_copy'](name, dest, **kwargs)
return ret