Welcome to kqueen’s documentation!

kqueen package

Models

class kqueen.models.Cluster(*arfg, **kwargs)

Bases: kqueen.storages.etcd.Model

engine
get_kubeconfig()
get_provisioner()
get_state()
id
kubeconfig
metadata
name
provisioner
state
status()

Return information about Kubernetes cluster

class kqueen.models.Provisioner(*arfg, **kwargs)

Bases: kqueen.storages.etcd.Model

engine
engine_name
engine_status(save=True)
get_engine_cls()

Return engine class

id
name
parameters
save(check_status=True)
state

Kubernetes API

class kqueen.kubeapi.KubernetesAPI(**kwargs)

Bases: object

count_pods_by_node()
get_kubeconfig_file()
get_version()
list_deployments()

List deployments in all namespaces

list_nodes()
list_pods()

List pods in all namespaces

list_pods_by_node()
list_services()

List services in all namespaces

resources_by_node()

Read pods on each node, compute sum or requested and limited resources

Returns:
Dict of nodes with allocated resources. CPU is float. Memory int is in bytes.
{
    'node1': {
        'limits': {'cpu': 2, 'mem': 100},
        'requests': {'cpu': 1.5, 'mem': 10098}
    }
}

Server

Helpers

kqueen.helpers.prefix_to_num(st)

Read string with prefix and return number

Args:
st (string): String representation of value with prefix
Returns:
float: Calculated value without binary prefix

Example:

>>> prefix_to_num('1k')
1000.0

Serializers

class kqueen.serializers.CustomJSONEncoder(skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)

Bases: flask.json.JSONEncoder

default(obj)

Wrappers

kqueen.wrappers.login_required(f)

Subpackages

Flask blueprints

Subpackages
kqueen.blueprints.api package
Submodules
kqueen.blueprints.api.tests module
class kqueen.blueprints.api.tests.TestClusterDetails

Bases: object

test_cluster_detail(cluster, client)
test_object_not_found(client, cluster_id)
class kqueen.blueprints.api.tests.TestClusterKubeconfig

Bases: object

test_kubeconfig(cluster, client)
class kqueen.blueprints.api.tests.TestClusterList

Bases: object

test_cluster_list(cluster, client)
class kqueen.blueprints.api.tests.TestClusterStatus

Bases: object

test_cluster_status_404(client, url, cluster_id)
test_cluster_status_returns(cluster, client)
kqueen.blueprints.api.tests.test_root(client)
kqueen.blueprints.api.views module
kqueen.blueprints.api.views.cluster_detail(cluster_id)
kqueen.blueprints.api.views.cluster_kubeconfig(cluster_id)
kqueen.blueprints.api.views.cluster_list()
kqueen.blueprints.api.views.cluster_status(cluster_id)
kqueen.blueprints.api.views.index()
kqueen.blueprints.api.views.not_found(error)
kqueen.blueprints.api.views.not_implemented(error)
Module contents
kqueen.blueprints.ui package
Submodules
kqueen.blueprints.ui.forms module
kqueen.blueprints.ui.tables module
class kqueen.blueprints.ui.tables.ClusterTable(items, classes=None, thead_classes=None, sort_by=None, sort_reverse=False, no_items=None, table_id=None, border=False)

Bases: flask_table.table.Table

classes = ['table']
delete = <kqueen.blueprints.ui.tables.DeleteCol object>
name = <flask_table.columns.LinkCol object>
provisioner = <flask_table.columns.Col object>
state = <kqueen.blueprints.ui.tables.StatusCol object>
class kqueen.blueprints.ui.tables.DeleteCol(*args, **kwargs)

Bases: flask_table.columns.LinkCol

class kqueen.blueprints.ui.tables.ProvisionerTable(items, classes=None, thead_classes=None, sort_by=None, sort_reverse=False, no_items=None, table_id=None, border=False)

Bases: flask_table.table.Table

classes = ['table']
delete = <kqueen.blueprints.ui.tables.DeleteCol object>
engine_name = <flask_table.columns.Col object>
name = <flask_table.columns.Col object>
state = <kqueen.blueprints.ui.tables.StatusCol object>
class kqueen.blueprints.ui.tables.StatusCol(*args, **kwargs)

Bases: flask_table.columns.Col

kqueen.blueprints.ui.tests module
kqueen.blueprints.ui.tests.test_index(client_login)
kqueen.blueprints.ui.tests.test_login_required(client, view, values)
kqueen.blueprints.ui.tests.test_logout(client_login)
kqueen.blueprints.ui.views module
Module contents
Module contents

Engines

Submodules
JenkinsEngine
Module contents
class kqueen.engines.base.BaseEngine(cluster, **kwargs)

Base Engine object.

When you initialize the engine through the prepared property engine() on kqueen.models.Cluster model object, all keys in engine object parameters attribute (JSONField) on kqueen.models.Provisioner object are passed as kwargs.

Example::
>>> print my_provisioner.parameters
{'username': 'foo', 'password': 'bar'}
>>> print my_cluster.engine.conn_kw
{'username': 'foo', 'password': 'bar'}

Credentials passed from parameters attribute to kwargs of MyProvisioner class used in conn_kw dict for client initialization.

Args:
cluster (kqueen.models.Cluster): Cluster model object related to this engine instance. **kwargs: Keyword arguments specific to Provisioner implementation.
Attributes:
cluster (kqueen.models.Cluster): Cluster model object related to this engine instance. name (str): Name of the engine usable by program. verbose_name (str): Human readable name of the engine.
cluster_get()

