~ubuntu-branches/ubuntu/raring/maas/raring-updates

« back to all changes in this revision

Viewing changes to src/metadataserver/models/__init__.py

  • Committer: Package Import Robot
  • Author(s): Andres Rodriguez
  • Date: 2012-07-03 17:42:37 UTC
  • mfrom: (1.1.13)
  • Revision ID: package-import@ubuntu.com-20120703174237-p8l0keuuznfg721k
Tags: 0.1+bzr709+dfsg-0ubuntu1
* New Upstream release
* debian/control:
  - Depends on python-celery, python-tempita, libjs-yui3-{full,min},
    libjs-raphael
* debian/maas.install:
  - Install apiclient, celeryconfig.py, maas-import-pxe-files, preseeds_v2.
  - Update to install various files from chroot, rather tha manually copy
    them from the source.
* debian/maas.links: symlink celeryconfig.py
* debian/maas.maas-celery.upstart: Add job.
* debian/rules:
  - Install celery upstart job.
  - Do not install jslibs as packages are now used.
  - Drop copying of maas_local_settings_sample.py as source now ships
    a maas_local_settings.py
* debian/patches:
  - 04-maas-http-fix.patch: Drop. Merged upstream.
  - 01-fix-database-settings.patch: Refreshed.
  - 99_enums_js.patch: Added until creation of enum.js / build process
    is fixed.
* debian/maas.postinst: Update bzr version to correctly handle upgrades.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright 2012 Canonical Ltd.  This software is licensed under the
 
2
# GNU Affero General Public License version 3 (see the file LICENSE).
 
3
 
 
4
"""Model for the metadata server.
 
5
 
 
6
DO NOT add new models to this module.  Add them to the package as separate
 
7
modules, but import them here and add them to `__all__`.
 
8
"""
 
9
 
 
10
from __future__ import (
 
11
    absolute_import,
 
12
    print_function,
 
13
    unicode_literals,
 
14
    )
 
15
 
 
16
__metaclass__ = type
 
17
__all__ = [
 
18
    'NodeCommissionResult',
 
19
    'NodeKey',
 
20
    'NodeUserData',
 
21
    ]
 
22
 
 
23
from django.db.models import (
 
24
    CharField,
 
25
    ForeignKey,
 
26
    Manager,
 
27
    Model,
 
28
    )
 
29
from django.shortcuts import get_object_or_404
 
30
from maasserver.models import Node
 
31
from maasserver.models.cleansave import CleanSave
 
32
from maasserver.utils import ignore_unused
 
33
from metadataserver import DefaultMeta
 
34
from metadataserver.models.nodekey import NodeKey
 
35
from metadataserver.models.nodeuserdata import NodeUserData
 
36
 
 
37
 
 
38
ignore_unused(NodeKey, NodeUserData)
 
39
 
 
40
 
 
41
class NodeCommissionResultManager(Manager):
 
42
# Scheduled for model migration on 2012-07-09
 
43
    """Utility to manage a collection of :class:`NodeCommissionResult`s."""
 
44
 
 
45
    def clear_results(self, node):
 
46
        """Remove all existing results for a node."""
 
47
        self.filter(node=node).delete()
 
48
 
 
49
    def store_data(self, node, name, data):
 
50
        """Store data about a node."""
 
51
        existing, created = self.get_or_create(
 
52
            node=node, name=name, defaults=dict(data=data))
 
53
        if not created:
 
54
            existing.data = data
 
55
            existing.save()
 
56
 
 
57
    def get_data(self, node, name):
 
58
        """Get data about a node."""
 
59
        ncr = get_object_or_404(NodeCommissionResult, node=node, name=name)
 
60
        return ncr.data
 
61
 
 
62
 
 
63
# Scheduled for model migration on 2012-07-09
 
64
class NodeCommissionResult(CleanSave, Model):
 
65
    """Storage for data returned from node commissioning.
 
66
 
 
67
    Commissioning a node results in various bits of data that need to be
 
68
    stored, such as lshw output.  This model allows storing of this data
 
69
    as unicode text, with an arbitrary name, for later retrieval.
 
70
 
 
71
    :ivar node: The context :class:`Node`.
 
72
    :ivar name: A unique name to use for the data being stored.
 
73
    :ivar data: The file's actual data, unicode only.
 
74
    """
 
75
 
 
76
    class Meta(DefaultMeta):
 
77
        unique_together = ('node', 'name')
 
78
 
 
79
    objects = NodeCommissionResultManager()
 
80
 
 
81
    node = ForeignKey(
 
82
        'maasserver.Node', null=False, editable=False, unique=False)
 
83
    name = CharField(max_length=100, unique=False, editable=False)
 
84
    data = CharField(max_length=1024 * 1024, editable=True)