1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2026-04-23 04:09:04 +00:00

Initial commit

This commit is contained in:
Ansible Core Team 2020-03-09 09:11:07 +00:00
commit aebc1b03fd
4861 changed files with 812621 additions and 0 deletions

View file

@ -0,0 +1 @@
oneview_datacenter_info.py

View file

@ -0,0 +1,156 @@
#!/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_datacenter_info
short_description: Retrieve information about the OneView Data Centers
description:
- Retrieve information about the OneView Data Centers.
- This module was called C(oneview_datacenter_facts) before Ansible 2.9, returning C(ansible_facts).
Note that the M(oneview_datacenter_info) module no longer returns C(ansible_facts)!
requirements:
- "hpOneView >= 2.0.1"
author:
- Alex Monteiro (@aalexmonteiro)
- Madhav Bharadwaj (@madhav-bharadwaj)
- Priyanka Sood (@soodpr)
- Ricardo Galeno (@ricardogpsf)
options:
name:
description:
- Data Center name.
options:
description:
- "Retrieve additional information. Options available: 'visualContent'."
extends_documentation_fragment:
- community.general.oneview
- community.general.oneview.factsparams
'''
EXAMPLES = '''
- name: Gather information about all Data Centers
oneview_datacenter_info:
hostname: 172.16.101.48
username: administrator
password: my_password
api_version: 500
delegate_to: localhost
register: result
- debug:
msg: "{{ result.datacenters }}"
- name: Gather paginated, filtered and sorted information about Data Centers
oneview_datacenter_info:
hostname: 172.16.101.48
username: administrator
password: my_password
api_version: 500
params:
start: 0
count: 3
sort: 'name:descending'
filter: 'state=Unmanaged'
register: result
- debug:
msg: "{{ result.datacenters }}"
- name: Gather information about a Data Center by name
oneview_datacenter_info:
hostname: 172.16.101.48
username: administrator
password: my_password
api_version: 500
name: "My Data Center"
delegate_to: localhost
register: result
- debug:
msg: "{{ result.datacenters }}"
- name: Gather information about the Data Center Visual Content
oneview_datacenter_info:
hostname: 172.16.101.48
username: administrator
password: my_password
api_version: 500
name: "My Data Center"
options:
- visualContent
delegate_to: localhost
register: result
- debug:
msg: "{{ result.datacenters }}"
- debug:
msg: "{{ result.datacenter_visual_content }}"
'''
RETURN = '''
datacenters:
description: Has all the OneView information about the Data Centers.
returned: Always, but can be null.
type: dict
datacenter_visual_content:
description: Has information about the Data Center Visual Content.
returned: When requested, but can be null.
type: dict
'''
from ansible_collections.community.general.plugins.module_utils.oneview import OneViewModuleBase
class DatacenterInfoModule(OneViewModuleBase):
argument_spec = dict(
name=dict(type='str'),
options=dict(type='list'),
params=dict(type='dict')
)
def __init__(self):
super(DatacenterInfoModule, self).__init__(additional_arg_spec=self.argument_spec)
self.is_old_facts = self.module._name == 'oneview_datacenter_facts'
if self.is_old_facts:
self.module.deprecate("The 'oneview_datacenter_facts' module has been renamed to 'oneview_datacenter_info', "
"and the renamed one no longer returns ansible_facts", version='2.13')
def execute_module(self):
client = self.oneview_client.datacenters
info = {}
if self.module.params.get('name'):
datacenters = client.get_by('name', self.module.params['name'])
if self.options and 'visualContent' in self.options:
if datacenters:
info['datacenter_visual_content'] = client.get_visual_content(datacenters[0]['uri'])
else:
info['datacenter_visual_content'] = None
info['datacenters'] = datacenters
else:
info['datacenters'] = client.get_all(**self.facts_params)
if self.is_old_facts:
return dict(changed=False,
ansible_facts=info)
else:
return dict(changed=False, **info)
def main():
DatacenterInfoModule().run()
if __name__ == '__main__':
main()

View file

@ -0,0 +1 @@
oneview_enclosure_info.py

View file

@ -0,0 +1,228 @@
#!/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_enclosure_info
short_description: Retrieve information about one or more Enclosures
description:
- Retrieve information about one or more of the Enclosures from OneView.
- This module was called C(oneview_enclosure_facts) before Ansible 2.9, returning C(ansible_facts).
Note that the M(oneview_enclosure_info) module no longer returns C(ansible_facts)!
requirements:
- hpOneView >= 2.0.1
author:
- Felipe Bulsoni (@fgbulsoni)
- Thiago Miotto (@tmiotto)
- Adriane Cardozo (@adriane-cardozo)
options:
name:
description:
- Enclosure name.
options:
description:
- "List with options to gather additional information about an Enclosure and related resources.
Options allowed: C(script), C(environmentalConfiguration), and C(utilization). For the option C(utilization),
you can provide specific parameters."
extends_documentation_fragment:
- community.general.oneview
- community.general.oneview.factsparams
'''
EXAMPLES = '''
- name: Gather information about all Enclosures
oneview_enclosure_info:
hostname: 172.16.101.48
username: administrator
password: my_password
api_version: 500
no_log: true
delegate_to: localhost
register: result
- debug:
msg: "{{ result.enclosures }}"
- name: Gather paginated, filtered and sorted information about Enclosures
oneview_enclosure_info:
params:
start: 0
count: 3
sort: name:descending
filter: status=OK
hostname: 172.16.101.48
username: administrator
password: my_password
api_version: 500
no_log: true
delegate_to: localhost
register: result
- debug:
msg: "{{ result.enclosures }}"
- name: Gather information about an Enclosure by name
oneview_enclosure_info:
name: Enclosure-Name
hostname: 172.16.101.48
username: administrator
password: my_password
api_version: 500
no_log: true
delegate_to: localhost
register: result
- debug:
msg: "{{ result.enclosures }}"
- name: Gather information about an Enclosure by name with options
oneview_enclosure_info:
name: Test-Enclosure
options:
- script # optional
- environmentalConfiguration # optional
- utilization # optional
hostname: 172.16.101.48
username: administrator
password: my_password
api_version: 500
no_log: true
delegate_to: localhost
register: result
- debug:
msg: "{{ result.enclosures }}"
- debug:
msg: "{{ result.enclosure_script }}"
- debug:
msg: "{{ result.enclosure_environmental_configuration }}"
- debug:
msg: "{{ result.enclosure_utilization }}"
- name: "Gather information about an Enclosure with temperature data at a resolution of one sample per day, between two
specified dates"
oneview_enclosure_info:
name: Test-Enclosure
options:
- utilization: # optional
fields: AmbientTemperature
filter:
- startDate=2016-07-01T14:29:42.000Z
- endDate=2017-07-01T03:29:42.000Z
view: day
refresh: false
hostname: 172.16.101.48
username: administrator
password: my_password
api_version: 500
no_log: true
delegate_to: localhost
register: result
- debug:
msg: "{{ result.enclosures }}"
- debug:
msg: "{{ result.enclosure_utilization }}"
'''
RETURN = '''
enclosures:
description: Has all the OneView information about the Enclosures.
returned: Always, but can be null.
type: dict
enclosure_script:
description: Has all the OneView information about the script of an Enclosure.
returned: When requested, but can be null.
type: str
enclosure_environmental_configuration:
description: Has all the OneView information about the environmental configuration of an Enclosure.
returned: When requested, but can be null.
type: dict
enclosure_utilization:
description: Has all the OneView information about the utilization of an Enclosure.
returned: When requested, but can be null.
type: dict
'''
from ansible_collections.community.general.plugins.module_utils.oneview import OneViewModuleBase
class EnclosureInfoModule(OneViewModuleBase):
argument_spec = dict(name=dict(type='str'), options=dict(type='list'), params=dict(type='dict'))
def __init__(self):
super(EnclosureInfoModule, self).__init__(additional_arg_spec=self.argument_spec)
self.is_old_facts = self.module._name == 'oneview_enclosure_facts'
if self.is_old_facts:
self.module.deprecate("The 'oneview_enclosure_facts' module has been renamed to 'oneview_enclosure_info', "
"and the renamed one no longer returns ansible_facts", version='2.13')
def execute_module(self):
info = {}
if self.module.params['name']:
enclosures = self._get_by_name(self.module.params['name'])
if self.options and enclosures:
info = self._gather_optional_info(self.options, enclosures[0])
else:
enclosures = self.oneview_client.enclosures.get_all(**self.facts_params)
info['enclosures'] = enclosures
if self.is_old_facts:
return dict(changed=False,
ansible_facts=info)
else:
return dict(changed=False, **info)
def _gather_optional_info(self, options, enclosure):
enclosure_client = self.oneview_client.enclosures
info = {}
if options.get('script'):
info['enclosure_script'] = enclosure_client.get_script(enclosure['uri'])
if options.get('environmentalConfiguration'):
env_config = enclosure_client.get_environmental_configuration(enclosure['uri'])
info['enclosure_environmental_configuration'] = env_config
if options.get('utilization'):
info['enclosure_utilization'] = self._get_utilization(enclosure, options['utilization'])
return info
def _get_utilization(self, enclosure, params):
fields = view = refresh = filter = ''
if isinstance(params, dict):
fields = params.get('fields')
view = params.get('view')
refresh = params.get('refresh')
filter = params.get('filter')
return self.oneview_client.enclosures.get_utilization(enclosure['uri'],
fields=fields,
filter=filter,
refresh=refresh,
view=view)
def _get_by_name(self, name):
return self.oneview_client.enclosures.get_by('name', name)
def main():
EnclosureInfoModule().run()
if __name__ == '__main__':
main()

