2020-03-09 10:11:07 +01:00
|
|
|
#!/usr/bin/python
|
2021-08-08 10:40:22 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
2020-03-09 10:11:07 +01:00
|
|
|
# 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
|
|
|
|
|
|
|
|
DOCUMENTATION = '''
|
|
|
|
---
|
|
|
|
module: oneview_fcoe_network
|
|
|
|
short_description: Manage OneView FCoE Network resources
|
|
|
|
description:
|
|
|
|
- Provides an interface to manage FCoE Network resources. Can create, update, or delete.
|
|
|
|
requirements:
|
|
|
|
- "python >= 2.7.9"
|
|
|
|
- "hpOneView >= 4.0.0"
|
|
|
|
author: "Felipe Bulsoni (@fgbulsoni)"
|
|
|
|
options:
|
|
|
|
state:
|
|
|
|
description:
|
|
|
|
- Indicates the desired state for the FCoE Network resource.
|
|
|
|
C(present) will ensure data properties are compliant with OneView.
|
|
|
|
C(absent) will remove the resource from OneView, if it exists.
|
2021-03-24 14:16:33 +01:00
|
|
|
type: str
|
2020-03-09 10:11:07 +01:00
|
|
|
default: present
|
|
|
|
choices: ['present', 'absent']
|
|
|
|
data:
|
|
|
|
description:
|
|
|
|
- List with FCoE Network properties.
|
2021-03-24 14:16:33 +01:00
|
|
|
type: dict
|
2020-03-09 10:11:07 +01:00
|
|
|
required: true
|
|
|
|
|
|
|
|
extends_documentation_fragment:
|
|
|
|
- community.general.oneview
|
|
|
|
- community.general.oneview.validateetag
|
|
|
|
|
|
|
|
'''
|
|
|
|
|
|
|
|
EXAMPLES = '''
|
|
|
|
- name: Ensure that FCoE Network is present using the default configuration
|
2020-07-13 21:50:31 +02:00
|
|
|
community.general.oneview_fcoe_network:
|
2020-03-09 10:11:07 +01:00
|
|
|
config: '/etc/oneview/oneview_config.json'
|
|
|
|
state: present
|
|
|
|
data:
|
|
|
|
name: Test FCoE Network
|
|
|
|
vlanId: 201
|
|
|
|
delegate_to: localhost
|
|
|
|
|
|
|
|
- name: Update the FCOE network scopes
|
2020-07-13 21:50:31 +02:00
|
|
|
community.general.oneview_fcoe_network:
|
2020-03-09 10:11:07 +01:00
|
|
|
config: '/etc/oneview/oneview_config.json'
|
|
|
|
state: present
|
|
|
|
data:
|
|
|
|
name: New FCoE Network
|
|
|
|
scopeUris:
|
|
|
|
- '/rest/scopes/00SC123456'
|
|
|
|
- '/rest/scopes/01SC123456'
|
|
|
|
delegate_to: localhost
|
|
|
|
|
|
|
|
- name: Ensure that FCoE Network is absent
|
2020-07-13 21:50:31 +02:00
|
|
|
community.general.oneview_fcoe_network:
|
2020-03-09 10:11:07 +01:00
|
|
|
config: '/etc/oneview/oneview_config.json'
|
|
|
|
state: absent
|
|
|
|
data:
|
|
|
|
name: New FCoE Network
|
|
|
|
delegate_to: localhost
|
|
|
|
'''
|
|
|
|
|
|
|
|
RETURN = '''
|
|
|
|
fcoe_network:
|
|
|
|
description: Has the facts about the OneView FCoE Networks.
|
|
|
|
returned: On state 'present'. Can be null.
|
|
|
|
type: dict
|
|
|
|
'''
|
|
|
|
|
|
|
|
from ansible_collections.community.general.plugins.module_utils.oneview import OneViewModuleBase
|
|
|
|
|
|
|
|
|
|
|
|
class FcoeNetworkModule(OneViewModuleBase):
|
|
|
|
MSG_CREATED = 'FCoE Network created successfully.'
|
|
|
|
MSG_UPDATED = 'FCoE Network updated successfully.'
|
|
|
|
MSG_DELETED = 'FCoE Network deleted successfully.'
|
|
|
|
MSG_ALREADY_PRESENT = 'FCoE Network is already present.'
|
|
|
|
MSG_ALREADY_ABSENT = 'FCoE Network is already absent.'
|
|
|
|
RESOURCE_FACT_NAME = 'fcoe_network'
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
|
|
|
|
additional_arg_spec = dict(data=dict(required=True, type='dict'),
|
|
|
|
state=dict(default='present',
|
|
|
|
choices=['present', 'absent']))
|
|
|
|
|
|
|
|
super(FcoeNetworkModule, self).__init__(additional_arg_spec=additional_arg_spec,
|
|
|
|
validate_etag_support=True)
|
|
|
|
|
|
|
|
self.resource_client = self.oneview_client.fcoe_networks
|
|
|
|
|
|
|
|
def execute_module(self):
|
|
|
|
resource = self.get_by_name(self.data.get('name'))
|
|
|
|
|
|
|
|
if self.state == 'present':
|
|
|
|
return self.__present(resource)
|
|
|
|
elif self.state == 'absent':
|
|
|
|
return self.resource_absent(resource)
|
|
|
|
|
|
|
|
def __present(self, resource):
|
|
|
|
scope_uris = self.data.pop('scopeUris', None)
|
|
|
|
result = self.resource_present(resource, self.RESOURCE_FACT_NAME)
|
|
|
|
if scope_uris is not None:
|
|
|
|
result = self.resource_scopes_set(result, 'fcoe_network', scope_uris)
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
FcoeNetworkModule().run()
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|