Merge lp:~mpontillo/maas/networks-list-view into lp:maas/trunk

Proposed by Mike Pontillo on 2017-01-26
Status: Rejected
Rejected by: MAAS Lander on 2017-06-22
Proposed branch: lp:~mpontillo/maas/networks-list-view
Merge into: lp:maas/trunk
Diff against target: 212 lines (+156/-0)
5 files modified
src/maasserver/__init__.py (+2/-0)
src/maasserver/dbviews.py (+58/-0)
src/maasserver/migrations/builtin/maasserver/0108_network_view.py (+31/-0)
src/maasserver/models/__init__.py (+4/-0)
src/maasserver/models/network.py (+61/-0)
To merge this branch: bzr merge lp:~mpontillo/maas/networks-list-view
Reviewer Review Type Date Requested Status
MAAS Maintainers 2017-01-26 Pending
Review via email: mp+315645@code.launchpad.net

Commit message

WIP

To post a comment you must log in.
MAAS Lander (maas-lander) wrote :

Transitioned to Git.

lp:maas has now moved from Bzr to Git.
Please propose your branches with Launchpad using Git.

git clone https://git.launchpad.net/maas

Unmerged revisions

5659. By Mike Pontillo on 2017-01-26

Bring migrations up to date.

5658. By Mike Pontillo on 2017-01-26

Merge trunk.

5657. By Mike Pontillo on 2017-01-26

New approach: unmanaged multi-table inheritance.

5656. By Mike Pontillo on 2017-01-25

