class shared.models.KamajiModel(*args, **kwargs)

Bases: django.db.models.base.Model

Abstract class that adds convenience methods and properties to the django django.db.models.Model class. More specifically it adds a validate method that is executed before saving.

save(force_insert=False, force_update=False, using=None, update_fields=None, perform_validation=True)
Raises:django.core.exceptions.ValidationError if the validation fails.

Override this method in the child class to validate model instances before saving them. Subclasses should call the super validate method if it is overwritten.

Raises:django.core.exceptions.ValidationError if the validation fails.
Raises:django.core.exceptions.ValidationError if the validation fails.
class shared.openstack2.models.KamajiRemoteModel(*args, **kwargs)

Bases: shared.models.KamajiModel

Abstract class that adds methods and properties related to remote resource manipulation to the deriving shared.models.KamajiModel class .

classmethod get_remote_mutable_targets()

Return a mapping of the model name and the target name of the field in OpenStack for all editable fields.

Returns:Mapping of model name -> target name
Return type:dict
classmethod get_remote_sources()

Return a mapping of the model name and the source name of the field in OpenStack.

Returns:A mapping of model name/source name
Return type:dict
classmethod get_remote_targets()

Return a mapping of the model name and the target name of the field in OpenStack.

Returns:A mapping of model name/target name
Return type:dict
classmethod synchronize()

Synchronize this model with OpenStack by retrieving all resources from OpenStack and create local entries for those that have none.


Checks uniqueness for all fields marked as ‘unique’ by looping through all existing model instances and checking for equality.

Parameters:exclude (list) – List of fields to exclude from the check.
class shared.openstack2.models.OSMetaModel(name, bases, attributes)

Bases: django.db.models.base.ModelBase

Metaclass that converts all instance variables of RemoteField into properties whose setters and getters are bound to the set_value resp. get_value of the field.

class shared.openstack2.models.OSModel(*args, **kwargs)

Bases: shared.openstack2.models.KamajiRemoteModel

Baseclass for all OpenStack models. Requires any subclasses to implement an inner class called OpenStackMeta that holds info about the OpenStack resource it is connected to. Stores a local id and the openstack_id in the database and the rest in the OpenStack backend using the OpenStack rest api.

Any instance variables of RemoteField on the subclass will be converted to properties with the getter and setter connected to the get_value resp. set_value of the RemoteField. The RemoteFields stores the actual values in the _values dict of this class. The actual RemoteField instances are stored in the OpenStackMeta.fields dict. See OSMetaModel for the logic of changing fields to properties.

Parameters:openstack_id (CharField) –

Update all fields in the model with fresh values from OpenStack. Calling this method will reset any local changes to the model that has not been saved.


Validate the model before saving


class shared.views.ActionView(**kwargs)

Bases: rest_framework.views.APIView

The ActionView facilitates views that implementents action-subendpoints. To implement a child to the ActionView inherit this class and implement methods for any actions you would like to support.

static action(view_func)

Decorator for marking a method as an action that can be called by the ActionView it belongs to.

class shared.views.LookupMixin

Bases: object

A mixin that implements the get_object method on the view. To use add a queryset field to the inheriting view or override the get_queryset method.

class shared.views.ReducedKwargsRedirectView(**kwargs)

Bases: django.views.generic.base.RedirectView

This view will redirect the user to another specified view. Compared to RedirectView this view takes a list of kwargs to use when resolving the url, useful when you have more kwargs than you need for the redirect..

get_redirect_url(*args, **kwargs)

Return the URL to redirect to. Uses only the kwargs specified in the self.use_kwargs list.

This method will remove any items in the kwargs dict not in the use_kwargs list. After the a new dict is generated the method will hand over control to the overridden method of the super class.

  • args (list) – args to use in the url mapping
  • kwargs (dict) – kwargs to use in the url mapping

The URL to redirect to

Return type:


class shared.views.RetrievePatchDestroyAPIView(**kwargs)

Bases: rest_framework.generics.RetrieveDestroyAPIView

Implements a view that only allows PATCH as a way of updating values. PUT is disallowed.

patch(request, *args, **kwargs)

Partially updates (Http PATCH) and no full replacement (Http PUT). :param request: The HttpRequest object for this update request. :param args: Miscellaneous args. :param kwargs: Miscellaneous kwargs. :return: A Response object containing the result of the update.


class shared.managers.FilteredManager(filters=None, *args, **kwargs)

Bases: django.db.models.manager.Manager

Provides a filtered object manager that returns only those objects matching the provided filter.


class shared.ansible_tasks.AnsiblePlaybookTask

Bases: shared.ansible_tasks._AnsibleTask

This class facilitates running a Celery task using an Ansible playbook.

execute(playbook_name, args, hosts, private_key_file=None, remote_user=None)

