1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00
community.general/plugins/modules/cloud/memset/memset_memstore_info.py

170 lines
4.6 KiB
Python
Raw Normal View History

2020-03-09 10:11:07 +01:00
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Copyright (c) 2018, Simon Weald <ansible@simonweald.com>
# 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
DOCUMENTATION = '''
---
module: memset_memstore_info
author: "Simon Weald (@glitchcrab)"
short_description: Retrieve Memstore product usage information.
notes:
- An API key generated via the Memset customer control panel is needed with the
following minimum scope - I(memstore.usage).
description:
- Retrieve Memstore product usage information.
- This module was called C(memset_memstore_facts) before Ansible 2.9. The usage did not change.
options:
api_key:
required: true
Tidy up validate-modules ignores for some cloud/ modules (#1354) * fixed validation-modules for plugins/modules/cloud/atomic/atomic_container.py * fixed validation-modules for plugins/modules/cloud/oracle/oci_vcn.py * fixed validation-modules for plugins/modules/cloud/heroku/heroku_collaborator.py * fixed validation-modules for plugins/modules/cloud/docker/docker_stack.py * fixed validation-modules for plugins/modules/cloud/pubnub/pubnub_blocks.py * fixed validation-modules for plugins/modules/cloud/huawei/hwc_ecs_instance.py * fixed validation-modules for plugins/modules/cloud/huawei/hwc_vpc_port.py * fixed validation-modules for plugins/modules/cloud/huawei/hwc_vpc_subnet.py * fixed validation-modules for plugins/modules/cloud/ovh/ovh_ip_failover.py * fixed validation-modules for plugins/modules/cloud/ovh/ovh_ip_loadbalancing_backend.py * fixed validation-modules for plugins/modules/cloud/softlayer/sl_vm.py * fixed validation-modules for plugins/modules/cloud/misc/proxmox_kvm.py * fixed validation-modules for plugins/modules/cloud/misc/proxmox_template.py * fixed validation-modules for plugins/modules/cloud/misc/terraform.py * fixed validation-modules for plugins/modules/cloud/memset/memset_dns_reload.py * fixed validation-modules for plugins/modules/cloud/memset/memset_memstore_info.py * fixed validation-modules for plugins/modules/cloud/memset/memset_server_info.py * fixed validation-modules for plugins/modules/cloud/memset/memset_zone_domain.py * fixed validation-modules for plugins/modules/cloud/memset/memset_zone.py * fixed validation-modules for plugins/modules/cloud/memset/memset_zone_record.py * fixed validation-modules for plugins/modules/cloud/linode/linode.py * fixed validation-modules for plugins/modules/cloud/linode/linode_v4.py * fixed validation-modules for plugins/doc_fragments/dimensiondata.py * fixed validation-modules for plugins/modules/cloud/dimensiondata/dimensiondata_network.py * fixed validation-modules for plugins/modules/cloud/dimensiondata/dimensiondata_vlan.py * fixed validation-modules for plugins/modules/cloud/xenserver/xenserver_guest_info.py * fixed validation-modules for plugins/modules/cloud/xenserver/xenserver_guest_powerstate.py * Tidy up validate-modules ignores for varied cloud modules - loking at the count of ignore lines, worked from the lower numbers up * rolled back line for docker_container, removed two extraneous for xenserver * rolled back lins for linode in 2.9
2020-11-23 09:22:30 +01:00
type: str
2020-03-09 10:11:07 +01:00
description:
- The API key obtained from the Memset control panel.
name:
required: true
Tidy up validate-modules ignores for some cloud/ modules (#1354) * fixed validation-modules for plugins/modules/cloud/atomic/atomic_container.py * fixed validation-modules for plugins/modules/cloud/oracle/oci_vcn.py * fixed validation-modules for plugins/modules/cloud/heroku/heroku_collaborator.py * fixed validation-modules for plugins/modules/cloud/docker/docker_stack.py * fixed validation-modules for plugins/modules/cloud/pubnub/pubnub_blocks.py * fixed validation-modules for plugins/modules/cloud/huawei/hwc_ecs_instance.py * fixed validation-modules for plugins/modules/cloud/huawei/hwc_vpc_port.py * fixed validation-modules for plugins/modules/cloud/huawei/hwc_vpc_subnet.py * fixed validation-modules for plugins/modules/cloud/ovh/ovh_ip_failover.py * fixed validation-modules for plugins/modules/cloud/ovh/ovh_ip_loadbalancing_backend.py * fixed validation-modules for plugins/modules/cloud/softlayer/sl_vm.py * fixed validation-modules for plugins/modules/cloud/misc/proxmox_kvm.py * fixed validation-modules for plugins/modules/cloud/misc/proxmox_template.py * fixed validation-modules for plugins/modules/cloud/misc/terraform.py * fixed validation-modules for plugins/modules/cloud/memset/memset_dns_reload.py * fixed validation-modules for plugins/modules/cloud/memset/memset_memstore_info.py * fixed validation-modules for plugins/modules/cloud/memset/memset_server_info.py * fixed validation-modules for plugins/modules/cloud/memset/memset_zone_domain.py * fixed validation-modules for plugins/modules/cloud/memset/memset_zone.py * fixed validation-modules for plugins/modules/cloud/memset/memset_zone_record.py * fixed validation-modules for plugins/modules/cloud/linode/linode.py * fixed validation-modules for plugins/modules/cloud/linode/linode_v4.py * fixed validation-modules for plugins/doc_fragments/dimensiondata.py * fixed validation-modules for plugins/modules/cloud/dimensiondata/dimensiondata_network.py * fixed validation-modules for plugins/modules/cloud/dimensiondata/dimensiondata_vlan.py * fixed validation-modules for plugins/modules/cloud/xenserver/xenserver_guest_info.py * fixed validation-modules for plugins/modules/cloud/xenserver/xenserver_guest_powerstate.py * Tidy up validate-modules ignores for varied cloud modules - loking at the count of ignore lines, worked from the lower numbers up * rolled back line for docker_container, removed two extraneous for xenserver * rolled back lins for linode in 2.9
2020-11-23 09:22:30 +01:00
type: str
2020-03-09 10:11:07 +01:00
description:
- The Memstore product name (i.e. C(mstestyaa1)).
'''
EXAMPLES = '''
2020-05-16 15:07:51 +02:00
- name: Get usage for mstestyaa1
community.general.memset_memstore_info:
2020-03-09 10:11:07 +01:00
name: mstestyaa1
api_key: 5eb86c9896ab03919abcf03857163741
delegate_to: localhost
'''
RETURN = '''
---
memset_api:
description: Info from the Memset API
returned: always
type: complex
contains:
cdn_bandwidth:
description: Dictionary of CDN bandwidth facts
returned: always
type: complex
contains:
bytes_out:
description: Outbound CDN bandwidth for the last 24 hours in bytes
returned: always
type: int
sample: 1000
requests:
description: Number of requests in the last 24 hours
returned: always
type: int
sample: 10
bytes_in:
description: Inbound CDN bandwidth for the last 24 hours in bytes
returned: always
type: int
sample: 1000
containers:
description: Number of containers
returned: always
type: int
sample: 10
bytes:
description: Space used in bytes
returned: always
type: int
sample: 3860997965
objs:
description: Number of objects
returned: always
type: int
sample: 1000
bandwidth:
description: Dictionary of CDN bandwidth facts
returned: always
type: complex
contains:
bytes_out:
description: Outbound bandwidth for the last 24 hours in bytes
returned: always
type: int
sample: 1000
requests:
description: Number of requests in the last 24 hours
returned: always
type: int
sample: 10
bytes_in:
description: Inbound bandwidth for the last 24 hours in bytes
returned: always
type: int
sample: 1000
'''
from ansible.module_utils.basic import AnsibleModule
from ansible_collections.community.general.plugins.module_utils.memset import memset_api_call
def get_facts(args=None):
'''
Performs a simple API call and returns a JSON blob.
'''
retvals, payload = dict(), dict()
has_changed, has_failed = False, False
msg, stderr, memset_api = None, None, None
payload['name'] = args['name']
api_method = 'memstore.usage'
has_failed, msg, response = memset_api_call(api_key=args['api_key'], api_method=api_method, payload=payload)
if has_failed:
# this is the first time the API is called; incorrect credentials will
# manifest themselves at this point so we need to ensure the user is
# informed of the reason.
retvals['failed'] = has_failed
retvals['msg'] = msg
retvals['stderr'] = "API returned an error: {0}" . format(response.status_code)
return retvals
2020-03-09 10:11:07 +01:00
# we don't want to return the same thing twice
msg = None
memset_api = response.json()
retvals['changed'] = has_changed
retvals['failed'] = has_failed
for val in ['msg', 'memset_api']:
if val is not None:
retvals[val] = eval(val)
return retvals
2020-03-09 10:11:07 +01:00
def main():
global module
module = AnsibleModule(
argument_spec=dict(
api_key=dict(required=True, type='str', no_log=True),
name=dict(required=True, type='str')
),
supports_check_mode=True,
2020-03-09 10:11:07 +01:00
)
# populate the dict with the user-provided vars.
args = dict()
for key, arg in module.params.items():
args[key] = arg
retvals = get_facts(args)
if retvals['failed']:
module.fail_json(**retvals)
else:
module.exit_json(**retvals)
if __name__ == '__main__':
main()