model modify
This commit is contained in:
parent
5c9d410421
commit
4f19af4b52
3 changed files with 23 additions and 17 deletions
|
@ -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,20 +292,27 @@ 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 = []
|
||||||
|
for addr in alladdr:
|
||||||
|
allmacs.expand(str(addr.mac))
|
||||||
|
while True:
|
||||||
mac = [ random.randint(0, 255) for x in range(0, 6) ]
|
mac = [ random.randint(0, 255) for x in range(0, 6) ]
|
||||||
mac[0] = (mac[0] & 0xfc) | 0x02
|
mac[0] = (mac[0] & 0xfc) | 0x02
|
||||||
mac = ''.join([ '{0:02x}'.format(x) for x in mac ])
|
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
|
return mac
|
||||||
|
|
||||||
class Domain(db.Model):
|
class Domain(db.Model):
|
||||||
|
|
|
@ -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>
|
||||||
|
|
|
@ -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 %}
|
||||||
|
|
Loading…
Reference in a new issue