Skip to main content

Giga

Giga is a Unix system orchestration framework for Python (>= 3.6) programmers.

Installation

python3 -m pip install giga

Features

The following snippets demonstrate giga's features in broad strokes by creating automation to install and uninstall the python package example-pkg from git.

  • An API for operating Unix systems.
import giga

# pass super=True to run all commands as the superuser. the login and
# superuser passwords can be given as arguments if needed
system = giga.unix.Ssh(host='albatross.local', user='jrandom', super=True)

# make a predicate that returns True if example-pkg is installed else False
installed = lambda: system.zero("pip3 list|grep '^example-pkg '")

# install example-pkg
if not installed():
  system.run('pip3 install git+https://github.com/mykelalvis/example_pkg')

# print example-pkg install state
print(installed()) # => 'True'

# uninstall example-pkg
if installed():
  system.run('yes|pip3 uninstall example-pkg')

# print example-pkg install state
print(installed()) # => 'False'
  • An API for creating reusable system configurations.
import giga

class ExamplePkg(giga.Config):
  'Apply or delete the example-pkg python package.'

  @property
  def installed(self):
    return self.system.zero("pip3 list|grep '^example-pkg '")

  # extend giga.Config.on_apply()
  def on_apply(self):
    super().on_apply()
    with giga.Task('Apply example-pkg') as task:
      if not self.installed:
        url = 'git+https://github.com/mykelalvis/example_pkg'
        self.system.run(f'pip3 install {url}')
        task.change()

  # extend giga.Config.on_delete()
  def on_delete(self):
    super().on_delete()
    with giga.Task('Delete example-pkg') as task:
      if self.installed:
        self.system.run('yes|pip3 uninstall example-pkg')
        task.change()

  # extend giga.Config.on_is_applied()
  def on_is_applied(self):
    return super().on_is_applied() and self.installed
# create a system
system = giga.unix.Ssh(host='albatross.local', user='jrandom', super=True)

# apply ExamplePkg to the system
system.apply(ExamplePkg)

# print ExamplePkg apply status
print(system.is_applied(ExamplePkg)) # => 'True'

# delete ExamplePkg from the system
system.delete(ExamplePkg)

# print ExamplePkg apply status
print(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
# configuration

class ExamplePkg(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 sequence

class ExamplePkg(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)]),
  ]

class ExamplePkg(giga.Config):

  def config_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 family

class ExamplePkg(giga.Config):

  @property
  def os_packages(self):
    family = self.system.os.family
    if family == 'debian':
      return giga.configs.os.debian.Packages(packages=['python3-pip'])
    elif family == 'redhat':
      return giga.configs.os.redhat.Packages(packages=['python36u-pip'])
    else:
      raise giga.error.NotImplementedFor(family)

  @property
  def py_packages(self):
    pkg = 'example-pkg'
    url = 'git+https://github.com/mykelalvis/example_pkg'
    return giga.configs.python.Packages(packages=[(pkg, url)])

  def config_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 handler

import giga

class ExamplePkg(giga.Config): pass # see previous examples

hosts = (
  'server1.local',
  'server2.local',
  'server3.local',
)

# create a group
group = giga.Group(hosts=hosts, user='jrandom', super=True)

# apply ExamplePkg to the group
ok, err = group.apply(ExamplePkg)
group.log_results(ok, err)

# print ExamplePkg apply status
ok, err = group.is_applied(ExamplePkg)
group.log_results(ok, err)

# delete ExamplePkg from the group
ok, err = group.delete(ExamplePkg)
group.log_results(ok, err)
# a fuller version showing the structure of the group result lists, ok and err

import giga, traceback

class ExamplePkg(giga.Config): pass # see previous examples

def results(ok, err):
  'Handle the results of Group.apply(), Group.delete(), or Group.is_applied().'

  # print tracebacks for all failed hosts
  for system, exc_info in err:
    _, exc, _ = exc_info
    # configs can raise either giga.Cancel or giga.Fail
    if isinstance(exc, giga.Cancel):
      # we should ignore these and look for the root cause, the giga.Fail
      continue
    assert(isinstance(exc, giga.Fail))
    print('-', system.name)
    traceback.print_exception(*exc.exc_info) # the exc_info of the real error
    print()

  # print results for all successful hosts
  for system, result in ok:

    if isinstance(result, int):
      # apply/delete return int, the number of changes made to the system
      print(f'- {system.name} made {result} changes')

    elif isinstance(result, bool):
      # is_applied returns bool, True if a configuration is applied else False
      status = 'applied' if result else 'not applied'
      print(f'- configuration is {status} to {system.name}')

hosts = (
  'server1.local',
  'server2.local',
  'server3.local',
)

# create a group
group = giga.Group(hosts=hosts, user='jrandom', super=True)

# apply ExamplePkg to the group
ok, err = group.apply(ExamplePkg)
results(ok, err)

# print ExamplePkg apply status
ok, err = group.is_applied(ExamplePkg)
results(ok, err)

# delete ExamplePkg from the group
ok, err = group.delete(ExamplePkg)
results(ok, err)
  • Command-line interface.
# apply config ExamplePkg in module examplepkg to 3 hosts
giga apply examplepkg.ExamplePkg -h host1,host2,host3 -u jrandom -s

# check apply status for config ExamplePkg in module examplepkg on 3 hosts
giga is-applied examplepkg.ExamplePkg -h host1,host2,host3 -u jrandom -s

# delete config ExamplePkg in module examplepkg from 3 hosts
giga delete examplepkg.ExamplePkg -h host1,host2,host3 -u jrandom -s

# show help
giga --help

Status

Giga 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.

Contributing

If you're interested in contributing, wow, I'm really quite shocked. :) I can be reached at eckso@eckso.io.

License

Giga is licensed under the Apache License Version 2.0.

Metadata

Release files for giga 0.0.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for giga 0.0.7
File Size Uploaded Provenance
giga-0.0.7.tar.gz 37.2 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for giga 0.0.7
File Interpreter ABI Platform
giga-0.0.7-py3-none-any.whl Python 3 none any Details

Total release size: 88.6 kB

Release files / giga-0.0.7.tar.gz

Download URL giga-0.0.7.tar.gz
Size 37.2 kB
Tags Source
SHA-256 checksum
How to use checksums
e29af006db21228dc3f5cbec3da2f45c00dec734d4bb87c7bc50e2af75a4d9c0
BLAKE2b-256 checksum
How to use checksums
eac872cdc41386aadba6f183bc3ed98be8469551868301c64e5d62d75f6e5cd2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.3

Release files / giga-0.0.7-py3-none-any.whl

Download URL giga-0.0.7-py3-none-any.whl
Size 51.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
29b71c99e77d24702ac287814b482716a7d3e091b55ee0ded4f07fb01b5391af
BLAKE2b-256 checksum
How to use checksums
cd33a8641f8f5ed9af5ac356cea457a56c02b9210f465209262f9b322feff944
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.3

Security for giga 0.0.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page