-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #498 from HewlettPackard/Certificate_server
Added certificate server resource for API 800, 1000 and 1200
- Loading branch information
Showing
10 changed files
with
734 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Oops, something went wrong.