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 pid = db.Column(db.Integer, primary_key=True) #PK
user_id = db.Column(db.Integer, db.ForeignKey('users.pid')) #FK user_id = db.Column(db.Integer, db.ForeignKey('users.pid')) #FK
date_created = db.Column(db.DateTime, index=True, default=datetime.utcnow) 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) enabled = db.Column(db.Boolean)
name = db.Column(db.String(64)) category = db.Column(db.String(64))
image = db.Column(db.String(128))
description = db.Column(db.Unicode(128)) description = db.Column(db.Unicode(128))
unit = db.Column(db.Integer) price = db.Column(db.Float)
unitprice = db.Column(db.Float)
class Deployment(db.Model): class Deployment(db.Model):
__tablename__ = 'deployments' __tablename__ = 'deployments'
pid = db.Column(db.Integer, primary_key=True) pid = db.Column(db.Integer, primary_key=True)
user_id = db.Column(db.Integer, db.ForeignKey('users.pid')) #FK user_id = db.Column(db.Integer, db.ForeignKey('users.pid')) #FK
date_created = db.Column(db.DateTime, index=True, default=datetime.utcnow) 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) enabled = db.Column(db.Boolean)
machine_id = db.Column(db.BigInteger) #cubeid machine_id = db.Column(db.BigInteger) #cubeid
@ -293,21 +292,28 @@ class Address(db.Model):
deploy_id = db.Column(db.Integer, db.ForeignKey('deployments.pid')) #FK deploy_id = db.Column(db.Integer, db.ForeignKey('deployments.pid')) #FK
ip = db.Column(db.String(64)) ip = db.Column(db.String(64))
mac = db.Column(db.String(128))
rdns = db.Column(db.String(256)) 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 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): def __init__(self):
if self.macaddr is None: if self.mac is None:
self.macaddr = self.genmac() self.mac = self.genmac()
def genmac(self): def genmac(self):
alladdr = Address.query.all() addr = Address.query.all()
allmacs = []
mac = [ random.randint(0, 255) for x in range(0, 6) ] for addr in alladdr:
mac[0] = (mac[0] & 0xfc) | 0x02 allmacs.expand(str(addr.mac))
mac = ''.join([ '{0:02x}'.format(x) for x in mac ]) while True:
return mac 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): class Domain(db.Model):
__tablename__ = 'domains' __tablename__ = 'domains'

View file

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

View file

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