Fabric

This package contains the Fabrics app and provides Django-style models, views and tasks for launching and configuring Computes complete with networks and block storage.

Models

This package contains Django-style models that allows to set up the fabric of your Kamaji environment.

class fabric.models.models_credentials.Credential(*args, **kwargs)

Bases: django.db.models.base.Model

Stores a username and password or token tied to a service. The items in the SERVICES tuple must match the services added in the install process.

Parameters:
  • id (AutoField) –
  • service (CharField) –
  • password (CharField) –
  • username (CharField) –
class fabric.models.models_credentials.SSHKey(*args, **kwargs)

Bases: django.db.models.base.Model

Stores an SSH key tied to a service.

Parameters:
  • id (AutoField) –
  • service (CharField) –
  • key (CharField) –
class fabric.models.models_hosts.Host(*args, **kwargs)

Bases: shared.models.KamajiModel

Stores a Controller host indexed by type and optionally an index. Hosts are tied to the controller specified by the index field if it is specified and it exists. Some hosts such as the loadbalancer stored with type:’vip’ has only one possible value and so needs no index.

Example:

vip_host = Host.objects.get(type='vip')
secondary_controller_nameserver_host = Host.objects.get(type='ns', index=1)
Parameters:
  • id (AutoField) –
  • ip_address (GenericIPAddressField) –
  • type (CharField) –
  • index (IntegerField) –
class fabric.models.models_nodes.Compute(*args, **kwargs)

Bases: shared.openstack2.models.OSModel

Stores information about a hypervisor in OpenStack.

Parameters:
  • id (AutoField) –
  • openstack_id (CharField) –
class fabric.models.models_nodes.Controller(*args, **kwargs)

Bases: shared.models.KamajiModel

Stores information about controller nodes. The brain of your openstack cluster. it contains all central OpenStack components such as databases, openstack controller software (keystone, nova etc).

Parameters:
  • id (AutoField) –
  • name (CharField) – Name of this node
  • primary (BooleanField) – Indicates if this controller is primary in environment
  • ip_address (GenericIPAddressField) – The allocated IP address of this node
  • hardware_inventory_id (OneToOneField) –
  • status (CharField) – The status of this controller.
class fabric.models.models_nodes.ControllerHostMapping(*args, **kwargs)

Bases: django.db.models.base.Model

This model maps a number of fabric.models.models_hosts.Host to a Controller.

Parameters:
  • id (AutoField) –
  • controller_id (ForeignKey) –
  • host_id (OneToOneField) –
class fabric.models.models_nodes.HardwareInventory(*args, **kwargs)

Bases: django.db.models.base.Model

Stores the hardware inventory of a node in JSON format.

Parameters:
  • id (AutoField) –
  • inventory (TextField) – Contains the Hardware inventory in Json format
class fabric.models.models_nodes.Node(*args, **kwargs)

Bases: django.db.models.base.Model

Stores a node that can be configured as a compute.

Parameters:
  • ip_address (GenericIPAddressField) – The allocated IP address of this node
  • mac_address (CharField) – The MAC address of this node
  • network_id (ForeignKey) –
  • last_boot (DateTimeField) – The date and time when this node was last seen
  • active (BooleanField) – True if node is active else false
  • node_type (CharField) – The type of this node
  • hardware_inventory_id (OneToOneField) –
  • revision (IntegerField) – Current revision
  • state (CharField) – Current state of this node
  • index (IntegerField) – The index of this node
hostname
Returns:The hostname by combining “node” and this nodes index padded to two digits.
class fabric.models.models_nodes.Zone(*args, **kwargs)

Bases: shared.openstack2.models.OSModel

Represents a Kamaji Zone (i.e. failure domain) mapped to an os-aggregate in OpenStack.

Parameters:
  • id (AutoField) –
  • openstack_id (CharField) –
class fabric.models.models_nodes.ZoneComputesMapping(*args, **kwargs)

Bases: shared.models.KamajiModel

A mapping of a Zone to a Compute.

