Skip to content

Commit c2b370c

Browse files
author
Bob Kukura
authored
Merge pull request noironetworks#278 from noironetworks/nested
Add the NestedParameter and VlanRange table
2 parents faf387f + f08e1ce commit c2b370c

File tree

9 files changed

+361
-10
lines changed

9 files changed

+361
-10
lines changed

aim/aim_manager.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ class AimManager(object):
8484
api_infra.HostDomainMappingV2,
8585
api_infra.HostLinkNetworkLabel,
8686
api_infra.ApicAssignment,
87+
api_infra.NestedParameter,
8788
api_res.SecurityGroup,
8889
api_res.SecurityGroupSubject,
8990
api_res.SecurityGroupRule,

aim/aim_store.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ class SqlAlchemyStore(AimStore):
233233
api_infra.HostLinkNetworkLabel: (
234234
infra_model.HostLinkNetworkLabel),
235235
api_infra.ApicAssignment: infra_model.ApicAssignment,
236+
api_infra.NestedParameter: infra_model.NestedParameter,
236237
api_res.SecurityGroup: models.SecurityGroup,
237238
api_res.SecurityGroupSubject: models.SecurityGroupSubject,
238239
api_res.SecurityGroupRule: models.SecurityGroupRule,

aim/api/infra.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
from aim.api import resource
2222
from aim.api import types as t
23+
from aim import exceptions as exc
2324

2425
WILDCARD_HOST = '*'
2526
LOG = logging.getLogger(__name__)
@@ -154,3 +155,46 @@ def is_available(self, context):
154155
LOG.debug("APIC %s is not available. Last update time was %s" %
155156
(self.apic_host, self.last_update_timestamp))
156157
return False
158+
159+
160+
# REVISIT(kentwu): We will need to deprecate this once there is
161+
# a proper fix in the openShift IPI installer.
162+
class NestedParameter(resource.ResourceBase):
163+
"""Nested parameters needed for openShift on openStack install"""
164+
165+
identity_attributes = t.identity(
166+
('project_id', t.name),
167+
('cluster_name', t.name))
168+
other_attributes = t.other(
169+
('domain_name', t.name),
170+
('domain_type', t.string(32)),
171+
('domain_infra_vlan', t.string()),
172+
('domain_service_vlan', t.string()),
173+
('domain_node_vlan', t.string()),
174+
('vlan_range_list', t.list_of_vlan_range))
175+
176+
def __init__(self, **kwargs):
177+
for vlan_type in ['domain_infra_vlan', 'domain_service_vlan',
178+
'domain_node_vlan']:
179+
vlan = kwargs.get(vlan_type)
180+
if vlan and (int(vlan) < 0 or int(vlan) > 4095):
181+
raise exc.AciResourceValueError(klass=type(self).__name__,
182+
value=vlan,
183+
attr=vlan_type)
184+
vlan_range_list = kwargs.get('vlan_range_list', [])
185+
for vlan_range in vlan_range_list:
186+
if 'start' not in vlan_range or 'end' not in vlan_range:
187+
continue
188+
start = int(vlan_range['start'])
189+
end = int(vlan_range['end'])
190+
if (start > end or start < 0 or start > 4095 or
191+
end < 0 or end > 4095):
192+
raise exc.AciResourceValueError(klass=type(self).__name__,
193+
value=vlan_range,
194+
attr='vlan_range_list')
195+
super(NestedParameter, self).__init__({'domain_type': 'k8s',
196+
'domain_infra_vlan': '0',
197+
'domain_service_vlan': '0',
198+
'domain_node_vlan': '0',
199+
'vlan_range_list': []},
200+
**kwargs)

aim/api/types.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,3 +157,8 @@ def list_of_dicts(*dict_keys_and_types):
157157
"preference": {"type": "string"}}}
158158
list_of_next_hop = {"type": "array", "items": next_hop}
159159
epoch = integer
160+
vlan_range = {
161+
"type": "object",
162+
"properties": {"start": string(),
163+
"end": string()}}
164+
list_of_vlan_range = {"type": "array", "items": vlan_range}

aim/db/infra_model.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
import sqlalchemy as sa
1717
from sqlalchemy.dialects.mysql import VARCHAR
18+
from sqlalchemy import orm
1819
from sqlalchemy.sql.expression import func
1920

