Package: giga
GigaGiga is a Unix system orchestration framework for Python (>= 3.6) programmers.Installationpython3 -m pip install gigaFeaturesThe following snippets demonstrate giga's features in broad strokes by
creating automation to install and uninstall the python packageexample-pkgfrom git.An API for operating Unix systems.importgiga# pass super=True to run all commands as the superuser. the login and# superuser passwords can be given as arguments if neededsystem=giga.unix.Ssh(host='albatross.local',user='jrandom',super=True)# make a predicate that returns True if example-pkg is installed else Falseinstalled=lambda:system.zero("pip3 list|grep '^example-pkg '")# install example-pkgifnotinstalled():system.run('pip3 install git+https://github.com/mykelalvis/example_pkg')# print example-pkg install stateprint(installed())# => 'True'# uninstall example-pkgifinstalled():system.run('yes|pip3 uninstall example-pkg')# print example-pkg install stateprint(installed())# => 'False'An API for creating reusable system configurations.importgigaclassExamplePkg(giga.Config):'Apply or delete the example-pkg python package.'@propertydefinstalled(self):returnself.system.zero("pip3 list|grep '^example-pkg '")# extend giga.Config.on_apply()defon_apply(self):super().on_apply()withgiga.Task('Apply example-pkg')astask:ifnotself.installed:url='git+https://github.com/mykelalvis/example_pkg'self.system.run(f'pip3 install{url}')task.change()# extend giga.Config.on_delete()defon_delete(self):super().on_delete()withgiga.Task('Delete example-pkg')astask:ifself.installed:self.system.run('yes|pip3 uninstall example-pkg')task.change()# extend giga.Config.on_is_applied()defon_is_applied(self):returnsuper().on_is_applied()andself.installed# create a systemsystem=giga.unix.Ssh(host='albatross.local',user='jrandom',super=True)# apply ExamplePkg to the systemsystem.apply(ExamplePkg)# print ExamplePkg apply statusprint(system.is_applied(ExamplePkg))# => 'True'# delete ExamplePkg from the systemsystem.delete(ExamplePkg)# print ExamplePkg apply statusprint(system.is_applied(ExamplePkg))# => 'False'Customization and composition of system configurations.# existing configurations can be customized via inheritance or instantiation.# here we use one of giga's base configurations to implement our ExamplePkg# configurationclassExamplePkg(giga.configs.python.Packages):packages=[('example-pkg','git+https://github.com/mykelalvis/example_pkg'),]example_pkg=giga.configs.python.Packages(packages=[('example-pkg','git+https://github.com/mykelalvis/example_pkg'),])# composition assembles many configurations into one and is delegated by# `giga.Config.config_include`, which may be a sequence or a callable# returning a sequenceclassExamplePkg(giga.Config):pkg='example-pkg'url='git+https://github.com/mykelalvis/example_pkg'config_include=[giga.configs.os.debian.Packages(packages=['python3-pip']),giga.configs.python.Packages(packages=[(pkg,url)]),]classExamplePkg(giga.Config):defconfig_include(self):pkg='example-pkg'url='git+https://github.com/mykelalvis/example_pkg'return[giga.configs.os.debian.Packages(packages=['python3-pip']),giga.configs.python.Packages(packages=[(pkg,url)]),]# the callable form of `config_include` can branch on things like os familyclassExamplePkg(giga.Config):@propertydefos_packages(self):family=self.system.os.familyiffamily=='debian':returngiga.configs.os.debian.Packages(packages=['python3-pip'])eliffamily=='redhat':returngiga.configs.os.redhat.Packages(packages=['python36u-pip'])else:raisegiga.error.NotImplementedFor(family)@propertydefpy_packages(self):pkg='example-pkg'url='git+https://github.com/mykelalvis/example_pkg'returngiga.configs.python.Packages(packages=[(pkg,url)])defconfig_include(self):return[self.os_packages,self.py_packages,]An API for operating groups of Unix systems.The command-line
interface typically handles all of this behind the scenes, but it is
perfectly reasonable to drive giga from other python code.# a simple version using the built-in result handlerimportgigaclassExamplePkg(giga.Config):pass# see previous exampleshosts=('server1.local','server2.local','server3.local',)# create a groupgroup=giga.Group(hosts=hosts,user='jrandom',super=True)# apply ExamplePkg to the groupok,err=group.apply(ExamplePkg)group.log_results(ok,err)# print ExamplePkg apply statusok,err=group.is_applied(ExamplePkg)group.log_results(ok,err)# delete ExamplePkg from the groupok,err=group.delete(ExamplePkg)group.log_results(ok,err)# a fuller version showing the structure of the group result lists, ok and errimportgiga,tracebackclassExamplePkg(giga.Config):pass# see previous examplesdefresults(ok,err):'Handle the results of Group.apply(), Group.delete(), or Group.is_applied().'# print tracebacks for all failed hostsforsystem,exc_infoinerr:_,exc,_=exc_info# configs can raise either giga.Cancel or giga.Failifisinstance(exc,giga.Cancel):# we should ignore these and look for the root cause, the giga.Failcontinueassert(isinstance(exc,giga.Fail))print('-',system.name)traceback.print_exception(*exc.exc_info)# the exc_info of the real errorprint()# print results for all successful hostsforsystem,resultinok:ifisinstance(result,int):# apply/delete return int, the number of changes made to the systemprint(f'-{system.name}made{result}changes')elifisinstance(result,bool):# is_applied returns bool, True if a configuration is applied else Falsestatus='applied'ifresultelse'not applied'print(f'- configuration is{status}to{system.name}')hosts=('server1.local','server2.local','server3.local',)# create a groupgroup=giga.Group(hosts=hosts,user='jrandom',super=True)# apply ExamplePkg to the groupok,err=group.apply(ExamplePkg)results(ok,err)# print ExamplePkg apply statusok,err=group.is_applied(ExamplePkg)results(ok,err)# delete ExamplePkg from the groupok,err=group.delete(ExamplePkg)results(ok,err)Command-line interface.# apply config ExamplePkg in module examplepkg to 3 hostsgigaapplyexamplepkg.ExamplePkg-hhost1,host2,host3-ujrandom-s# check apply status for config ExamplePkg in module examplepkg on 3 hostsgigais-appliedexamplepkg.ExamplePkg-hhost1,host2,host3-ujrandom-s# delete config ExamplePkg in module examplepkg from 3 hostsgigadeleteexamplepkg.ExamplePkg-hhost1,host2,host3-ujrandom-s# show helpgiga--helpStatusGiga is undergoing heavy development and refinement. While some things are
still held together with tape and glue, it continues to improve steadily, and
is used daily by its author to deploy and maintain enterprise infrastructure.ContributingIf you're interested in contributing, wow, I'm really quite shocked. :) I can
be reached ateckso@eckso.io.LicenseGiga is licensed under the Apache License Version 2.0.