← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~rvb/maas/maas-models-doc into lp:maas

 

Raphaël Badin has proposed merging lp:~rvb/maas/maas-models-doc into lp:maas.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~rvb/maas/maas-models-doc/+merge/91464

Add documentation to models.py.
-- 
https://code.launchpad.net/~rvb/maas/maas-models-doc/+merge/91464
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~rvb/maas/maas-models-doc into lp:maas.
=== modified file 'docs/conf.py'
--- docs/conf.py	2012-01-20 14:37:55 +0000
+++ docs/conf.py	2012-02-04 22:27:19 +0000
@@ -91,6 +91,7 @@
 # A list of ignored prefixes for module index sorting.
 #modindex_common_prefix = []
 
+autodoc_member_order = 'bysource'
 
 # -- Options for HTML output ---------------------------------------------------
 

=== modified file 'docs/models.rst'
--- docs/models.rst	2012-01-24 18:15:21 +0000
+++ docs/models.rst	2012-02-04 22:27:19 +0000
@@ -2,8 +2,28 @@
 MaaS Objects
 ============
 
+
 .. automodule:: maasserver.models
+
+.. autoclass:: CommonInfo
+    :show-inheritance:
+    :members:
+
 .. autoclass:: Node
+    :show-inheritance:
+    :members:
+
+.. autoclass:: NODE_STATUS
+    :members:
+
+.. autoclass:: NODE_AFTER_COMMISSIONING_ACTION
+    :members:
+
 .. autoclass:: NodeManager
-    :members: get_visible_nodes, get_visible_node_or_404
+    :show-inheritance:
+    :members:
+
 .. autoclass:: MACAddress
+    :show-inheritance:
+    :members:
+

=== modified file 'src/maasserver/models.py'
--- src/maasserver/models.py	2012-01-31 10:45:03 +0000
+++ src/maasserver/models.py	2012-02-04 22:27:19 +0000
@@ -1,7 +1,7 @@
 # Copyright 2012 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
