mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-05-03 15:51:30 -07:00
* openstack: standardize tls params * tower: tower_verify_ssl->validate_certs * docker: use standard tls config params - cacert_path -> ca_cert - cert_path -> client_cert - key_path -> client_key - tls_verify -> validate_certs * k8s: standardize tls connection params - verify_ssl -> validate_certs - ssl_ca_cert -> ca_cert - cert_file -> client_cert - key_file -> client_key * ingate: verify_ssl -> validate_certs * manageiq: standardize tls params - verify_ssl -> validate_certs - ca_bundle_path -> ca_cert * mysql: standardize tls params - ssl_ca -> ca_cert - ssl_cert -> client_cert - ssl_key -> client_key * nios: ssl_verify -> validate_certs * postgresql: ssl_rootcert -> ca_cert * rabbitmq: standardize tls params - cacert -> ca_cert - cert -> client_cert - key -> client_key * rackspace: verify_ssl -> validate_certs * vca: verify_certs -> validate_certs * kubevirt_cdi_upload: upload_host_verify_ssl -> upload_host_validate_certs * lxd: standardize tls params - key_file -> client_key - cert_file -> client_cert * get_certificate: ca_certs -> ca_cert * get_certificate.py: clarify one or more certs in a file Co-Authored-By: jamescassell <code@james.cassell.me> * zabbix: tls_issuer -> ca_cert * bigip_device_auth_ldap: standardize tls params - ssl_check_peer -> validate_certs - ssl_client_cert -> client_cert - ssl_client_key -> client_key - ssl_ca_cert -> ca_cert * vdirect: vdirect_validate_certs -> validate_certs * mqtt: standardize tls params - ca_certs -> ca_cert - certfile -> client_cert - keyfile -> client_key * pulp_repo: standardize tls params remove `importer_ssl` prefix * rhn_register: sslcacert -> ca_cert * yum_repository: standardize tls params The fix for yum_repository is not straightforward since this module is only a thin wrapper for the underlying commands and config. In this case, we add the new values as aliases, keeping the old as primary, only due to the internal structure of the module. Aliases added: - sslcacert -> ca_cert - sslclientcert -> client_cert - sslclientkey -> client_key - sslverify -> validate_certs * gitlab_hook: enable_ssl_verification -> hook_validate_certs * Adjust arguments for docker_swarm inventory plugin. * foreman callback: standardize tls params - ssl_cert -> client_cert - ssl_key -> client_key * grafana_annotations: validate_grafana_certs -> validate_certs * nrdp callback: validate_nrdp_certs -> validate_certs * kubectl connection: standardize tls params - kubectl_cert_file -> client_cert - kubectl_key_file -> client_key - kubectl_ssl_ca_cert -> ca_cert - kubectl_verify_ssl -> validate_certs * oc connection: standardize tls params - oc_cert_file -> client_cert - oc_key_file -> client_key - oc_ssl_ca_cert -> ca_cert - oc_verify_ssl -> validate_certs * psrp connection: cert_trust_path -> ca_cert TODO: cert_validation -> validate_certs (multi-valued vs bool) * k8s inventory: standardize tls params - cert_file -> client_cert - key_file -> client_key - ca_cert -> ca_cert - verify_ssl -> validate_certs * openshift inventory: standardize tls params - cert_file -> client_cert - key_file -> client_key - ca_cert -> ca_cert - verify_ssl -> validate_certs * tower inventory: verify_ssl -> validate_certs * hashi_vault lookup: cacert -> ca_cert * k8s lookup: standardize tls params - cert_file -> client_cert - key_file -> client_key - ca_cert -> ca_cert - verify_ssl -> validate_certs * laps_passord lookup: cacert_file -> ca_cert * changelog for TLS parameter standardization
178 lines
4.9 KiB
Python
178 lines
4.9 KiB
Python
#!/usr/bin/python
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# Copyright: (c) 2019, Ansible Project
|
|
# 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: kubevirt_cdi_upload
|
|
|
|
short_description: Upload local VM images to CDI Upload Proxy.
|
|
|
|
version_added: "2.8"
|
|
|
|
author: KubeVirt Team (@kubevirt)
|
|
|
|
|
|
description:
|
|
- Use Openshift Python SDK to create UploadTokenRequest objects.
|
|
- Transfer contents of local files to the CDI Upload Proxy.
|
|
|
|
options:
|
|
pvc_name:
|
|
description:
|
|
- Use to specify the name of the target PersistentVolumeClaim.
|
|
required: true
|
|
pvc_namespace:
|
|
description:
|
|
- Use to specify the namespace of the target PersistentVolumeClaim.
|
|
required: true
|
|
upload_host:
|
|
description:
|
|
- URL containing the host and port on which the CDI Upload Proxy is available.
|
|
- "More info: U(https://github.com/kubevirt/containerized-data-importer/blob/master/doc/upload.md#expose-cdi-uploadproxy-service)"
|
|
upload_host_validate_certs:
|
|
description:
|
|
- Whether or not to verify the CDI Upload Proxy's SSL certificates against your system's CA trust store.
|
|
default: true
|
|
type: bool
|
|
aliases: [ upload_host_verify_ssl ]
|
|
path:
|
|
description:
|
|
- Path of local image file to transfer.
|
|
merge_type:
|
|
description:
|
|
- Whether to override the default patch merge approach with a specific type. By default, the strategic
|
|
merge will typically be used.
|
|
type: list
|
|
choices: [ json, merge, strategic-merge ]
|
|
|
|
extends_documentation_fragment:
|
|
- k8s_auth_options
|
|
|
|
requirements:
|
|
- python >= 2.7
|
|
- openshift >= 0.8.2
|
|
- requests >= 2.0.0
|
|
'''
|
|
|
|
EXAMPLES = '''
|
|
- name: Upload local image to pvc-vm1
|
|
kubevirt_cdi_upload:
|
|
pvc_namespace: default
|
|
pvc_name: pvc-vm1
|
|
upload_host: https://localhost:8443
|
|
upload_host_validate_certs: false
|
|
path: /tmp/cirros-0.4.0-x86_64-disk.img
|
|
'''
|
|
|
|
RETURN = '''# '''
|
|
|
|
import copy
|
|
import traceback
|
|
|
|
from collections import defaultdict
|
|
|
|
from ansible.module_utils.k8s.common import AUTH_ARG_SPEC
|
|
from ansible.module_utils.k8s.raw import KubernetesRawModule
|
|
|
|
# 3rd party imports
|
|
try:
|
|
import requests
|
|
HAS_REQUESTS = True
|
|
except ImportError:
|
|
HAS_REQUESTS = False
|
|
|
|
|
|
SERVICE_ARG_SPEC = {
|
|
'pvc_name': {'required': True},
|
|
'pvc_namespace': {'required': True},
|
|
'upload_host': {'required': True},
|
|
'upload_host_validate_certs': {
|
|
'type': 'bool',
|
|
'default': True,
|
|
'aliases': ['upload_host_verify_ssl']
|
|
},
|
|
'path': {'required': True},
|
|
'merge_type': {
|
|
'type': 'list',
|
|
'choices': ['json', 'merge', 'strategic-merge']
|
|
},
|
|
}
|
|
|
|
|
|
class KubeVirtCDIUpload(KubernetesRawModule):
|
|
def __init__(self, *args, **kwargs):
|
|
super(KubeVirtCDIUpload, self).__init__(*args, k8s_kind='UploadTokenRequest', **kwargs)
|
|
|
|
if not HAS_REQUESTS:
|
|
self.fail("This module requires the python 'requests' package. Try `pip install requests`.")
|
|
|
|
@property
|
|
def argspec(self):
|
|
""" argspec property builder """
|
|
argument_spec = copy.deepcopy(AUTH_ARG_SPEC)
|
|
argument_spec.update(SERVICE_ARG_SPEC)
|
|
return argument_spec
|
|
|
|
def execute_module(self):
|
|
""" Module execution """
|
|
|
|
API = 'v1alpha1'
|
|
KIND = 'UploadTokenRequest'
|
|
|
|
self.client = self.get_api_client()
|
|
|
|
api_version = 'upload.cdi.kubevirt.io/{0}'.format(API)
|
|
pvc_name = self.params.get('pvc_name')
|
|
pvc_namespace = self.params.get('pvc_namespace')
|
|
upload_host = self.params.get('upload_host')
|
|
upload_host_verify_ssl = self.params.get('upload_host_validate_certs')
|
|
path = self.params.get('path')
|
|
|
|
definition = defaultdict(defaultdict)
|
|
|
|
definition['kind'] = KIND
|
|
definition['apiVersion'] = api_version
|
|
|
|
def_meta = definition['metadata']
|
|
def_meta['name'] = pvc_name
|
|
def_meta['namespace'] = pvc_namespace
|
|
|
|
def_spec = definition['spec']
|
|
def_spec['pvcName'] = pvc_name
|
|
|
|
# Let's check the file's there before we do anything else
|
|
imgfile = open(path, 'rb')
|
|
|
|
resource = self.find_resource(KIND, api_version, fail=True)
|
|
definition = self.set_defaults(resource, definition)
|
|
result = self.perform_action(resource, definition)
|
|
|
|
headers = {'Authorization': "Bearer {0}".format(result['result']['status']['token'])}
|
|
url = "{0}/{1}/upload".format(upload_host, API)
|
|
requests.post(url, data=imgfile, headers=headers, verify=upload_host_verify_ssl)
|
|
|
|
self.exit_json(changed=True)
|
|
|
|
|
|
def main():
|
|
module = KubeVirtCDIUpload()
|
|
try:
|
|
module.execute_module()
|
|
except Exception as e:
|
|
module.fail_json(msg=str(e), exception=traceback.format_exc())
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|