Skip to content

Commit

Permalink
Merge pull request #773 from stacywsmith/vmhost_sw_install
Browse files Browse the repository at this point in the history
Add vmhost parameter to SW.install() to support upgrading the VM Host.
  • Loading branch information
vnitinv authored Aug 29, 2017
2 parents e7fb00e + 1c9446b commit 9c0c860
Show file tree
Hide file tree
Showing 3 changed files with 356 additions and 41 deletions.
123 changes: 85 additions & 38 deletions lib/jnpr/junos/utils/sw.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,17 +192,27 @@ def put(self, package, remote_path='/var/tmp', progress=None):
# pkgadd - used to perform the 'request system software add ...'
# -------------------------------------------------------------------------

def pkgadd(self, remote_package, **kvargs):
def pkgadd(self, remote_package, vmhost=False, **kvargs):
"""
Issue the 'request system software add' command on the package.
The "no-validate" options is set by default. If you want to validate
the image, do that using the specific :meth:`validate` method. Also,
if you want to reboot the device, suggest using the :meth:`reboot`
method rather ``reboot=True``.
Issue the RPC equivalent of the 'request system software add' command
or the 'request vmhost software add' command on the package.
If vhmhost=False, the <request-package-add> RPC is used and the
The "no-validate" options is set. If you want to validate
the image, do that using the specific :meth:`validate` method.
If vmhost=True, the <request-vmhost-package-add> RPC is used.
If you want to reboot the device, invoke the :meth:`reboot` method
after installing the software rather than passing the ``reboot=True``
parameter.
:param str remote_package:
The file-path to the install package on the remote (Junos) device.
:param bool vhmhost:
(Optional) A boolean indicating if this is a software update of the
vhmhost. The default is ``vmhost=False``.
:param dict kvargs:
Any additional parameters to the 'request' command can
be passed within **kvargs**, following the RPC syntax
Expand All @@ -211,18 +221,23 @@ def pkgadd(self, remote_package, **kvargs):
.. warning:: Refer to the restrictions listed in :meth:`install`.
"""

if isinstance(remote_package, (list, tuple)) and self._mixed_VC:
args = dict(no_validate=True, set=remote_package)
if vmhost is False:
if isinstance(remote_package, (list, tuple)) and self._mixed_VC:
args = dict(no_validate=True, set=remote_package)
else:
args = dict(no_validate=True, package_name=remote_package)
args.update(kvargs)
rsp = self.rpc.request_package_add(**args)
else:
args = dict(no_validate=True, package_name=remote_package)
args.update(kvargs)
rsp = self.rpc.request_vmhost_package_add(
package_name=remote_package,
**kvargs)

rsp = self.rpc.request_package_add(**args)
return self._parse_pkgadd_response(rsp)

# -------------------------------------------------------------------------
# pkgaddNSSU - used to perform NSSU upgrade
# -------------------------------------------------------------------------
# -------------------------------------------------------------------------
# pkgaddNSSU - used to perform NSSU upgrade
# -------------------------------------------------------------------------

