Skip to content

Commit

Permalink
Merge branch 'master' into OV6.10_validation
Browse files Browse the repository at this point in the history
  • Loading branch information
SHANDCRUZ authored Apr 8, 2021
2 parents a6af3b3 + 7a833f6 commit 2f2c1a3
Show file tree
Hide file tree
Showing 10 changed files with 591 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ examples/vars/config.yml
*~
examples/vars/os_attributes.yaml
**/.coverage
htmlcov
htmlcov
coverage.xml
1 change: 1 addition & 0 deletions endpoints-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@
|<sub>/rest/logical-interconnects/{id}/telemetry-configurations/{tcId}</sub> | PUT | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
|<sub>/rest/logical-interconnects/{id}</sub> | PATCH | :white_check_mark: | :heavy_minus_sign: | :heavy_minus_sign: | :heavy_minus_sign: | :heavy_minus_sign: | :heavy_minus_sign: | :heavy_minus_sign: | :heavy_minus_sign: | :heavy_minus_sign: | :heavy_minus_sign: | :heavy_minus_sign: | :heavy_minus_sign: |
| **Logical Switch Groups** |

|<sub>/rest/logical-switch-groups</sub> | GET | :white_check_mark: | :white_check_mark: | :white_check_mark: |
|<sub>/rest/logical-switch-groups</sub> |POST | :white_check_mark: | :white_check_mark: | :white_check_mark: |
|<sub>/rest/logical-switch-groups/{id}</sub> |GET | :white_check_mark: | :white_check_mark: | :white_check_mark: |
Expand Down
54 changes: 54 additions & 0 deletions examples/oneview_label.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
###
# Copyright (2016-2021) Hewlett Packard Enterprise Development LP
#
# Licensed under the Apache License, Version 2.0 (the "License");
# You may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
###
---
- hosts: all
vars:
- config: "{{ playbook_dir }}/oneview_config.json"
tasks:
- name: Create Labels for enclosure resource
oneview_label:
config: "{{ config }}"
state: present
data:
resourceUri: "/rest/enclosures/0000000000A66102"
labels:
- name: "Test label 1"
- name: "Test Label 2"
delegate_to: localhost
register: label

- name: Update label of given resource for enclosure resource
oneview_label:
config: "{{ config }}"
state: present
data:
resourceUri: "/rest/enclosures/0000000000A66102"
labels:
- name: "Test label 1 Renamed"
uri: "/rest/labels/130"
- name: "Test label 2 Renamed"
uri: null
- name: "Test label 3"
uri: null
delegate_to: localhost

- name: Delete Labels for enclosure resource
oneview_label:
config: "{{ config }}"
state: absent
data:
resourceUri: "/rest/enclosures/0000000000A66102"
delegate_to: localhost
52 changes: 52 additions & 0 deletions examples/oneview_label_facts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
###
# Copyright (2016-2021) Hewlett Packard Enterprise Development LP
#
# Licensed under the Apache License, Version 2.0 (the "License");
# You may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
###
---
- hosts: all
vars:
- config: "{{ playbook_dir }}/oneview_config.json"
tasks:
- name: Gather facts about all Labels
oneview_label_facts:
config: "{{ config }}"
delegate_to: localhost

- debug: var=labels

- name: Gather paginated, filtered and sorted facts about Labels
oneview_label_facts:
config: "{{ config }}"
params:
start: 0
count: 3
sort: 'name:descending'
filter: ''
- debug: var=labels

- name: Gather facts about a Label by name
oneview_label_facts:
config: "{{ config }}"
name: "{{ labels[0]['name'] }}"
delegate_to: localhost

- debug: var=labels

- name: Gather facts about a Label by Resource
oneview_label_facts:
config: "{{ config }}"
resourceUri: "/rest/enclosures/0000000000A66102"
delegate_to: localhost

- debug: var=labels
140 changes: 140 additions & 0 deletions library/oneview_label.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
###
# Copyright (2016-2021) Hewlett Packard Enterprise Development LP
#
# Licensed under the Apache License, Version 2.0 (the "License");
# You may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
###

ANSIBLE_METADATA = {'status': ['stableinterface'],
'supported_by': 'community',
'metadata_version': '1.1'}

DOCUMENTATION = '''
---
module: oneview_label
short_description: Manage OneView Label resources.
description:
- Provides an interface to manage ID pools IPV4 Range resources. Can create, update, or delete.
version_added: "2.3"
requirements:
- "python >= 2.7.9"
- "hpeOneView >= 6.0.0"
- "ansible >= 2.9"
author: "Asis Bagga (@asisbagga)"
options:
state:
description:
- Indicates the desired state for the label 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 Label properties.
required: true
extends_documentation_fragment:
- oneview
- oneview.validateetag
'''

