Skip to content

Commit

Permalink
Add tangible ComputeResource entities for vmware and ovirt (#440)
Browse files Browse the repository at this point in the history
originally developped by @philippj in foreman-ansible-modules
  • Loading branch information
Matthias Dellweg authored and abalakh committed Nov 9, 2017
1 parent 1c18726 commit 1a42807
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
50 changes: 50 additions & 0 deletions nailgun/entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -1105,6 +1105,56 @@ def __init__(self, server_config=None, **kwargs):
self._fields['provider_friendly_name'].default = 'Libvirt'


class OVirtComputeResource(AbstractComputeResource):
# pylint: disable=too-many-ancestors
"""A representation for compute resources with Ovirt provider
"""
def __init__(self, server_config=None, **kwargs):
self._fields = {
'password': entity_fields.StringField(),
'user': entity_fields.StringField(),
}
super(OVirtComputeResource, self).__init__(server_config, **kwargs)
self._fields['provider'].default = 'Ovirt'
self._fields['provider'].required = True
self._fields['provider_friendly_name'].default = 'OVirt'

def read(self, entity=None, attrs=None, ignore=None, params=None):
"""Make sure, ``password`` is in the ignore list for read
"""
if ignore is None:
ignore = set()
ignore.add('password')
return super(OVirtComputeResource, self).read(
entity, attrs, ignore, params)


class VMWareComputeResource(AbstractComputeResource):
# pylint: disable=too-many-ancestors
"""A representation for compute resources with Vmware provider
"""
def __init__(self, server_config=None, **kwargs):
self._fields = {
'datacenter': entity_fields.StringField(),
'password': entity_fields.StringField(),
'set_console_password': entity_fields.BooleanField(),
'user': entity_fields.StringField(),
}
super(VMWareComputeResource, self).__init__(server_config, **kwargs)
self._fields['provider'].default = 'Vmware'
self._fields['provider'].required = True
self._fields['provider_friendly_name'].default = 'VMware'

def read(self, entity=None, attrs=None, ignore=None, params=None):
"""Make sure, ``password`` is in the ignore list for read
"""
if ignore is None:
ignore = set()
ignore.add('password')
return super(VMWareComputeResource, self).read(
entity, attrs, ignore, params)


class ConfigGroup(
Entity,
EntityCreateMixin,
Expand Down
4 changes: 4 additions & 0 deletions tests/test_entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ def test_init_succeeds(self):
# entities.OSDefaultTemplate, # see below
entities.OperatingSystem,
entities.Organization,
entities.OVirtComputeResource,
entities.PackageGroupContentViewFilter,
entities.PartitionTable,
entities.Permission,
Expand Down Expand Up @@ -165,6 +166,7 @@ def test_init_succeeds(self):
entities.TemplateKind,
entities.User,
entities.UserGroup,
entities.VMWareComputeResource,
)
]
entities_.extend([
Expand Down Expand Up @@ -1143,6 +1145,7 @@ def test_ignore_arg_v1(self):
for entity, ignored_attrs in (
(entities.Errata,
{'content_view_version', 'environment', 'repository'}),
(entities.OVirtComputeResource, {'password'}),
(entities.SmartProxy, {'download_policy'}),
(entities.SmartClassParameters, {'hidden_value'}),
(entities.SmartVariable, {'hidden_value'}),
Expand All @@ -1151,6 +1154,7 @@ def test_ignore_arg_v1(self):
(entities.Subscription, {'organization'}),
(entities.Repository, {'organization'}),
(entities.User, {'password'}),
(entities.VMWareComputeResource, {'password'}),
):
with self.subTest(entity):
with mock.patch.object(EntityReadMixin, 'read') as read:
Expand Down

0 comments on commit 1a42807

Please sign in to comment.