def pkgaddNSSU(self, remote_package, **kvargs):
"""
Expand All @@ -241,17 +256,32 @@ def pkgaddNSSU(self, remote_package, **kvargs):
# pkgaddISSU - used to perform ISSU upgrade
# -------------------------------------------------------------------------

def pkgaddISSU(self, remote_package, **kvargs):
def pkgaddISSU(self, remote_package, vmhost=False, **kvargs):
"""
Issue the 'request system software nonstop-upgrade' command on the
package.
Issue the RPC equivalent of the
'request system software in-service-upgrade' command
or the 'request vmhost software in-service-upgrade' command on the
package. If vhmhost=False, the <request-package-in-service-upgrade>
RPC is used. If vmhost=True, the
<request-vmhost-package-in-service-upgrade> RPC is used.
:param str remote_package:
The file-path to the install package on the remote (Junos) device.
:param bool vhmhost:
(Optional) A boolean indicating if this is a software update of the
vhmhost. The default is ``vmhost=False``.
"""

rsp = self.rpc.request_package_in_service_upgrade(
package_name=remote_package, **kvargs)
if vmhost is False:
rsp = self.rpc.request_package_in_service_upgrade(
package_name=remote_package,
**kvargs)
else:
rsp = self.rpc.request_vmhost_package_in_service_upgrade(
package_name=remote_package,
**kvargs)
return self._parse_pkgadd_response(rsp)

def _parse_pkgadd_response(self, rsp):
Expand Down Expand Up @@ -596,7 +626,7 @@ def install(self, package=None, pkg_set=None, remote_path='/var/tmp',
no_copy=False, issu=False, nssu=False, timeout=1800,
cleanfs_timeout=300, checksum_timeout=300,
checksum_algorithm='md5', force_copy=False, all_re=True,
**kwargs):
vmhost=False, **kwargs):
"""
Performs the complete installation of the **package** that includes the
following steps:
Expand Down Expand Up @@ -649,21 +679,21 @@ def install(self, package=None, pkg_set=None, remote_path='/var/tmp',
to reboot the device.
:param str package:
Either the full file path to the install package tarball on the local
(PyEZ host's) filesystem OR a URL (from the target device's
perspcective) from which the device retrieves installed. When the
Either the full file path to the install package tarball on the local
(PyEZ host's) filesystem OR a URL (from the target device's
perspcective) from which the device retrieves installed. When the
value is a URL, then the :no_copy: and :remote_path: values are
unused. The acceptable formats for a URL value may be found at:
https://www.juniper.net/documentation/en_US/junos/topics/concept/junos-software-formats-filenames-urls.html
:param list pkg_set:
A list/tuple of :package: values which will be installed on a mixed VC
setup.
A list/tuple of :package: values which will be installed on a mixed
VC setup.
:param str remote_path:
If the value of :package: or :pkg_set: is a file path on the local
(PyEZ host's) filesystem, then the image is copied from the local
filesystem to the :remote_path: directory on the target Junos
(PyEZ host's) filesystem, then the image is copied from the local
filesystem to the :remote_path: directory on the target Junos
device. The default is ``/var/tmp``. If the value of :package: or
:pkg_set: is a URL, then the value of :remote_path: is unused.
Expand Down Expand Up @@ -699,7 +729,7 @@ def myprogress(dev, report):
directory of the target Junos device. When the value of :no_copy: is
``False`` (the default), then the package is copied from the local
PyEZ host to the :remote_path: directory of the target Junos device.
If the value of :package: or :pkg_set: is a URL, then the value of
If the value of :package: or :pkg_set: is a URL, then the value of
:no_copy: is unused.
:param bool issu:
Expand Down Expand Up @@ -747,6 +777,10 @@ def myprogress(dev, report):
all Routing Engines of the Junos device. When ``False`` if the
only preform the software install on the current Routing Engine.
:param bool vhmhost:
(Optional) A boolean indicating if this is a software update of the
vhmhost. The default is ``vmhost=False``.
:param kwargs **kwargs:
(Optional) Additional keyword arguments are passed through to the
"package add" RPC.
Expand Down Expand Up @@ -816,20 +850,26 @@ def _progress(report):
if len(remote_pkg_set) == 1:
remote_package = remote_pkg_set[0]
# validate can't be used in the case of a Mixed VC
if validate is True and self._mixed_VC is False:
_progress(
"validating software against current config,"
" please be patient ...")
v_ok = self.validate(remote_package, issu, nssu,
dev_timeout=timeout)

if v_ok is not True:
return v_ok
# With vmhost=True, validate is handled in the package add.
if validate is True:
if self._mixed_VC is False and vmhost is not True:
_progress(
"validating software against current config,"
" please be patient ...")
v_ok = self.validate(remote_package, issu, nssu,
dev_timeout=timeout)
if v_ok is not True:
return v_ok
else:
if vmhost is True:
# Need to pass the no_validate option via kwargs.
kwargs.update({'no_validate': True})

if issu is True:
_progress(
"ISSU: installing software ... please be patient ...")
return self.pkgaddISSU(remote_package,
vmhost=vmhost,
dev_timeout=timeout, **kwargs)
elif nssu is True:
_progress(
Expand All @@ -841,6 +881,7 @@ def _progress(report):
_progress("installing software ... please be patient ...")
add_ok = self.pkgadd(
remote_package,
vmhost=vmhost,
dev_timeout=timeout,
**kwargs)
return add_ok
Expand All @@ -859,6 +900,7 @@ def _progress(report):
"be patient ...".format(vc_id))
ok &= self.pkgadd(
remote_package,
vmhost=vmhost,
member=vc_id,
dev_timeout=timeout,
**kwargs)
Expand All @@ -871,21 +913,26 @@ def _progress(report):
"installing software on RE0 ... please be patient ...")
ok &= self.pkgadd(
remote_package,
vmhost=vmhost,
re0=True,
dev_timeout=timeout,
**kwargs)
_progress(
"installing software on RE1 ... please be patient ...")
ok &= self.pkgadd(
remote_package,
vmhost=vmhost,
re1=True,
dev_timeout=timeout,
**kwargs)
return ok

elif len(remote_pkg_set) > 1 and self._mixed_VC:
_progress("installing software ... please be patient ...")
add_ok = self.pkgadd(remote_pkg_set, dev_timeout=timeout, **kwargs)
add_ok = self.pkgadd(remote_pkg_set,
vmhost=vmhost,
dev_timeout=timeout,
**kwargs)
return add_ok

# -------------------------------------------------------------------------
Expand Down
Loading

0 comments on commit 9c0c860

Please sign in to comment.