EXAMPLES = '''
- name: Create Labels for enclosure reosurces
oneview_label:
config: "{{ config }}"
state: present
data:
resourceUri: "/rest/enclosures/0000000000A66102"
labels:
- name: "Test label 1"
- name: "Test Label 2"
delegate_to: localhost
register: label
- debug: var=label
- name: Update label of given reosurce for enclosure reosurces
oneview_label:
config: "{{ config }}"
state: present
data:
resourceUri: "/rest/enclosures/0000000000A66102"
labels:
- name: "Test label 1 Renamed"
uri: null
- name: "Test label 2 Renamed"
uri: null
- name: "Test label 3"
uri: null
delegate_to: localhost
register: label
- debug: var=label
- name: Delete Labels for enclosure reosurces
oneview_label:
config: "{{ config }}"
state: absent
data:
resourceUri: "/rest/enclosures/0000000000A66102"
delegate_to: localhost
register: label
- debug: var=label
'''

RETURN = '''
label:
description: Has the facts about the OneView label.
returned: On state 'present'. Can be null.
type: dict
'''

from ansible.module_utils.oneview import OneViewModule


class LabelModule(OneViewModule):
MSG_CREATED = 'Label created successfully.'
MSG_UPDATED = 'Label updated successfully.'
MSG_DELETED = 'Label deleted successfully.'
MSG_ALREADY_PRESENT = 'Label is already present.'
MSG_ALREADY_ABSENT = 'Label is already absent.'
RESOURCE_FACT_NAME = 'Labels'

def __init__(self):
additional_arg_spec = dict(data=dict(required=True, type='dict'),
state=dict(required=True, choices=['present', 'absent']))
super(LabelModule, self).__init__(additional_arg_spec=additional_arg_spec, validate_etag_support=True)
self.resource_client = self.oneview_client.labels

def execute_module(self):
self.current_resource = None
if self.state == 'present':
return self._present()
elif self.state == 'absent':
self.current_resource = self.resource_client.get_by_resource(self.data.get('resourceUri'))
return self.resource_absent()

def _present(self):
if self.data.get('resourceUri'):
all_labels = self.resource_client.get_by_resource(self.data.get('resourceUri'))
if all_labels.data['labels']:
self.current_resource = all_labels
result = self.resource_present(self.RESOURCE_FACT_NAME)
return result


def main():
LabelModule().run()


if __name__ == '__main__':
main()
131 changes: 131 additions & 0 deletions library/oneview_label_facts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
###
# Copyright (2016-2021) Hewlett Packard Enterprise Development LP
#
# Licensed under the Apache License, Version 2.0 (the "License");
# You may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
###

ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['preview'],
'supported_by': 'community'}

DOCUMENTATION = '''
---
module: oneview_label_facts
short_description: Retrieve the facts about one or more of the OneView Labels.
description:
- Retrieve the facts about one or more of the Labels from OneView.
version_added: "2.4"
requirements:
- hpeOneView >= 5.4.0
author:
- Asis Bagga (@asisbagga)
options:
name:
description:
- Label name.
type: str
resourceUri:
description:
- Uri of the resource which labels are associated with.
type: str
extends_documentation_fragment:
- oneview
- oneview.factsparams
'''

EXAMPLES = '''
- name: Gather facts about all Labels
oneview_label_facts:
hostname: 172.16.101.48
username: administrator
password: my_password
api_version: 2600
delegate_to: localhost
- debug: var=labels
- name: Gather paginated, filtered and sorted facts about Labels
oneview_label_facts:
hostname: 172.16.101.48
username: administrator
password: my_password
api_version: 2600
params:
start: 0
count: 3
sort: 'name:descending'
filter: ''
- debug: var=labels
- name: Gather facts about a Label by name
oneview_label_facts:
hostname: 172.16.101.48
username: administrator
password: my_password
api_version: 2600
name: "{{ labels[0]['name'] }}"
delegate_to: localhost
- debug: var=labels
- name: Gather facts about a Label by Resource
oneview_label_facts:
hostname: 172.16.101.48
username: administrator
password: my_password
api_version: 2600
resourceUri: "/rest/enclosures/0000000000A66102"
delegate_to: localhost
- debug: var=labels
'''

RETURN = '''
labels:
description: Has all the OneView facts about the Labels.
returned: Always, but can be null.
type: dict
'''

from ansible.module_utils.oneview import OneViewModule


class LabelFactsModule(OneViewModule):
def __init__(self):
argument_spec = dict(
name=dict(required=False, type='str'),
resourceUri=dict(required=False, type='str'),
params=dict(required=False, type='dict')
)
super(LabelFactsModule, self).__init__(additional_arg_spec=argument_spec)
self.resource_client = self.oneview_client.labels

def execute_module(self):
if self.module.params['name']:
labels = self.resource_client.get_by('name', self.module.params['name'])
elif self.module.params.get('resourceUri'):
labels = self.oneview_client.labels.get_by_resource(self.module.params['resourceUri']).data
else:
labels = self.resource_client.get_all(**self.facts_params)
return dict(changed=False, ansible_facts=dict(labels=labels))


def main():
LabelFactsModule().run()


if __name__ == '__main__':
main()
Loading

0 comments on commit 2f2c1a3

Please sign in to comment.