launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #08508
[Merge] lp:~julian-edwards/maas/node_group_model into lp:maas
Julian Edwards has proposed merging lp:~julian-edwards/maas/node_group_model into lp:maas.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~julian-edwards/maas/node_group_model/+merge/108678
This is a basic implementation of a NodeGroup schema. It is required now because we need to store DHCP parameters on a per-nodegroup basis, so it makes sense to define the schema now.
--
https://code.launchpad.net/~julian-edwards/maas/node_group_model/+merge/108678
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~julian-edwards/maas/node_group_model into lp:maas.
=== added file 'src/maasserver/migrations/0009_add_nodegroup.py'
--- src/maasserver/migrations/0009_add_nodegroup.py 1970-01-01 00:00:00 +0000
+++ src/maasserver/migrations/0009_add_nodegroup.py 2012-06-05 06:21:23 +0000
@@ -0,0 +1,166 @@
+# flake8: noqa
+# SKIP this file when reformatting.
+# The rest of this file was generated by South.
+
+# encoding: utf-8
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+class Migration(SchemaMigration):
+
+ def forwards(self, orm):
+
+ # Adding model 'NodeGroup'
+ db.create_table(u'maasserver_nodegroup', (
+ ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+ ('created', self.gf('django.db.models.fields.DateTimeField')()),
+ ('updated', self.gf('django.db.models.fields.DateTimeField')()),
+ ('name', self.gf('django.db.models.fields.CharField')(default=u'', unique=True, max_length=80)),
+ ('api_token', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['piston.Token'], unique=True)),
+ ('api_key', self.gf('django.db.models.fields.CharField')(unique=True, max_length=18)),
+ ('worker_ip', self.gf('django.db.models.fields.IPAddressField')(unique=True, max_length=15)),
+ ('subnet_mask', self.gf('django.db.models.fields.IPAddressField')(max_length=15)),
+ ('broadcast_ip', self.gf('django.db.models.fields.IPAddressField')(max_length=15)),
+ ('router_ip', self.gf('django.db.models.fields.IPAddressField')(max_length=15)),
+ ('ip_range_low', self.gf('django.db.models.fields.IPAddressField')(unique=True, max_length=15)),
+ ('ip_range_high', self.gf('django.db.models.fields.IPAddressField')(unique=True, max_length=15)),
+ ))
+ db.send_create_signal(u'maasserver', ['NodeGroup'])
+
+
+ def backwards(self, orm):
+
+ # Deleting model 'NodeGroup'
+ db.delete_table(u'maasserver_nodegroup')
+
+
+ models = {
+ 'auth.group': {
+ 'Meta': {'object_name': 'Group'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
+ 'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
+ },
+ 'auth.permission': {
+ 'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
+ 'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
+ },
+ 'auth.user': {
+ 'Meta': {'object_name': 'User'},
+ 'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+ 'email': ('django.db.models.fields.EmailField', [], {'unique': 'True', 'max_length': '75', 'blank': 'True'}),
+ 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+ 'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+ 'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+ 'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+ 'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
+ 'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
+ 'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
+ },
+ 'contenttypes.contenttype': {
+ 'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
+ 'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
+ },
+ u'maasserver.config': {
+ 'Meta': {'object_name': 'Config'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'value': ('maasserver.fields.JSONObjectField', [], {'null': 'True'})
+ },
+ u'maasserver.filestorage': {
+ 'Meta': {'object_name': 'FileStorage'},
+ 'data': ('django.db.models.fields.files.FileField', [], {'max_length': '255'}),
+ 'filename': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '200'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
+ },
+ u'maasserver.macaddress': {
+ 'Meta': {'object_name': 'MACAddress'},
+ 'created': ('django.db.models.fields.DateTimeField', [], {}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'mac_address': ('maasserver.fields.MACAddressField', [], {'unique': 'True'}),
+ 'node': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['maasserver.Node']"}),
+ 'updated': ('django.db.models.fields.DateTimeField', [], {})
+ },
+ u'maasserver.node': {
+ 'Meta': {'object_name': 'Node'},
+ 'after_commissioning_action': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
+ 'architecture': ('django.db.models.fields.CharField', [], {'default': "u'i386'", 'max_length': '10'}),
+ 'created': ('django.db.models.fields.DateTimeField', [], {}),
+ 'error': ('django.db.models.fields.CharField', [], {'default': "u''", 'max_length': '255', 'blank': 'True'}),
+ 'hostname': ('django.db.models.fields.CharField', [], {'default': "u''", 'max_length': '255', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'owner': ('django.db.models.fields.related.ForeignKey', [], {'default': 'None', 'to': "orm['auth.User']", 'null': 'True', 'blank': 'True'}),
+ 'power_parameters': ('maasserver.fields.JSONObjectField', [], {'default': "u''", 'blank': 'True'}),
+ 'power_type': ('django.db.models.fields.CharField', [], {'default': "u''", 'max_length': '10', 'blank': 'True'}),
+ 'status': ('django.db.models.fields.IntegerField', [], {'default': '0', 'max_length': '10'}),
+ 'system_id': ('django.db.models.fields.CharField', [], {'default': "u'node-e3dbb694-aed1-11e1-84fa-002215205ce8'", 'unique': 'True', 'max_length': '41'}),
+ 'token': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['piston.Token']", 'null': 'True'}),
+ 'updated': ('django.db.models.fields.DateTimeField', [], {})
+ },
+ u'maasserver.nodegroup': {
+ 'Meta': {'object_name': 'NodeGroup'},
+ 'api_key': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '18'}),
+ 'api_token': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['piston.Token']", 'unique': 'True'}),
+ 'broadcast_ip': ('django.db.models.fields.IPAddressField', [], {'max_length': '15'}),
+ 'created': ('django.db.models.fields.DateTimeField', [], {}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'ip_range_high': ('django.db.models.fields.IPAddressField', [], {'unique': 'True', 'max_length': '15'}),
+ 'ip_range_low': ('django.db.models.fields.IPAddressField', [], {'unique': 'True', 'max_length': '15'}),
+ 'name': ('django.db.models.fields.CharField', [], {'default': "u''", 'unique': 'True', 'max_length': '80'}),
+ 'router_ip': ('django.db.models.fields.IPAddressField', [], {'max_length': '15'}),
+ 'subnet_mask': ('django.db.models.fields.IPAddressField', [], {'max_length': '15'}),
+ 'updated': ('django.db.models.fields.DateTimeField', [], {}),
+ 'worker_ip': ('django.db.models.fields.IPAddressField', [], {'unique': 'True', 'max_length': '15'})
+ },
+ u'maasserver.sshkey': {
+ 'Meta': {'unique_together': "((u'user', u'key'),)", 'object_name': 'SSHKey'},
+ 'created': ('django.db.models.fields.DateTimeField', [], {}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'key': ('django.db.models.fields.TextField', [], {}),
+ 'updated': ('django.db.models.fields.DateTimeField', [], {}),
+ 'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']"})
+ },
+ u'maasserver.userprofile': {
+ 'Meta': {'object_name': 'UserProfile'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'user': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['auth.User']", 'unique': 'True'})
+ },
+ 'piston.consumer': {
+ 'Meta': {'object_name': 'Consumer'},
+ 'description': ('django.db.models.fields.TextField', [], {}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'key': ('django.db.models.fields.CharField', [], {'max_length': '18'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'secret': ('django.db.models.fields.CharField', [], {'max_length': '32'}),
+ 'status': ('django.db.models.fields.CharField', [], {'default': "'pending'", 'max_length': '16'}),
+ 'user': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'consumers'", 'null': 'True', 'to': "orm['auth.User']"})
+ },
+ 'piston.token': {
+ 'Meta': {'object_name': 'Token'},
+ 'callback': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
+ 'callback_confirmed': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'consumer': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['piston.Consumer']"}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'is_approved': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'key': ('django.db.models.fields.CharField', [], {'max_length': '18'}),
+ 'secret': ('django.db.models.fields.CharField', [], {'max_length': '32'}),
+ 'timestamp': ('django.db.models.fields.IntegerField', [], {'default': '1338875229L'}),
+ 'token_type': ('django.db.models.fields.IntegerField', [], {}),
+ 'user': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'tokens'", 'null': 'True', 'to': "orm['auth.User']"}),
+ 'verifier': ('django.db.models.fields.CharField', [], {'max_length': '10'})
+ }
+ }
+
+ complete_apps = ['maasserver']
=== modified file 'src/maasserver/models/__init__.py'
--- src/maasserver/models/__init__.py 2012-05-31 20:51:10 +0000
+++ src/maasserver/models/__init__.py 2012-06-05 06:21:23 +0000
@@ -24,6 +24,7 @@
"FileStorage",
"NODE_TRANSITIONS",
"Node",
+ "NodeGroup",
"MACAddress",
"SSHKey",
"UserProfile",
@@ -72,6 +73,8 @@
from maasserver.models.cleansave import CleanSave
from maasserver.models.config import Config
from maasserver.models.filestorage import FileStorage
+from maasserver.models.nodegroup import NodeGroup
+NodeGroup
from maasserver.models.sshkey import SSHKey
from maasserver.models.timestampedmodel import TimestampedModel
from maasserver.models.userprofile import UserProfile
=== added file 'src/maasserver/models/nodegroup.py'
--- src/maasserver/models/nodegroup.py 1970-01-01 00:00:00 +0000
+++ src/maasserver/models/nodegroup.py 2012-06-05 06:21:23 +0000
@@ -0,0 +1,64 @@
+# Copyright 2012 Canonical Ltd. This software is licensed under the
+# GNU Affero General Public License version 3 (see the file LICENSE).
+
+"""Model definition for NodeGroup which models a collection of Nodes."""
+
+from __future__ import (
+ absolute_import,
+ print_function,
+ unicode_literals,
+ )
+
+__metaclass__ = type
+__all__ = [
+ 'NodeGroup',
+ 'NodeGroupManager',
+ ]
+
+
+from django.db.models import (
+ CharField,
+ ForeignKey,
+ IPAddressField,
+ Manager,
+ )
+from maasserver import DefaultMeta
+from maasserver.models.timestampedmodel import TimestampedModel
+from piston.models import (
+ KEY_SIZE,
+ Token,
+ )
+
+
+class NodeGroupManager(Manager):
+ """Manager for the NodeGroup class.
+
+ Don't import or instantiate this directly; access as `<Class>.objects` on
+ the model class it manages.
+ """
+
+
+class NodeGroup(TimestampedModel):
+
+ class Meta(DefaultMeta):
+ """Needed for South to recognize this model."""
+
+ objects = NodeGroupManager()
+
+ name = CharField(
+ max_length=80, unique=True, editable=True, default="")
+
+ api_token = ForeignKey(Token, null=False, editable=False, unique=True)
+ api_key = CharField(
+ max_length=KEY_SIZE, null=False, editable=False, unique=True)
+
+ worker_ip = IPAddressField(null=False, editable=True, unique=True)
+
+ subnet_mask = IPAddressField(null=False, editable=True, unique=False)
+
+ broadcast_ip = IPAddressField(null=False, editable=True, unique=False)
+
+ router_ip = IPAddressField(null=False, editable=True, unique=False)
+
+ ip_range_low = IPAddressField(null=False, editable=True, unique=True)
+ ip_range_high = IPAddressField(null=False, editable=True, unique=True)
=== modified file 'src/maasserver/testing/factory.py'
--- src/maasserver/testing/factory.py 2012-05-23 16:32:15 +0000
+++ src/maasserver/testing/factory.py 2012-06-05 06:21:23 +0000
@@ -24,12 +24,15 @@
NODE_STATUS,
)
from maasserver.models import (
+ create_auth_token,
FileStorage,
MACAddress,
Node,
+ NodeGroup,
NODE_TRANSITIONS,
SSHKey,
)
+from maasserver.models.nodegroup import NodeGroup
from maasserver.testing import (
get_data,
reload_object,
@@ -105,6 +108,14 @@
Node.objects.filter(id=node.id).update(created=created)
return reload_object(node)
+ def make_node_group(self, api_token=None, **kwargs):
+ if api_token is None:
+ user = self.make_user()
+ api_token = create_auth_token(user)
+ ng = NodeGroup(api_token=api_token, api_key=api_token.key, **kwargs)
+ ng.save()
+ return ng
+
def make_node_commission_result(self, node=None, name=None, data=None):
if node is None:
node = self.make_node()
=== added file 'src/maasserver/tests/test_nodegroup.py'
--- src/maasserver/tests/test_nodegroup.py 1970-01-01 00:00:00 +0000
+++ src/maasserver/tests/test_nodegroup.py 2012-06-05 06:21:23 +0000
@@ -0,0 +1,39 @@
+# Copyright 2012 Canonical Ltd. This software is licensed under the
+# GNU Affero General Public License version 3 (see the file LICENSE).
+
+"""Tests for the NodeGroup model."""
+
+from __future__ import (
+ absolute_import,
+ print_function,
+ unicode_literals,
+ )
+
+__metaclass__ = type
+__all__ = []
+
+from testtools.matchers import MatchesStructure
+
+from maasserver.testing.factory import factory
+from maastesting.testcase import TestCase
+
+
+class TestNodeGroup(TestCase):
+
+ def test_model_stores_to_database(self):
+ ng = factory.make_node_group(
+ name=factory.getRandomString(80),
+ worker_ip="10.1.1.1",
+ subnet_mask="255.0.0.0",
+ broadcast_ip="10.255.255.255",
+ router_ip="10.1.1.254",
+ ip_range_low="10.1.1.2",
+ ip_range_high="10.254.254.253")
+ self.assertThat(
+ ng, MatchesStructure.byEquality(
+ worker_ip="10.1.1.1",
+ subnet_mask="255.0.0.0",
+ broadcast_ip="10.255.255.255",
+ router_ip="10.1.1.254",
+ ip_range_low="10.1.1.2",
+ ip_range_high="10.254.254.253"))