View file

@ -0,0 +1,251 @@
#!/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_ethernet_network
short_description: Manage OneView Ethernet Network resources
description:
- Provides an interface to manage Ethernet Network resources. Can create, update, or delete.
requirements:
- hpOneView >= 3.1.0
author:
- Felipe Bulsoni (@fgbulsoni)
- Thiago Miotto (@tmiotto)
- Adriane Cardozo (@adriane-cardozo)
options:
state:
description:
- Indicates the desired state for the Ethernet Network resource.
- C(present) will ensure data properties are compliant with OneView.
- C(absent) will remove the resource from OneView, if it exists.
- C(default_bandwidth_reset) will reset the network connection template to the default.
default: present
choices: [present, absent, default_bandwidth_reset]
data:
description:
- List with Ethernet Network properties.
required: true
extends_documentation_fragment:
- community.general.oneview
- community.general.oneview.validateetag
'''
EXAMPLES = '''
- name: Ensure that the Ethernet Network is present using the default configuration
oneview_ethernet_network:
config: '/etc/oneview/oneview_config.json'
state: present
data:
name: 'Test Ethernet Network'
vlanId: '201'
delegate_to: localhost
- name: Update the Ethernet Network changing bandwidth and purpose
oneview_ethernet_network:
config: '/etc/oneview/oneview_config.json'
state: present
data:
name: 'Test Ethernet Network'
purpose: Management
bandwidth:
maximumBandwidth: 3000
typicalBandwidth: 2000
delegate_to: localhost
- name: Ensure that the Ethernet Network is present with name 'Renamed Ethernet Network'
oneview_ethernet_network:
config: '/etc/oneview/oneview_config.json'
state: present
data:
name: 'Test Ethernet Network'
newName: 'Renamed Ethernet Network'
delegate_to: localhost
- name: Ensure that the Ethernet Network is absent
oneview_ethernet_network:
config: '/etc/oneview/oneview_config.json'
state: absent
data:
name: 'New Ethernet Network'
delegate_to: localhost
- name: Create Ethernet networks in bulk
oneview_ethernet_network:
config: '/etc/oneview/oneview_config.json'
state: present
data:
vlanIdRange: '1-10,15,17'
purpose: General
namePrefix: TestNetwork
smartLink: false
privateNetwork: false
bandwidth:
maximumBandwidth: 10000
typicalBandwidth: 2000
delegate_to: localhost
- name: Reset to the default network connection template
oneview_ethernet_network:
config: '/etc/oneview/oneview_config.json'
state: default_bandwidth_reset
data:
name: 'Test Ethernet Network'
delegate_to: localhost
'''
RETURN = '''
ethernet_network:
description: Has the facts about the Ethernet Networks.
returned: On state 'present'. Can be null.
type: dict
ethernet_network_bulk:
description: Has the facts about the Ethernet Networks affected by the bulk insert.
returned: When 'vlanIdRange' attribute is in data argument. Can be null.
type: dict
ethernet_network_connection_template:
description: Has the facts about the Ethernet Network Connection Template.
returned: On state 'default_bandwidth_reset'. Can be null.
type: dict
'''
from ansible_collections.community.general.plugins.module_utils.oneview import OneViewModuleBase, OneViewModuleResourceNotFound
class EthernetNetworkModule(OneViewModuleBase):
MSG_CREATED = 'Ethernet Network created successfully.'
MSG_UPDATED = 'Ethernet Network updated successfully.'
MSG_DELETED = 'Ethernet Network deleted successfully.'
MSG_ALREADY_PRESENT = 'Ethernet Network is already present.'
MSG_ALREADY_ABSENT = 'Ethernet Network is already absent.'
MSG_BULK_CREATED = 'Ethernet Networks created successfully.'
MSG_MISSING_BULK_CREATED = 'Some missing Ethernet Networks were created successfully.'
MSG_BULK_ALREADY_EXIST = 'The specified Ethernet Networks already exist.'
MSG_CONNECTION_TEMPLATE_RESET = 'Ethernet Network connection template was reset to the default.'
MSG_ETHERNET_NETWORK_NOT_FOUND = 'Ethernet Network was not found.'
RESOURCE_FACT_NAME = 'ethernet_network'
def __init__(self):
argument_spec = dict(
state=dict(type='str', default='present', choices=['absent', 'default_bandwidth_reset', 'present']),
data=dict(type='dict', required=True),
)
super(EthernetNetworkModule, self).__init__(additional_arg_spec=argument_spec, validate_etag_support=True)
self.resource_client = self.oneview_client.ethernet_networks
def execute_module(self):
changed, msg, ansible_facts, resource = False, '', {}, None
if self.data.get('name'):
resource = self.get_by_name(self.data['name'])
if self.state == 'present':
if self.data.get('vlanIdRange'):
return self._bulk_present()
else:
return self._present(resource)
elif self.state == 'absent':
return self.resource_absent(resource)
elif self.state == 'default_bandwidth_reset':
changed, msg, ansible_facts = self._default_bandwidth_reset(resource)
return dict(changed=changed, msg=msg, ansible_facts=ansible_facts)
def _present(self, resource):
bandwidth = self.data.pop('bandwidth', None)
scope_uris = self.data.pop('scopeUris', None)
result = self.resource_present(resource, self.RESOURCE_FACT_NAME)
if bandwidth:
if self._update_connection_template(result['ansible_facts']['ethernet_network'], bandwidth)[0]:
result['changed'] = True
result['msg'] = self.MSG_UPDATED
if scope_uris is not None:
result = self.resource_scopes_set(result, 'ethernet_network', scope_uris)
return result
def _bulk_present(self):
vlan_id_range = self.data['vlanIdRange']
result = dict(ansible_facts={})
ethernet_networks = self.resource_client.get_range(self.data['namePrefix'], vlan_id_range)
if not ethernet_networks:
self.resource_client.create_bulk(self.data)
result['changed'] = True
result['msg'] = self.MSG_BULK_CREATED
else:
vlan_ids = self.resource_client.dissociate_values_or_ranges(vlan_id_range)
for net in ethernet_networks[:]:
vlan_ids.remove(net['vlanId'])
if len(vlan_ids) == 0:
result['msg'] = self.MSG_BULK_ALREADY_EXIST
result['changed'] = False
else:
if len(vlan_ids) == 1:
self.data['vlanIdRange'] = '{0}-{1}'.format(vlan_ids[0], vlan_ids[0])
else:
self.data['vlanIdRange'] = ','.join(map(str, vlan_ids))
self.resource_client.create_bulk(self.data)
result['changed'] = True
result['msg'] = self.MSG_MISSING_BULK_CREATED
result['ansible_facts']['ethernet_network_bulk'] = self.resource_client.get_range(self.data['namePrefix'], vlan_id_range)
return result
def _update_connection_template(self, ethernet_network, bandwidth):
if 'connectionTemplateUri' not in ethernet_network:
return False, None
connection_template = self.oneview_client.connection_templates.get(ethernet_network['connectionTemplateUri'])
merged_data = connection_template.copy()
merged_data.update({'bandwidth': bandwidth})
if not self.compare(connection_template, merged_data):
connection_template = self.oneview_client.connection_templates.update(merged_data)
return True, connection_template
else:
return False, None
def _default_bandwidth_reset(self, resource):
if not resource:
raise OneViewModuleResourceNotFound(self.MSG_ETHERNET_NETWORK_NOT_FOUND)
default_connection_template = self.oneview_client.connection_templates.get_default()
changed, connection_template = self._update_connection_template(resource, default_connection_template['bandwidth'])
return changed, self.MSG_CONNECTION_TEMPLATE_RESET, dict(
ethernet_network_connection_template=connection_template)
def main():
EthernetNetworkModule().run()
if __name__ == '__main__':
main()

View file

@ -0,0 +1 @@
oneview_ethernet_network_info.py

View file

@ -0,0 +1,168 @@
#!/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_ethernet_network_info
short_description: Retrieve the information about one or more of the OneView Ethernet Networks
description:
- Retrieve the information about one or more of the Ethernet Networks from OneView.
- This module was called C(oneview_ethernet_network_facts) before Ansible 2.9, returning C(ansible_facts).
Note that the M(oneview_ethernet_network_info) module no longer returns C(ansible_facts)!
requirements:
- hpOneView >= 2.0.1
author:
- Felipe Bulsoni (@fgbulsoni)
- Thiago Miotto (@tmiotto)
- Adriane Cardozo (@adriane-cardozo)
options:
name:
description:
- Ethernet Network name.
options:
description:
- "List with options to gather additional information about an Ethernet Network and related resources.
Options allowed: C(associatedProfiles) and C(associatedUplinkGroups)."
extends_documentation_fragment:
- community.general.oneview
- community.general.oneview.factsparams
'''
EXAMPLES = '''
- name: Gather information about all Ethernet Networks
oneview_ethernet_network_info:
config: /etc/oneview/oneview_config.json
delegate_to: localhost
register: result
- debug:
msg: "{{ result.ethernet_networks }}"
- name: Gather paginated and filtered information about Ethernet Networks
oneview_ethernet_network_info:
config: /etc/oneview/oneview_config.json
params:
start: 1
count: 3
sort: 'name:descending'
filter: 'purpose=General'
delegate_to: localhost
register: result
- debug:
msg: "{{ result.ethernet_networks }}"
- name: Gather information about an Ethernet Network by name
oneview_ethernet_network_info:
config: /etc/oneview/oneview_config.json
name: Ethernet network name
delegate_to: localhost
register: result
- debug:
msg: "{{ result.ethernet_networks }}"
- name: Gather information about an Ethernet Network by name with options
oneview_ethernet_network_info:
config: /etc/oneview/oneview_config.json
name: eth1
options:
- associatedProfiles
- associatedUplinkGroups
delegate_to: localhost
register: result
- debug:
msg: "{{ result.enet_associated_profiles }}"
- debug:
msg: "{{ result.enet_associated_uplink_groups }}"
'''
RETURN = '''
ethernet_networks:
description: Has all the OneView information about the Ethernet Networks.
returned: Always, but can be null.
type: dict
enet_associated_profiles:
description: Has all the OneView information about the profiles which are using the Ethernet network.
returned: When requested, but can be null.
type: dict
enet_associated_uplink_groups:
description: Has all the OneView information about the uplink sets which are using the Ethernet network.
returned: When requested, but can be null.
type: dict
'''
from ansible_collections.community.general.plugins.module_utils.oneview import OneViewModuleBase
class EthernetNetworkInfoModule(OneViewModuleBase):
argument_spec = dict(
name=dict(type='str'),
options=dict(type='list'),
params=dict(type='dict')
)
def __init__(self):
super(EthernetNetworkInfoModule, self).__init__(additional_arg_spec=self.argument_spec)
self.is_old_facts = self.module._name == 'oneview_ethernet_network_facts'
if self.is_old_facts:
self.module.deprecate("The 'oneview_ethernet_network_facts' module has been renamed to 'oneview_ethernet_network_info', "
"and the renamed one no longer returns ansible_facts", version='2.13')
self.resource_client = self.oneview_client.ethernet_networks
def execute_module(self):
info = {}
if self.module.params['name']:
ethernet_networks = self.resource_client.get_by('name', self.module.params['name'])
if self.module.params.get('options') and ethernet_networks:
info = self.__gather_optional_info(ethernet_networks[0])
else:
ethernet_networks = self.resource_client.get_all(**self.facts_params)
info['ethernet_networks'] = ethernet_networks
if self.is_old_facts:
return dict(changed=False, ansible_facts=info)
else:
return dict(changed=False, **info)
def __gather_optional_info(self, ethernet_network):
info = {}
if self.options.get('associatedProfiles'):
info['enet_associated_profiles'] = self.__get_associated_profiles(ethernet_network)
if self.options.get('associatedUplinkGroups'):
info['enet_associated_uplink_groups'] = self.__get_associated_uplink_groups(ethernet_network)
return info
def __get_associated_profiles(self, ethernet_network):
associated_profiles = self.resource_client.get_associated_profiles(ethernet_network['uri'])
return [self.oneview_client.server_profiles.get(x) for x in associated_profiles]
def __get_associated_uplink_groups(self, ethernet_network):
uplink_groups = self.resource_client.get_associated_uplink_groups(ethernet_network['uri'])
return [self.oneview_client.uplink_sets.get(x) for x in uplink_groups]
def main():
EthernetNetworkInfoModule().run()
if __name__ == '__main__':
main()

