← Back to team overview

launchpad-reviewers team mailing list archive

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

 

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

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

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

This branch introduces maasserver.enum with all the enums from the maasserver application.  This is a first step towards splitting up maasserver.models.
-- 
https://code.launchpad.net/~rvb/maas/maas-models-refactor/+merge/102881
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~rvb/maas/maas-models-refactor into lp:maas.
=== added file 'docs/enum.rst'
--- docs/enum.rst	1970-01-01 00:00:00 +0000
+++ docs/enum.rst	2012-04-20 15:20:29 +0000
@@ -0,0 +1,16 @@
+==========
+MAAS Enums
+==========
+
+.. automodule:: maasserver.models
+
+.. autoclass:: NODE_STATUS
+    :members:
+
+.. autoclass:: NODE_AFTER_COMMISSIONING_ACTION
+    :members:
+
+.. autoclass:: ARCHITECTURE
+    :members:
+
+

=== modified file 'docs/index.rst'
--- docs/index.rst	2012-03-26 11:50:56 +0000
+++ docs/index.rst	2012-04-20 15:20:29 +0000
@@ -33,6 +33,7 @@
 
 .. toctree::
    models
+   enum
 
 Indices and tables
 ==================

=== modified file 'docs/models.rst'
--- docs/models.rst	2012-03-23 18:12:27 +0000
+++ docs/models.rst	2012-04-20 15:20:29 +0000
@@ -13,12 +13,6 @@
     :show-inheritance:
     :members:
 
-.. autoclass:: NODE_STATUS
-    :members:
-
-.. autoclass:: NODE_AFTER_COMMISSIONING_ACTION
-    :members:
-
 .. autoclass:: NodeManager
     :show-inheritance:
     :members:

=== modified file 'src/maasserver/api.py'
--- src/maasserver/api.py	2012-04-16 10:00:51 +0000
+++ src/maasserver/api.py	2012-04-20 15:20:29 +0000
@@ -90,6 +90,10 @@
 from docutils import core
 from formencode import validators
 from formencode.validators import Invalid
+from maasserver.enum import (
+    NODE_PERMISSION,
+    NODE_STATUS,
+    )
 from maasserver.exceptions import (
     MAASAPIBadRequest,
     MAASAPINotFound,
@@ -104,8 +108,6 @@
     FileStorage,
     MACAddress,
     Node,
-    NODE_PERMISSION,
-    NODE_STATUS,
     )
 from piston.doc import generate_doc
 from piston.handler import (

=== added file 'src/maasserver/enum.py'
--- src/maasserver/enum.py	1970-01-01 00:00:00 +0000
+++ src/maasserver/enum.py	2012-04-20 15:20:29 +0000
@@ -0,0 +1,117 @@
+# Copyright 2012 Canonical Ltd.  This software is licensed under the
+# GNU Affero General Public License version 3 (see the file LICENSE).
+
+"""Enumerations meaningful to the masserver application."""
+
+from __future__ import (
+    absolute_import,
+    print_function,
+    unicode_literals,
+    )
+
+__metaclass__ = type
+__all__ = [
+    'ARCHITECTURE',
+    'ARCHITECTURE_CHOICES',
+    'NODE_PERMISSION',
+    'NODE_STATUS',
+    'NODE_STATUS_CHOICES',
+    'NODE_STATUS_CHOICES_DICT',
+    ]
+
+from collections import (
+    OrderedDict,
+    )
+
+
+class NODE_STATUS:
+    """The vocabulary of a `Node`'s possible statuses."""
+    # A node starts out as READY.
+    DEFAULT_STATUS = 0
+
+    #: The node has been created and has a system ID assigned to it.
+    DECLARED = 0
+    #: Testing and other commissioning steps are taking place.
+    COMMISSIONING = 1
+    #: Smoke or burn-in testing has a found a problem.
+    FAILED_TESTS = 2
+    #: The node can't be contacted.
+    MISSING = 3
+    #: The node is in the general pool ready to be deployed.
+    READY = 4
+    #: The node is ready for named deployment.
+    RESERVED = 5
+    #: The node is powering a service from a charm or is ready for use with
+    #: a fresh Ubuntu install.
+    ALLOCATED = 6
+    #: The node has been removed from service manually until an admin
+    #: overrides the retirement.
+    RETIRED = 7
+
+
+# Django choices for NODE_STATUS: sequence of tuples (key, UI
+# representation).
+NODE_STATUS_CHOICES = (
+    (NODE_STATUS.DECLARED, "Declared"),
+    (NODE_STATUS.COMMISSIONING, "Commissioning"),
+    (NODE_STATUS.FAILED_TESTS, "Failed tests"),
+    (NODE_STATUS.MISSING, "Missing"),
+    (NODE_STATUS.READY, "Ready"),
+    (NODE_STATUS.RESERVED, "Reserved"),
+    (NODE_STATUS.ALLOCATED, "Allocated"),
+    (NODE_STATUS.RETIRED, "Retired"),
+)
+
+
+NODE_STATUS_CHOICES_DICT = OrderedDict(NODE_STATUS_CHOICES)
+
+
+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
+
+
+NODE_AFTER_COMMISSIONING_ACTION_CHOICES = (
+    (NODE_AFTER_COMMISSIONING_ACTION.QUEUE,
+        "Queue for dynamic allocation to services"),
+    (NODE_AFTER_COMMISSIONING_ACTION.CHECK,
+        "Check compatibility and hold for future decision"),
+    (NODE_AFTER_COMMISSIONING_ACTION.DEPLOY_12_04,
+        "Deploy with Ubuntu 12.04 LTS"),
+)
+
+
+NODE_AFTER_COMMISSIONING_ACTION_CHOICES_DICT = dict(
+    NODE_AFTER_COMMISSIONING_ACTION_CHOICES)
+
+
+# List of supported architectures.
+class ARCHITECTURE:
+    #:
+    i386 = 'i386'
+    #:
+    amd64 = 'amd64'
+
+
+# Architecture names.
+ARCHITECTURE_CHOICES = (
+    (ARCHITECTURE.i386, "i386"),
+    (ARCHITECTURE.amd64, "amd64"),
+)
+
+
+class NODE_PERMISSION:
+    VIEW = 'view_node'
+    EDIT = 'edit_node'
+    ADMIN = 'admin_node'

=== modified file 'src/maasserver/forms.py'
--- src/maasserver/forms.py	2012-04-16 10:00:51 +0000
+++ src/maasserver/forms.py	2012-04-20 15:20:29 +0000
@@ -44,16 +44,18 @@
     Form,
     ModelForm,
     )