Parameters:
  • id (AutoField) –
  • zone_id (ForeignKey) –
  • compute_id (OneToOneField) –
class fabric.models.models_physicalnetworks.PhysicalNetwork(*args, **kwargs)

Bases: shared.models.KamajiModel

There are two different types of physical networks in Kamaji, one for Compute and one for Controller. Starting a Node on a compute network will allow it to be configured as a Compute.

Parameters:
  • id (AutoField) –
  • name (CharField) – The human readable name of this physical network
  • subnet (GenericIPAddressField) – The subnet address of this physical network.
  • prefix (IntegerField) – The subnet prefix of the physical network
  • gateway (GenericIPAddressField) – The gateway address of this physical network
  • range_start (GenericIPAddressField) – The first address in this physical network range
  • range_end (GenericIPAddressField) – The last address in this physical network range
  • type (CharField) – The type of this network.
static get_range(subnet, prefix, gateway)

Get the first and last valid address in the IP range that does not conflict with the gateway.

netmask

The netmask of the network, represented as a string.

validate()

Validates that the values for the ip range and gateway are sane. If no range is specified we define our own.

class fabric.models.models_settings.NTPSetting(*args, **kwargs)

Bases: django.db.models.base.Model

Configures NTP servers in Kamaji.

Parameters:
  • id (AutoField) –
  • address (CharField) –
  • status (CharField) –
  • connection_status (CharField) –
  • last_test (DateTimeField) –
  • last_test_stratum (IntegerField) –
class fabric.models.models_settings.Setting(*args, **kwargs)

Bases: django.db.models.base.Model

A global setting i Kamaji.

Parameters:
  • id (AutoField) –
  • setting (CharField) –
  • data (TextField) –
class fabric.models.models_storage.CEPHCluster(*args, **kwargs)

Bases: fabric.models.models_storage.StorageTarget

Represents a connection to a CEPH cluster that are used for image storage.

Parameters:
  • name (CharField) – A local identifier for the cluster
  • cephx (BooleanField) – Whether the cluster uses CEPHx
  • uuid (UUIDField) – A generated UUID used by libvirt
  • fsid (UUIDField) – The fsid of the cluster
  • mon_host (GenericIPAddressField) – The monitor config host of the cluster
  • status (CharField) – The connection status of the cluster (disconnected/connecting/connected/error)
  • username (CharField) – The username to use when Kamaji is authenticating against the cluster
  • password (CharField) – The password to use when Kamaji is authenticating against the cluster
connect()

Create a connection to the storage backend using the data in the instance.

test_connection()

Tests the connection to the ceph cluster.

to_config_format()

Export the CEPH cluster configuration to config file format for use together with Ansible.

Returns:The cluster connection configuration in config file format.
Return type:str
class fabric.models.models_storage.CEPHClusterPool(*args, **kwargs)

Bases: django.db.models.base.Model

Represents a CEPH cluster pool.

Parameters:
  • id (AutoField) –
  • cluster_id (ForeignKey) – The CEPH cluster to tie this pool to
  • pool (CharField) – The CEPH cluster pool identifier
  • type (CharField) – The type of data to store in this pool (volume/image/meta). Only one pool per type is allowed.
class fabric.models.models_storage.StorageTarget(*args, **kwargs)

Bases: django.db.models.base.Model

Base class for any Storage class.

fabric.models.models_storage.generate_uuid()

Generate a random UUID. :return: Randomly generated UUID :rtype: string

Views

class fabric.views.CEPHClusterAction(**kwargs)

Bases: shared.views.ActionView, shared.views.LookupMixin

Provides the possibility to connect and test configured CEPH cluster. Connecting a cluster is performed by posting an JSON object on the form {‘action’: ‘connect’}. Testing a cluster is performed by posting an JSON object on the form {‘action’: ‘test’}.

connect(request, *args, **kwargs)

Setup the connection to the cluster.

test(request, *args, **kwargs)

Test the connection to the cluster.

class fabric.views.CEPHClusterList(**kwargs)