Run an Ansible playbook on a specific set of hosts.

  • playbook_name (str) – The name of the playbook.
  • args (dict) – Arguments to the playbook.
  • hosts (list) – A list of hosts to execute the playbook on.
  • private_key_file (str) – A path to the private key for the connection.
  • remote_user (str) – The user to execute the playbook as.

The resulting TaskQueueManager.

Return type:


class shared.ansible_tasks.AnsibleRunnerTask

Bases: shared.ansible_tasks._AnsibleTask

This class facilitates running a Celery task using an Ansible module.

execute(module, host, become=None)

Run an Ansible module on a specific host.

  • module (str) – The module to execute.
  • host (str) – The ip of the host to run the module on.
  • become – Use privilege escalation to become another user than the currently logged in one.

The corresponding hostvars.

Return type:



exception shared.exceptions.IllegalPlaybookFormatError(message=None, *args, **kwargs)

Bases: shared.exceptions.KamajiError

Thrown when a malformed playbook is uploaded

exception shared.exceptions.IllegalState(message=None, *args, **kwargs)

Bases: shared.exceptions.KamajiError

Thrown when the user is trying to perform an action on a resource which can’t be fulfilled due to the state of said resource.

exception shared.exceptions.InvalidSSHKeyError(message=None, *args, **kwargs)

Bases: shared.exceptions.KamajiError

Thrown when trying to create a KamajiUser with an invalid ssh key.

exception shared.exceptions.KamajiApiException(detail=None)

Bases: rest_framework.exceptions.APIException

The base of all Kamaji Api Exceptions.

exception shared.exceptions.KamajiError(message=None, *args, **kwargs)

Bases: exceptions.Exception

The base exception for all Kamaji Errors.

exception shared.exceptions.KamajiOpenStackError(message=None, status_code=None)

Bases: shared.exceptions.KamajiError

The base exception for all OpenStack exceptions.

exception shared.exceptions.OperationTimedOut(message=None, *args, **kwargs)

Bases: shared.exceptions.KamajiError

Thrown when the API has waited longer than the defined threshold for an external system to perform an operation.

exception shared.exceptions.ResourceInUseError(message=None, *args, **kwargs)

Bases: shared.exceptions.KamajiError

Thrown when the user is trying to delete a resource that is in use. For example if the user tries to delete a layer when the layer is already added to a stack.

exception shared.exceptions.UnsupportedOperation(message=None, *args, **kwargs)

Bases: shared.exceptions.KamajiError

Thrown when the user is trying to do something thatis not allowed. For example if the user is trying to remove a controller network.

exception shared.exceptions.UpdatesNotSupported(message=None, *args, **kwargs)

Bases: shared.exceptions.KamajiError

Thrown when an update is initiated on a model which does not support updates.


class shared.rest_validators.ContainedIn(value_list, field=None)

Bases: object

Validates that the value exists in the specified list.

class shared.rest_validators.IsNodeType

Bases: shared.rest_validators.ContainedIn

Validates that the value is a valid NodeType.

class shared.rest_validators.IsSSHKey(allow_blank=False)

Bases: object

class shared.rest_validators.Not(validation, message_template, field=None)

Bases: object

Inverts a validation. Results in a failed validation if the specified validation succeeds and vice versa.

class shared.rest_validators.ValidationAggregator(**validations)

Bases: object

Allows aggregation of rest_framework.serializers.ValidationError, if one or more errors are detected the resulting rest_framework.serializers.ValidationError will contain the details of all failed validations.


Validates all validations and aggregates the exception details into a dictionary with the validated fields as keys and error details as values.

shared.rest_validators.contained_in_dict(field, attrs)

Validate that a dict contains a specified field

  • field (str) – The field that must be present in the attrs dict
  • attrs (dict) – The dict where to search for the field


shared.rest_validators.validate_address_in_network(subnet, prefix, *addresses)

Validate that the address or addresses are in the specified network.

  • subnet (string) – The network subnet
  • prefix (integer) – The network prefix
  • addresses (string or list) – The address or addresses to validate



Validate that a hostname is valid.

Parameters:value (str) – The hostname to validate.
shared.rest_validators.validate_ipv4_network(subnet, prefix, gateway=None)

Validates that the subnet and prefix describes a valid IP network (ex If gateway address is specified, check that the IP address is within the network range.

  • subnet – The subnet to validate.
  • prefix – The prefix to validate.
  • gateway – The gateway to validate.



Validates that the provided value describes a network together with a prefix on the form:

Parameters:value – The value to validate.

Validate a Network MAC address given as a string, on the form XX:XX:XX:XX:XX:XX

Parameters:value (str) – The MAC address to validate

Validate a network prefix given as an integer.

Parameters:value (int) – The network prefix to validate

Validate a vlan-id given as an integer.

Parameters:value (int) – The vlan-id to validate.