launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #12208
[Merge] lp:~jameinel/maas/tag-tables into lp:maas
John A Meinel has proposed merging lp:~jameinel/maas/tag-tables into lp:maas.
Requested reviews:
MAAS Maintainers (maas-maintainers)
For more details, see:
https://code.launchpad.net/~jameinel/maas/tag-tables/+merge/125192
I'd like to get some feedback on this before I proceed much further.
I'm updating the database to be able to store Tag definitions. Specifically the idea is to have a short-name which is what will be displayed in a UI, then the xpath (I'm using definition here), and then the user can optionally add a comment about the tag, which is a long-form description for a human being.
Each node has potentially many tags (and each tag has many nodes), so there is a many-many relationship. And I think we are going to have UI like Juju's that is going to want to know what Nodes have a given Tag, and UI like the web interface that is going to want to display what Tags a Node has. So I think it is a bit arbitrary where the many-to-many object lives.
I think I did all the South migration stuff correctly, and I think this is the correct definition of the tables. Obviously we still need to hook up the logic to these classes.
--
https://code.launchpad.net/~jameinel/maas/tag-tables/+merge/125192
Your team MAAS Maintainers is requested to review the proposed merge of lp:~jameinel/maas/tag-tables into lp:maas.
=== added file 'src/maasserver/migrations/0027_add_tag_table.py'
--- src/maasserver/migrations/0027_add_tag_table.py 1970-01-01 00:00:00 +0000
+++ src/maasserver/migrations/0027_add_tag_table.py 2012-09-19 13:00:45 +0000
@@ -0,0 +1,195 @@
+# 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 'Tag'
+ db.create_table(u'maasserver_tag', (
+ ('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')(unique=True, max_length=256)),
+ ('definition', self.gf('django.db.models.fields.TextField')()),
+ ('comment', self.gf('django.db.models.fields.TextField')(blank=True)),
+ ))
+ db.send_create_signal(u'maasserver', ['Tag'])
+
+
+ def backwards(self, orm):
+
+ # Deleting model 'Tag'
+ db.delete_table(u'maasserver_tag')
+
+
+ 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.bootimage': {
+ 'Meta': {'unique_together': "((u'architecture', u'subarchitecture', u'release', u'purpose'),)", 'object_name': 'BootImage'},
+ 'architecture': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'purpose': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'release': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'subarchitecture': ('django.db.models.fields.CharField', [], {'max_length': '255'})
+ },
+ 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.dhcplease': {
+ 'Meta': {'object_name': 'DHCPLease'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'ip': ('django.db.models.fields.IPAddressField', [], {'unique': 'True', 'max_length': '15'}),
+ 'mac': ('maasserver.fields.MACAddressField', [], {}),
+ 'nodegroup': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['maasserver.NodeGroup']"})
+ },
+ 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', [], {}),
+ 'distro_series': ('django.db.models.fields.CharField', [], {'default': "u''", 'max_length': '10', 'null': 'True', 'blank': 'True'}),
+ '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'}),
+ 'netboot': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+ 'nodegroup': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['maasserver.NodeGroup']", 'null': '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-71a8acb4-0258-11e2-b82f-00163e9c8bf7'", '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'}),
+ 'created': ('django.db.models.fields.DateTimeField', [], {}),
+ 'dhcp_key': ('django.db.models.fields.CharField', [], {'default': "u''", 'max_length': '255', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
+ 'status': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
+ 'updated': ('django.db.models.fields.DateTimeField', [], {}),
+ 'uuid': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '36'})
+ },
+ u'maasserver.nodegroupinterface': {
+ 'Meta': {'unique_together': "((u'nodegroup', u'interface'),)", 'object_name': 'NodeGroupInterface'},
+ 'broadcast_ip': ('django.db.models.fields.IPAddressField', [], {'default': 'None', 'max_length': '15', 'null': 'True', 'blank': 'True'}),
+ 'created': ('django.db.models.fields.DateTimeField', [], {}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'interface': ('django.db.models.fields.CharField', [], {'default': "u''", 'max_length': '255', 'blank': 'True'}),
+ 'ip': ('django.db.models.fields.IPAddressField', [], {'max_length': '15'}),
+ 'ip_range_high': ('django.db.models.fields.IPAddressField', [], {'default': 'None', 'max_length': '15', 'unique': 'True', 'null': 'True', 'blank': 'True'}),
+ 'ip_range_low': ('django.db.models.fields.IPAddressField', [], {'default': 'None', 'max_length': '15', 'unique': 'True', 'null': 'True', 'blank': 'True'}),
+ 'management': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
+ 'nodegroup': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['maasserver.NodeGroup']"}),
+ 'router_ip': ('django.db.models.fields.IPAddressField', [], {'default': 'None', 'max_length': '15', 'null': 'True', 'blank': 'True'}),
+ 'subnet_mask': ('django.db.models.fields.IPAddressField', [], {'default': 'None', 'max_length': '15', 'null': 'True', 'blank': 'True'}),
+ 'updated': ('django.db.models.fields.DateTimeField', [], {})
+ },
+ 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.tag': {
+ 'Meta': {'object_name': 'Tag'},
+ 'comment': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
+ 'created': ('django.db.models.fields.DateTimeField', [], {}),
+ 'definition': ('django.db.models.fields.TextField', [], {}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '256'}),
+ 'updated': ('django.db.models.fields.DateTimeField', [], {})
+ },
+ 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': '1348058966L'}),
+ '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-09-13 10:16:33 +0000
+++ src/maasserver/models/__init__.py 2012-09-19 13:00:45 +0000
@@ -21,6 +21,7 @@
'NodeGroup',
'NodeGroupInterface',
'SSHKey',
+ 'Tag',
'UserProfile',
]
@@ -40,6 +41,7 @@
from maasserver.models.nodegroup import NodeGroup
from maasserver.models.nodegroupinterface import NodeGroupInterface
from maasserver.models.sshkey import SSHKey
+from maasserver.models.tag import Tag
from maasserver.models.user import create_user
from maasserver.models.userprofile import UserProfile
from maasserver.utils import ignore_unused
@@ -53,7 +55,7 @@
# export in __all__.
ignore_unused(
Config, DHCPLease, FileStorage, MACAddress, NodeGroup, SSHKey,
- UserProfile, NodeGroupInterface)
+ Tag, UserProfile, NodeGroupInterface)
# Connect the 'create_user' method to the post save signal of User.
@@ -71,6 +73,7 @@
admin.site.register(FileStorage)
admin.site.register(MACAddress)
admin.site.register(Node)
+admin.site.register(Tag)
admin.site.register(SSHKey)
=== added file 'src/maasserver/models/tag.py'
--- src/maasserver/models/tag.py 1970-01-01 00:00:00 +0000
+++ src/maasserver/models/tag.py 2012-09-19 13:00:45 +0000
@@ -0,0 +1,58 @@
+# Copyright 2012 Canonical Ltd. This software is licensed under the
+# GNU Affero General Public License version 3 (see the file LICENSE).
+
+"""Node objects."""
+
+from __future__ import (
+ absolute_import,
+ print_function,
+ unicode_literals,
+ )
+
+__metaclass__ = type
+__all__ = [
+ "Tag",
+ ]
+
+from django.db.models import (
+ CharField,
+ TextField,
+ Manager,
+ )
+from maasserver import DefaultMeta
+from maasserver.models.cleansave import CleanSave
+from maasserver.models.config import Config
+from maasserver.models.timestampedmodel import TimestampedModel
+from maasserver.models.node import Node
+
+
+class TagManager(Manager):
+ """A utility to manage the collection of Tags."""
+ pass # I don't know what I'm doing
+
+
+class Tag(CleanSave, TimestampedModel):
+ """A `Tag` is a label applied to a `Node`.
+
+ :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 power_type: The :class:`POWER_TYPE` that determines how this
+ node will be powered on. If not given, the default will be used as
+ configured in the `node_power_type` setting.
+ :ivar objects: The :class:`NodeManager`.
+ """
+
+ class Meta(DefaultMeta):
+ """Needed for South to recognize this model."""
+
+ name = CharField(max_length=256, unique=True, editable=True)
+ definition = TextField()
+ comment = TextField(blank=True)
+
+ objects = TagManager()
+
+ def __unicode__(self):
+ return self.name
+
=== modified file 'src/maasserver/testing/factory.py'
--- src/maasserver/testing/factory.py 2012-09-16 17:30:30 +0000
+++ src/maasserver/testing/factory.py 2012-09-19 13:00:45 +0000
@@ -33,6 +33,7 @@
Node,
NodeGroup,
SSHKey,
+ Tag,
)
from maasserver.models.node import NODE_TRANSITIONS
from maasserver.testing import (
@@ -224,6 +225,18 @@
key.save()
return key
+ def make_tag(self, name, definition, comment='', created=None,
+ updated=None):
+ tag = Tag(name=name, definition=definition, comment=comment)
+ self._save_node_unchecked(tag)
+ # Update the 'updated'/'created' fields with a call to 'update'
+ # preventing a call to save() from overriding the values.
+ if updated is not None:
+ Tag.objects.filter(id=tag.id).update(updated=updated)
+ if created is not None:
+ Tag.objects.filter(id=tag.id).update(created=created)
+ return reload_object(tag)
+
def make_user_with_keys(self, n_keys=2, user=None, **kwargs):
"""Create a user with n `SSHKey`. If user is not None, use this user
instead of creating one.
=== added file 'src/maasserver/tests/test_tag.py'
--- src/maasserver/tests/test_tag.py 1970-01-01 00:00:00 +0000
+++ src/maasserver/tests/test_tag.py 2012-09-19 13:00:45 +0000
@@ -0,0 +1,59 @@
+# Copyright 2012 Canonical Ltd. This software is licensed under the
+# GNU Affero General Public License version 3 (see the file LICENSE).
+
+"""Test maasserver models."""
+
+from __future__ import (
+ absolute_import,
+ print_function,
+ unicode_literals,
+ )
+
+__metaclass__ = type
+__all__ = []
+
+from django.conf import settings
+from django.core.exceptions import (
+ PermissionDenied,
+ ValidationError,
+ )
+from maasserver.enum import (
+ NODE_PERMISSION,
+ NODE_STATUS,
+ NODE_STATUS_CHOICES,
+ NODE_STATUS_CHOICES_DICT,
+ )
+from maasserver.exceptions import NodeStateViolation
+from maasserver.models import (
+ Config,
+ MACAddress,
+ Node,
+ )
+from maasserver.models.node import NODE_TRANSITIONS
+from maasserver.models.user import create_auth_token
+from maasserver.testing import reload_object
+from maasserver.testing.factory import factory
+from maasserver.testing.testcase import TestCase
+from maasserver.utils import map_enum
+from metadataserver.models import (
+ NodeCommissionResult,
+ NodeUserData,
+ )
+from provisioningserver.enum import POWER_TYPE
+from provisioningserver.power.poweraction import PowerAction
+from testtools.matchers import FileContains
+
+
+class TagTest(TestCase):
+
+ def test_factory_make_tag(self):
+ """
+ The generated system_id looks good.
+
+ """
+ tag = factory.make_tag('tag-name', '//node[@id=display]')
+ self.assertEqual('tag-name', tag.name)
+ self.assertEqual('//node[@id=display]', tag.definition)
+ self.assertEqual('', tag.comment)
+ self.assertIsNot(None, tag.updated)
+ self.assertIsNot(None, tag.created)
Follow ups