Hi Russ,
I'm familiar mainly with software provider. Therefore following
script
utilizes it. Although I think there are more interesting examples
for
other providers to be found.
Let's suppose we are not interested in updates-testing repository
which
is disabled. But there is just one thing we want to keep up to date
(keep in sync with updates-testing). Let's choose for example vlc
package.
Following example is written in pure LMIShell:
c = connect('localhost')
# get installation service
service =
c.root.cimv2.LMI_SoftwareInstallationService.first_instance()
# get software collection
collection = c.root.cimv2.LMI_SystemSoftwareCollection \
first_instance_name()
# get updates-testing repository
repo = c.root.cimv2.LMI_SoftwareIdentityResource.first_instance(
{'Name' : 'updates-testing'})
# get installed packages
installed =
c.root.cimv2.LMI_InstalledSoftwareIdentity.instance_names()
# filter out vlc unrelated stuff
installed = [p.to_instance() for p in installed if
p.InstanceID.contains('vlc')]
# temporarily enable updates-testing
repo.RequestStateChange(RequestedState=c.root.cimv2. \
LMI_SoftwareIdentityResource.RequestedStateValues.Enabled)
try:
for pkg in installed:
# do the update synchronously
rval, rparms, errstr =
service.SyncInstallFromSoftwareIdentity(
Source=pkg.path,
# see the documentation for InstallFromIdentity
method
InstallOptions=[5], # 5 here means Update
Collection=collection)
if rval == 0: # Job completed with no error
orig_nevra = pkg.ElementName
# get the newly installed version
pkg.refresh()
print "updated %s to %s" % (orig_nevra,
pkg.ElementName)
finally:
# disable updates-testing again
repo.RequestStateChange(RequestedState=c.root.cimv2. \
LMI_SoftwareIdentityResource.RequestedStateValues.Disabled)
And the same based on software scripts library:
from lmi.scripts import software as sw
from lmi.scripts.common import LMIFailed
ns = connect('localhost').root.cimv2
installed = sw.list_installed_packages(ns)
# filter out vlc unrelated stuff
installed = [p for p in installed if
p.InstanceID.contains('vlc')]
# temporarily enable updates-testing
sw.set_repository_enabled(ns, 'updates-testing')
try:
for pkg in installed:
try:
updated = sw.install_package(ns, pkg, update=True)
except LMIFailed as err:
print "failed to update %s: %s" % (
pkg.ElementName, str(err))
else:
print "updated %s to %s" % (pkg.ElementName,
updated.ElementName)
finally:
# disable updates-testing again
sw.set_repository_enabled(ns, 'updates-testing', False)
I hope it meets some of your criteria. It's not part of any LMI
command,
but it can be written into a file (update-vlc.lmi) and be directly
executed.
As an enhancement, user could make it generic - accept any other
package
name and try to update it.
Cheers,
Michal
On 10.12.2013 19:47, Russell Doty wrote:
> I'm working on a writeup of
LMIShell and need an LMIShell Script to
> dissect as an example. Please nominate your favorite script:
>
> * Does something interesting and useful.
> * Good example of a SysAdmin friendly interface.
> * Shows solid software engineering practices.
> * Uses low-level OpenLMI API calls to change a system.
> * Bonus points if it is used in an LMI Command.
> * Can be extended and modified.
> * Bonus points if we can suggest useful changes someone
could write.
> * Short and simple enough that I can explain it.
>
> Thanks,
> Russ
>
>
> _______________________________________________
> openlmi-devel mailing list
> openlmi-devel@lists.fedorahosted.org
> https://lists.fedorahosted.org/mailman/listinfo/openlmi-devel