View file

@ -0,0 +1,124 @@
#!/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_fc_network
short_description: Manage OneView Fibre Channel Network resources.
description:
- Provides an interface to manage Fibre Channel Network resources. Can create, update, and delete.
requirements:
- "hpOneView >= 4.0.0"
author: "Felipe Bulsoni (@fgbulsoni)"
options:
state:
description:
- Indicates the desired state for the Fibre Channel Network resource.
C(present) will ensure data properties are compliant with OneView.
C(absent) will remove the resource from OneView, if it exists.
choices: ['present', 'absent']
data:
description:
- List with the Fibre Channel Network properties.
required: true
extends_documentation_fragment:
- community.general.oneview
- community.general.oneview.validateetag
'''
EXAMPLES = '''
- name: Ensure that the Fibre Channel Network is present using the default configuration
oneview_fc_network:
config: "{{ config_file_path }}"
state: present
data:
name: 'New FC Network'
- name: Ensure that the Fibre Channel Network is present with fabricType 'DirectAttach'
oneview_fc_network:
config: "{{ config_file_path }}"
state: present
data:
name: 'New FC Network'
fabricType: 'DirectAttach'
- name: Ensure that the Fibre Channel Network is present and is inserted in the desired scopes
oneview_fc_network:
config: "{{ config_file_path }}"
state: present
data:
name: 'New FC Network'
scopeUris:
- '/rest/scopes/00SC123456'
- '/rest/scopes/01SC123456'
- name: Ensure that the Fibre Channel Network is absent
oneview_fc_network:
config: "{{ config_file_path }}"
state: absent
data:
name: 'New FC Network'
'''
RETURN = '''
fc_network:
description: Has the facts about the managed OneView FC Network.
returned: On state 'present'. Can be null.
type: dict
'''
from ansible_collections.community.general.plugins.module_utils.oneview import OneViewModuleBase
class FcNetworkModule(OneViewModuleBase):
MSG_CREATED = 'FC Network created successfully.'
MSG_UPDATED = 'FC Network updated successfully.'
MSG_DELETED = 'FC Network deleted successfully.'
MSG_ALREADY_PRESENT = 'FC Network is already present.'
MSG_ALREADY_ABSENT = 'FC Network is already absent.'
RESOURCE_FACT_NAME = 'fc_network'
def __init__(self):
additional_arg_spec = dict(data=dict(required=True, type='dict'),
state=dict(
required=True,
choices=['present', 'absent']))
super(FcNetworkModule, self).__init__(additional_arg_spec=additional_arg_spec,
validate_etag_support=True)
self.resource_client = self.oneview_client.fc_networks
def execute_module(self):
resource = self.get_by_name(self.data['name'])
if self.state == 'present':
return self._present(resource)
else:
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, 'fc_network', scope_uris)
return result
def main():
FcNetworkModule().run()
if __name__ == '__main__':
main()

View file

@ -0,0 +1 @@
oneview_fc_network_info.py

View file

@ -0,0 +1,113 @@
#!/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_fc_network_info
short_description: Retrieve the information about one or more of the OneView Fibre Channel Networks
description:
- Retrieve the information about one or more of the Fibre Channel Networks from OneView.
- This module was called C(oneview_fc_network_facts) before Ansible 2.9, returning C(ansible_facts).
Note that the M(oneview_fc_network_info) module no longer returns C(ansible_facts)!
requirements:
- hpOneView >= 2.0.1
author:
- Felipe Bulsoni (@fgbulsoni)
- Thiago Miotto (@tmiotto)
- Adriane Cardozo (@adriane-cardozo)
options:
name:
description:
- Fibre Channel Network name.
extends_documentation_fragment:
- community.general.oneview
- community.general.oneview.factsparams
'''
EXAMPLES = '''
- name: Gather information about all Fibre Channel Networks
oneview_fc_network_info:
config: /etc/oneview/oneview_config.json
delegate_to: localhost
register: result
- debug:
msg: "{{ result.fc_networks }}"
- name: Gather paginated, filtered and sorted information about Fibre Channel Networks
oneview_fc_network_info:
config: /etc/oneview/oneview_config.json
params:
start: 1
count: 3
sort: 'name:descending'
filter: 'fabricType=FabricAttach'
delegate_to: localhost
register: result
- debug:
msg: "{{ result.fc_networks }}"
- name: Gather information about a Fibre Channel Network by name
oneview_fc_network_info:
config: /etc/oneview/oneview_config.json
name: network name
delegate_to: localhost
register: result
- debug:
msg: "{{ result.fc_networks }}"
'''
RETURN = '''
fc_networks:
description: Has all the OneView information about the Fibre Channel Networks.
returned: Always, but can be null.
type: dict
'''
from ansible_collections.community.general.plugins.module_utils.oneview import OneViewModuleBase
class FcNetworkInfoModule(OneViewModuleBase):
def __init__(self):
argument_spec = dict(
name=dict(required=False, type='str'),
params=dict(required=False, type='dict')
)
super(FcNetworkInfoModule, self).__init__(additional_arg_spec=argument_spec)
self.is_old_facts = self.module._name == 'oneview_fc_network_facts'
if self.is_old_facts:
self.module.deprecate("The 'oneview_fc_network_facts' module has been renamed to 'oneview_fc_network_info', "
"and the renamed one no longer returns ansible_facts", version='2.13')
def execute_module(self):
if self.module.params['name']:
fc_networks = self.oneview_client.fc_networks.get_by('name', self.module.params['name'])
else:
fc_networks = self.oneview_client.fc_networks.get_all(**self.facts_params)
if self.is_old_facts:
return dict(changed=False, ansible_facts=dict(fc_networks=fc_networks))
else:
return dict(changed=False, fc_networks=fc_networks)
def main():
FcNetworkInfoModule().run()
if __name__ == '__main__':
main()

