Hardware¶
Hardware data model¶
This module provide Hardware and Interface models and all associated method.
- For Hardware
Hardware.show: method to return a dict abstraction of a Hardware
Hardware.create: a staticmethod to create a Hardware w/ some check associated to it
Hardware.update: a staticmethod to update Hardware field
Hardware.remove: a staticmethod to delete a Hardware w/ some check associated to it
Hardware.add: a staticmethod to add a Interface to a Hardware
Hardware.get: a staticmethod to get a dict abstraction of a Hardware w/o instanciate it before
Hardware.search: a staticmethod to get all Hardware match the filter
- For Interface
Interface.show: method to return a dict abstraction of a Interface
Interface.create: a staticmethod to create a Interface w/ some check associated to it
Interface.update: a staticmethod to update Interface field
Interface.remove: a staticmethod to delete a Interface w/ some check associated to it
Interface.add: a staticmethod to add a IP to a Interface
Interface.get: a staticmethod to get a dict abstraction of a Interface w/o instanciate it before
Interface.search: a staticmethod to get all Interface match the filter
-
class
slam_hardware.models.Hardware(*args, **kwargs)[source]¶ - A Hardware represent a physical machine.
name: a hardware name, there are no relation between hardware name and NS record by default, it’s build by Host.create named it name-mac_address
buying_date: when hardware has been buy. By default, it’s when it’s created
description: a short description of the machine
owner: the owner of the machine
vendor: manifacturor name of the machine
model: the model of the machine
serial_number: unique serial number from manifacturer
inventory: local inventory identifier
warranty: warranty duration
-
exception
DoesNotExist¶
-
exception
MultipleObjectsReturned¶
-
static
create(name, interfaces=None, args=None)[source]¶ This is a custom method to create a hardware. args represent all Hardware self attributes. interfaces represent a list of interface.
- Parameters
name – name of the hardware
interfaces – interfaces in the hardware
args – a dict of field used to create the hardware
- Returns
-
static
get(name)[source]¶ This is a custom method to get hardware information.
- Parameters
name – name of the hardware
- Returns
-
interfaces()[source]¶ This method return all Interfaces attached to this hardware. A hardware can have more than one Interface.
- Returns
-
static
remove(name)[source]¶ This is a custom way to delete a hardware. As django model have its own delete method, we call it remove.
- Returns
-
static
search(filters=None)[source]¶ This is a custom way to get all hardware match the filter
- Parameters
filters –
- Returns
-
show(key=False, short=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
-
class
slam_hardware.models.Interface(*args, **kwargs)[source]¶ A interface represent a specific hardware device. A physical machine can have more than one interface device but a device is only attached to one and only one hardware.
-
exception
DoesNotExist¶
-
exception
MultipleObjectsReturned¶
-
static
create(mac_address, hardware, args=None)[source]¶ This is a custom method to create a interface
- Parameters
mac_address – mac address of the interface
hardware – hardware where interface is attached
args – options for Interface creation
- Returns
-
static
get(mac_address, short=False)[source]¶ This is a custom method to get a interface from a mac address
- Parameters
mac_address – the mac address we want to get
short – The output version
- Returns
-
static
search(filters=None)[source]¶ This is a custom way to get all hardware match the filter
- Parameters
filters –
- Returns
-
show(key=False, short=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
-
exception
Hardware view¶
This module provide different view to manage domain. To avoid shadow name declaration, we use those following nomenclature
hardware: a hardware is a representation of real machine
inventory: a list of hardware
interface: a physical interface represented by a MAC address
interfaces: a list of interface
*_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
As django models are generic classes, pylint can’t check if member of model Class exists, we must disable pylint E1101 (no-member) test from this file
-
slam_hardware.views.hardware_view(request, uri_hardware)[source]¶ This view manage interaction with hardware. A hardware is a representation of a real machine. URI is represented by https://slam.example.com/hardware/my-machine
- Parameters
request – full HTTP request from user
uri_hardware – the name of the hardware from URI
-
slam_hardware.views.interface_view(request, uri_hardware, uri_interface)[source]¶ This function manage interaction between user and SLAM interface for ethernet interface management. URI is represented by https://slam.example.com/hardware/my-computer/interfaces/00:11:22:33:44:55
- Parameters
request – full HTTP request from user
uri_hardware – the hardware where interface is attached
uri_interface – the ethernet interface
- Returns
-
slam_hardware.views.inventory_view(request)[source]¶ This function manage interaction between user and SLAM for hardware management. URI is represented by https://slam.example.com/hardware
- Parameters
request – full HTTP request from user