diff --git a/CHANGELOG.md b/CHANGELOG.md index 50d5cf9a8..38c74b287 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,9 +5,11 @@ This release extends the planned support of the modules to OneView REST API vers #### Major changes 1. Extended support of planned modules to API800/1000/1200. -2. Modules implemented in this release requires hpOneView version 5.1.0. +2. Modules implemented in this release requires hpOneView version 5.1.1. #### Modules supported in this release +- oneview_certificates_server +- oneview_certificates_server_facts - oneview_hypervisor_cluster_profile - oneview_hypervisor_cluster_profile_facts - oneview_hypervisor_manager diff --git a/endpoints-support.md b/endpoints-support.md index e4a0c0bcb..987b7f29a 100755 --- a/endpoints-support.md +++ b/endpoints-support.md @@ -52,6 +52,12 @@ | **Appliance Time and Locale Configuration** | |/rest/appliance/configuration/time-locale |GET | :white_check_mark: | |/rest/appliance/configuration/time-locale |POST | :white_check_mark: | +| **Certificates Server** +|/rest/certificates/servers |POST | :heavy_minus_sign: | :heavy_minus_sign: | :white_check_mark: | :white_check_mark: | :white_check_mark: | +|/rest/certificates/https/remote/example.com |GET | :heavy_minus_sign: | :heavy_minus_sign: | :white_check_mark: | :white_check_mark: | :white_check_mark: | +|/rest/certificates/servers/{aliasName} |GET | :heavy_minus_sign: | :heavy_minus_sign: | :white_check_mark: | :white_check_mark: | :white_check_mark: | +|/rest/certificates/servers/{aliasName} |PUT | :heavy_minus_sign: | :heavy_minus_sign: | :white_check_mark: | :white_check_mark: | :white_check_mark: | +|/rest/certificates/servers/{aliasName} |DELETE | :heavy_minus_sign: | :heavy_minus_sign: | :white_check_mark: | :white_check_mark: | :white_check_mark: | | **Connection Templates** | |/rest/connection-templates |GET | :white_check_mark: | :white_check_mark: | :white_check_mark: | |/rest/connection-templates/defaultConnectionTemplate |GET | :white_check_mark: | :white_check_mark: | :white_check_mark: | diff --git a/examples/oneview_certificates_server.yml b/examples/oneview_certificates_server.yml new file mode 100644 index 000000000..9f66f1351 --- /dev/null +++ b/examples/oneview_certificates_server.yml @@ -0,0 +1,82 @@ +### +# Copyright (2016-2020) 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" + remote_server: '172.18.13.11' + tasks: + - name: Gather facts about a Server Certificate by remote address + oneview_certificates_server_facts: + config: "{{ config }}" + remote: "{{ remote_server }}" + delegate_to: localhost + + - set_fact: + certificate: "{{ remote_certificate['certificateDetails'][0]['base64Data'] }}" + + - name: Create a Server Certificate + oneview_certificates_server: + config: "{{ config }}" + state: present + name: "{{ remote_server }}" + data: + certificateDetails: + - aliasName: "{{ remote_server }}" + base64Data: "{{ certificate }}" + delegate_to: localhost + register: svr_cert + + - name: Do nothing with the Server Certificate when no changes are provided + oneview_certificates_server: + config: "{{ config }}" + state: present + name: "{{ remote_server }}" + data: + certificateDetails: + - aliasName: "{{ remote_server }}" + base64Data: "{{ certificate }}" + delegate_to: localhost + + - name: Update the Server Certificate changing the attribute name + oneview_certificates_server: + config: "{{ config }}" + state: present + name: "{{ remote_server }}" + data: + name: "test" + certificateDetails: + - aliasName: "{{ remote_server }}" + base64Data: "{{ certificate }}" + delegate_to: localhost + + - name: Delete the Server Certificate + oneview_certificates_server: + config: "{{ config }}" + state: absent + name: "{{ remote_server }}" + data: "{{ svr_cert.ansible_facts.certificate_server }}" + delegate_to: localhost + register: deleted + + - name: Do nothing when Server Certificate is absent + oneview_certificates_server: + config: "{{ config }}" + state: absent + name: "{{ remote_server }}" + data: "{{ svr_cert.ansible_facts.certificate_server }}" + delegate_to: localhost + register: deleted diff --git a/examples/oneview_certificates_server_facts.yml b/examples/oneview_certificates_server_facts.yml new file mode 100644 index 000000000..cae33d18e --- /dev/null +++ b/examples/oneview_certificates_server_facts.yml @@ -0,0 +1,35 @@ +### +# Copyright (2016-2020) 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 a Server Certificate by remote address + oneview_certificates_server_facts: + config: "{{ config }}" + remote: "172.18.13.11" + delegate_to: localhost + + - debug: var=remote_certificate['certificateDetails'][0]['base64Data'] + + - name: Gather facts about a Server Certificate by alias_name + oneview_certificates_server_facts: + config: "{{ config }}" + aliasName: "172.18.13.11" + delegate_to: localhost + + - debug: var=certificates_server diff --git a/library/oneview_certificates_server.py b/library/oneview_certificates_server.py new file mode 100644 index 000000000..7e556cd08 --- /dev/null +++ b/library/oneview_certificates_server.py @@ -0,0 +1,141 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +### +# Copyright (2016-2020) 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_certificates_server +short_description: Manage OneView Server Certificate resources. +description: + - Provides an interface to manage Server Certificate resources. Can create, update, and delete. +version_added: "2.4" +requirements: + - "python >= 3.4.2" + - "hpOneView >= 5.1.1" +author: "Venkatesh Ravula (@VenkateshRavula)" +options: + state: + description: + - Indicates the desired state for the Server Certificate 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 Server Certificate properties. + required: true + +extends_documentation_fragment: + - oneview + - oneview.validateetag +''' + +EXAMPLES = ''' +- name: Create a Server Certificate + oneview_certificates_server: + hostname: 172.16.101.48 + username: administrator + password: my_password + api_version: 1200 + state: present + name: "172.18.13.11" + data: + certificateDetails: + - aliasName: 'vcenter' + base64Data: '--- Certificate ---' + +- name: Update the Server Certificate name to 'vcenter Renamed' + oneview_certificates_server: + hostname: 172.16.101.48 + username: administrator + password: my_password + api_version: 1200 + state: present + name: "172.18.13.11" + data: + name: 'vcenter renamed' + certificateDetails: + - aliasName: 'vcenter' + base64Data: '--- Certificate ---' + +- name: Ensure that the Hypervisor Manager is absent + oneview_certificates_server: + hostname: 172.16.101.48 + username: administrator + password: my_password + api_version: 1200 + state: absent + name: "172.18.13.11" + data: + alias_name: 'vcenter' +''' + +RETURN = ''' +certificate_server: + description: Has the facts about the managed OneView Hypervisor Manager. + returned: On state 'present'. Can be null. + type: dict +''' + +from ansible.module_utils.oneview import OneViewModule + + +class CertificatesServerModule(OneViewModule): + MSG_CREATED = 'Server Certificate created successfully.' + MSG_UPDATED = 'Server Certificate updated successfully.' + MSG_DELETED = 'Server Certificate deleted successfully.' + MSG_ALREADY_PRESENT = 'Server Certificate is already present.' + MSG_ALREADY_ABSENT = 'Server Certificate is already absent.' + RESOURCE_FACT_NAME = 'certificate_server' + + def __init__(self): + additional_arg_spec = dict(data=dict(required=True, type='dict'), + name=dict(required=False, type='str'), + state=dict( + required=True, + choices=['present', 'absent'])) + + super(CertificatesServerModule, self).__init__(additional_arg_spec=additional_arg_spec, validate_etag_support=True) + self.__set_current_resource(self.oneview_client.certificates_server) + + def execute_module(self): + if self.state == 'present': + return self.resource_present(self.RESOURCE_FACT_NAME) + elif self.state == 'absent': + return self.resource_absent() + + def __set_current_resource(self, resource_client): + self.resource_client = resource_client + aliasname = None + + if self.module.params.get('name'): + aliasname = self.module.params['name'] + + if self.resource_client.get_by_alias_name(aliasname): + self.current_resource = self.resource_client.get_by_alias_name(aliasname) + + +def main(): + CertificatesServerModule().run() + + +if __name__ == '__main__': + main() diff --git a/library/oneview_certificates_server_facts.py b/library/oneview_certificates_server_facts.py new file mode 100644 index 000000000..51ddba86a --- /dev/null +++ b/library/oneview_certificates_server_facts.py @@ -0,0 +1,110 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +### +# Copyright (2016-2020) 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_certificates_server_facts +short_description: Retrieve the facts about one or more of the OneView Server Certificates +description: + - Retrieve the facts about one or more of the Server Certificates from OneView. +version_added: "2.4" +requirements: + - "python >= 3.4.2" + - hpOneView >= 5.1.1 +author: "Venkatesh Ravula (@VenkateshRavula)" +options: + alias_name: + description: + - Server Certificate aliasname. + +extends_documentation_fragment: + - oneview + - oneview.factsparams +''' + +EXAMPLES = ''' +- name: Gather facts about a Server Certificate by remote address + oneview_certificates_server_facts: + hostname: 172.16.101.48 + username: administrator + password: my_password + api_version: 1200 + remote: "172.18.13.11" + delegate_to: localhost + +- debug: var=remote_certificate['certificateDetails'][0]['base64Data'] + +- name: Gather facts about a Server Certificate by alias_name + oneview_certificates_server_facts: + hostname: 172.16.101.48 + username: administrator + password: my_password + api_version: 1200 + aliasName: "172.18.13.11" + delegate_to: localhost + +- debug: var=certificate +''' + +RETURN = ''' +certificate_server: + description: Has all the OneView facts about the Server Certificates. + returned: Always, but can be null. + type: dict +''' + +from ansible.module_utils.oneview import OneViewModule + + +class CertificatesServerFactsModule(OneViewModule): + def __init__(self): + + argument_spec = dict( + remote=dict(required=False, type='str'), + aliasName=dict(required=False, type='str'), + ) + + super(CertificatesServerFactsModule, self).__init__(additional_arg_spec=argument_spec) + self.resource_client = self.oneview_client.certificates_server + + def execute_module(self): + ansible_facts = {} + + if self.module.params.get('aliasName'): + aliasname = self.module.params['aliasName'] + certificates_server = self.resource_client.get_by_alias_name(aliasname) + ansible_facts['certificates_server'] = certificates_server.data if certificates_server else None + + elif self.module.params.get('remote'): + remote_address = self.module.params['remote'] + remote_cert = self.resource_client.get_remote(remote_address) + ansible_facts['remote_certificate'] = remote_cert.data + + return dict(changed=False, ansible_facts=ansible_facts) + + +def main(): + CertificatesServerFactsModule().run() + + +if __name__ == '__main__': + main() diff --git a/oneview-ansible.md b/oneview-ansible.md index c087b4177..880d9d838 100644 --- a/oneview-ansible.md +++ b/oneview-ansible.md @@ -27,6 +27,8 @@ * [oneview_appliance_device_snmp_v3_users_facts - Retrieve the facts about the OneView appliance SNMPv3 users.](#oneview_appliance_device_snmp_v3_users_facts) * [oneview_appliance_time_and_locale_configuration - Manage OneView Appliance Locale and Time Configuration.](#oneview_appliance_time_and_locale_configuration) * [oneview_appliance_time_and_locale_configuration_facts - Retrieve the facts about the OneView appliance time and locale configuration.](#oneview_appliance_time_and_locale_configuration_facts) + * [oneview_certificates_server - Manage OneView Certificates Server resources.](#oneview_certificates_server) + * [oneview_certificates_server_facts - Retrieve the facts about one or more of the OneView Certificates Server.](#oneview_certificates_server_facts) * [oneview_connection_template - Manage the OneView Connection Template resources.](#oneview_connection_template) * [oneview_connection_template_facts - Retrieve facts about the OneView Connection Templates.](#oneview_connection_template_facts) * [oneview_datacenter - Manage OneView Data Center resources.](#oneview_datacenter) @@ -2270,6 +2272,157 @@ Retrieve the facts about the OneView appliance time and locale configuration. --- +## oneview_certificates_server +Manage OneView Certificates Server resources. + +#### Synopsis + Provides an interface to manage Certificates Server resources. Can create, update, or delete. + +#### Requirements (on the host that executes the module) + * hpOneView >= 5.1.1 + * python >= 3.4.2 + +#### Options + +| Parameter | Required | Default | Choices | Comments | +| ------------- |-------------| ---------|----------- |--------- | +| config | | | | Path to a .json configuration file containing the OneView client configuration. The configuration file is optional and when used should be present in the host running the ansible commands. If the file path is not provided, the configuration will be loaded from environment variables. For links to example configuration files or how to use the environment variables verify the notes section. | +| data | Yes | | | List with the Certificates Server properties. | +| state | | |