Investigate providing the networks listing based on a database view.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/maasserver/__init__.py'
2--- src/maasserver/__init__.py 2016-12-07 12:46:14 +0000
3+++ src/maasserver/__init__.py 2017-01-26 04:30:59 +0000
4@@ -32,6 +32,8 @@
5
6 class DefaultViewMeta(DefaultMeta):
7 """Default `Meta` class for a view-backed model."""
8+ # When managed is False, Django will not create a migration for this
9+ # model class. This is required for model classes based on views.
10 managed = False
11
12
13
14=== modified file 'src/maasserver/dbviews.py'
15--- src/maasserver/dbviews.py 2017-01-08 02:48:36 +0000
16+++ src/maasserver/dbviews.py 2017-01-26 04:30:59 +0000
17@@ -139,6 +139,63 @@
18 AND family(sip_left.ip) = family(sip_right.ip)
19 """)
20
21+maasserver_network = dedent("""\
22+ SELECT
23+ -- subnet.*,
24+ subnet.id AS "subnet_ptr_id",
25+ fabric.id AS "fabric_id", fabric.name AS "fabric_name",
26+ vlan.vid AS "vlan_vid", vlan.name AS "vlan_name",
27+ space.id AS "space_id", space.name AS "space_name"
28+ FROM maasserver_fabric fabric
29+ LEFT OUTER JOIN maasserver_vlan vlan ON vlan.fabric_id = fabric.id
30+ LEFT OUTER JOIN maasserver_subnet subnet ON subnet.vlan_id = vlan.id
31+ LEFT OUTER JOIN maasserver_space space
32+ ON space.id IS NOT DISTINCT FROM vlan.space_id
33+ ORDER BY
34+ fabric.name,
35+ vlan.vid,
36+ subnet.cidr
37+""")
38+
39+maasserver_networks_by_fabric = dedent("""\
40+ SELECT
41+ subnet.*,
42+ fabric.id AS "fabric_id", fabric.name AS "fabric_name",
43+ vlan.vid AS "vlan_vid", vlan.name AS "vlan_name",
44+ subnet.id AS "subnet_id", subnet.name AS "subnet_name",
45+ subnet.cidr AS "subnet_cidr",
46+ space.id AS "space_id", space.name AS "space_name"
47+ FROM maasserver_fabric fabric
48+ LEFT OUTER JOIN maasserver_vlan vlan ON vlan.fabric_id = fabric.id
49+ LEFT OUTER JOIN maasserver_subnet subnet ON subnet.vlan_id = vlan.id
50+ LEFT OUTER JOIN maasserver_space space
51+ ON space.id IS NOT DISTINCT FROM vlan.space_id
52+ ORDER BY
53+ fabric.name,
54+ vlan.vid,
55+ subnet.cidr
56+""")
57+
58+
59+maasserver_networks_by_space = dedent("""\
60+ SELECT
61+ subnet.*,
62+ space.id AS "space_id", space.name AS "space_name",
63+ fabric.id AS "fabric_id", fabric.name AS "fabric_name",
64+ vlan.vid AS "vlan_vid", vlan.name AS "vlan_name",
65+ subnet.id AS "subnet_id", subnet.name AS "subnet_name",
66+ subnet.cidr AS "subnet_cidr"
67+ FROM maasserver_subnet subnet
68+ LEFT OUTER JOIN maasserver_vlan vlan ON subnet.vlan_id = vlan.id
69+ LEFT OUTER JOIN maasserver_space space ON space.id
70+ IS NOT DISTINCT FROM vlan.space_id
71+ LEFT OUTER JOIN maasserver_fabric fabric ON vlan.fabric_id = fabric.id
72+ ORDER BY
73+ space.name,
74+ vlan.name,
75+ subnet.cidr
76+""")
77+
78
79 # Views that are helpful for supporting MAAS.
80 # These can be batch-run using the maas-region-support-dump script.
81@@ -274,6 +331,7 @@
82 _ALL_VIEWS = {
83 "maasserver_discovery": maasserver_discovery,
84 "maasserver_routable_pairs": maasserver_routable_pairs,
85+ "maasserver_network": maasserver_network,
86 "maas_support__node_overview": maas_support__node_overview,
87 "maas_support__device_overview": maas_support__device_overview,
88 "maas_support__node_networking": maas_support__node_networking,
89
90=== added file 'src/maasserver/migrations/builtin/maasserver/0108_network_view.py'
91--- src/maasserver/migrations/builtin/maasserver/0108_network_view.py 1970-01-01 00:00:00 +0000
92+++ src/maasserver/migrations/builtin/maasserver/0108_network_view.py 2017-01-26 04:30:59 +0000
93@@ -0,0 +1,31 @@
94+# -*- coding: utf-8 -*-
95+from __future__ import unicode_literals
96+
97+from django.db import migrations, models
98+
99+
100+class Migration(migrations.Migration):
101+
102+ dependencies = [
103+ ('maasserver', '0107_chassis_to_pods'),
104+ ]
105+
106+ operations = [
107+ migrations.CreateModel(
108+ name='Network',
109+ fields=[
110+ ('subnet_ptr', models.OneToOneField(serialize=False, primary_key=True, to='maasserver.Subnet', auto_created=True, parent_link=True)),
111+ ('space_name', models.CharField(blank=True, max_length=256, null=True, editable=False)),
112+ ('fabric_name', models.CharField(blank=True, max_length=256, null=True, editable=False)),
113+ ('vlan_name', models.CharField(blank=True, max_length=256, null=True, editable=False)),
114+ ('vlan_vid', models.IntegerField(blank=True, null=True)),
115+ ],
116+ options={
117+ 'managed': False,
118+ 'verbose_name': 'Network',
119+ 'verbose_name_plural': 'Networks',
120+ 'db_table': 'maasserver_network',
121+ },
122+ bases=('maasserver.subnet', models.Model),
123+ ),
124+ ]
125
126=== modified file 'src/maasserver/models/__init__.py'
127--- src/maasserver/models/__init__.py 2017-01-23 19:56:16 +0000
128+++ src/maasserver/models/__init__.py 2017-01-26 04:30:59 +0000
129@@ -43,6 +43,7 @@
130 'Machine',
131 'MDNS',
132 'Neighbour',
133+ 'Networks',
134 'Node',
135 'NodeGroupToRackController',
136 'Notification',
137@@ -142,6 +143,9 @@
138 from maasserver.models.licensekey import LicenseKey
139 from maasserver.models.mdns import MDNS
140 from maasserver.models.neighbour import Neighbour
141+from maasserver.models.network import (
142+ Network,
143+)
144 from maasserver.models.node import (
145 Controller,
146 Device,
147
148=== added file 'src/maasserver/models/network.py'
149--- src/maasserver/models/network.py 1970-01-01 00:00:00 +0000
150+++ src/maasserver/models/network.py 2017-01-26 04:30:59 +0000
151@@ -0,0 +1,61 @@
152+# Copyright 2017 Canonical Ltd. This software is licensed under the
153+# GNU Affero General Public License version 3 (see the file LICENSE).
154+
155+"""Model definition for a `Discovery` (a discovered network device)."""
156+
157+__all__ = [
158+ 'Network',
159+ 'NetworksByFabric',
160+ 'NetworksBySpace',
161+]
162+
163+from django.db.models import (
164+ CharField,
165+ DO_NOTHING,
166+ ForeignKey,
167+ IntegerField,
168+)
169+from maasserver import DefaultViewMeta
170+from maasserver.models.subnet import Subnet
171+from maasserver.models.viewmodel import ViewModel
172+from provisioningserver.logger import get_maas_logger
173+
174+
175+maaslog = get_maas_logger("discovery")
176+
177+
178+class Network(Subnet, ViewModel):
179+ """A `Network` object represents the combined data for a MAAS network."""
180+
181+ class Meta(DefaultViewMeta):
182+ managed = False
183+ db_table = "maasserver_network"
184+ verbose_name = "Network"
185+ verbose_name_plural = "Networks"
186+
187+ fabric = ForeignKey(
188+ 'Fabric', related_name='+', unique=False, blank=False, null=False,
189+ editable=False, on_delete=DO_NOTHING)
190+
191+ space = ForeignKey(
192+ 'VLAN', related_name='+', unique=False, blank=False, null=True,
193+ editable=False, on_delete=DO_NOTHING)
194+
195+ space_name = CharField(
196+ max_length=256, editable=False, null=True, blank=True)
197+
198+ fabric_name = CharField(
199+ max_length=256, editable=False, null=True, blank=True)
200+
201+ vlan_name = CharField(
202+ max_length=256, editable=False, null=True, blank=True)
203+
204+ vlan_vid = IntegerField(null=True, blank=True)
205+
206+ def save(self, *args, **kwargs):
207+ # Hack to allow saving this unmanaged model.
208+ self.__class__ = Subnet
209+ Subnet.save(self, *args, **kwargs)
210+ self.__class__ = Network
211+
212+