launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #09035
[Merge] lp:~jtv/maas/migrate-node-user-data into lp:maas
Jeroen T. Vermeulen has proposed merging lp:~jtv/maas/migrate-node-user-data into lp:maas.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~jtv/maas/migrate-node-user-data/+merge/111261
As per the migration plan. The only exciting thing this time was that it's the first metadataserver class to go.
Jeroen
--
https://code.launchpad.net/~jtv/maas/migrate-node-user-data/+merge/111261
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~jtv/maas/migrate-node-user-data into lp:maas.
=== modified file 'src/metadataserver/models/__init__.py'
--- src/metadataserver/models/__init__.py 2012-06-15 05:36:23 +0000
+++ src/metadataserver/models/__init__.py 2012-06-20 17:19:22 +0000
@@ -29,11 +29,9 @@
from maasserver.models import Node
from maasserver.models.cleansave import CleanSave
from maasserver.models.user import create_auth_token
+from maasserver.utils import ignore_unused
from metadataserver import DefaultMeta
-from metadataserver.fields import (
- Bin,
- BinaryField,
- )
+from metadataserver.models.nodeuserdata import NodeUserData
from metadataserver.nodeinituser import get_node_init_user
from piston.models import (
KEY_SIZE,
@@ -41,6 +39,9 @@
)
+ignore_unused(NodeUserData)
+
+
class NodeKeyManager(Manager):
"""Utility for the collection of NodeKeys.
@@ -136,64 +137,6 @@
max_length=KEY_SIZE, null=False, editable=False, unique=True)
-# Scheduled for model migration on 2012-06-22
-class NodeUserDataManager(Manager):
- """Utility for the collection of NodeUserData items."""
-
- def set_user_data(self, node, data):
- """Set user data for the given node.
-
- If `data` is None, remove user data for the node.
- """
- if data is None:
- self._remove(node)
- else:
- self._set(node, data)
-
- def get_user_data(self, node):
- """Retrieve user data for the given node."""
- return self.get(node=node).data
-
- def has_user_data(self, node):
- """Do we have user data registered for node?"""
- return self.filter(node=node).exists()
-
- def _set(self, node, data):
- """Set actual user data for a node. Not usable if data is None."""
- wrapped_data = Bin(data)
- (existing_entry, created) = self.get_or_create(
- node=node, defaults={'data': wrapped_data})
- if not created:
- existing_entry.data = wrapped_data
- existing_entry.save()
-
- def _remove(self, node):
- """Remove metadata from node, if it has any any."""
- self.filter(node=node).delete()
-
-
-# Scheduled for model migration on 2012-06-22
-class NodeUserData(CleanSave, Model):
- """User-data portion of a node's metadata.
-
- When cloud-init sets up a node, it retrieves specific data for that node
- from the metadata service. One portion of that is the "user-data" binary
- blob.
-
- :ivar node: Node that this is for.
- :ivar data: base64-encoded data.
- """
-
- class Meta(DefaultMeta):
- """Needed for South to recognize this model."""
-
- objects = NodeUserDataManager()
-
- node = ForeignKey(
- 'maasserver.Node', null=False, editable=False, unique=True)
- data = BinaryField(null=False)
-
-
class NodeCommissionResultManager(Manager):
"""Utility to manage a collection of :class:`NodeCommissionResult`s."""
=== added file 'src/metadataserver/models/nodeuserdata.py'
--- src/metadataserver/models/nodeuserdata.py 1970-01-01 00:00:00 +0000
+++ src/metadataserver/models/nodeuserdata.py 2012-06-20 17:19:22 +0000
@@ -0,0 +1,84 @@
+# Copyright 2012 Canonical Ltd. This software is licensed under the
+# GNU Affero General Public License version 3 (see the file LICENSE).
+
+"""Node user-data for cloud-init's use."""
+
+from __future__ import (
+ absolute_import,
+ print_function,
+ unicode_literals,
+ )
+
+__metaclass__ = type
+__all__ = [
+ 'NodeUserData',
+ ]
+
+
+from django.db.models import (
+ ForeignKey,
+ Manager,
+ Model,
+ )
+from maasserver.models.cleansave import CleanSave
+from metadataserver import DefaultMeta
+from metadataserver.fields import (
+ Bin,
+ BinaryField,
+ )
+
+
+class NodeUserDataManager(Manager):
+ """Utility for the collection of NodeUserData items."""
+
+ def set_user_data(self, node, data):
+ """Set user data for the given node.
+
+ If `data` is None, remove user data for the node.
+ """
+ if data is None:
+ self._remove(node)
+ else:
+ self._set(node, data)
+
+ def get_user_data(self, node):
+ """Retrieve user data for the given node."""
+ return self.get(node=node).data
+
+ def has_user_data(self, node):
+ """Do we have user data registered for node?"""
+ return self.filter(node=node).exists()
+
+ def _set(self, node, data):
+ """Set actual user data for a node. Not usable if data is None."""
+ wrapped_data = Bin(data)
+ (existing_entry, created) = self.get_or_create(
+ node=node, defaults={'data': wrapped_data})
+ if not created:
+ existing_entry.data = wrapped_data
+ existing_entry.save()
+
+ def _remove(self, node):
+ """Remove metadata from node, if it has any any."""
+ self.filter(node=node).delete()
+
+
+class NodeUserData(CleanSave, Model):
+ """User-data portion of a node's metadata.
+
+ When cloud-init sets up a node, it retrieves specific data for that node
+ from the metadata service. One portion of that is the "user-data" binary
+ blob.
+
+ :ivar node: Node that this is for.
+ :ivar data: base64-encoded data.
+ """
+
+ class Meta(DefaultMeta):
+ """Needed for South to recognize this model."""
+
+ objects = NodeUserDataManager()
+
+ node = ForeignKey(
+ 'maasserver.Node', null=False, editable=False, unique=True)
+ data = BinaryField(null=False)