View file

@ -0,0 +1,121 @@
#!/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
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.
default: present
choices: ['present', 'absent']
data:
description:
- List with FCoE Network properties.
required: true
extends_documentation_fragment:
- community.general.oneview
- community.general.oneview.validateetag
'''
EXAMPLES = '''
- name: Ensure that FCoE Network is present using the default configuration
oneview_fcoe_network:
config: '/etc/oneview/oneview_config.json'
state: present
data:
name: Test FCoE Network
vlanId: 201
delegate_to: localhost
- name: Update the FCOE network scopes
oneview_fcoe_network:
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
oneview_fcoe_network:
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()

View file

@ -0,0 +1 @@
oneview_fcoe_network_info.py

View file

@ -0,0 +1,113 @@
#!/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_info
short_description: Retrieve the information about one or more of the OneView FCoE Networks
description:
- Retrieve the information about one or more of the FCoE Networks from OneView.
- This module was called C(oneview_fcoe_network_facts) before Ansible 2.9, returning C(ansible_facts).
Note that the M(oneview_fcoe_network_info) module no longer returns C(ansible_facts)!
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:
- community.general.oneview
- community.general.oneview.factsparams
'''
EXAMPLES = '''
- name: Gather information about all FCoE Networks
oneview_fcoe_network_info:
config: /etc/oneview/oneview_config.json
delegate_to: localhost
register: result
- debug:
msg: "{{ result.fcoe_networks }}"
- name: Gather paginated, filtered and sorted information about FCoE Networks
oneview_fcoe_network_info:
config: /etc/oneview/oneview_config.json
params:
start: 0
count: 3
sort: 'name:descending'
filter: 'vlanId=2'
delegate_to: localhost
register: result
- debug:
msg: "{{ result.fcoe_networks }}"
- name: Gather information about a FCoE Network by name
oneview_fcoe_network_info:
config: /etc/oneview/oneview_config.json
name: Test FCoE Network Information
delegate_to: localhost
register: result
- debug:
msg: "{{ result.fcoe_networks }}"
'''
RETURN = '''
fcoe_networks:
description: Has all the OneView information about the FCoE Networks.
returned: Always, but can be null.
type: dict
'''
from ansible_collections.community.general.plugins.module_utils.oneview import OneViewModuleBase
class FcoeNetworkInfoModule(OneViewModuleBase):
def __init__(self):
argument_spec = dict(
name=dict(type='str'),
params=dict(type='dict'),
)
super(FcoeNetworkInfoModule, self).__init__(additional_arg_spec=argument_spec)
self.is_old_facts = self.module._name == 'oneview_fcoe_network_facts'
if self.is_old_facts:
self.module.deprecate("The 'oneview_fcoe_network_facts' module has been renamed to 'oneview_fcoe_network_info', "
"and the renamed one no longer returns ansible_facts", version='2.13')
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)
if self.is_old_facts:
return dict(changed=False,
ansible_facts=dict(fcoe_networks=fcoe_networks))
else:
return dict(changed=False, fcoe_networks=fcoe_networks)
def main():
FcoeNetworkInfoModule().run()
if __name__ == '__main__':
main()

View file

@ -0,0 +1,168 @@
#!/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_logical_interconnect_group
short_description: Manage OneView Logical Interconnect Group resources
description:
- Provides an interface to manage Logical Interconnect Group resources. Can create, update, or delete.
requirements:
- hpOneView >= 4.0.0
author:
- Felipe Bulsoni (@fgbulsoni)
- Thiago Miotto (@tmiotto)
- Adriane Cardozo (@adriane-cardozo)
options:
state:
description:
- Indicates the desired state for the Logical Interconnect Group resource.
C(absent) will remove the resource from OneView, if it exists.
C(present) will ensure data properties are compliant with OneView.
choices: [absent, present]
default: present
data:
description:
- List with the Logical Interconnect Group properties.
required: true
extends_documentation_fragment:
- community.general.oneview
- community.general.oneview.validateetag
'''
EXAMPLES = '''
- name: Ensure that the Logical Interconnect Group is present
oneview_logical_interconnect_group:
config: /etc/oneview/oneview_config.json
state: present
data:
name: Test Logical Interconnect Group
uplinkSets: []
enclosureType: C7000
interconnectMapTemplate:
interconnectMapEntryTemplates:
- logicalDownlinkUri: ~
logicalLocation:
locationEntries:
- relativeValue: 1
type: Bay
- relativeValue: 1
type: Enclosure
permittedInterconnectTypeName: HP VC Flex-10/10D Module
# Alternatively you can inform permittedInterconnectTypeUri
delegate_to: localhost
- name: Ensure that the Logical Interconnect Group has the specified scopes
oneview_logical_interconnect_group:
config: /etc/oneview/oneview_config.json
state: present
data:
name: Test Logical Interconnect Group
scopeUris:
- /rest/scopes/00SC123456
- /rest/scopes/01SC123456
delegate_to: localhost
- name: Ensure that the Logical Interconnect Group is present with name 'Test'
oneview_logical_interconnect_group:
config: /etc/oneview/oneview_config.json
state: present
data:
name: New Logical Interconnect Group
newName: Test
delegate_to: localhost
- name: Ensure that the Logical Interconnect Group is absent
oneview_logical_interconnect_group:
config: /etc/oneview/oneview_config.json
state: absent
data:
name: New Logical Interconnect Group
delegate_to: localhost
'''
RETURN = '''
logical_interconnect_group:
description: Has the facts about the OneView Logical Interconnect Group.
returned: On state 'present'. Can be null.
type: dict
'''
from ansible_collections.community.general.plugins.module_utils.oneview import OneViewModuleBase, OneViewModuleResourceNotFound
class LogicalInterconnectGroupModule(OneViewModuleBase):
MSG_CREATED = 'Logical Interconnect Group created successfully.'
MSG_UPDATED = 'Logical Interconnect Group updated successfully.'
MSG_DELETED = 'Logical Interconnect Group deleted successfully.'
MSG_ALREADY_PRESENT = 'Logical Interconnect Group is already present.'
MSG_ALREADY_ABSENT = 'Logical Interconnect Group is already absent.'
MSG_INTERCONNECT_TYPE_NOT_FOUND = 'Interconnect Type was not found.'
RESOURCE_FACT_NAME = 'logical_interconnect_group'
def __init__(self):
argument_spec = dict(
state=dict(default='present', choices=['present', 'absent']),
data=dict(required=True, type='dict')
)
super(LogicalInterconnectGroupModule, self).__init__(additional_arg_spec=argument_spec,
validate_etag_support=True)
self.resource_client = self.oneview_client.logical_interconnect_groups
def execute_module(self):
resource = self.get_by_name(self.data['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)
self.__replace_name_by_uris(self.data)
result = self.resource_present(resource, self.RESOURCE_FACT_NAME)
if scope_uris is not None:
result = self.resource_scopes_set(result, 'logical_interconnect_group', scope_uris)
return result
def __replace_name_by_uris(self, data):
map_template = data.get('interconnectMapTemplate')
if map_template:
map_entry_templates = map_template.get('interconnectMapEntryTemplates')
if map_entry_templates:
for value in map_entry_templates:
permitted_interconnect_type_name = value.pop('permittedInterconnectTypeName', None)
if permitted_interconnect_type_name:
value['permittedInterconnectTypeUri'] = self.__get_interconnect_type_by_name(
permitted_interconnect_type_name).get('uri')
def __get_interconnect_type_by_name(self, name):
i_type = self.oneview_client.interconnect_types.get_by('name', name)
if i_type:
return i_type[0]
else:
raise OneViewModuleResourceNotFound(self.MSG_INTERCONNECT_TYPE_NOT_FOUND)
def main():
LogicalInterconnectGroupModule().run()
if __name__ == '__main__':
main()

View file

@ -0,0 +1 @@
oneview_logical_interconnect_group_info.py

View file

@ -0,0 +1,125 @@
#!/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_logical_interconnect_group_info
short_description: Retrieve information about one or more of the OneView Logical Interconnect Groups
description:
- Retrieve information about one or more of the Logical Interconnect Groups from OneView
- This module was called C(oneview_logical_interconnect_group_facts) before Ansible 2.9, returning C(ansible_facts).
Note that the M(oneview_logical_interconnect_group_info) module no longer returns C(ansible_facts)!
requirements:
- hpOneView >= 2.0.1
author:
- Felipe Bulsoni (@fgbulsoni)
- Thiago Miotto (@tmiotto)
- Adriane Cardozo (@adriane-cardozo)
options:
name:
description:
- Logical Interconnect Group name.
extends_documentation_fragment:
- community.general.oneview
- community.general.oneview.factsparams
'''
EXAMPLES = '''
- name: Gather information about all Logical Interconnect Groups
oneview_logical_interconnect_group_info:
hostname: 172.16.101.48
username: administrator
password: my_password
api_version: 500
no_log: true
delegate_to: localhost
register: result
- debug:
msg: "{{ result.logical_interconnect_groups }}"
- name: Gather paginated, filtered and sorted information about Logical Interconnect Groups
oneview_logical_interconnect_group_info:
params:
start: 0
count: 3
sort: name:descending
filter: name=LIGName
hostname: 172.16.101.48
username: administrator
password: my_password
api_version: 500
no_log: true
delegate_to: localhost
register: result
- debug:
msg: "{{ result.logical_interconnect_groups }}"
- name: Gather information about a Logical Interconnect Group by name
oneview_logical_interconnect_group_info:
name: logical interconnect group name
hostname: 172.16.101.48
username: administrator
password: my_password
api_version: 500
no_log: true
delegate_to: localhost
register: result
- debug:
msg: "{{ result.logical_interconnect_groups }}"
'''
RETURN = '''
logical_interconnect_groups:
description: Has all the OneView information about the Logical Interconnect Groups.
returned: Always, but can be null.
type: dict
'''
from ansible_collections.community.general.plugins.module_utils.oneview import OneViewModuleBase
class LogicalInterconnectGroupInfoModule(OneViewModuleBase):
def __init__(self):
argument_spec = dict(
name=dict(type='str'),
params=dict(type='dict'),
)
super(LogicalInterconnectGroupInfoModule, self).__init__(additional_arg_spec=argument_spec)
self.is_old_facts = self.module._name == 'oneview_logical_interconnect_group_facts'
if self.is_old_facts:
self.module.deprecate("The 'oneview_logical_interconnect_group_facts' module has been renamed to 'oneview_logical_interconnect_group_info', "
"and the renamed one no longer returns ansible_facts", version='2.13')
def execute_module(self):
if self.module.params.get('name'):
ligs = self.oneview_client.logical_interconnect_groups.get_by('name', self.module.params['name'])
else:
ligs = self.oneview_client.logical_interconnect_groups.get_all(**self.facts_params)
if self.is_old_facts:
return dict(changed=False, ansible_facts=dict(logical_interconnect_groups=ligs))
else:
return dict(changed=False, logical_interconnect_groups=ligs)
def main():
LogicalInterconnectGroupInfoModule().run()
if __name__ == '__main__':
main()

View file

@ -0,0 +1,154 @@
#!/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_network_set
short_description: Manage HPE OneView Network Set resources
description:
- Provides an interface to manage Network Set resources. Can create, update, or delete.
requirements:
- hpOneView >= 4.0.0
author:
- Felipe Bulsoni (@fgbulsoni)
- Thiago Miotto (@tmiotto)
- Adriane Cardozo (@adriane-cardozo)
options:
state:
description:
- Indicates the desired state for the Network Set resource.
- C(present) will ensure data properties are compliant with OneView.
- C(absent) will remove the resource from OneView, if it exists.
default: present
choices: ['present', 'absent']
data:
description:
- List with the Network Set properties.
required: true
extends_documentation_fragment:
- community.general.oneview
- community.general.oneview.validateetag
'''
EXAMPLES = '''
- name: Create a Network Set
oneview_network_set:
config: /etc/oneview/oneview_config.json
state: present
data:
name: OneViewSDK Test Network Set
networkUris:
- Test Ethernet Network_1 # can be a name
- /rest/ethernet-networks/e4360c9d-051d-4931-b2aa-7de846450dd8 # or a URI
delegate_to: localhost
- name: Update the Network Set name to 'OneViewSDK Test Network Set - Renamed' and change the associated networks
oneview_network_set:
config: /etc/oneview/oneview_config.json
state: present
data:
name: OneViewSDK Test Network Set
newName: OneViewSDK Test Network Set - Renamed
networkUris:
- Test Ethernet Network_1
delegate_to: localhost
- name: Delete the Network Set
oneview_network_set:
config: /etc/oneview/oneview_config.json
state: absent
data:
name: OneViewSDK Test Network Set - Renamed
delegate_to: localhost
- name: Update the Network set with two scopes
oneview_network_set:
config: /etc/oneview/oneview_config.json
state: present
data:
name: OneViewSDK Test Network Set
scopeUris:
- /rest/scopes/01SC123456
- /rest/scopes/02SC123456
delegate_to: localhost
'''
RETURN = '''
network_set:
description: Has the facts about the Network Set.
returned: On state 'present', but can be null.
type: dict
'''
from ansible_collections.community.general.plugins.module_utils.oneview import OneViewModuleBase, OneViewModuleResourceNotFound
class NetworkSetModule(OneViewModuleBase):
MSG_CREATED = 'Network Set created successfully.'
MSG_UPDATED = 'Network Set updated successfully.'
MSG_DELETED = 'Network Set deleted successfully.'
MSG_ALREADY_PRESENT = 'Network Set is already present.'
MSG_ALREADY_ABSENT = 'Network Set is already absent.'
MSG_ETHERNET_NETWORK_NOT_FOUND = 'Ethernet Network not found: '
RESOURCE_FACT_NAME = 'network_set'
argument_spec = dict(
state=dict(default='present', choices=['present', 'absent']),
data=dict(required=True, type='dict'))
def __init__(self):
super(NetworkSetModule, self).__init__(additional_arg_spec=self.argument_spec,
validate_etag_support=True)
self.resource_client = self.oneview_client.network_sets
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)
self._replace_network_name_by_uri(self.data)
result = self.resource_present(resource, self.RESOURCE_FACT_NAME)
if scope_uris is not None:
result = self.resource_scopes_set(result, self.RESOURCE_FACT_NAME, scope_uris)
return result
def _get_ethernet_network_by_name(self, name):
result = self.oneview_client.ethernet_networks.get_by('name', name)
return result[0] if result else None
def _get_network_uri(self, network_name_or_uri):
if network_name_or_uri.startswith('/rest/ethernet-networks'):
return network_name_or_uri
else:
enet_network = self._get_ethernet_network_by_name(network_name_or_uri)
if enet_network:
return enet_network['uri']
else:
raise OneViewModuleResourceNotFound(self.MSG_ETHERNET_NETWORK_NOT_FOUND + network_name_or_uri)
def _replace_network_name_by_uri(self, data):
if 'networkUris' in data:
data['networkUris'] = [self._get_network_uri(x) for x in data['networkUris']]
def main():
NetworkSetModule().run()
if __name__ == '__main__':
main()

View file

@ -0,0 +1 @@
oneview_network_set_info.py

View file

@ -0,0 +1,169 @@
#!/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_network_set_info
short_description: Retrieve information about the OneView Network Sets
description:
- Retrieve information about the Network Sets from OneView.
- This module was called C(oneview_network_set_facts) before Ansible 2.9, returning C(ansible_facts).
Note that the M(oneview_network_set_info) module no longer returns C(ansible_facts)!
requirements:
- hpOneView >= 2.0.1
author:
- Felipe Bulsoni (@fgbulsoni)
- Thiago Miotto (@tmiotto)
- Adriane Cardozo (@adriane-cardozo)
options:
name:
description:
- Network Set name.
options:
description:
- "List with options to gather information about Network Set.
Option allowed: C(withoutEthernet).
The option C(withoutEthernet) retrieves the list of network_sets excluding Ethernet networks."
extends_documentation_fragment:
- community.general.oneview
- community.general.oneview.factsparams
'''
EXAMPLES = '''
- name: Gather information about all Network Sets
oneview_network_set_info:
hostname: 172.16.101.48
username: administrator
password: my_password
api_version: 500
no_log: true
delegate_to: localhost
register: result
- debug:
msg: "{{ result.network_sets }}"
- name: Gather paginated, filtered, and sorted information about Network Sets
oneview_network_set_info:
hostname: 172.16.101.48
username: administrator
password: my_password
api_version: 500
params:
start: 0
count: 3
sort: 'name:descending'
filter: name='netset001'
no_log: true
delegate_to: localhost
register: result
- debug:
msg: "{{ result.network_sets }}"
- name: Gather information about all Network Sets, excluding Ethernet networks
oneview_network_set_info:
hostname: 172.16.101.48
username: administrator
password: my_password
api_version: 500
options:
- withoutEthernet
no_log: true
delegate_to: localhost
register: result
- debug:
msg: "{{ result.network_sets }}"
- name: Gather information about a Network Set by name
oneview_network_set_info:
hostname: 172.16.101.48
username: administrator
password: my_password
api_version: 500
name: Name of the Network Set
no_log: true
delegate_to: localhost
register: result
- debug:
msg: "{{ result.network_sets }}"
- name: Gather information about a Network Set by name, excluding Ethernet networks
oneview_network_set_info:
hostname: 172.16.101.48
username: administrator
password: my_password
api_version: 500
name: Name of the Network Set
options:
- withoutEthernet
no_log: true
delegate_to: localhost
register: result
- debug:
msg: "{{ result.network_sets }}"
'''
RETURN = '''
network_sets:
description: Has all the OneView information about the Network Sets.
returned: Always, but can be empty.
type: dict
'''
from ansible_collections.community.general.plugins.module_utils.oneview import OneViewModuleBase
class NetworkSetInfoModule(OneViewModuleBase):
argument_spec = dict(
name=dict(type='str'),
options=dict(type='list'),
params=dict(type='dict'),
)
def __init__(self):
super(NetworkSetInfoModule, self).__init__(additional_arg_spec=self.argument_spec)
self.is_old_facts = self.module._name == 'oneview_network_set_facts'
if self.is_old_facts:
self.module.deprecate("The 'oneview_network_set_facts' module has been renamed to 'oneview_network_set_info', "
"and the renamed one no longer returns ansible_facts", version='2.13')
def execute_module(self):
name = self.module.params.get('name')
if 'withoutEthernet' in self.options:
filter_by_name = ("\"'name'='%s'\"" % name) if name else ''
network_sets = self.oneview_client.network_sets.get_all_without_ethernet(filter=filter_by_name)
elif name:
network_sets = self.oneview_client.network_sets.get_by('name', name)
else:
network_sets = self.oneview_client.network_sets.get_all(**self.facts_params)
if self.is_old_facts:
return dict(changed=False,
ansible_facts=dict(network_sets=network_sets))
else:
return dict(changed=False, network_sets=network_sets)
def main():
NetworkSetInfoModule().run()
if __name__ == '__main__':
main()

View file

@ -0,0 +1,219 @@
#!/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_san_manager
short_description: Manage OneView SAN Manager resources
description:
- Provides an interface to manage SAN Manager resources. Can create, update, or delete.
requirements:
- hpOneView >= 3.1.1
author:
- Felipe Bulsoni (@fgbulsoni)
- Thiago Miotto (@tmiotto)
- Adriane Cardozo (@adriane-cardozo)
options:
state:
description:
- Indicates the desired state for the Uplink Set resource.
- C(present) ensures data properties are compliant with OneView.
- C(absent) removes the resource from OneView, if it exists.
- C(connection_information_set) updates the connection information for the SAN Manager. This operation is non-idempotent.
default: present
choices: [present, absent, connection_information_set]
data:
description:
- List with SAN Manager properties.
required: true
extends_documentation_fragment:
- community.general.oneview
- community.general.oneview.validateetag
'''
EXAMPLES = '''
- name: Creates a Device Manager for the Brocade SAN provider with the given hostname and credentials
oneview_san_manager:
config: /etc/oneview/oneview_config.json
state: present
data:
providerDisplayName: Brocade Network Advisor
connectionInfo:
- name: Host
value: 172.18.15.1
- name: Port
value: 5989
- name: Username
value: username
- name: Password
value: password
- name: UseSsl
value: true
delegate_to: localhost
- name: Ensure a Device Manager for the Cisco SAN Provider is present
oneview_san_manager:
config: /etc/oneview/oneview_config.json
state: present
data:
name: 172.18.20.1
providerDisplayName: Cisco
connectionInfo:
- name: Host
value: 172.18.20.1
- name: SnmpPort
value: 161
- name: SnmpUserName
value: admin
- name: SnmpAuthLevel
value: authnopriv
- name: SnmpAuthProtocol
value: sha
- name: SnmpAuthString
value: password
delegate_to: localhost
- name: Sets the SAN Manager connection information
oneview_san_manager:
config: /etc/oneview/oneview_config.json
state: connection_information_set
data:
connectionInfo:
- name: Host
value: '172.18.15.1'
- name: Port
value: '5989'
- name: Username
value: 'username'
- name: Password
value: 'password'
- name: UseSsl
value: true
delegate_to: localhost
- name: Refreshes the SAN Manager
oneview_san_manager:
config: /etc/oneview/oneview_config.json
state: present
data:
name: 172.18.15.1
refreshState: RefreshPending
delegate_to: localhost
- name: Delete the SAN Manager recently created
oneview_san_manager:
config: /etc/oneview/oneview_config.json
state: absent
data:
name: '172.18.15.1'
delegate_to: localhost
'''
RETURN = '''
san_manager:
description: Has the OneView facts about the SAN Manager.
returned: On state 'present'. Can be null.
type: dict
'''
from ansible_collections.community.general.plugins.module_utils.oneview import OneViewModuleBase, OneViewModuleValueError
class SanManagerModule(OneViewModuleBase):
MSG_CREATED = 'SAN Manager created successfully.'
MSG_UPDATED = 'SAN Manager updated successfully.'
MSG_DELETED = 'SAN Manager deleted successfully.'
MSG_ALREADY_PRESENT = 'SAN Manager is already present.'
MSG_ALREADY_ABSENT = 'SAN Manager is already absent.'
MSG_SAN_MANAGER_PROVIDER_DISPLAY_NAME_NOT_FOUND = "The provider '{0}' was not found."
argument_spec = dict(
state=dict(type='str', default='present', choices=['absent', 'present', 'connection_information_set']),
data=dict(type='dict', required=True)
)
def __init__(self):
super(SanManagerModule, self).__init__(additional_arg_spec=self.argument_spec, validate_etag_support=True)
self.resource_client = self.oneview_client.san_managers
def execute_module(self):
if self.data.get('connectionInfo'):
for connection_hash in self.data.get('connectionInfo'):
if connection_hash.get('name') == 'Host':
resource_name = connection_hash.get('value')
elif self.data.get('name'):
resource_name = self.data.get('name')
else:
msg = 'A "name" or "connectionInfo" must be provided inside the "data" field for this operation. '
msg += 'If a "connectionInfo" is provided, the "Host" name is considered as the "name" for the resource.'
raise OneViewModuleValueError(msg.format())
resource = self.resource_client.get_by_name(resource_name)
if self.state == 'present':
changed, msg, san_manager = self._present(resource)
return dict(changed=changed, msg=msg, ansible_facts=dict(san_manager=san_manager))
elif self.state == 'absent':
return self.resource_absent(resource, method='remove')
elif self.state == 'connection_information_set':
changed, msg, san_manager = self._connection_information_set(resource)
return dict(changed=changed, msg=msg, ansible_facts=dict(san_manager=san_manager))
def _present(self, resource):
if not resource:
provider_uri = self.data.get('providerUri', self._get_provider_uri_by_display_name(self.data))
return True, self.MSG_CREATED, self.resource_client.add(self.data, provider_uri)
else:
merged_data = resource.copy()
merged_data.update(self.data)
# Remove 'connectionInfo' from comparison, since it is not possible to validate it.
resource.pop('connectionInfo', None)
merged_data.pop('connectionInfo', None)
if self.compare(resource, merged_data):
return False, self.MSG_ALREADY_PRESENT, resource
else:
updated_san_manager = self.resource_client.update(resource=merged_data, id_or_uri=resource['uri'])
return True, self.MSG_UPDATED, updated_san_manager
def _connection_information_set(self, resource):
if not resource:
return self._present(resource)
else:
merged_data = resource.copy()
merged_data.update(self.data)
merged_data.pop('refreshState', None)
if not self.data.get('connectionInfo', None):
raise OneViewModuleValueError('A connectionInfo field is required for this operation.')
updated_san_manager = self.resource_client.update(resource=merged_data, id_or_uri=resource['uri'])
return True, self.MSG_UPDATED, updated_san_manager
def _get_provider_uri_by_display_name(self, data):
display_name = data.get('providerDisplayName')
provider_uri = self.resource_client.get_provider_uri(display_name)
if not provider_uri:
raise OneViewModuleValueError(self.MSG_SAN_MANAGER_PROVIDER_DISPLAY_NAME_NOT_FOUND.format(display_name))
return provider_uri
def main():
SanManagerModule().run()
if __name__ == '__main__':
main()

View file

@ -0,0 +1 @@
oneview_san_manager_info.py

View file

@ -0,0 +1,124 @@
#!/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_san_manager_info
short_description: Retrieve information about one or more of the OneView SAN Managers
description:
- Retrieve information about one or more of the SAN Managers from OneView
- This module was called C(oneview_san_manager_facts) before Ansible 2.9, returning C(ansible_facts).
Note that the M(oneview_san_manager_info) module no longer returns C(ansible_facts)!
requirements:
- hpOneView >= 2.0.1
author:
- Felipe Bulsoni (@fgbulsoni)
- Thiago Miotto (@tmiotto)
- Adriane Cardozo (@adriane-cardozo)
options:
provider_display_name:
description:
- Provider Display Name.
params:
description:
- List of params to delimit, filter and sort the list of resources.
- "params allowed:
- C(start): The first item to return, using 0-based indexing.
- C(count): The number of resources to return.
- C(query): A general query string to narrow the list of resources returned.
- C(sort): The sort order of the returned data set."
extends_documentation_fragment:
- community.general.oneview
'''
EXAMPLES = '''
- name: Gather information about all SAN Managers
oneview_san_manager_info:
config: /etc/oneview/oneview_config.json
delegate_to: localhost
register: result
- debug:
msg: "{{ result.san_managers }}"
- name: Gather paginated, filtered and sorted information about SAN Managers
oneview_san_manager_info:
config: /etc/oneview/oneview_config.json
params:
start: 0
count: 3
sort: name:ascending
query: isInternal eq false
delegate_to: localhost
register: result
- debug:
msg: "{{ result.san_managers }}"
- name: Gather information about a SAN Manager by provider display name
oneview_san_manager_info:
config: /etc/oneview/oneview_config.json
provider_display_name: Brocade Network Advisor
delegate_to: localhost
register: result
- debug:
msg: "{{ result.san_managers }}"
'''
RETURN = '''
san_managers:
description: Has all the OneView information about the SAN Managers.
returned: Always, but can be null.
type: dict
'''
from ansible_collections.community.general.plugins.module_utils.oneview import OneViewModuleBase
class SanManagerInfoModule(OneViewModuleBase):
argument_spec = dict(
provider_display_name=dict(type='str'),
params=dict(type='dict')
)
def __init__(self):
super(SanManagerInfoModule, self).__init__(additional_arg_spec=self.argument_spec)
self.resource_client = self.oneview_client.san_managers
self.is_old_facts = self.module._name == 'oneview_san_manager_facts'
if self.is_old_facts:
self.module.deprecate("The 'oneview_san_manager_facts' module has been renamed to 'oneview_san_manager_info', "
"and the renamed one no longer returns ansible_facts", version='2.13')
def execute_module(self):
if self.module.params.get('provider_display_name'):
provider_display_name = self.module.params['provider_display_name']
san_manager = self.oneview_client.san_managers.get_by_provider_display_name(provider_display_name)
if san_manager:
resources = [san_manager]
else:
resources = []
else:
resources = self.oneview_client.san_managers.get_all(**self.facts_params)
if self.is_old_facts:
return dict(changed=False, ansible_facts=dict(san_managers=resources))
else:
return dict(changed=False, san_managers=resources)
def main():
SanManagerInfoModule().run()
if __name__ == '__main__':
main()