+from maasserver.enum import (
+    ARCHITECTURE,
+    ARCHITECTURE_CHOICES,
+    NODE_AFTER_COMMISSIONING_ACTION_CHOICES,
+    NODE_PERMISSION,
+    NODE_STATUS,
+    )
 from maasserver.fields import MACAddressFormField
 from maasserver.models import (
-    ARCHITECTURE,
-    ARCHITECTURE_CHOICES,
     Config,
     MACAddress,
     Node,
-    NODE_AFTER_COMMISSIONING_ACTION_CHOICES,
-    NODE_PERMISSION,
-    NODE_STATUS,
     SSHKey,
     )
 

=== modified file 'src/maasserver/models.py'
--- src/maasserver/models.py	2012-04-20 07:16:57 +0000
+++ src/maasserver/models.py	2012-04-20 15:20:29 +0000
@@ -18,8 +18,6 @@
     "get_html_display_for_key",
     "Config",
     "FileStorage",
-    "NODE_STATUS",
-    "NODE_PERMISSION",
     "NODE_TRANSITIONS",
     "Node",
     "MACAddress",
@@ -29,10 +27,7 @@
 
 import binascii
 from cgi import escape
-from collections import (
-    defaultdict,
-    OrderedDict,
-    )
+from collections import defaultdict
 import copy
 import datetime
 from errno import ENOENT
@@ -58,6 +53,16 @@
 from django.db.models.signals import post_save
 from django.shortcuts import get_object_or_404
 from django.utils.safestring import mark_safe
