Added ip on port GET
This commit is contained in:
@@ -77,6 +77,8 @@ class IPAddress(BASEV2, CreatedAt, HasId, HasTenant):
|
|||||||
port_id = sa.Column(sa.String(36),
|
port_id = sa.Column(sa.String(36),
|
||||||
sa.ForeignKey("quark_ports.id", ondelete="CASCADE"))
|
sa.ForeignKey("quark_ports.id", ondelete="CASCADE"))
|
||||||
|
|
||||||
|
version = sa.Column(sa.Integer())
|
||||||
|
|
||||||
# Need a constant to facilitate the indexed search for new IPs
|
# Need a constant to facilitate the indexed search for new IPs
|
||||||
_deallocated = sa.Column(sa.Boolean())
|
_deallocated = sa.Column(sa.Boolean())
|
||||||
|
|
||||||
@@ -93,6 +95,12 @@ class IPAddress(BASEV2, CreatedAt, HasId, HasTenant):
|
|||||||
def deallocated(cls):
|
def deallocated(cls):
|
||||||
return IPAddress._deallocated
|
return IPAddress._deallocated
|
||||||
|
|
||||||
|
def formatted(self):
|
||||||
|
ip = netaddr.IPAddress(self.address_readable)
|
||||||
|
if self.version == 4:
|
||||||
|
return str(ip.ipv4())
|
||||||
|
return str(ip.ipv6())
|
||||||
|
|
||||||
deallocated_at = sa.Column(sa.DateTime())
|
deallocated_at = sa.Column(sa.DateTime())
|
||||||
|
|
||||||
|
|
||||||
@@ -129,6 +137,8 @@ class Subnet(BASEV2, CreatedAt, HasId, HasTenant):
|
|||||||
@cidr.setter
|
@cidr.setter
|
||||||
def cidr(self, val):
|
def cidr(self, val):
|
||||||
self._cidr = val
|
self._cidr = val
|
||||||
|
preip = netaddr.IPNetwork(val)
|
||||||
|
self.version = preip.version
|
||||||
ip = netaddr.IPNetwork(val).ipv6()
|
ip = netaddr.IPNetwork(val).ipv6()
|
||||||
self.first_ip = ip.first
|
self.first_ip = ip.first
|
||||||
self.last_ip = ip.last
|
self.last_ip = ip.last
|
||||||
@@ -136,9 +146,10 @@ class Subnet(BASEV2, CreatedAt, HasId, HasTenant):
|
|||||||
@cidr.expression
|
@cidr.expression
|
||||||
def cidr(cls):
|
def cidr(cls):
|
||||||
return Subnet._cidr
|
return Subnet._cidr
|
||||||
|
|
||||||
first_ip = sa.Column(sa.LargeBinary())
|
first_ip = sa.Column(sa.LargeBinary())
|
||||||
last_ip = sa.Column(sa.LargeBinary())
|
last_ip = sa.Column(sa.LargeBinary())
|
||||||
|
version = sa.Column(sa.Integer())
|
||||||
|
|
||||||
allocated_ips = orm.relationship(IPAddress, backref="subnet")
|
allocated_ips = orm.relationship(IPAddress, backref="subnet")
|
||||||
routes = orm.relationship(Route, backref='subnet', cascade='delete')
|
routes = orm.relationship(Route, backref='subnet', cascade='delete')
|
||||||
|
|||||||
@@ -112,6 +112,7 @@ class QuarkIpam(object):
|
|||||||
address["address_readable"] = str(first_address)
|
address["address_readable"] = str(first_address)
|
||||||
|
|
||||||
address["subnet_id"] = subnet["id"]
|
address["subnet_id"] = subnet["id"]
|
||||||
|
address["version"] = subnet["version"]
|
||||||
address["network_id"] = net_id
|
address["network_id"] = net_id
|
||||||
address["tenant_id"] = subnet["tenant_id"]
|
address["tenant_id"] = subnet["tenant_id"]
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,8 @@
|
|||||||
v2 Quantum Plug-in API Quark Implementation
|
v2 Quantum Plug-in API Quark Implementation
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import pprint
|
||||||
|
|
||||||
import netaddr
|
import netaddr
|
||||||
from sqlalchemy import func as sql_func
|
from sqlalchemy import func as sql_func
|
||||||
|
|
||||||
@@ -506,8 +508,15 @@ class Plugin(quantum_plugin_base_v2.QuantumPluginBaseV2):
|
|||||||
will be returned.
|
will be returned.
|
||||||
"""
|
"""
|
||||||
#TODO(mdietz): May need to build a list of fields to query for later
|
#TODO(mdietz): May need to build a list of fields to query for later
|
||||||
return [self._make_port_dict(p)
|
ports = self._ports_query(context, filters).all()
|
||||||
for p in self._ports_query(context, filters).all()]
|
query = context.session.query(models.IPAddress)
|
||||||
|
for p in ports:
|
||||||
|
p["fixed_ips"] = []
|
||||||
|
ips = query.filter(models.IPAddress.port_id == p["id"]).all()
|
||||||
|
for ip in ips:
|
||||||
|
p["fixed_ips"].append({"subnet_id": ip["subnet_id"],
|
||||||
|
"ip_address": ip.formatted()})
|
||||||
|
return [self._make_port_dict(p) for p in ports]
|
||||||
|
|
||||||
def get_ports_count(self, context, filters=None):
|
def get_ports_count(self, context, filters=None):
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user