Bases: rest_framework.generics.ListCreateAPIView

List existing or create a new connection to a CEPH storage cluster.

serializer_class

alias of CEPHClusterSerializer

class fabric.views.CEPHClusterSingle(**kwargs)

Bases: rest_framework.generics.RetrieveUpdateDestroyAPIView

Delete, update or show info about the CEPH cluster connection.

serializer_class

alias of CEPHClusterSerializer

class fabric.views.ComputeList(**kwargs)

Bases: rest_framework.generics.ListAPIView

List all existing compute nodes.

class fabric.views.ComputeSingle(**kwargs)

Bases: rest_framework.generics.RetrieveUpdateAPIView

Retrieve or update a specific compute node.

class fabric.views.ControllerList(**kwargs)

Bases: rest_framework.generics.ListCreateAPIView

List or create controllers.

class fabric.views.ControllerSingle(**kwargs)

Bases: rest_framework.generics.RetrieveUpdateDestroyAPIView

Retrieve or delete a specific controller.

class fabric.views.ExternalStorageMenu(**kwargs)

Bases: rest_framework.views.APIView

List available endpoints under external_storage

Bases: rest_framework.views.APIView

Available endpoints under Fabric

class fabric.views.NTPAction(**kwargs)

Bases: shared.views.ActionView

Allows testing the configured NTP servers. The test is performed by posting an JSON object on the form {‘action’: ‘test’}

test(request, *args, **kwargs)

Execute a connection test to the listed NTP servers in Kamaji settings and update their status.

class fabric.views.NodeList(**kwargs)

Bases: rest_framework.generics.ListCreateAPIView

List and create Nodes.

Called when a compute nodes has booted up.

Note

Changes in unregistered node IP’s are handled.

class fabric.views.NodeSingle(**kwargs)

Bases: rest_framework.generics.RetrieveUpdateAPIView

Lookup or update a specific Node.

class fabric.views.PhysicalNetworkList(**kwargs)

Bases: rest_framework.generics.ListCreateAPIView

Create or list compute networks.

serializer_class

alias of PhysicalNetworkSerializer

class fabric.views.PhysicalNetworkSingle(**kwargs)

Bases: rest_framework.generics.RetrieveUpdateDestroyAPIView

Retrieve, update or remove a compute network.

serializer_class

alias of PhysicalNetworkSerializer

class fabric.views.PublicKeySingle(**kwargs)

Bases: rest_framework.generics.RetrieveAPIView

Retrieve public key used in Kamaji.

class fabric.views.SMTPRelayAction(**kwargs)

Bases: shared.views.ActionView

Allows testing the configured SMTP settings. The test is performed by posting an JSON object on the form {‘action’: ‘test’, ‘recipient’: ‘your@mail.com’}

test(request, *args, **kwargs)

Test sending an email to verify that SMTP settings are correctly configured

class fabric.views.SettingSingle(**kwargs)

Bases: rest_framework.generics.RetrieveUpdateAPIView

Retrieve or update a specific setting in Kamaji.

class fabric.views.SettingsList(**kwargs)

Bases: rest_framework.views.APIView

List links to all available settings in Kamaji.

class fabric.views.SharesPerTargetList(**kwargs)

Bases: rest_framework.generics.ListCreateAPIView

List the existing pools or create a new pool for the configured CEPH cluster.

serializer_class

alias of CEPHClusterPoolSerializer

class fabric.views.StorageShareSingle(**kwargs)

Bases: rest_framework.generics.RetrieveUpdateDestroyAPIView

Allow retrieval, updates and removal of shares

class fabric.views.StorageSharesList(**kwargs)

Bases: rest_framework.generics.ListCreateAPIView

List and create storage shares

class fabric.views.StorageTargetList(**kwargs)

Bases: rest_framework.views.APIView

Fetch all storage targets, serialize them and present them in the same endpoint.

class fabric.views.StorageTargetRedirect(**kwargs)

Bases: rest_framework.generics.RetrieveAPIView