+from maasserver.enum import (
+    ARCHITECTURE,
+    ARCHITECTURE_CHOICES,
+    NODE_AFTER_COMMISSIONING_ACTION,
+    NODE_AFTER_COMMISSIONING_ACTION_CHOICES,
+    NODE_PERMISSION,
+    NODE_STATUS,
+    NODE_STATUS_CHOICES,
+    NODE_STATUS_CHOICES_DICT,
+    )
 from maasserver.exceptions import (
     CannotDeleteUserException,
     NodeStateViolation,
@@ -118,48 +123,6 @@
     return 'node-%s' % uuid1()
 
 
-class NODE_STATUS:
-    """The vocabulary of a `Node`'s possible statuses."""
-    # A node starts out as READY.
-    DEFAULT_STATUS = 0
-
-    #: The node has been created and has a system ID assigned to it.
-    DECLARED = 0
-    #: Testing and other commissioning steps are taking place.
-    COMMISSIONING = 1
-    #: Smoke or burn-in testing has a found a problem.
-    FAILED_TESTS = 2
-    #: The node can't be contacted.
-    MISSING = 3
-    #: The node is in the general pool ready to be deployed.
-    READY = 4
-    #: The node is ready for named deployment.
-    RESERVED = 5
-    #: The node is powering a service from a charm or is ready for use with
-    #: a fresh Ubuntu install.
-    ALLOCATED = 6
-    #: The node has been removed from service manually until an admin
-    #: overrides the retirement.
-    RETIRED = 7
-
-
-# Django choices for NODE_STATUS: sequence of tuples (key, UI
-# representation).
-NODE_STATUS_CHOICES = (
-    (NODE_STATUS.DECLARED, "Declared"),
-    (NODE_STATUS.COMMISSIONING, "Commissioning"),
-    (NODE_STATUS.FAILED_TESTS, "Failed tests"),
-    (NODE_STATUS.MISSING, "Missing"),
-    (NODE_STATUS.READY, "Ready"),
-    (NODE_STATUS.RESERVED, "Reserved"),
-    (NODE_STATUS.ALLOCATED, "Allocated"),
-    (NODE_STATUS.RETIRED, "Retired"),
-)
-
-
-NODE_STATUS_CHOICES_DICT = OrderedDict(NODE_STATUS_CHOICES)
-
-
 # Information about valid node status transitions.
 # The format is:
 # {
@@ -220,49 +183,6 @@
     }
 
 
-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
-
-
-NODE_AFTER_COMMISSIONING_ACTION_CHOICES = (
-    (NODE_AFTER_COMMISSIONING_ACTION.QUEUE,
-        "Queue for dynamic allocation to services"),
-    (NODE_AFTER_COMMISSIONING_ACTION.CHECK,
-        "Check compatibility and hold for future decision"),
-    (NODE_AFTER_COMMISSIONING_ACTION.DEPLOY_12_04,
-        "Deploy with Ubuntu 12.04 LTS"),
-)
-
-
-NODE_AFTER_COMMISSIONING_ACTION_CHOICES_DICT = dict(
-    NODE_AFTER_COMMISSIONING_ACTION_CHOICES)
-
-
-# List of supported architectures.
-class ARCHITECTURE:
-    i386 = 'i386'
-    amd64 = 'amd64'
-
-
-# Architecture names.
-ARCHITECTURE_CHOICES = (
-    (ARCHITECTURE.i386, "i386"),
-    (ARCHITECTURE.amd64, "amd64"),
-)
-
-
 def get_papi():
     """Return a provisioning server API proxy."""
     # Avoid circular imports.
@@ -454,12 +374,6 @@
         return None
 
 
