Skip to content

Commit

Permalink
added setup.cfg, pyproject.toml and bootstrap function.
Browse files Browse the repository at this point in the history
  • Loading branch information
mofm committed Feb 24, 2022
1 parent 67560c3 commit 96cc420
Show file tree
Hide file tree
Showing 19 changed files with 261 additions and 8 deletions.
182 changes: 181 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,188 @@ nspctl supports containers with any init system. nspctl provides almost all of t
* Bootstrap **Ubuntu** container ("xenial" and newer are supported)
* Bootstrap **Arch Linux** container

Installation
############

Requirements:
*************

- Python >=3.8

Dependencies:
*************

- systemd-container package

For Debian and Ubuntu:

.. code-block::
$ apt-get install systemd-container
For Centos, Fedora or Redhat Based Distributions:

.. code-block::
$ yum install systemd-container
or

.. code-block::
$ dnf install systemd-container
.. note::

Gentoo with systemd and Arch Linux users don't need to install any packages.

Install:
********

**From Github:**

* Clone this repository:

.. code-block::
$ git clone https://github.com/mofm/nspctl
* and install via pip:

.. code-block::
$ pip install -e nspctl
Usage:
######

**Synopsis:**

.. code-block::
nspctl [ arguments ] [ options ] [ container name | URL | distribution ] [ ... ]
Commands:
*********

- '*list*' : List currently running (online) containers.

.. code-block::
$ nspctl list
- '*list-stopped*' : List stopped containers.( shortopts: 'lss')

.. code-block::
$ nspctl list-stopped
$ nspctl lss
- '*list-running*' : List currently running containers.(alias: 'list', shortopt: 'lsr')

.. code-block::
$ nspctl list-running
$ nspctl lsr
- '*list-all*' : List all containers.(shortopt: 'lsa')

.. code-block::
$ nspctl list-all
$ nspctl lsa
- '*info NAME*' : Show properties of container.

.. code-block::
$ nspctl info ubuntu-20.04
- '*start NAME*' : Start a container as system service.

.. code-block::
$ nspctl start ubuntu-20.04
- '*reboot NAME*' : Reboot a container.

.. code-block::
$ nspctl reboot ubuntu-20.04
- '*stop NAME*' : Stop a container. Shutdown cleanly.(alias: 'poweroff')

.. code-block::
$ nspctl stop ubuntu-20.04
- '*terminate NAME*' : Immediately terminates container without cleanly shutting it down.

.. code-block::
$ nspctl terminate ubuntu-20.04
- '*poweroff NAME*' : Poweroff a container. Shutdown cleanly.

.. code-block::
$ nspctl poweroff ubuntu-20.04
- '*enable NAME*' : Enable a container as a system service at system boot.

.. code-block::
$ nspctl enable ubuntu-20.04
- '*disable NAME*' : Disable a container as a system service at system boot.

.. code-block::
$ nspctl disable ubuntu-20.04
- '*remove NAME*' : Remove a container completely.

.. code-block::
$ nspctl remove ubuntu-20.04
- '*shell NAME*' : Open an interactive shell session in a container.

.. code-block::
$ nspctl shell ubuntu-20.04
Container Operations:
*********************

- '*pull-tar URL NAME*' : Downloads a .tar container image from the specified URL.(tar, tar.gz, tar.xz, tar.bz2)

.. code-block::
$ nspctl pul-tar https://github.com/mofm/meta-econ/releases/download/v0.3.0-r2/econ-tiny-nginx-20220123-qemux86-64.tar.xz econ-nginx
- '*pull-raw URL NAME*' : Downloads a .raw container from the specified URL.(qcow2 or compressed as gz, xz, bz2)

.. code-block::
$ nspctl pull-raw http://ftp.fau.de/gentoo/experimental/amd64/qemu/allpython-amd64-qemu-20100531.qcow2.xz gentoo-python
- '*pull-dkr URL NAME INDEX*' : Download a docker image from the specified URL.

.. code-block::
$ nspctl pull-dkr centos/centos6 cent6 https://get.docker.com
- '*bootstrap NAME DIST VERSION*' : Bootstrap a container from package servers. Supported Distributions are Debian, Ubuntu and Arch Linux.

.. code-block::
$ nspctl bootstrap ubuntu-20.04 ubuntu focal
$ nspctl bootstrap debian-bullseye debian stable
$ nspctl bootstrap arch-test arch
Roadmap
########

