class MemoryModels(ma.Document): make = ma.RefField('Manufacturers') model = ma.StringField() type = ma.StringField() part_number = ma.StringField() capacity = ma.DocumentField('Bytes') speed = ma.DocumentField('Frequency')
class CpuModels(ma.Document): # parameters make_ref = ma.RefField('Manufacturers') make = make_ref.rel() name = ma.StringField() speed = ma.DocumentField('Frequency') cores = ma.IntField() cache = ma.ListField(ma.DocumentField('CpuCaches'), required=False, default_empty=True) # magic methods def __str__(self): return '{}'.format(self.name)
class Racks(ma.Document): model_ref = ma.RefField('RackModels', required=True) model = model_ref.rel() serial_number = ma.StringField(required=False, allow_none=True) location_ref = ma.RefField('Rooms') location = location_ref.rel() number = ma.IntField(min_value=0) name = ma.StringField(required=False) notes = ma.StringField(required=False) units = ma.ListField(ma.DocumentField('RackUnits'), default_empty=True) # link to info page @property def link(self): return "/racks/{}".format(self.mongo_id) @property def render(self): return '<a href="{}">{}</a>'.format(self.link, self.name) # magic methods def __str__(self): return 'Rack {}'.format(self.number) def __repr__(self): return "<Rack '{}'>".format(self.number)
class Projects(ma.Document): # parameters owner_ref = ma.RefField('Users') owner = owner_ref.rel() group_ref = ma.RefField('Groups') group = group_ref.rel() name = ma.StringField() description = ma.StringField(allow_none=True, ignore_missing=True, required=False) created_on = ma.CreatedField(tz_aware=True) modified_on = ma.ModifiedField(tz_aware=True) start_date = DateField(ignore_missing=True, allow_none=True, required=False) target_end_date = DateField(ignore_missing=True, allow_none=True, required=False) status_ref = ma.RefField('ProjectStatusTypes', allow_none=True, ignore_missing=True) status = status_ref.rel(allow_none=True) updates = ma.ListField(ma.DocumentField('ProjectUpdates'), required=False, allow_none=True, default_empty=True) member_refs = ma.ListField(ma.RefField('Users'), required=False, default_empty=True, ignore_missing=True) members = member_refs.rel(ignore_missing=True) archived = ma.BoolField(required=False, default=False) # link to info page @property def link(self): return "/projects/{}".format(self.mongo_id) @property def render(self): return '<a href="{}">{}</a>'.format(self.link, self.name) # relationships @property def servers(self): return Servers.query.filter(Servers.project_ref == self.to_ref()).all() # indexes project_name_index = Index().ascending('name').unique() # magic methods def __repr__(self): return "<Project {}>".format(self.name) def __str__(self): return str(self.name)
class Jobs(ma.Document): _mapping = { 0: 'Unknown', 1: 'Started', 2: 'Pending', 3: 'Completed', 4: 'Failed' } # parameters user_ref = ma.RefField('Users') user = user_ref.rel() description = ma.StringField() start_time = ma.DateTimeField(use_tz=False) end_time = ma.DateTimeField(use_tz=False, allow_none=True) status_number = ma.IntField() details = ma.ListField(ma.DocumentField('JobDetails'), default_empty=True) # properties def _get_status(self): return self._mapping[self.status_number] def _set_status(self, value): for k, v in self._mapping.items(): if v.lower() == value.lower(): self.status_number = int(k) break else: self.status_number = 0 status = property(_get_status, _set_status) # magic methods def __repr__(self): return '<Jobs id {}>'.format(self.mongo_id) def __str__(self): return "JID {}".format(self.mongo_id)
class RackModels(ma.Document): make_ref = ma.RefField('Manufacturers', required=True) make = make_ref.rel() name = ma.StringField() dimensions = ma.DocumentField('RackDimensionDocuments') number_of_units = ma.IntField(min_value=1) # link to info page @property def link(self): return "/admin/racks/models/{}".format(self.mongo_id) @property def render(self): return '<a href="{}">{}</a>'.format(self.link, self.name) # magic methods def __repr__(self): return "<RackModels {} {}>".format(self.make, self.name) def __str__(self): return "{}".format(self.name)
class Servers(ma.Document): # parameters id = ma.StringField() model_ref = ma.RefField('ServerModels') model = model_ref.rel() host_name = ma.StringField(required=False, ignore_missing=True) name = ma.StringField(required=False, ignore_missing=True, allow_none=True) bios_version = ma.StringField(required=False, allow_none=True) bios_date = DateField(required=False, allow_none=True, ignore_missing=True) # cpu info cpus = ma.ListField(ma.DocumentField('Cpus'), required=False, ignore_missing=True, default_empty=True) # memory info memory_refs = ma.SetField(ma.RefField('ServerMemory'), default_empty=True) memory = memory_refs.rel(ignore_missing=True) @property def memory_capacity(self): return sum([m.capacity for m in self.memory]) # management info management = ma.DocumentField('ManagementCredentials', required=False, ignore_missing=True, allow_none=True) # group group_ref = ma.RefField('Groups', allow_none=True, ignore_missing=True) group = group_ref.rel(allow_none=True) # project project_ref = ma.RefField('Projects', required=False, allow_none=True, ignore_missing=True, default=None) project = project_ref.rel(allow_none=True) # drives drive_refs = ma.ListField(ma.RefField('Drives'), required=False, default_empty=True) drives = drive_refs.rel(ignore_missing=True) # virtual drives virtual_drives = ma.ListField(ma.DocumentField('VirtualDrives'), required=False, default_empty=True, ignore_missing=True) # interfaces interface_refs = ma.SetField(ma.RefField(), required=False, default_empty=True, ignore_missing=True) interfaces = interface_refs.rel(ignore_missing=True) # location location_ref = ma.RefField(required=False, validator=_validate_location, allow_none=True, ignore_missing=True) location = location_ref.rel(allow_none=True) # properties @property def cpu_count(self): return len(self.cpus) @property def cpu_model(self): if len(self.cpus) > 0: return self.cpus[0] return None @property def link(self): return '/servers/{}'.format(self.id) @property def render(self): return '<a href="{}">{}</a>'.format(self.link, self.id) @property def management_link(self): if self.management: if self.management.link: return str(self.management.link) elif self.management.link: return self.management.link # indexes id_index = Index().ascending('id').unique() name_index = Index().ascending('name').unique() # magic methods def __str__(self): return "{} {}".format(self.model, self.id)
class CpuCaches(ma.Document): # parameters level = ma.IntField() capacity = ma.DocumentField('Bytes')