Skip to content
This repository has been archived by the owner on Feb 2, 2018. It is now read-only.

Commit

Permalink
Multiple Model Enhancements (#65)
Browse files Browse the repository at this point in the history
* models: Host now has a source attribute.

The new source attribute is an optional field on the Host model. In the
future, when the field is not empty, the value will be used when
deciding which StoreHandler to utilize when populating data for the
instance.

For more information see
http://commissaire.readthedocs.io/en/latest/cpd/61.html#model-changes

Closes #64.

* models: Added string representation method.

* models: Added missing doc for primary_key property.

* fixup! models: Added string representation method.
  • Loading branch information
ashcrow authored and mbarnes committed Dec 1, 2016
1 parent 49f382f commit 0a8bebc
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/commissaire/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,25 @@ def new(cls, **kwargs):
instance.__init__(**init_args)
return instance

def __str__(self): # pragma: no cover
"""
Returns a string representation of the instance.
:returns: String representation of this instance.
:rtype: str
"""
readable = '<{}'.format(self.__class__.__name__)
for k, v in self.to_dict_safe().items():
readable += ' {}={},'.format(k, v or '<Empty>')
return readable + '...>'

@property
def primary_key(self): # pragma: no cover
"""
Shortcut property to get the value of the primary key.
:returns: The primary key value.
:rtype: mixed
"""
return getattr(self, self._primary_key)

Expand Down Expand Up @@ -481,11 +496,12 @@ class Host(Model):
'last_check': {'type': str},
'ssh_priv_key': {'type': str},
'remote_user': {'type': str},
'source': {'type': str},
}
_attribute_defaults = {
'address': '', 'status': '', 'os': '', 'cpus': 0,
'memory': 0, 'space': 0, 'last_check': '', 'ssh_priv_key': '',
'remote_user': 'root'}
'remote_user': 'root', 'source': ''}
_hidden_attributes = ('ssh_priv_key', 'remote_user')
_primary_key = 'address'

Expand Down

0 comments on commit 0a8bebc

Please sign in to comment.