Get single cluster from backend related to this engine instance.

Although this function doesn’t take any arguments, it is expected that the implementation of the Provisioner gets self.cluster to provide the relevant object for which we want to get data from backend.

Returns:

dict: Dictionary format should be:

{
    'key': key,     # (str) this record should be cached under this key if you choose to cache
    'name': name,   # (str) name of the cluster in its respective backend
    'id': id,       # (str or UUID) id of `kqueen.models.Cluster` object in KQueen database
    'state': state, # (str) cluster.state
    'metadata': {
        'foo': bar  # any keys specific for the Provisioner implementation
    }
}
cluster_list()

Get all clusters available on backend.

Returns:

list: list of dictionaries. Dictionary format should be:

{
    'key': key,     # this record should be cached under this key if you choose to cache
    'name': name,   # name of the cluster in its respective backend
    'id': id,       # id of `kqueen.models.Cluster` object in KQueen database
    'state': state, # cluster.state
    'metadata': {
        'foo': bar  # any keys specific for the Provisioner implementation
    }
}
deprovision()

Deprovision the cluster related to this engine instance from backend.

Although this function doesn’t take any arguments, it is expected that the implementation of the Provisioner gets self.cluster to provide the relevant object which we want to remove from backend.

Returns:

tuple: First item is bool (success/failure), second item is error, can be None:

(True, None)                            # successful provisioning
(False, 'Could not connect to backend') # failed provisioning
static engine_status()

Check if backend this Provisioner implements is reachable and/or working.

Returns:
str: Return status of engine, should use statuses from app.config
get_kubeconfig()

Get kubeconfig of the cluster related to this engine from backend.

Although this function doesn’t take any arguments, it is expected that the implementation of the Provisioner gets self.cluster to provide the relevant object which we want to get kubeconfig for.

Returns:
dict: Dictionary form of kubeconfig (yaml.load(kubeconfig_file))
get_parameter_schema()

Return parameters specific for this Provisioner implementation.

This method should return parameters specific to the Provisioner implementation, these are used to generate form for creation of Provisioner object and are stored in parameters attribute (JSONField) of the kqueen.models.Provisioner object.

Returns:

dict: Dictionary representation of the parameters with hints for form rendering.:

{
    'username': {
        'type': 'text',
        'required': True,
        'initial': None
    }
    'password': {
        'type': 'password',
        'required': True,
        'initial': None
    }
}
get_progress()

Get progress of provisioning if its possible to determine.

Although this function doesn’t take any arguments, it is expected that the implementation of the Provisioner gets self.cluster to provide the relevant object which we want to get provisioning progress for.

Returns:

dict: Dictionary representation of the provisioning provress.:

{
    'response': response, # (int) any number other than 0 means failure to determine progress
    'progress': progress, # (int) provisioning progress in percents
    'result': result      # (str) current state of the cluster, i.e. 'Deploying'
}
name = 'base_engine'
provision()

Provision the cluster related to this engine instance to backend.

Although this function doesn’t take any arguments, it is expected that the implementation of the Provisioner gets self.cluster to provide the relevant object which we want to provision to backend.

Returns:

tuple: First item is bool (success/failure), second item is error, can be None:

(True, None)                            # successful provisioning
(False, 'Could not connect to backend') # failed provisioning
verbose_name = 'Base Engine'

Model storages

Submodules
Etcd
class kqueen.storages.etcd.EtcdOrm(**kwargs)

Bases: object

class kqueen.storages.etcd.Field(*args, **kwargs)

Bases: object

empty()
get_value()
is_field = True
serialize()
set_value(value)
class kqueen.storages.etcd.IdField(*args, **kwargs)

Bases: kqueen.storages.etcd.Field

set_value(value)

Don’t serialize None

class kqueen.storages.etcd.JSONField(*args, **kwargs)

Bases: kqueen.storages.etcd.Field

JSON is stored as value

serialize()
set_value(value)
class kqueen.storages.etcd.Model(*arfg, **kwargs)

Bases: object

Parent class for all models

classmethod create(**kwargs)

Create new object

delete()

Delete the object

classmethod deserialize(serialized, **kwargs)
classmethod exists(object_id)

Check if object exists

get_db_key()
classmethod get_db_prefix()

Calculate prefix for writing DB objects

Returns:
string: Database prefix

Example:

/kqueen/default/MyModel/
get_dict()
classmethod get_field_names()

Return list of field names

classmethod get_fields()

Return dict of fields and it classes

classmethod get_model_name()

Return lowercased name of the class

id = <kqueen.storages.etcd.IdField object>
classmethod list(return_objects=True)

List objects in the database

classmethod load(object_id)

Load object from database

save(validate=True, assign_id=True)

Save object to database

Attributes:
validate (bool): Validate model before saving. Defaults to True. assign_id (bool): Assing id (if missing) before saving model. Defaults to True
Return:
bool: True if model was saved without errors, False otherwise.
serialize()
validate() → bool

Validate the model object pass all requirements

Checks:
  • Required fields
Returns:
Validation result. True for passed, False for failed.
verify_id()
class kqueen.storages.etcd.ModelMeta

Bases: type

class kqueen.storages.etcd.SecretField(*args, **kwargs)

Bases: kqueen.storages.etcd.Field

class kqueen.storages.etcd.StringField(*args, **kwargs)

Bases: kqueen.storages.etcd.Field

Module contents

Module contents

Indices and tables