-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathmodels.py
More file actions
130 lines (102 loc) · 4.03 KB
/
Copy pathmodels.py
File metadata and controls
130 lines (102 loc) · 4.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
from django.db import models
from django.contrib.auth.models import Group
from django.conf import settings
from six import python_2_unicode_compatible
AUTH_USER_MODEL = getattr(settings, 'AUTH_USER_MODEL', 'auth.User')
SERVER_STATUS = (
(0, u"Normal"),
(1, u"Down"),
(2, u"No Connect"),
(3, u"Error"),
)
SERVICE_TYPES = (
('moniter', u"Moniter"),
('lvs', u"LVS"),
('db', u"Database"),
('analysis', u"Analysis"),
('admin', u"Admin"),
('storge', u"Storge"),
('web', u"WEB"),
('email', u"Email"),
('mix', u"Mix"),
)
@python_2_unicode_compatible
class IDC(models.Model):
name = models.CharField(max_length=64)
description = models.TextField()
contact = models.CharField(max_length=32)
telphone = models.CharField(max_length=32)
address = models.CharField(max_length=128)
customer_id = models.CharField(max_length=128)
groups = models.ManyToManyField(Group) # many
create_time = models.DateField(auto_now=True)
def __str__(self):
return self.name
class Meta:
verbose_name = u"IDC"
verbose_name_plural = verbose_name
@python_2_unicode_compatible
class Host(models.Model):
idc = models.ForeignKey(IDC)
name = models.CharField(max_length=64)
nagios_name = models.CharField(u"Nagios Host ID", max_length=64, blank=True, null=True)
ip = models.GenericIPAddressField(blank=True, null=True)
internal_ip = models.GenericIPAddressField(blank=True, null=True)
user = models.CharField(max_length=64)
password = models.CharField(max_length=128)
ssh_port = models.IntegerField(blank=True, null=True)
status = models.SmallIntegerField(choices=SERVER_STATUS)
brand = models.CharField(max_length=64, choices=[(i, i) for i in (u"DELL", u"HP", u"Other")])
model = models.CharField(max_length=64)
cpu = models.CharField(max_length=64)
core_num = models.SmallIntegerField(choices=[(i * 2, "%s Cores" % (i * 2)) for i in range(1, 15)])
hard_disk = models.IntegerField()
memory = models.IntegerField()
system = models.CharField(u"System OS", max_length=32, choices=[(i, i) for i in (u"CentOS", u"FreeBSD", u"Ubuntu")])
system_version = models.CharField(max_length=32)
system_arch = models.CharField(max_length=32, choices=[(i, i) for i in (u"x86_64", u"i386")])
create_time = models.DateField()
guarantee_date = models.DateField()
service_type = models.CharField(max_length=32, choices=SERVICE_TYPES)
description = models.TextField()
administrator = models.ForeignKey(AUTH_USER_MODEL, verbose_name="Admin")
def __str__(self):
return self.name
class Meta:
verbose_name = u"Host"
verbose_name_plural = verbose_name
@python_2_unicode_compatible
class MaintainLog(models.Model):
host = models.ForeignKey(Host)
maintain_type = models.CharField(max_length=32)
hard_type = models.CharField(max_length=16)
time = models.DateTimeField()
operator = models.CharField(max_length=16)
note = models.TextField()
def __str__(self):
return '%s maintain-log [%s] %s %s' % (self.host.name, self.time.strftime('%Y-%m-%d %H:%M:%S'),
self.maintain_type, self.hard_type)
class Meta:
verbose_name = u"Maintain Log"
verbose_name_plural = verbose_name
@python_2_unicode_compatible
class HostGroup(models.Model):
name = models.CharField(max_length=32)
description = models.TextField()
hosts = models.ManyToManyField(
Host, verbose_name=u'Hosts', blank=True, related_name='groups')
class Meta:
verbose_name = u"Host Group"
verbose_name_plural = verbose_name
def __str__(self):
return self.name
@python_2_unicode_compatible
class AccessRecord(models.Model):
date = models.DateField()
user_count = models.IntegerField()
view_count = models.IntegerField()
class Meta:
verbose_name = u"Access Record"
verbose_name_plural = verbose_name
def __str__(self):
return "%s Access Record" % self.date.strftime('%Y-%m-%d')