-"""Model."""
+"""MaaS model objects."""
 
 from __future__ import (
     print_function,
@@ -30,6 +30,13 @@
 
 
 class CommonInfo(models.Model):
+    """A base model which records the creation date and the last modification
+    date.
+
+    :ivar created: The creation date.
+    :ivar updated: The last modification date.
+
+    """
     created = models.DateField(editable=False)
     updated = models.DateTimeField(editable=False)
 
@@ -48,11 +55,19 @@
 
 
 class NODE_STATUS:
+    """The vocabulary of a `Node`'s possible statuses."""
+# TODO: document this when it's stabilized.
+    #:
     DEFAULT_STATUS = 0
+    #:
     NEW = 0
+    #:
     READY = 1
+    #:
     DEPLOYED = 2
+    #:
     COMMISSIONED = 3
+    #:
     DECOMMISSIONED = 4
 
 
@@ -69,12 +84,24 @@
 
 
 class NODE_AFTER_COMMISSIONING_ACTION:
+    """The vocabulary of a `Node`'s possible value for its field
+    after_commissioning_action.
+
+    """
+# TODO: document this when it's stabilized.
+    #:
     DEFAULT = 0
+    #:
     QUEUE = 0
+    #:
     CHECK = 1
+    #:
     DEPLOY_12_04 = 2
+    #:
     DEPLOY_11_10 = 3
+    #:
     DEPLOY_11_04 = 4
+    #:
     DEPLOY_10_10 = 5
 
 
@@ -99,14 +126,17 @@
 
 
 class NodeManager(models.Manager):
-    """A utility to manage collections of Nodes."""
+    """A utility to manage the collection of Nodes."""
 
     def get_visible_nodes(self, user):
-        """Fetch all the `Nodes` visible by a User.  Available via
-        `Node.objects`.
+        """Fetch all the Nodes visible by a User_.
 
         :param user: The user that should be used in the permission check.
-        :type user: django.contrib.auth.models.User
+        :type user: User_
+
+        .. _User: https://
+           docs.djangoproject.com/en/dev/topics/auth/
+           #django.contrib.auth.models.User
 
         """
         if user.is_superuser:
@@ -123,8 +153,15 @@
         :type name: str
         :param user: The user that should be used in the permission check.
         :type user: django.contrib.auth.models.User
-        :raises: django.http.Http404, django.core.exceptions.PermissionDenied
+        :raises: django.http.Http404_,
+            django.core.exceptions.PermissionDenied_.
 
+        .. _django.http.Http404: https://
+           docs.djangoproject.com/en/dev/topics/http/views/
+           #the-http404-exception
+        .. _django.core.exceptions.PermissionDenied: https://
+           docs.djangoproject.com/en/dev/ref/exceptions/
+           #django.core.exceptions.PermissionDenied
         """
         node = get_object_or_404(Node, system_id=system_id)
         if user.has_perm('access', node):
@@ -134,16 +171,35 @@
 
 
 class Node(CommonInfo):
-    """A `Node` represents a physical machine used by the MaaS Server."""
+    """A `Node` represents a physical machine used by the MaaS Server.
+
+    :ivar system_id: The unique identifier for this `Node`.
+        (e.g. 'node-41eba45e-4cfa-11e1-a052-00225f89f211').
+    :ivar hostname: This `Node`'s hostname.
+    :ivar status: This `Node`'s status. See the vocabulary
+        :class:`NODE_STATUS`.
+    :ivar owner: This `Node`'s owner if it's in use, None otherwise.
+    :ivar after_commissioning_action: The action to perform after
+        commissioning. See vocabulary
+        :class:`NODE_AFTER_COMMISSIONING_ACTION`.
+    :ivar objects: The :class:`NodeManager`.
+    :ivar hostname: This `Node`'s hostname.
+
+    """
+
     system_id = models.CharField(
         max_length=41, unique=True, default=generate_node_system_id,
         editable=False)
+
     hostname = models.CharField(max_length=255, default='', blank=True)
+
     status = models.IntegerField(
         max_length=10, choices=NODE_STATUS_CHOICES, editable=False,
         default=NODE_STATUS.DEFAULT_STATUS)
+
     owner = models.ForeignKey(
         User, default=None, blank=True, null=True, editable=False)
+
     after_commissioning_action = models.IntegerField(
         choices=NODE_AFTER_COMMISSIONING_ACTION_CHOICES,
         default=NODE_AFTER_COMMISSIONING_ACTION.DEFAULT)
@@ -160,14 +216,32 @@
         return NODE_STATUS_CHOICES_DICT[self.status]
 
     def add_mac_address(self, mac_address):
+        """Add a new MAC Address to this `Node`.
+
+        :param mac_address: The MAC Address to be added.
+        :type mac_address: str
+        :raises: django.core.exceptions.ValidationError_
+
+        .. _django.core.exceptions.ValidationError: https://
+           docs.djangoproject.com/en/dev/ref/exceptions/
+           #django.core.exceptions.ValidationError
+        """
+
         mac = MACAddress(mac_address=mac_address, node=self)
         mac.full_clean()
         mac.save()
         return mac
 
     def remove_mac_address(self, mac_address):
-        mac = MACAddress.objects.filter(mac_address=mac_address, node=self)
-        mac.delete()
+        """Remove a MAC Address from this `Node`.
+
+        :param mac_address: The MAC Address to be removed.
+        :type mac_address: str
+
+        """
+        mac = MACAddress.objects.get(mac_address=mac_address, node=self)
+        if mac:
+            mac.delete()
 
 
 mac_re = re.compile(r'^([0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}$')
@@ -175,7 +249,11 @@
 
 class MACAddress(CommonInfo):
     """A `MACAddress` represents a `MAC Address
-    <http://en.wikipedia.org/wiki/MAC_address>`_ attached to a `Node`.
+    <http://en.wikipedia.org/wiki/MAC_address>`_ attached to a :class:`Node`.
+
+    :ivar mac_address: The MAC Address.
+    :ivar node: The `Node` related to this `MACAddress`.
+
     """
     mac_address = MACAddressField()
     node = models.ForeignKey(Node, editable=False)