Perform a redirect from the targets endpoint to the appropriate storage backend endpoint: /target/<name> -> /<backend>/<name>/

class fabric.views.ZoneList(**kwargs)

Bases: rest_framework.generics.ListCreateAPIView

List or create new zones in the Kamaji cloud.

class fabric.views.ZoneSingle(**kwargs)

Bases: rest_framework.generics.RetrieveUpdateDestroyAPIView

Retrieve, update or remove an existing zone in the Kamaji cloud.

Tasks

class fabric.tasks.ConfigureCephTask

Bases: shared.ansible_tasks.AnsiblePlaybookTask

Celery task to configure OpenStack to use CEPH as storage backend

on_failure(exc, task_id, args, kwargs, einfo)

Update the CEPHCluster object if the Celery task fails.

Parameters:args – The CEPHCluster object that is being manipulated on
Returns:None
on_success(retval, task_id, args, kwargs)

Update the CEPHCluster object if the Celery task succeed.

Parameters:args – The CEPHCluster object that is being manipulated on
Returns:None
run(ceph_cluster)
Parameters:ceph_cluster (fabric.models.CEPHCluster) – The CEPHCluster object to configure.
class fabric.tasks.ConfigureComputeTask

Bases: shared.ansible_tasks.AnsiblePlaybookTask

Celery task to configure OpenStack on computes with Ansible.

on_failure(exc, task_id, args, kwargs, einfo)

In case the Compute configuration fails, set the node status to failed.

on_success(retval, task_id, args, kwargs)

In case the Compute configuration is successful, set the node status to created.

run(ip_address)
Parameters:ip_address (str) – The ip address to execute the task on.
class fabric.tasks.ConfigureDHCPTask

Bases: shared.ansible_tasks.AnsiblePlaybookTask

Celery task to configure dhcp servers with Ansible.

run(compute_network)
Parameters:compute_network (fabric.models.ComputeNetwork) – The compute network to configure the dhcp with.
class fabric.tasks.ConfigureNTPServersTask

Bases: shared.ansible_tasks.AnsiblePlaybookTask

Task to configure NTP on computes, service nodes and instances.

run(ntp_instance)

Configure all Computes, ServiceNodes and Instances with the specified NTP servers. :param ntp: NTP setting object containing info about ntp. :type ntp: NTPSetting :param ntp_servers: The ntp servers to apply described as a list of strings. :type ntp_servers: list :param args: :param kwargs: :return:

class fabric.tasks.DeployInstanceTask

Bases: shared.ansible_tasks.AnsiblePlaybookTask

Task to create instance(s) in OpenStack with help of Kamaji API.

run(group_id=None, instance=None, instance_data=None, instances_to_create=None)
Parameters:
  • instance_data (dict) – All data needed to create an instance.
  • instances_to_create (int) – The number of instances to create.
  • group_id (int) – The group to create the instance in.
  • instance (fabric.models.Instance) – Instance to work with, in case one is already created
Returns:

The public ip address of the instance and a service object

Return type:

Tuple

class fabric.tasks.UpdateHardwareInventoryTask

Bases: shared.ansible_tasks.AnsibleRunnerTask

Celery task to gather hardware inventory data from servers and update add it to a separate table in the database and updates the calling models one-to-one relation.

on_success(retval, task_id, (server), kwargs)

Create a new HardwareInventory record and update the calling object with the relation to the record

run(server)

Run the ansible task to gater the data

Parameters:server (fabric.models.Controller or fabric.models.Node) – The server object needs to have an ip_address member
Returns:The fetched ansible facts about the server
Return type:dict
class fabric.tasks.UploadImageDataFromUrlTask

Bases: celery.app.task.Task

Task to download an image file and PUT it to the OpenStack image service.

run(image_id, image_class, *args, **kwargs)

Prepare the image file data.

Should be called like: delay(image.id, Image)

Parameters:
  • image_id – The id of the image to prepare.
  • image_class – The Image class.

Validators

fabric.validators.validate_single_controller_network(network_type)

Validate that there is no existing controller network.