我目前有一个用于 DSL 连接的有效 DSLAM 管理站点。目前我想要开始工作的是通过自动 ping DSLAM ip 地址来自行更新 DSLAM 状态。如果一个请求是好的,那么它将返回 boolean=True 并保存,否则 boolean=False 并保存。到目前为止它不起作用,不知道从这里去哪里。
模型.py
from django.db import models
import os,sys
class DslamManager(models.Manager):
def dslam_status(self, ip_address):
if os.system('ping' + ip_address):
dslam_status = super(DslamManager, self).get(ip_address)
dslam_status = True
dslam_status.save()
else:
dslam_status = super(DslamManager, self)
dslam_status = False
dslam_status.save()
class Location(models.Model):
location_name = models.CharField(max_length=30)
island_name = models.CharField(max_length=30)
class Meta:
ordering = ['location_name']
def __unicode__(self):
return self.location_name
class Dslam(models.Model):
dslam_name = models.CharField(max_length=32)
ip_address = models.CharField(max_length=128)
location = models.ForeignKey(Location)
notes = models.TextField(blank=True)
dslam_status = models.BooleanField()
objects = DslamManager()
class Meta:
ordering = ['location', 'id']
def __unicode__(self):
return self.dslam_name