2021
from aim.api import infra
@@ -164,3 +165,63 @@ class ApicAssignment(model_base.Base, model_base.AttributeMixin):
164165
aim_aid_id = sa.Column(sa.String(64))
165166
last_update_timestamp = sa.Column(sa.TIMESTAMP, server_default=func.now(),
166167
onupdate=func.now())
168+
169+
170+
# REVISIT(kentwu): We will need to deprecate this class along with
171+
# NestedParameter class once there is a proper fix in the openShift
172+
# IPI installer.
173+
class VlanRange(model_base.Base):
174+
"""DB model for vlan ranges under a NestedParameter."""
175+
176+
__tablename__ = 'aim_vlan_ranges'
177+
178+
nested_parameter_aim_id = sa.Column(
179+
sa.Integer, sa.ForeignKey('aim_nested_parameter.aim_id'),
180+
primary_key=True)
181+
start = sa.Column(sa.Integer, primary_key=True)
182+
end = sa.Column(sa.Integer, nullable=False)
183+
184+
185+
class NestedParameter(model_base.Base, model_base.HasAimId,
186+
model_base.AttributeMixin):
187+
__tablename__ = 'aim_nested_parameter'
188+
189+
project_id = model_base.name_column(nullable=False)
190+
cluster_name = model_base.name_column(nullable=False)
191+
__table_args__ = (model_base.uniq_column(__tablename__, 'project_id',
192+
'cluster_name') +
193+
model_base.to_tuple(model_base.Base.__table_args__))
194+
195+
domain_name = model_base.name_column()
196+
domain_type = sa.Column(sa.String(32), nullable=False)
197+
domain_infra_vlan = sa.Column(sa.Integer, nullable=False)
198+
domain_service_vlan = sa.Column(sa.Integer, nullable=False)
199+
domain_node_vlan = sa.Column(sa.Integer, nullable=False)
200+
201+
vlan_range_list = orm.relationship(VlanRange,
202+
backref='nested_parameter',
203+
cascade='all, delete-orphan',
204+
lazy='joined')
205+
206+
def from_attr(self, session, res_attr):
207+
if 'vlan_range_list' in res_attr:
208+
vlan_range_list = []
209+
for p in (res_attr.pop('vlan_range_list', []) or []):
210+
if p.get('start') and p.get('end'):
211+
vlan_range_list.append(VlanRange(
212+
start=int(p['start']), end=int(p['end'])))
213+
self.vlan_range_list = vlan_range_list
214+
215+
# map remaining attributes to model
216+
super(NestedParameter, self).from_attr(session, res_attr)
217+
218+
def to_attr(self, session):
219+
res_attr = super(NestedParameter, self).to_attr(session)
220+
for vlan_type in ['domain_infra_vlan', 'domain_service_vlan',
221+
'domain_node_vlan']:
222+
if vlan_type in res_attr:
223+
res_attr[vlan_type] = str(res_attr[vlan_type])
224+
for p in res_attr.pop('vlan_range_list', []):
225+
res_attr.setdefault('vlan_range_list', []).append(
226+
{'start': str(p.start), 'end': str(p.end)})
227+
return res_attr
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Copyright (c) 2016 Cisco Systems
2+
# All Rights Reserved.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
5+
# not use this file except in compliance with the License. You may obtain
6+
# a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
# License for the specific language governing permissions and limitations
14+
# under the License.
15+
16+
"""Create table for NestedParameter and VlanRange.
17+
18+
Revision ID: 8c6cbd136805
19+
Revises: 3880e0a62e1f
20+
Create Date: 2020-02-21 19:02:47.560600
21+
22+
"""
23+
24+
# revision identifiers, used by Alembic.
25+
revision = '8c6cbd136805'
26+
down_revision = '3880e0a62e1f'
27+
branch_labels = None
28+
depends_on = None
29+
30+
from alembic import op
31+
import sqlalchemy as sa
32+
33+
34+
def upgrade():
35+
op.create_table(
36+
'aim_nested_parameter',
37+
sa.Column('aim_id', sa.String(255), nullable=False),
38+
sa.Column('project_id', sa.String(64), nullable=False),
39+
sa.Column('cluster_name', sa.String(64), nullable=False),
40+
sa.Column('domain_name', sa.String(64)),
41+
sa.Column('domain_type', sa.String(32), nullable=False),
42+
sa.Column('domain_infra_vlan', sa.Integer, nullable=False),
43+
sa.Column('domain_service_vlan', sa.Integer, nullable=False),
44+
sa.Column('domain_node_vlan', sa.Integer, nullable=False),
45+
sa.Column('epoch', sa.BigInteger(), nullable=False,
46+
server_default='0'),
47+
sa.PrimaryKeyConstraint('aim_id'),
48+
sa.UniqueConstraint('project_id', 'cluster_name',
49+
name='uniq_aim_nested_parameter_identity'),
50+
sa.Index('idx_aim_nested_parameter_identity',
51+
'project_id', 'cluster_name'))
52+
53+
op.create_table(
54+
'aim_vlan_ranges',
55+
sa.Column('nested_parameter_aim_id', sa.String(255),
56+
nullable=False),
57+
sa.Column('start', sa.Integer, nullable=False),
58+
sa.Column('end', sa.Integer),
59+
sa.PrimaryKeyConstraint('nested_parameter_aim_id', 'start'),
60+
sa.ForeignKeyConstraint(['nested_parameter_aim_id'],
61+
['aim_nested_parameter.aim_id']))
62+
63+
64+
def downgrade():
65+
pass
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3880e0a62e1f
1+
8c6cbd136805

0 commit comments

Comments
 (0)