Skip to main content

A utility for command line MaaS interrogation

Project description


`|Version|\ |Status|\ |Downloads| <>`__\ |Build

json yaml cat for kubernetes


This program concats just like cat from unix does, except, it takes as
input json and yaml files. These json and yaml files must be well
formed. This program reads each file, converts internally to a
dictionary using yaml.load(), then adds that dictionary to a list called
'items'. When all files are imported the resulting dictionary is turned
back into a yaml (or json) representation (with two added elements at
the top level for Kubernetes). If those files were Kubernetes pod,
replicationcontroller or service declarations, the resulting list is the
concatenation of those. This new list can be used to turn up/down all of
the listed resources at once.



usage: [-h] [-p] [-t {json,yaml}]
[files [files ...]]

yaml json k8s laundry

positional arguments:

optional arguments:
-h, --help show this help message and exit
-p, --pretty
-t {json,yaml}, --type {json,yaml}
Output type, json or yaml
is: INFO
-s, --save save select command line arguments (default is always)
in "/home/gfausak/.maasutil.conf" file
maasutil pod.yaml service.yaml replicationcontroller.yaml > /tmp/bigfile.yaml


- --pretty, make the output (json) pretty. yaml is already pretty.
default is false.
- --help, the usage message is printed.
- --type, json or yaml (this is the OUTPUT type, input can be either),
default yaml.
- ---loglevel, for debugging, default INFO.
- --save, save current arguments to persistent file in home directory,
this file will be read as if it came from the command line in
subsequent invocations of this program. To remove it you have to
remove the ~/.maasutil.conf file manually. Do this for making pretty
default, for example. the default is no save is done.
- files, this is the list of files to process. must have at least one.
any one of the files can be a - dash indicating taking it from stdin.
default is a single file -. One note here, if a single file is
specified the output will not be a List.


The top of the file will look like this (in yaml presentation):


apiVersion: v1beta3
kind: List

Then, for each file that is concatenated, there are two spaces inserted
before each line, and the first line has - added (indicating an element
of item).


I initially wrote this to create encapsulated Kubernetes scripts that
can be launched with a single command. I found another use when the api
was upgraded from v1beta1 to v1beta3, there is a program called
kube-version-change which converts json from beta 1 to beta 3. It
doesn't work with yaml. My scripts are all yaml, so this was modified to
convert from one to another. So, here is how you might update a yaml
from beta 1 to 3:


maasutil beta1.yaml -t json | kube-version-change | maasutil - > beta3.yaml

In the previous example the yaml file is promoted to json, then the json
is processed by the kube-version-change go program, finally, maasutil -
converts the imput back to yaml.

The next example shows how to 'package' more than one Kubernetes
resource file into a single file:


maasutil file1.yaml file2.yaml file3.yaml > package.yaml

The resulting file is passable to kubectl, like this:


kubectl create -f package.yaml

which does about the same thing as this:


kubectl create -f file1.yaml
kubectl create -f file2.yaml
kubectl create -f file3.yaml

.. |Version| image::
.. |Status| image::
.. |Downloads| image::
.. |Build Status| image::

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

maasutil-0.0.5.tar.gz (7.5 kB view hashes)

Uploaded source

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page