FcoeNetworkFactsModule for HPE OneView (#28728)

* Add FcoeNetworkFactsModule for retrieving HPE OneView FCoE Networks

- Allow querying for FCoE Network resources in HPE OneView
- Adds unit tests to new module

* Fix "required: no"
This commit is contained in:
Felipe Garcia Bulsoni 2017-08-30 11:51:28 -03:00 committed by Dag Wieers
parent 6ea2099ee4
commit 1e785d4117
3 changed files with 159 additions and 0 deletions

View file

@ -0,0 +1,98 @@
#!/usr/bin/python
# Copyright (c) 2016-2017 Hewlett Packard Enterprise Development LP
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['preview'],
'supported_by': 'community'}
DOCUMENTATION = '''
---
module: oneview_fcoe_network_facts
short_description: Retrieve the facts about one or more of the OneView FCoE Networks
description:
- Retrieve the facts about one or more of the FCoE Networks from OneView.
version_added: "2.4"
requirements:
- hpOneView >= 2.0.1
author:
- Felipe Bulsoni (@fgbulsoni)
- Thiago Miotto (@tmiotto)
- Adriane Cardozo (@adriane-cardozo)
options:
name:
description:
- FCoE Network name.
extends_documentation_fragment:
- oneview
- oneview.factsparams
'''
EXAMPLES = '''
- name: Gather facts about all FCoE Networks
oneview_fcoe_network_facts:
config: /etc/oneview/oneview_config.json
delegate_to: localhost
- debug: var=fcoe_networks
- name: Gather paginated, filtered and sorted facts about FCoE Networks
oneview_fcoe_network_facts:
config: /etc/oneview/oneview_config.json
params:
start: 0
count: 3
sort: 'name:descending'
filter: 'vlanId=2'
delegate_to: localhost
- debug: var=fcoe_networks
- name: Gather facts about a FCoE Network by name
oneview_fcoe_network_facts:
config: /etc/oneview/oneview_config.json
name: Test FCoE Network Facts
delegate_to: localhost
- debug: var=fcoe_networks
'''
RETURN = '''
fcoe_networks:
description: Has all the OneView facts about the FCoE Networks.
returned: Always, but can be null.
type: dict
'''
from ansible.module_utils.oneview import OneViewModuleBase
class FcoeNetworkFactsModule(OneViewModuleBase):
def __init__(self):
argument_spec = dict(
name=dict(type='str'),
params=dict(type='dict'),
)
super(FcoeNetworkFactsModule, self).__init__(additional_arg_spec=argument_spec)
def execute_module(self):
if self.module.params['name']:
fcoe_networks = self.oneview_client.fcoe_networks.get_by('name', self.module.params['name'])
else:
fcoe_networks = self.oneview_client.fcoe_networks.get_all(**self.facts_params)
return dict(changed=False,
ansible_facts=dict(fcoe_networks=fcoe_networks))
def main():
FcoeNetworkFactsModule().run()
if __name__ == '__main__':
main()

View file

@ -20,5 +20,6 @@ from ansible.modules.remote_management.oneview.oneview_ethernet_network_facts im
from ansible.modules.remote_management.oneview.oneview_fc_network import FcNetworkModule from ansible.modules.remote_management.oneview.oneview_fc_network import FcNetworkModule
from ansible.modules.remote_management.oneview.oneview_fc_network_facts import FcNetworkFactsModule from ansible.modules.remote_management.oneview.oneview_fc_network_facts import FcNetworkFactsModule
from ansible.modules.remote_management.oneview.oneview_fcoe_network import FcoeNetworkModule from ansible.modules.remote_management.oneview.oneview_fcoe_network import FcoeNetworkModule
from ansible.modules.remote_management.oneview.oneview_fcoe_network_facts import FcoeNetworkFactsModule
from ansible.modules.remote_management.oneview.oneview_network_set import NetworkSetModule from ansible.modules.remote_management.oneview.oneview_network_set import NetworkSetModule
from ansible.modules.remote_management.oneview.oneview_network_set_facts import NetworkSetFactsModule from ansible.modules.remote_management.oneview.oneview_network_set_facts import NetworkSetFactsModule

View file

@ -0,0 +1,60 @@
# Copyright (c) 2016-2017 Hewlett Packard Enterprise Development LP
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from ansible.compat.tests import unittest
from oneview_module_loader import FcoeNetworkFactsModule
from hpe_test_utils import FactsParamsTestCase
ERROR_MSG = 'Fake message error'
PARAMS_GET_ALL = dict(
config='config.json',
name=None
)
PARAMS_GET_BY_NAME = dict(
config='config.json',
name="Test FCoE Networks"
)
PRESENT_NETWORKS = [{
"name": "Test FCoE Networks",
"uri": "/rest/fcoe-networks/c6bf9af9-48e7-4236-b08a-77684dc258a5"
}]
class FcoeNetworkFactsSpec(unittest.TestCase,
FactsParamsTestCase
):
def setUp(self):
self.configure_mocks(self, FcoeNetworkFactsModule)
self.fcoe_networks = self.mock_ov_client.fcoe_networks
FactsParamsTestCase.configure_client_mock(self, self.fcoe_networks)
def test_should_get_all_fcoe_network(self):
self.fcoe_networks.get_all.return_value = PRESENT_NETWORKS
self.mock_ansible_module.params = PARAMS_GET_ALL
FcoeNetworkFactsModule().run()
self.mock_ansible_module.exit_json.assert_called_once_with(
changed=False,
ansible_facts=dict(fcoe_networks=PRESENT_NETWORKS)
)
def test_should_get_fcoe_network_by_name(self):
self.fcoe_networks.get_by.return_value = PRESENT_NETWORKS
self.mock_ansible_module.params = PARAMS_GET_BY_NAME
FcoeNetworkFactsModule().run()
self.mock_ansible_module.exit_json.assert_called_once_with(
changed=False,
ansible_facts=dict(fcoe_networks=PRESENT_NETWORKS)
)
if __name__ == '__main__':
unittest.main()