Uncommented the subnet dict routine
This commit is contained in:
@@ -13,13 +13,18 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import netaddr
|
||||
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy import orm
|
||||
from sqlalchemy.ext import hybrid
|
||||
|
||||
from quantum.db.model_base import BASEV2
|
||||
from quantum.db.models_v2 import HasTenant, HasId
|
||||
from quantum.openstack.common import timeutils
|
||||
from quantum.openstack.common import log as logging
|
||||
|
||||
LOG = logging.getLogger("quantum")
|
||||
|
||||
class CreatedAt(object):
|
||||
created_at = sa.Column(sa.DateTime(), default=timeutils.utcnow)
|
||||
@@ -100,7 +105,27 @@ class Subnet(BASEV2, CreatedAt, HasId, HasTenant):
|
||||
"""
|
||||
__tablename__ = "quark_subnets"
|
||||
network_id = sa.Column(sa.String(36), sa.ForeignKey('quark_networks.id'))
|
||||
cidr = sa.Column(sa.String(64), nullable=False)
|
||||
_cidr = sa.Column(sa.String(64), nullable=False)
|
||||
|
||||
@hybrid.hybrid_property
|
||||
def cidr(self):
|
||||
return self._cidr
|
||||
|
||||
@cidr.setter
|
||||
def cidr(self, val):
|
||||
self._cidr = val
|
||||
ip = netaddr.IPNetwork(val)
|
||||
LOG.critical("Setting range to: %d and %d" % (ip.first, ip.last))
|
||||
self.first_ip = ip.first
|
||||
self.last_ip = ip.last
|
||||
|
||||
@cidr.expression
|
||||
def cidr(cls):
|
||||
return Subnet._cidr
|
||||
|
||||
first_ip = sa.Column(sa.LargeBinary())
|
||||
last_ip = sa.Column(sa.LargeBinary())
|
||||
|
||||
allocated_ips = orm.relationship(IPAddress, backref="subnet")
|
||||
routes = orm.relationship(Route, backref='subnet', cascade='delete')
|
||||
|
||||
|
||||
@@ -83,20 +83,21 @@ class Plugin(quantum_plugin_base_v2.QuantumPluginBaseV2):
|
||||
'network_id': subnet.get('network_id'),
|
||||
'ip_version': subnet.get('ip_version'),
|
||||
'cidr': subnet.get('cidr'),
|
||||
'allocation_pools': [{'start': pool.get('first_ip'),
|
||||
'end': pool.get('last_ip')}
|
||||
for pool in subnet.get('allocation_pools')],
|
||||
'gateway_ip': subnet.get('gateway_ip'),
|
||||
'enable_dhcp': subnet.get('enable_dhcp'),
|
||||
'dns_nameservers': [dns.get('address')
|
||||
for dns in subnet.get('dns_nameservers')],
|
||||
'host_routes': [{'destination': route.get('destination'),
|
||||
'nexthop': route.get('nexthop')}
|
||||
for route in subnet.get('routes', [])],
|
||||
'shared': subnet.get('shared')
|
||||
}
|
||||
if subnet.get('gateway_ip'):
|
||||
res['gateway_ip'] = subnet.get('gateway_ip')
|
||||
'enable_dhcp': subnet.get('enable_dhcp'),}
|
||||
#'dns_nameservers': [dns.get('address')
|
||||
# for dns in subnet.get('dns_nameservers')],
|
||||
#'gateway_ip': subnet.get('gateway_ip'),
|
||||
#'host_routes': [{'destination': route.get('destination'),
|
||||
# 'nexthop': route.get('nexthop')}
|
||||
# for route in subnet.get('routes', [])],
|
||||
#'shared': subnet.get('shared')
|
||||
#}
|
||||
#'allocation_pools': [{'start': pool.get('first_ip'),
|
||||
# 'end': pool.get('last_ip')}
|
||||
# for pool in subnet.get('allocation_pools')],
|
||||
#}
|
||||
#if subnet.get('gateway_ip'):
|
||||
# res['gateway_ip'] = subnet.get('gateway_ip')
|
||||
return res
|
||||
|
||||
def _make_port_dict(self, port, fields=None):
|
||||
@@ -133,6 +134,8 @@ class Plugin(quantum_plugin_base_v2.QuantumPluginBaseV2):
|
||||
session = context.session
|
||||
new_subnet = self._create_subnet(context, subnet, session)
|
||||
session.flush()
|
||||
subnet_dict = self._make_subnet_dict(new_subnet)
|
||||
LOG.critical(subnet_dict)
|
||||
return self._make_subnet_dict(new_subnet)
|
||||
|
||||
def update_subnet(self, context, id, subnet):
|
||||
|
||||
Reference in New Issue
Block a user