15914b719038e89079f990c2bcdeffa43641a1af — fabrixxm 2 years ago 3faea00
Add examples
2 files changed, 83 insertions(+), 0 deletions(-)

A examples/simple.py
A examples/vm.py
A examples/simple.py => examples/simple.py +14 -0
@@ 0,0 1,14 @@
from climatik import command, run

def sum(a:int, b:int):
    """Sum two integers"""
    print(a + b)

def mult(a:int, b:int):
    """Multiply two integers"""
    print(a * b)

if __name__ == "__main__":

A examples/vm.py => examples/vm.py +69 -0
@@ 0,0 1,69 @@
from typing import Optional
from climatik import command, group, run

def ps(all:bool):
    """List running VMs.
    @param all:  list also stopped VMs

    p = ['alpine-001', 'fedora']
    if all:
        p += ['debian11']

def stop(name:str):
    """Stop a VM.

    @param name: VM to stop
    print(f"Stopping {name}...")

def info(name:Optional[str] = None):
    """Print info about VMs.

    If no name is passed, a summary is printed

    if name is None:
        print('alpine-001   - running')
        print('\tRam: 500MB cpu: 10%')
        print('fedora       - running')
        print('\tRam: 1.5GB cpu: 40%')
        print('\tRam: 1.5GB')
        print('\tcpu: 40%')
        print('\tdisk: 1GB')

with group('image', help='Image management', description='Manage system images'):
    def ls():
        """List images"""
        print("no images")

    def rm(name:str):
        """Remove image from system.

        @param name: image name to remove.
        print(f"image '{name} does not exists")

    def purge(force:bool):
        """Remove unused images from system.

        Images used by running processes are kept, unless --force is passed.

        @param force: remove in use images (dangerous!)
        print("0 images removed")

if __name__ == "__main__":
    run(description="Manage VMs (not really)")