Esempio n. 1
0
class VirtualDrives(ma.Document):

    # parameters
    name = ma.StringField()
    number = ma.IntField()
    capacity = ma.IntField()
    raid = ma.StringField()

    # magic methods
    def __repr__(self):
        return "<VirtualDrives {}>".format(self.name)

    def __str__(self):
        return str(self.name)
Esempio n. 2
0
class ServerModels(ma.Document):

    make_ref = ma.RefField('Manufacturers')
    make = make_ref.rel()
    name = ma.StringField()
    height = ma.IntField(min_value=1)
    drive_slots = ma.IntField(required=False, allow_none=True)
    modular = ma.BoolField(default=False)

    def __str__(self):
        return "{}".format(self.name)

    # indexes
    make_model_index = Index().ascending('make_ref') \
        .ascending('name').unique()
Esempio n. 3
0
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)
Esempio n. 4
0
class Cpus(ma.Document):

    # parameters
    socket_number = ma.IntField()
    model_ref = ma.RefField('CpuModels')
    model = model_ref.rel()

    def __str__(self):
        return '{}'.format(self.model)
Esempio n. 5
0
class RackUnits(ma.Document):

    number = ma.IntField(required=True)

    # magic methods
    def __str__(self):
        return str(self.number)

    def __repr__(self):
        return "<RackUnit '{}'>".format(self.number)
Esempio n. 6
0
class Frequency(ma.Document):

    # parameters
    value = ma.IntField()
    units_ref = ma.RefField('FrequencyUnits')
    units = units_ref.rel()

    # magic methods
    def __str__(self):
        return '{} {}'.format(self.value, self.units)
Esempio n. 7
0
class ServerMemory(ma.Document):

    # parameters
    module_ref = ma.RefField('Memory')
    module = module_ref.rel()
    bank = ma.StringField()
    slot = ma.StringField()
    current_speed = ma.IntField()

    # indexes
    module_index = Index().ascending('module_ref').unique()
Esempio n. 8
0
class NetworkInterfaces(ma.Document):
    def _validate_type(type_):
        if type_ not in ('oob', 'ib'):
            raise BadValueException('Wrong interface type.')

    def _validate_mac(value):
        if value != value.replace(':', '').lower():
            raise BadValueException('MAC Address must be in all lower case,'
                                    'and with no special characters')

    # parameters
    serial_number = ma.StringField(required=False, allow_none=True)
    model_ref = ma.RefField('NetworkInterfaceModels',
                            required=False,
                            allow_none=True,
                            ignore_missing=True)
    model = model_ref.rel(allow_none=True)
    mac = ma.StringField(validator=_validate_mac)
    ip = ma.StringField(required=False, allow_none=True, ignore_missing=True)
    name = ma.StringField()
    slot_type = ma.StringField(required=False,
                               allow_none=True,
                               ignore_missing=True)
    slot = ma.IntField()
    port = ma.IntField(required=False, allow_none=True, ignore_missing=True)
    type = ma.StringField(validator=_validate_type)

    @property
    def formatted_mac(self):
        return ":".join(s.encode('hex')
                        for s in self.mac.decode('hex')).upper()

    # indexes
    serial_number_index = SparseIndex().ascending('serial_number').unique()
    mac_index = Index().ascending('mac').unique()

    # magic methods
    def __str__(self):
        return "<NetworkInterfaces {}>".format(self.formatted_mac)
Esempio n. 9
0
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)
Esempio n. 10
0
class DriveTypes(ma.Document):

    # form factor: 1.8", 2.5", 3.5"
    form_factor = ma.StringField()
    # protocol: ATA, SATA, SAS, NVMe
    protocol = ma.StringField()
    # media: NAND, spinning, 3DXpoint/SCM, PCM
    media = ma.StringField()
    # speed (optional): 7.2k, 10k, 15k
    speed = ma.StringField()
    # capacity: in GB
    capacity = ma.IntField(required=True)

    # magic methods
    def __repr__(self):
        return "<DriveType {} {} {}>".format(self.capacity, self.protocol,
                                             self.media)

    def __str__(self):
        return "{} {}".format(self.make, self.model)
Esempio n. 11
0
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)
Esempio n. 12
0
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)
Esempio n. 13
0
class NetworkInterfaceModels(ma.Document):

    make = ma.RefField('Manufacturers')
    name = ma.StringField()
    port_count = ma.IntField(required=False, ignore_missing=True)
    speed = ma.IntField()  # change to BitRate
Esempio n. 14
0
class CpuCaches(ma.Document):

    # parameters
    level = ma.IntField()
    capacity = ma.DocumentField('Bytes')