Convenience library for configuring Kazoo & it's components
Project description
# kzconfig
General kazoo configuration wrappers and helpers. Wraps the following libraries:
* python-couchdb
* kazoo-sdk
* pyrkube
* dnsimple
## Customizing
Subclass `kzconfig.Context`. In this example, I've chosen to show how a user who wants to use the default conventions except for using a different provider for DNS.
```python
from kzconfig import Context, meta
class MyContext(Context):
_configs = ('environment',)
_secrets = ('couchdb', 'rabbitmq', 'master-account', 'dns.coredns')
def __init__(self, domain='example.org'):
self.domain = domain
@meta.lazy_property
def dns(self):
return MyDNS(self, self.domain)
...
import CoreDNS
class MyDNS:
def __init__(self, context, domain):
self.context = context
self.domain = domain
creds = self.context.secrets['dns.coredns']
self.api = CoreDNS(
username=creds['email'],
password=creds['password']
)
```
Quick example of subclassing without a DNS implementation.
```python
from kzconfig import Context, meta
class MyContext(Context):
_configs = ('environment',)
_secrets = ('couchdb', 'rabbitmq', 'master-account', 'dns.coredns')
_domain = 'example.org'
def __init__(self, domain='example.org'):
self.domain = domain
def dns(self):
raise NotImplemented
```
## Usage
### Initializing a new context
```python
from kzconfig import Context, meta
context = Context()
```
### Kubernetes
```python
# get the pod named rabbitmq
rabbit_pod = context.kube.api.get('pod', 'rabbitmq')
# defaults to default namespace
all_pods = context.kube.api.get('pod')
# all kube-system pods
all_system_pods = context.kube.api.get('pod', namespace='kube-system')
# get first pod using label selector app=couchdb
first_couchdb_pod = context.kube.api.get_first('pod', selector=dict(app='couchdb'))
```
for more see my pyrkube library...
### CouchDB
```python
# get the system_config database
db = context.couchdb['system_config']
doc = dict(_id='hello')
# save new document to it
db.save(doc)
```
### Kazoo
```python
# get the master account object in kazoo
master_acct = context.kazoo.get_account(context.secrets['master-account'])
```
### DNS
```python
context.dns.add('A', '192.168.0.1')
```
### Sup
```python
context.sup.kz_nodes.status()
```
## CLI Commands
### `sup`
#### Usage
```
Usage: sup [OPTIONS] MODULE FUNCTION [ARGS]...
Options:
--help Show this message and exit.
```
### `install-kubectl`
#### Usage
```
Usage: install-kubectl [OPTIONS]
Options:
--help Show this message and exit.
```
Installs kubectl version == KUBECTL_VERSION || 1.7.8
If you override the version using environment variables, be sure to override KUBECTL_SHA256 also.
#### Example
```
sup kz_nodes status
```
General kazoo configuration wrappers and helpers. Wraps the following libraries:
* python-couchdb
* kazoo-sdk
* pyrkube
* dnsimple
## Customizing
Subclass `kzconfig.Context`. In this example, I've chosen to show how a user who wants to use the default conventions except for using a different provider for DNS.
```python
from kzconfig import Context, meta
class MyContext(Context):
_configs = ('environment',)
_secrets = ('couchdb', 'rabbitmq', 'master-account', 'dns.coredns')
def __init__(self, domain='example.org'):
self.domain = domain
@meta.lazy_property
def dns(self):
return MyDNS(self, self.domain)
...
import CoreDNS
class MyDNS:
def __init__(self, context, domain):
self.context = context
self.domain = domain
creds = self.context.secrets['dns.coredns']
self.api = CoreDNS(
username=creds['email'],
password=creds['password']
)
```
Quick example of subclassing without a DNS implementation.
```python
from kzconfig import Context, meta
class MyContext(Context):
_configs = ('environment',)
_secrets = ('couchdb', 'rabbitmq', 'master-account', 'dns.coredns')
_domain = 'example.org'
def __init__(self, domain='example.org'):
self.domain = domain
def dns(self):
raise NotImplemented
```
## Usage
### Initializing a new context
```python
from kzconfig import Context, meta
context = Context()
```
### Kubernetes
```python
# get the pod named rabbitmq
rabbit_pod = context.kube.api.get('pod', 'rabbitmq')
# defaults to default namespace
all_pods = context.kube.api.get('pod')
# all kube-system pods
all_system_pods = context.kube.api.get('pod', namespace='kube-system')
# get first pod using label selector app=couchdb
first_couchdb_pod = context.kube.api.get_first('pod', selector=dict(app='couchdb'))
```
for more see my pyrkube library...
### CouchDB
```python
# get the system_config database
db = context.couchdb['system_config']
doc = dict(_id='hello')
# save new document to it
db.save(doc)
```
### Kazoo
```python
# get the master account object in kazoo
master_acct = context.kazoo.get_account(context.secrets['master-account'])
```
### DNS
```python
context.dns.add('A', '192.168.0.1')
```
### Sup
```python
context.sup.kz_nodes.status()
```
## CLI Commands
### `sup`
#### Usage
```
Usage: sup [OPTIONS] MODULE FUNCTION [ARGS]...
Options:
--help Show this message and exit.
```
### `install-kubectl`
#### Usage
```
Usage: install-kubectl [OPTIONS]
Options:
--help Show this message and exit.
```
Installs kubectl version == KUBECTL_VERSION || 1.7.8
If you override the version using environment variables, be sure to override KUBECTL_SHA256 also.
#### Example
```
sup kz_nodes status
```
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
kzconfig-0.3.4.tar.gz
(8.3 kB
view details)
File details
Details for the file kzconfig-0.3.4.tar.gz
.
File metadata
- Download URL: kzconfig-0.3.4.tar.gz
- Upload date:
- Size: 8.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8f3785948bde827869f0c9edc29e71c345acd5e8f30a915ec7a981df0354a603 |
|
MD5 | 3a9473deedfc2f1bc5458227130337ec |
|
BLAKE2b-256 | b855e42aa35344de70770559d2f8d2695994cb1aab52bdebfcb5933612bab846 |