nspctl is under development. First release will be released soon.
nspctl is under development.
6 changes: 6 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[build-system]
requires = [
"setuptools>=42",
"wheel"
]
build-backend = "setuptools.build_meta"
33 changes: 33 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
[metadata]
name = nspctl
version = 0.0.1-dev1
author = Emre Eryilmaz
author_email = [email protected]
license = GPLv3
url = https://github.com/mofm/nspctl
description = management tool for systemd-nspawn containers
long_description = file:README.rst
keywords = nspawn, container, systemd, systemd-nspawn, systemd-container
classifiers =
Development Status :: 4 - Beta
Environment :: Console
Intended Audience :: Developers
Intended Audience :: Information Technology
Intended Audience :: System Administrators
License :: OSI Approved :: GNU General Public License v3 (GPLv3)
Operating System :: POSIX :: Linux
Programming Language :: Python
Programming Language :: Python :: 3.8
Topic :: System :: Systems Administration
Topic :: Terminals
Topic :: Utilities

[options]
package_dir =
= src
packages = find:
scripts = scripts/nspctl
python_requires = >=3.8

[options.packages.find]
where = src
9 changes: 5 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from setuptools import setup
import nspctl
from setuptools import setup, find_packages
from src.nspctl import __version__


classifiers = [
Expand All @@ -20,8 +20,9 @@

setup(
name='nspctl',
version=nspctl.__version__,
packages=['nspctl', 'nspctl.utils', 'nspctl.lib'],
version=__version__,
packages=find_packages(where='src'),
packages_dir={"": "src"},
url='https://github.com/mofm/nspctl',
license='GPLv3',
author='Emre Eryilmaz',
Expand Down
File renamed without changes.
6 changes: 5 additions & 1 deletion nspctl/_nspctl.py → src/nspctl/_nspctl.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ def _bootstrap_ubuntu(name, **kwargs):
return ret


@_check_useruid
def bootstrap_container(name, dist=None, version=None):
"""
Bootstrap a container from package servers
Expand All @@ -225,6 +226,9 @@ def bootstrap_container(name, dist=None, version=None):
raise Exception('Unsupported distribution "{}"'.format(dist))


bootstrap = alias_function(bootstrap_container, "bootstrap")


def _ensure_running(name):
"""
Raise an exception if the container does not exist
Expand Down Expand Up @@ -315,7 +319,7 @@ def list_running():


# 'machinectl list' shows only running containers, so allow this to work as an
# alias to nspawn.list_running
# alias to list_running
list = alias_function(list_running, "list")


Expand Down
File renamed without changes.
File renamed without changes.
16 changes: 14 additions & 2 deletions nspctl/lib/help.py → src/nspctl/lib/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

def nspctl_help():
print(yellow("nspctl:") + " management tool for systemd-nspawn containers")
print(yellow("Usage:"))
print(yellow("Synopsis:"))
print(
" "
+ turquoise("nspctl")
Expand All @@ -19,6 +19,7 @@ def nspctl_help():
+ turquoise("distribution")
+ " ] [ ... ]"
)
print(yellow("Usage:"))
print(
" "
+ turquoise("nspctl")
Expand Down Expand Up @@ -54,6 +55,17 @@ def nspctl_help():
+ turquoise("container name")
+ " ] "
)
print(
" "
+ turquoise("nspctl")
+ " [ "
+ green("poweroff")
+ " | "
+ green("terminate")
+ " ] [ "
+ turquoise("container name")
+ " ] "
)
print(
" "
+ turquoise("nspctl")
Expand Down Expand Up @@ -105,7 +117,7 @@ def nspctl_help():
+ " | "
+ green("pull-tar")
+ " | "
+ green("pull-docker")
+ green("pull-dkr")
+ " ] [ "
+ turquoise("URL")
+ " ] [ "
Expand Down
17 changes: 17 additions & 0 deletions nspctl/lib/main.py → src/nspctl/lib/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,3 +322,20 @@ def pull_dkr(self, args=None, subparsers=None):

args = 'pull_dkr'
return args

@command
def bootstrap(self, args=None, subparsers=None):
"""
Bootstrap a container from package servers
All parameters are mandatory
"""
if subparsers is not None:
sp = subparsers.add_parser("bootstrap")
sp.add_argument("name")
sp.add_argument("dist")
sp.add_argument("version")
sp.set_defaults(func=self.bootstrap)
return

args = 'bootstrap'
return args
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 96cc420

Please sign in to comment.