Skip to content

Commit

Permalink
Added certificate server resource for API 800, 1000 and 1200
Browse files Browse the repository at this point in the history
  • Loading branch information
VenkateshRavula committed Apr 30, 2020
1 parent d72996d commit b20af33
Show file tree
Hide file tree
Showing 10 changed files with 734 additions and 1 deletion.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions endpoints-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@
| **Appliance Time and Locale Configuration** |
|<sub>/rest/appliance/configuration/time-locale</sub> |GET | :white_check_mark: |
|<sub>/rest/appliance/configuration/time-locale</sub> |POST | :white_check_mark: |
| **Certificates Server**
|<sub>/rest/certificates/servers</sub> |POST | :heavy_minus_sign: | :heavy_minus_sign: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
|<sub>/rest/certificates/https/remote/example.com</sub> |GET | :heavy_minus_sign: | :heavy_minus_sign: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
|<sub>/rest/certificates/servers/{aliasName}</sub> |GET | :heavy_minus_sign: | :heavy_minus_sign: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
|<sub>/rest/certificates/servers/{aliasName}</sub> |PUT | :heavy_minus_sign: | :heavy_minus_sign: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
|<sub>/rest/certificates/servers/{aliasName}</sub> |DELETE | :heavy_minus_sign: | :heavy_minus_sign: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| **Connection Templates** |
|<sub>/rest/connection-templates</sub> |GET | :white_check_mark: | :white_check_mark: | :white_check_mark: |
|<sub>/rest/connection-templates/defaultConnectionTemplate</sub> |GET | :white_check_mark: | :white_check_mark: | :white_check_mark: |
Expand Down
82 changes: 82 additions & 0 deletions examples/oneview_certificates_server.yml
Original file line number Diff line number Diff line change
@@ -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
35 changes: 35 additions & 0 deletions examples/oneview_certificates_server_facts.yml
Original file line number Diff line number Diff line change
@@ -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
141 changes: 141 additions & 0 deletions library/oneview_certificates_server.py
Original file line number Diff line number Diff line change
@@ -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()
110 changes: 110 additions & 0 deletions library/oneview_certificates_server_facts.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit b20af33

Please sign in to comment.