model modify

This commit is contained in:
deflax 2017-06-09 17:11:03 +03:00
parent 5c9d410421
commit 4f19af4b52
3 changed files with 23 additions and 17 deletions

View file

@ -228,21 +228,20 @@ class Service(db.Model):
pid = db.Column(db.Integer, primary_key=True) #PK
user_id = db.Column(db.Integer, db.ForeignKey('users.pid')) #FK
date_created = db.Column(db.DateTime, index=True, default=datetime.utcnow)
date_expire = db.Column(db.DateTime)
date_last_charge = db.Column(db.DateTime)
period = db.Column(db.Integer)
enabled = db.Column(db.Boolean)
name = db.Column(db.String(64))
image = db.Column(db.String(128))
category = db.Column(db.String(64))
description = db.Column(db.Unicode(128))
unit = db.Column(db.Integer)
unitprice = db.Column(db.Float)
price = db.Column(db.Float)
class Deployment(db.Model):
__tablename__ = 'deployments'
pid = db.Column(db.Integer, primary_key=True)
user_id = db.Column(db.Integer, db.ForeignKey('users.pid')) #FK
date_created = db.Column(db.DateTime, index=True, default=datetime.utcnow)
date_expire = db.Column(db.DateTime)
date_last_charge = db.Column(db.DateTime)
enabled = db.Column(db.Boolean)
machine_id = db.Column(db.BigInteger) #cubeid
@ -293,20 +292,27 @@ class Address(db.Model):
deploy_id = db.Column(db.Integer, db.ForeignKey('deployments.pid')) #FK
ip = db.Column(db.String(64))
mac = db.Column(db.String(128))
rdns = db.Column(db.String(256))
macaddr = db.Column(db.String(128))
reserved = db.Column(db.Boolean, default=False) #this ip SHOULD NOT be listed as available to assign even if its not currently owned by anyone
def __init__(self):
if self.macaddr is None:
self.macaddr = self.genmac()
if self.mac is None:
self.mac = self.genmac()
def genmac(self):
alladdr = Address.query.all()
addr = Address.query.all()
allmacs = []
for addr in alladdr:
allmacs.expand(str(addr.mac))
while True:
mac = [ random.randint(0, 255) for x in range(0, 6) ]
mac[0] = (mac[0] & 0xfc) | 0x02
mac = ''.join([ '{0:02x}'.format(x) for x in mac ])
if mac in allmacs:
current_app.logger.warning('mac address {} is in the pool. regenerating...'.format(mac))
continue
else:
return mac
class Domain(db.Model):

View file

@ -83,7 +83,7 @@
<tr>
<td>{{ address.ip }}</td>
<td>{{ address.rdns }}</td>
<td>{{ address.macaddr }}</td>
<td>{{ address.mac }}</td>
<td><a href="{{ url_for('admin.dashboard', user_pid=address.user_id) }}">{{ address.owner.email }}</a></td>
{% endfor %}
</tr>

View file

@ -205,7 +205,7 @@ addEventListener("DOMContentLoaded", function() {
{% for address in inv_addresses %}
<tr>
<td data-title="IP">{{ address.ip }}</td>
<td data-title="MAC">{{ address.macaddr }}</td>
<td data-title="MAC">{{ address.mac }}</td>
<td data-title="RDNS">{{ address.rdns }}</td>
<td data-title="Control">soon...</td>
{% endfor %}