Host

Host data model

This module provide a Host model and all associated method.
  • Host.show: method to return a dict abstraction of a Host

  • Host.create: a staticmethod to create a Host w/ some check associated to it

  • Host.update: a staticmethod to update Host field

  • Host.remove: a staticmethod to delete a Host w/ some check associated to it

  • Host.add: a staticmethod to add a IP to a Host

  • Host.get: a staticmethod to get a dict abstraction of a Host w/o instanciate it before

  • Host.search: a staticmethod to get all Host match the filter

class slam_host.models.Host(*args, **kwargs)[source]
Host represent a association between hardware, network and domain name service
  • name: a name for the hosts, by default, the name fqdn of the host

  • addresses: a list of IP address. Should be one-to-many relation but for some mistake, it s a many-to-many relation…

  • interface: the MAC address of the host

  • network: the main network for the host (ie. where it will be put by freeradius)

  • creation_date: When Host has been created

  • dhcp: a flag to enable, disable DHCP configuration.

exception DoesNotExist
exception MultipleObjectsReturned
static add(name, address, args=None)[source]

This is a custom method to add a IP to a host.

Parameters
  • name – the host name

  • address – IP address

  • args – some optional options

Returns

static create(name, address=None, interface=None, network=None, owner=None, dns_entry=None, options=None)[source]
This is a custom method to create a host w/ some check like.
  • Interface: check if it exist and it s free. If not, create a new one.

  • Address: check if it exist,it s free and in the network. If no address as been provide, get a free IP from the network

  • NS record: A and PTR record will be created

Parameters
  • name – name of the Host

  • address – IP address for the Host

  • interface – interface associated to this Host

  • network – network associated to this Host

  • owner – the owner of this Host

  • dns_entry – NS record for the Host

  • options – Some other options like ‘no_ip’ to force not get IP (Host w/o IP)

Returns

static get(name)[source]

This is a custom method to get the dict abstraction of a Host. We get a standard version of the abstraction (see show method comment).

Parameters

name – name of the host

Returns

static remove(name, addresses=True, hardware=False, dns_entry=True)[source]

This method is a method to delete a Host. As django use a internal method called delete to delete a instanciated object, we call the method remove.

Parameters
  • name – name of host

  • addresses – if set to True, we also delete all addresses (default: True)

  • hardware – if set to True, we also delete hardware (default: False)

  • dns_entry – if set to True, we also delete dns_entry (default: True)

Returns

static search(filters=None)[source]

This is a custom method to get a dict abstraction of all Host on database. We get a short version of Host (see show method comment).

Parameters

filters – a dict of field as QuerySet

Returns

show(short=False, key=False)[source]
This method return a dict construction of the object. We have 3 types of output,
  • standard: all information about object it-self, short information about associated objects (like ForeignKey and ManyToManyField)

  • short: some basic information about object it-self, primary key of associated objects

  • key: primary key of the object

Parameters
  • short – if set to True, method return a short output

  • key – if set to True, method return a key output. It will overwrite short param

Returns

static update(name, address=None, interface=None, network=None, dns_entry=None, dhcp=None)[source]

This is a custom method to update a Host. Depending of options give, the rightfull field.

Parameters
  • name – name of the host (not used to update but to retrieve Host)

  • address – IP address of the host

  • interface – mac-address of the host

  • network – network of the host

  • dns_entry – NS record of the host

  • dhcp – should DHCP be generated

Returns

Host views

This module provide different view to manage hosts. To avoid shadow name declaration, we use those following nomenclature

  • host: a host is a relation between a interface, a network and a domain entry

  • hosts: a list of host

  • interface: a physical interface represented by a MAC address

  • interfaces: a list of interface

  • network: a IPv4 or IPv6 network

  • ip_address: a IPv4 or IPv6 address

  • domain: a DNS domain

  • ns_entry: a DNS entry

  • *_view: a function that manage the web interface (per example domains_view manage web interface of domains, …)

  • rest_api: a boolean which say if REST API is used. If not, HTML rendering will be used

  • options: a generic structure that represent arguments we send to function

  • data: a generic structure that represent arguments we received from a function

  • result: a temporary structure that represent the output of the view

  • result_*: a temporary structure that represent a part of the output (per example result_entries)

  • uri_*: input retrieve from URI structure itself

  • raw_*: a raw version of variable

slam_host.views.address_view(request, uri_host, uri_address)[source]

This function manage interaction between user and SLAM to manage IP address list of a Host. URI is represented by https://slam.example.com/hosts/host.example.com/192.168.0.1

We currently support only POST method.

Parameters
  • request – full HTTP request from user

  • uri_host – the host name

  • uri_address – the IP address

Returns

slam_host.views.host_view(request, uri_host)[source]

This function manage interaction between user and SLAM for host management. URI is represented by https://slam.example.com/hosts/host.example.com. We supported the following method:

  • GET: to get a Host, in case of headers ‘Accept’ is not ‘application/json’, so we return a HTML render

  • POST: to create a Host

  • DELETE: to delete a Host

  • PUT: to modify a Host

Parameters
  • request – full HTTP request from user

  • uri_host – host name from URI

Returns

slam_host.views.hosts_view(request)[source]

This function manage interaction between user and SLAM for hosts management. URI is represented by https://slam.example.com/hosts

We currently support only GET method.

Parameters

request – full HTTP request from user

Returns