-class NODE_PERMISSION:
-    VIEW = 'view_node'
-    EDIT = 'edit_node'
-    ADMIN = 'admin_node'
-
-
 class Node(CommonInfo):
     """A `Node` represents a physical machine used by the MAAS Server.
 

=== modified file 'src/maasserver/provisioning.py'
--- src/maasserver/provisioning.py	2012-04-17 13:45:55 +0000
+++ src/maasserver/provisioning.py	2012-04-20 15:20:29 +0000
@@ -38,13 +38,15 @@
     discard_persistent_error,
     register_persistent_error,
     )
+from maasserver.enum import (
+    ARCHITECTURE_CHOICES,
+    NODE_STATUS,
+    )
 from maasserver.exceptions import ExternalComponentException
 from maasserver.models import (
-    ARCHITECTURE_CHOICES,
     Config,
     MACAddress,
     Node,
-    NODE_STATUS,
     )
 from provisioningserver.enum import PSERV_FAULT
 import yaml

=== modified file 'src/maasserver/testing/factory.py'
--- src/maasserver/testing/factory.py	2012-04-16 10:00:51 +0000
+++ src/maasserver/testing/factory.py	2012-04-20 15:20:29 +0000
@@ -19,12 +19,14 @@
 import time
 
 from django.contrib.auth.models import User
+from maasserver.enum import (
+    ARCHITECTURE,
+    NODE_STATUS,
+    )
 from maasserver.models import (
-    ARCHITECTURE,
     FileStorage,
     MACAddress,
     Node,
-    NODE_STATUS,
     SSHKey,
     )
 from maasserver.testing import get_data

=== modified file 'src/maasserver/tests/test_api.py'
--- src/maasserver/tests/test_api.py	2012-04-20 12:54:26 +0000
+++ src/maasserver/tests/test_api.py	2012-04-20 15:20:29 +0000
@@ -28,15 +28,17 @@
     extract_constraints,
     extract_oauth_key,
     )
+from maasserver.enum import (
+    ARCHITECTURE_CHOICES,
+    NODE_STATUS,
+    NODE_STATUS_CHOICES_DICT,
+    )
 from maasserver.models import (
-    ARCHITECTURE_CHOICES,
     Config,
     create_auth_token,
     get_auth_tokens,
     MACAddress,
     Node,
-    NODE_STATUS,
-    NODE_STATUS_CHOICES_DICT,
     )
 from maasserver.testing import (
     reload_object,

=== modified file 'src/maasserver/tests/test_auth.py'
--- src/maasserver/tests/test_auth.py	2012-04-16 10:00:51 +0000
+++ src/maasserver/tests/test_auth.py	2012-04-20 15:20:29 +0000
@@ -15,11 +15,13 @@
 import httplib
 
 from django.core.urlresolvers import reverse
+from maasserver.enum import (
+    NODE_PERMISSION,
+    NODE_STATUS,
+    )
 from maasserver.models import (
     MAASAuthorizationBackend,
     Node,
-    NODE_PERMISSION,
-    NODE_STATUS,
     )
 from maasserver.testing.factory import factory
 from maasserver.testing.testcase import TestCase

=== modified file 'src/maasserver/tests/test_forms.py'
--- src/maasserver/tests/test_forms.py	2012-04-16 10:00:51 +0000
+++ src/maasserver/tests/test_forms.py	2012-04-20 15:20:29 +0000
@@ -18,6 +18,13 @@
     ValidationError,
     )
 from django.http import QueryDict
+from maasserver.enum import (
+    ARCHITECTURE,
+    NODE_AFTER_COMMISSIONING_ACTION_CHOICES,
+    NODE_PERMISSION,
+    NODE_STATUS,
+    NODE_STATUS_CHOICES_DICT,
+    )
 from maasserver.forms import (
     ConfigForm,
     EditUserForm,
@@ -33,18 +40,13 @@
     validate_hostname,
     )
 from maasserver.models import (
-    ARCHITECTURE,
     Config,
     DEFAULT_CONFIG,
-    NODE_AFTER_COMMISSIONING_ACTION_CHOICES,
-    NODE_PERMISSION,
-    NODE_STATUS,
-    NODE_STATUS_CHOICES_DICT,
-    POWER_TYPE_CHOICES,
     )
 from maasserver.provisioning import get_provisioning_api_proxy
 from maasserver.testing.factory import factory
 from maasserver.testing.testcase import TestCase
+from provisioningserver.enum import POWER_TYPE_CHOICES
 from testtools.matchers import (
     AllMatch,
     Equals,

=== modified file 'src/maasserver/tests/test_models.py'
--- src/maasserver/tests/test_models.py	2012-04-20 12:54:26 +0000
+++ src/maasserver/tests/test_models.py	2012-04-20 15:20:29 +0000
@@ -28,6 +28,12 @@
 from django.db import IntegrityError
 from django.utils.safestring import SafeUnicode
 from fixtures import TestWithFixtures
+from maasserver.enum import (
+    NODE_PERMISSION,
+    NODE_STATUS,
+    NODE_STATUS_CHOICES,
+    NODE_STATUS_CHOICES_DICT,
+    )
 from maasserver.exceptions import (
     CannotDeleteUserException,
     NodeStateViolation,
@@ -45,10 +51,6 @@
     HELLIPSIS,
     MACAddress,
     Node,
-    NODE_PERMISSION,
-    NODE_STATUS,
-    NODE_STATUS_CHOICES,
-    NODE_STATUS_CHOICES_DICT,
     NODE_TRANSITIONS,
     SSHKey,
     SYSTEM_USERS,

=== modified file 'src/maasserver/tests/test_provisioning.py'
--- src/maasserver/tests/test_provisioning.py	2012-04-17 13:45:55 +0000
+++ src/maasserver/tests/test_provisioning.py	2012-04-20 15:20:29 +0000
@@ -26,17 +26,19 @@
     get_persistent_errors,
     register_persistent_error,
     )
+from maasserver.enum import (
+    ARCHITECTURE,
+    NODE_AFTER_COMMISSIONING_ACTION,
+    NODE_STATUS,
+    NODE_STATUS_CHOICES,
+    )
 from maasserver.exceptions import (
     ExternalComponentException,
     MAASAPIException,
     )
 from maasserver.models import (
-    ARCHITECTURE,
     Config,
     Node,
-    NODE_AFTER_COMMISSIONING_ACTION,
-    NODE_STATUS,
-    NODE_STATUS_CHOICES,
     )
 from maasserver.provisioning import (
     check_profiles,

=== modified file 'src/maasserver/tests/test_views.py'
--- src/maasserver/tests/test_views.py	2012-04-20 08:19:25 +0000
+++ src/maasserver/tests/test_views.py	2012-04-20 15:20:29 +0000
@@ -34,6 +34,10 @@
     views,
     )
 from maasserver.components import register_persistent_error
+from maasserver.enum import (
+    NODE_AFTER_COMMISSIONING_ACTION,
+    NODE_STATUS,
+    )
 from maasserver.exceptions import (
     ExternalComponentException,
     NoRabbit,
@@ -42,9 +46,6 @@
 from maasserver.models import (
     Config,
     Node,
-    NODE_AFTER_COMMISSIONING_ACTION,
-    NODE_STATUS,
-    POWER_TYPE_CHOICES,
     SSHKey,
     UserProfile,
     )
@@ -70,7 +71,10 @@
     proxy_to_longpoll,
     )
 from maastesting.rabbit import uses_rabbit_fixture
-from provisioningserver.enum import PSERV_FAULT
+from provisioningserver.enum import (
+    POWER_TYPE_CHOICES,
+    PSERV_FAULT,
+    )
 from testtools.matchers import (
     Contains,
     MatchesAll,

=== modified file 'src/maasserver/views.py'
--- src/maasserver/views.py	2012-04-20 08:19:25 +0000
+++ src/maasserver/views.py	2012-04-20 15:20:29 +0000
@@ -77,6 +77,10 @@
 from django.views.generic.base import TemplateView
 from django.views.generic.detail import SingleObjectTemplateResponseMixin
 from django.views.generic.edit import ModelFormMixin
+from maasserver.enum import (
+    NODE_PERMISSION,
+    NODE_STATUS,
+    )
 from maasserver.exceptions import (
     CannotDeleteUserException,
     NoRabbit,
@@ -97,8 +101,6 @@
 from maasserver.messages import messaging
 from maasserver.models import (
     Node,
-    NODE_PERMISSION,
-    NODE_STATUS,
     SSHKey,
     UserProfile,
     )

=== modified file 'src/metadataserver/api.py'
--- src/metadataserver/api.py	2012-04-16 10:00:51 +0000
+++ src/metadataserver/api.py	2012-04-20 15:20:29 +0000
@@ -25,17 +25,17 @@
     extract_oauth_key,
     get_mandatory_param,
     )
+from maasserver.enum import (
+    NODE_STATUS,
+    NODE_STATUS_CHOICES_DICT,
+    )
 from maasserver.exceptions import (
     MAASAPIBadRequest,
     MAASAPINotFound,
     NodeStateViolation,
     Unauthorized,
     )
-from maasserver.models import (
-    NODE_STATUS,
-    NODE_STATUS_CHOICES_DICT,
-    SSHKey,
-    )
+from maasserver.models import SSHKey
 from metadataserver.models import (
     NodeCommissionResult,
     NodeKey,

=== modified file 'src/metadataserver/tests/test_api.py'
--- src/metadataserver/tests/test_api.py	2012-04-19 15:48:46 +0000
+++ src/metadataserver/tests/test_api.py	2012-04-20 15:20:29 +0000
@@ -16,11 +16,9 @@
 import httplib
 from io import BytesIO
 
+from maasserver.enum import NODE_STATUS
 from maasserver.exceptions import Unauthorized
-from maasserver.models import (
-    NODE_STATUS,
-    SSHKey,
-    )
+from maasserver.models import SSHKey
 from maasserver.provisioning import get_provisioning_api_proxy
 from maasserver.testing import reload_object
 from maasserver.testing.factory import factory