gce: PEP8 compliancy Fixes (#32311)
* gce: PEP8 compliancy Fixes * Documentation updates * Documentation updates * Documentation update
This commit is contained in:
parent
6ddc7c8524
commit
585ecc2867
4 changed files with 196 additions and 215 deletions
|
@ -1,17 +1,16 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
#
|
# -*- coding: utf-8 -*-
|
||||||
# Copyright: Ansible Project
|
|
||||||
|
# Copyright: (c) 2017, Ansible Project
|
||||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
# 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
|
from __future__ import absolute_import, division, print_function
|
||||||
__metaclass__ = type
|
__metaclass__ = type
|
||||||
|
|
||||||
|
|
||||||
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
||||||
'status': ['preview'],
|
'status': ['preview'],
|
||||||
'supported_by': 'community'}
|
'supported_by': 'community'}
|
||||||
|
|
||||||
|
|
||||||
DOCUMENTATION = '''
|
DOCUMENTATION = '''
|
||||||
---
|
---
|
||||||
module: gce_tag
|
module: gce_tag
|
||||||
|
@ -19,64 +18,43 @@ version_added: "2.0"
|
||||||
short_description: add or remove tag(s) to/from GCE instances
|
short_description: add or remove tag(s) to/from GCE instances
|
||||||
description:
|
description:
|
||||||
- This module can add or remove tags U(https://cloud.google.com/compute/docs/label-or-tag-resources#tags)
|
- This module can add or remove tags U(https://cloud.google.com/compute/docs/label-or-tag-resources#tags)
|
||||||
to/from GCE instances. Use 'instance_pattern' to update multiple instances in a specify zone
|
to/from GCE instances. Use 'instance_pattern' to update multiple instances in a specify zone.
|
||||||
options:
|
options:
|
||||||
instance_name:
|
instance_name:
|
||||||
description:
|
description:
|
||||||
- The name of the GCE instance to add/remove tags. Required if instance_pattern is not specified.
|
- The name of the GCE instance to add/remove tags.
|
||||||
required: false
|
- Required if C(instance_pattern) is not specified.
|
||||||
default: null
|
|
||||||
aliases: []
|
|
||||||
instance_pattern:
|
instance_pattern:
|
||||||
description:
|
description:
|
||||||
- The pattern of GCE instance names to match for adding/removing tags. Full-Python regex is supported.
|
- The pattern of GCE instance names to match for adding/removing tags. Full-Python regex is supported.
|
||||||
See U(https://docs.python.org/2/library/re.html) for details.
|
See U(https://docs.python.org/2/library/re.html) for details.
|
||||||
If instance_name is not specified, this field is required.
|
- If C(instance_name) is not specified, this field is required.
|
||||||
required: false
|
|
||||||
default: null
|
|
||||||
aliases: []
|
|
||||||
version_added: "2.3"
|
version_added: "2.3"
|
||||||
tags:
|
tags:
|
||||||
description:
|
description:
|
||||||
- comma-separated list of tags to add or remove
|
- Comma-separated list of tags to add or remove.
|
||||||
required: true
|
required: yes
|
||||||
default: null
|
|
||||||
aliases: []
|
|
||||||
state:
|
state:
|
||||||
description:
|
description:
|
||||||
- desired state of the tags
|
- Desired state of the tags.
|
||||||
required: false
|
choices: [ absent, present ]
|
||||||
default: "present"
|
default: present
|
||||||
choices: ["present", "absent"]
|
|
||||||
aliases: []
|
|
||||||
zone:
|
zone:
|
||||||
description:
|
description:
|
||||||
- the zone of the disk specified by source
|
- The zone of the disk specified by source.
|
||||||
required: false
|
default: us-central1-a
|
||||||
default: "us-central1-a"
|
|
||||||
aliases: []
|
|
||||||
service_account_email:
|
service_account_email:
|
||||||
description:
|
description:
|
||||||
- service account email
|
- Service account email.
|
||||||
required: false
|
|
||||||
default: null
|
|
||||||
aliases: []
|
|
||||||
pem_file:
|
pem_file:
|
||||||
description:
|
description:
|
||||||
- path to the pem file associated with the service account email
|
- Path to the PEM file associated with the service account email.
|
||||||
required: false
|
|
||||||
default: null
|
|
||||||
aliases: []
|
|
||||||
project_id:
|
project_id:
|
||||||
description:
|
description:
|
||||||
- your GCE project ID
|
- Your GCE project ID.
|
||||||
required: false
|
|
||||||
default: null
|
|
||||||
aliases: []
|
|
||||||
|
|
||||||
requirements:
|
requirements:
|
||||||
- "python >= 2.6"
|
- python >= 2.6
|
||||||
- "apache-libcloud >= 0.17.0"
|
- apache-libcloud >= 0.17.0
|
||||||
notes:
|
notes:
|
||||||
- Either I(instance_name) or I(instance_pattern) is required.
|
- Either I(instance_name) or I(instance_pattern) is required.
|
||||||
author:
|
author:
|
||||||
|
@ -85,27 +63,27 @@ author:
|
||||||
'''
|
'''
|
||||||
|
|
||||||
EXAMPLES = '''
|
EXAMPLES = '''
|
||||||
# Add tags 'http-server', 'https-server', 'staging' to instance name 'staging-server' in zone us-central1-a.
|
- name: Add tags to instance
|
||||||
- gce_tag:
|
gce_tag:
|
||||||
instance_name: staging-server
|
instance_name: staging-server
|
||||||
tags: http-server,https-server,staging
|
tags: http-server,https-server,staging
|
||||||
zone: us-central1-a
|
zone: us-central1-a
|
||||||
state: present
|
state: present
|
||||||
|
|
||||||
# Remove tags 'foo', 'bar' from instance 'test-server' in default zone (us-central1-a)
|
- name: Remove tags from instance in default zone (us-central1-a)
|
||||||
- gce_tag:
|
gce_tag:
|
||||||
instance_name: test-server
|
instance_name: test-server
|
||||||
tags: foo,bar
|
tags: foo,bar
|
||||||
state: absent
|
state: absent
|
||||||
|
|
||||||
# Add tags 'foo', 'bar' to instances in zone that match pattern
|
- name: Add tags to instances in zone that match pattern
|
||||||
- gce_tag:
|
gce_tag:
|
||||||
instance_pattern: test-server-*
|
instance_pattern: test-server-*
|
||||||
tags: foo,bar
|
tags: foo,bar
|
||||||
zone: us-central1-a
|
zone: us-central1-a
|
||||||
state: present
|
state: present
|
||||||
|
|
||||||
'''
|
'''
|
||||||
|
|
||||||
import re
|
import re
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
|
@ -128,14 +106,17 @@ def _union_items(baselist, comparelist):
|
||||||
"""Combine two lists, removing duplicates."""
|
"""Combine two lists, removing duplicates."""
|
||||||
return list(set(baselist) | set(comparelist))
|
return list(set(baselist) | set(comparelist))
|
||||||
|
|
||||||
|
|
||||||
def _intersect_items(baselist, comparelist):
|
def _intersect_items(baselist, comparelist):
|
||||||
"""Return matching items in both lists."""
|
"""Return matching items in both lists."""
|
||||||
return list(set(baselist) & set(comparelist))
|
return list(set(baselist) & set(comparelist))
|
||||||
|
|
||||||
|
|
||||||
def _get_changed_items(baselist, comparelist):
|
def _get_changed_items(baselist, comparelist):
|
||||||
"""Return changed items as they relate to baselist."""
|
"""Return changed items as they relate to baselist."""
|
||||||
return list(set(baselist) & set(set(baselist) ^ set(comparelist)))
|
return list(set(baselist) & set(set(baselist) ^ set(comparelist)))
|
||||||
|
|
||||||
|
|
||||||
def modify_tags(gce, module, node, tags, state='present'):
|
def modify_tags(gce, module, node, tags, state='present'):
|
||||||
"""Modify tags on an instance."""
|
"""Modify tags on an instance."""
|
||||||
|
|
||||||
|
@ -164,24 +145,25 @@ def modify_tags(gce, module, node, tags, state='present'):
|
||||||
except (GoogleBaseError, InvalidRequestError) as e:
|
except (GoogleBaseError, InvalidRequestError) as e:
|
||||||
module.fail_json(msg=str(e), changed=False)
|
module.fail_json(msg=str(e), changed=False)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
module = AnsibleModule(
|
module = AnsibleModule(
|
||||||
argument_spec=dict(
|
argument_spec=dict(
|
||||||
instance_name=dict(required=False),
|
instance_name=dict(type='str'),
|
||||||
instance_pattern=dict(required=False),
|
instance_pattern=dict(type='str'),
|
||||||
tags=dict(type='list', required=True),
|
tags=dict(type='list', required=True),
|
||||||
state=dict(default='present', choices=['present', 'absent']),
|
state=dict(type='str', default='present', choices=['absent', 'present']),
|
||||||
zone=dict(default='us-central1-a'),
|
zone=dict(type='str', default='us-central1-a'),
|
||||||
service_account_email=dict(),
|
service_account_email=dict(type='str'),
|
||||||
pem_file=dict(type='path'),
|
pem_file=dict(type='path'),
|
||||||
project_id=dict(),
|
project_id=dict(type='str'),
|
||||||
),
|
),
|
||||||
mutually_exclusive=[
|
mutually_exclusive=[
|
||||||
[ 'instance_name', 'instance_pattern' ]
|
['instance_name', 'instance_pattern']
|
||||||
],
|
],
|
||||||
required_one_of=[
|
required_one_of=[
|
||||||
[ 'instance_name', 'instance_pattern' ]
|
['instance_name', 'instance_pattern']
|
||||||
]
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
instance_name = module.params.get('instance_name')
|
instance_name = module.params.get('instance_name')
|
||||||
|
|
|
@ -1,49 +1,46 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
# Copyright 2016 Google Inc.
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
# Copyright: (c) 2016, Google Inc.
|
||||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
# 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
|
from __future__ import absolute_import, division, print_function
|
||||||
__metaclass__ = type
|
__metaclass__ = type
|
||||||
|
|
||||||
|
|
||||||
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
||||||
'status': ['preview'],
|
'status': ['preview'],
|
||||||
'supported_by': 'community'}
|
'supported_by': 'community'}
|
||||||
|
|
||||||
|
|
||||||
DOCUMENTATION = '''
|
DOCUMENTATION = '''
|
||||||
---
|
---
|
||||||
module: gcpubsub
|
module: gcpubsub
|
||||||
version_added: "2.3"
|
version_added: "2.3"
|
||||||
short_description: Create and Delete Topics/Subscriptions, Publish and pull messages on PubSub.
|
short_description: Create and Delete Topics/Subscriptions, Publish and pull messages on PubSub
|
||||||
description:
|
description:
|
||||||
- Create and Delete Topics/Subscriptions, Publish and pull messages on PubSub.
|
- Create and Delete Topics/Subscriptions, Publish and pull messages on PubSub.
|
||||||
See U(https://cloud.google.com/pubsub/docs) for an overview.
|
See U(https://cloud.google.com/pubsub/docs) for an overview.
|
||||||
requirements:
|
requirements:
|
||||||
- "python >= 2.6"
|
- google-auth >= 0.5.0
|
||||||
- "google-auth >= 0.5.0"
|
- google-cloud-pubsub >= 0.22.0
|
||||||
- "google-cloud-pubsub >= 0.22.0"
|
|
||||||
notes:
|
notes:
|
||||||
- Subscription pull happens before publish. You cannot publish and pull in the same task.
|
- Subscription pull happens before publish. You cannot publish and pull in the same task.
|
||||||
author:
|
author:
|
||||||
- "Tom Melendez (@supertom) <tom@supertom.com>"
|
- Tom Melendez (@supertom) <tom@supertom.com>
|
||||||
options:
|
options:
|
||||||
topic:
|
topic:
|
||||||
description:
|
description:
|
||||||
- GCP pubsub topic name. Only the name, not the full path, is required.
|
- GCP pubsub topic name.
|
||||||
required: True
|
- Only the name, not the full path, is required.
|
||||||
|
required: yes
|
||||||
subscription:
|
subscription:
|
||||||
description:
|
description:
|
||||||
- Dictionary containing a subscripton name associated with a topic (required), along with optional ack_deadline, push_endpoint and pull.
|
- Dictionary containing a subscripton name associated with a topic (required), along with optional ack_deadline, push_endpoint and pull.
|
||||||
For pulling from a subscription, message_ack (bool), max_messages (int) and return_immediate are available as subfields.
|
For pulling from a subscription, message_ack (bool), max_messages (int) and return_immediate are available as subfields.
|
||||||
See subfields name, push_endpoint and ack_deadline for more information.
|
See subfields name, push_endpoint and ack_deadline for more information.
|
||||||
required: False
|
|
||||||
name:
|
name:
|
||||||
description: Subfield of subscription. Required if subscription is specified. See examples.
|
description: Subfield of subscription. Required if subscription is specified. See examples.
|
||||||
required: False
|
|
||||||
ack_deadline:
|
ack_deadline:
|
||||||
description: Subfield of subscription. Not required. Default deadline for subscriptions to ACK the message before it is resent. See examples.
|
description: Subfield of subscription. Not required. Default deadline for subscriptions to ACK the message before it is resent. See examples.
|
||||||
required: False
|
|
||||||
pull:
|
pull:
|
||||||
description:
|
description:
|
||||||
- Subfield of subscription. Not required. If specified, messages will be retrieved from topic via the provided subscription name.
|
- Subfield of subscription. Not required. If specified, messages will be retrieved from topic via the provided subscription name.
|
||||||
|
@ -53,63 +50,61 @@ options:
|
||||||
description:
|
description:
|
||||||
- Subfield of subscription. Not required. If specified, message will be sent to an endpoint.
|
- Subfield of subscription. Not required. If specified, message will be sent to an endpoint.
|
||||||
See U(https://cloud.google.com/pubsub/docs/advanced#push_endpoints) for more information.
|
See U(https://cloud.google.com/pubsub/docs/advanced#push_endpoints) for more information.
|
||||||
required: False
|
|
||||||
publish:
|
publish:
|
||||||
description:
|
description:
|
||||||
- List of dictionaries describing messages and attributes to be published. Dictionary is in message(str):attributes(dict) format.
|
- List of dictionaries describing messages and attributes to be published. Dictionary is in message(str):attributes(dict) format.
|
||||||
Only message is required.
|
Only message is required.
|
||||||
required: False
|
|
||||||
state:
|
state:
|
||||||
description:
|
description:
|
||||||
- State of the topic or queue (absent, present). Applies to the most granular resource. Remove the most granular resource. If subcription is
|
- State of the topic or queue.
|
||||||
specified we remove it. If only topic is specified, that is what is removed. Note that a topic can be removed without first removing the
|
- Applies to the most granular resource.
|
||||||
subscription.
|
- If subscription isspecified we remove it.
|
||||||
required: False
|
- If only topic is specified, that is what is removed.
|
||||||
default: "present"
|
- NOTE - A topic can be removed without first removing the subscription.
|
||||||
|
choices: [ absent, present ]
|
||||||
|
default: present
|
||||||
'''
|
'''
|
||||||
|
|
||||||
EXAMPLES = '''
|
EXAMPLES = '''
|
||||||
# Create a topic and publish a message to it
|
|
||||||
# (Message will be pushed; there is no check to see if the message was pushed before
|
# (Message will be pushed; there is no check to see if the message was pushed before
|
||||||
# Topics:
|
- name: Create a topic and publish a message to it
|
||||||
## Create Topic
|
gcpubsub:
|
||||||
gcpubsub:
|
|
||||||
topic: ansible-topic-example
|
topic: ansible-topic-example
|
||||||
state: present
|
state: present
|
||||||
|
|
||||||
## Delete Topic
|
# Subscriptions associated with topic are not deleted.
|
||||||
### Subscriptions associated with topic are not deleted.
|
- name: Delete Topic
|
||||||
gcpubsub:
|
gcpubsub:
|
||||||
topic: ansible-topic-example
|
topic: ansible-topic-example
|
||||||
state: absent
|
state: absent
|
||||||
|
|
||||||
## Messages: publish multiple messages, with attributes (key:value available with the message)
|
# Setting absent will keep the messages from being sent
|
||||||
### setting absent will keep the messages from being sent
|
- name: Publish multiple messages, with attributes (key:value available with the message)
|
||||||
gcpubsub:
|
gcpubsub:
|
||||||
topic: "{{ topic_name }}"
|
topic: '{{ topic_name }}'
|
||||||
state: present
|
state: present
|
||||||
publish:
|
publish:
|
||||||
- message: "this is message 1"
|
- message: this is message 1
|
||||||
attributes:
|
attributes:
|
||||||
mykey1: myvalue
|
mykey1: myvalue
|
||||||
mykey2: myvalu2
|
mykey2: myvalu2
|
||||||
mykey3: myvalue3
|
mykey3: myvalue3
|
||||||
- message: "this is message 2"
|
- message: this is message 2
|
||||||
attributes:
|
attributes:
|
||||||
server: prod
|
server: prod
|
||||||
sla: "99.9999"
|
sla: "99.9999"
|
||||||
owner: fred
|
owner: fred
|
||||||
|
|
||||||
# Subscriptions
|
- name: Create Subscription (pull)
|
||||||
## Create Subscription (pull)
|
gcpubsub:
|
||||||
gcpubsub:
|
|
||||||
topic: ansible-topic-example
|
topic: ansible-topic-example
|
||||||
subscription:
|
subscription:
|
||||||
- name: mysub
|
- name: mysub
|
||||||
state: present
|
state: present
|
||||||
|
|
||||||
## Create Subscription with ack_deadline and push endpoint
|
# pull is default, ack_deadline is not required
|
||||||
### pull is default, ack_deadline is not required
|
- name: Create Subscription with ack_deadline and push endpoint
|
||||||
gcpubsub:
|
gcpubsub:
|
||||||
topic: ansible-topic-example
|
topic: ansible-topic-example
|
||||||
subscription:
|
subscription:
|
||||||
- name: mysub
|
- name: mysub
|
||||||
|
@ -117,25 +112,25 @@ gcpubsub:
|
||||||
push_endpoint: http://pushendpoint.example.com
|
push_endpoint: http://pushendpoint.example.com
|
||||||
state: present
|
state: present
|
||||||
|
|
||||||
## Subscription change from push to pull
|
# Setting push_endpoint to "None" converts subscription to pull.
|
||||||
### setting push_endpoint to "None" converts subscription to pull.
|
- name: Subscription change from push to pull
|
||||||
gcpubsub:
|
gcpubsub:
|
||||||
topic: ansible-topic-example
|
topic: ansible-topic-example
|
||||||
subscription:
|
subscription:
|
||||||
name: mysub
|
name: mysub
|
||||||
push_endpoint: "None"
|
push_endpoint: "None"
|
||||||
|
|
||||||
## Delete subscription
|
|
||||||
### Topic will not be deleted
|
### Topic will not be deleted
|
||||||
gcpubsub:
|
- name: Delete subscription
|
||||||
|
gcpubsub:
|
||||||
topic: ansible-topic-example
|
topic: ansible-topic-example
|
||||||
subscription:
|
subscription:
|
||||||
- name: mysub
|
- name: mysub
|
||||||
state: absent
|
state: absent
|
||||||
|
|
||||||
## Pull messages from subscription
|
# only pull keyword is required.
|
||||||
### only pull keyword is required.
|
- name: Pull messages from subscription
|
||||||
gcpubsub:
|
gcpubsub:
|
||||||
topic: ansible-topic-example
|
topic: ansible-topic-example
|
||||||
subscription:
|
subscription:
|
||||||
name: ansible-topic-example-sub
|
name: ansible-topic-example-sub
|
||||||
|
@ -208,24 +203,24 @@ def publish_messages(message_list, topic):
|
||||||
batch.publish(bytes(msg), **attrs)
|
batch.publish(bytes(msg), **attrs)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def pull_messages(pull_params, sub):
|
def pull_messages(pull_params, sub):
|
||||||
"""
|
"""
|
||||||
:rtype: tuple (output, changed)
|
:rtype: tuple (output, changed)
|
||||||
"""
|
"""
|
||||||
changed = False
|
changed = False
|
||||||
max_messages=pull_params.get('max_messages', None)
|
max_messages = pull_params.get('max_messages', None)
|
||||||
message_ack = pull_params.get('message_ack', 'no')
|
message_ack = pull_params.get('message_ack', 'no')
|
||||||
return_immediately = pull_params.get('return_immediately', False)
|
return_immediately = pull_params.get('return_immediately', False)
|
||||||
|
|
||||||
output= []
|
output = []
|
||||||
pulled = sub.pull(return_immediately=return_immediately,
|
pulled = sub.pull(return_immediately=return_immediately, max_messages=max_messages)
|
||||||
max_messages=max_messages)
|
|
||||||
|
|
||||||
for ack_id, msg in pulled:
|
for ack_id, msg in pulled:
|
||||||
msg_dict = {'message_id': msg.message_id,
|
msg_dict = {'message_id': msg.message_id,
|
||||||
'attributes': msg.attributes,
|
'attributes': msg.attributes,
|
||||||
'data': msg.data,
|
'data': msg.data,
|
||||||
'ack_id': ack_id }
|
'ack_id': ack_id}
|
||||||
output.append(msg_dict)
|
output.append(msg_dict)
|
||||||
|
|
||||||
if message_ack:
|
if message_ack:
|
||||||
|
@ -238,14 +233,17 @@ def pull_messages(pull_params, sub):
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
||||||
module = AnsibleModule(argument_spec=dict(
|
module = AnsibleModule(
|
||||||
topic=dict(required=True),
|
argument_spec=dict(
|
||||||
state=dict(choices=['absent', 'present'], default='present'),
|
topic=dict(type='str', required=True),
|
||||||
publish=dict(type='list', default=None),
|
state=dict(type='str', default='present', choices=['absent', 'present']),
|
||||||
subscription=dict(type='dict', default=None),
|
publish=dict(type='list'),
|
||||||
service_account_email=dict(),
|
subscription=dict(type='dict'),
|
||||||
credentials_file=dict(),
|
service_account_email=dict(type='str'),
|
||||||
project_id=dict(), ),)
|
credentials_file=dict(type='str'),
|
||||||
|
project_id=dict(type='str'),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
if not HAS_PYTHON26:
|
if not HAS_PYTHON26:
|
||||||
module.fail_json(
|
module.fail_json(
|
||||||
|
@ -307,7 +305,7 @@ def main():
|
||||||
# Subscription operations
|
# Subscription operations
|
||||||
# TODO(supertom): if more 'update' operations arise, turn this into a function.
|
# TODO(supertom): if more 'update' operations arise, turn this into a function.
|
||||||
s.reload()
|
s.reload()
|
||||||
push_endpoint=mod_params['subscription'].get('push_endpoint', None)
|
push_endpoint = mod_params['subscription'].get('push_endpoint', None)
|
||||||
if push_endpoint is not None:
|
if push_endpoint is not None:
|
||||||
if push_endpoint != s.push_endpoint:
|
if push_endpoint != s.push_endpoint:
|
||||||
if push_endpoint == 'None':
|
if push_endpoint == 'None':
|
||||||
|
@ -326,11 +324,9 @@ def main():
|
||||||
if mod_params['publish'] and len(mod_params['publish']) > 0:
|
if mod_params['publish'] and len(mod_params['publish']) > 0:
|
||||||
changed = publish_messages(mod_params['publish'], t)
|
changed = publish_messages(mod_params['publish'], t)
|
||||||
|
|
||||||
|
|
||||||
json_output['changed'] = changed
|
json_output['changed'] = changed
|
||||||
json_output.update(mod_params)
|
json_output.update(mod_params)
|
||||||
module.exit_json(**json_output)
|
module.exit_json(**json_output)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
# Copyright 2017 Google Inc.
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
# Copyright: (c) 2017, Google Inc.
|
||||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
# 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
|
from __future__ import absolute_import, division, print_function
|
||||||
__metaclass__ = type
|
__metaclass__ = type
|
||||||
|
|
||||||
|
|
||||||
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
||||||
'status': ['preview'],
|
'status': ['preview'],
|
||||||
'supported_by': 'community'}
|
'supported_by': 'community'}
|
||||||
|
@ -14,71 +15,72 @@ DOCUMENTATION = '''
|
||||||
---
|
---
|
||||||
module: gcspanner
|
module: gcspanner
|
||||||
version_added: "2.3"
|
version_added: "2.3"
|
||||||
short_description: Create and Delete Instances/Databases on Spanner.
|
short_description: Create and Delete Instances/Databases on Spanner
|
||||||
description:
|
description:
|
||||||
- Create and Delete Instances/Databases on Spanner.
|
- Create and Delete Instances/Databases on Spanner.
|
||||||
See U(https://cloud.google.com/spanner/docs) for an overview.
|
See U(https://cloud.google.com/spanner/docs) for an overview.
|
||||||
requirements:
|
requirements:
|
||||||
- "python >= 2.6"
|
- python >= 2.6
|
||||||
- "google-auth >= 0.5.0"
|
- google-auth >= 0.5.0
|
||||||
- "google-cloud-spanner >= 0.23.0"
|
- google-cloud-spanner >= 0.23.0
|
||||||
notes:
|
notes:
|
||||||
- Changing the configuration on an existing instance is not supported.
|
- Changing the configuration on an existing instance is not supported.
|
||||||
author:
|
author:
|
||||||
- "Tom Melendez (@supertom) <tom@supertom.com>"
|
- Tom Melendez (@supertom) <tom@supertom.com>
|
||||||
options:
|
options:
|
||||||
configuration:
|
configuration:
|
||||||
description:
|
description:
|
||||||
- Configuration the instance should use. Examples are us-central1, asia-east1 and europe-west1.
|
- Configuration the instance should use.
|
||||||
required: True
|
- Examples are us-central1, asia-east1 and europe-west1.
|
||||||
|
required: yes
|
||||||
instance_id:
|
instance_id:
|
||||||
description:
|
description:
|
||||||
- GCP spanner instance name.
|
- GCP spanner instance name.
|
||||||
required: True
|
required: yes
|
||||||
database_name:
|
database_name:
|
||||||
description:
|
description:
|
||||||
- Name of database contained on the instance.
|
- Name of database contained on the instance.
|
||||||
required: False
|
|
||||||
force_instance_delete:
|
force_instance_delete:
|
||||||
description:
|
description:
|
||||||
- To delete an instance, this argument must exist and be true (along with state being equal to absent).
|
- To delete an instance, this argument must exist and be true (along with state being equal to absent).
|
||||||
required: False
|
type: bool
|
||||||
default: False
|
default: 'no'
|
||||||
instance_display_name:
|
instance_display_name:
|
||||||
description:
|
description:
|
||||||
- Name of Instance to display. If not specified, instance_id will be used instead.
|
- Name of Instance to display.
|
||||||
required: False
|
- If not specified, instance_id will be used instead.
|
||||||
node_count:
|
node_count:
|
||||||
description:
|
description:
|
||||||
- Number of nodes in the instance. If not specified while creating an instance,
|
- Number of nodes in the instance.
|
||||||
node_count will be set to 1.
|
default: 1
|
||||||
required: False
|
|
||||||
state:
|
state:
|
||||||
description: State of the instance or database (absent, present). Applies to the most granular
|
description:
|
||||||
resource. If a database_name is specified we remove it. If only instance_id
|
- State of the instance or database. Applies to the most granular resource.
|
||||||
is specified, that is what is removed.
|
- If a C(database_name) is specified we remove it.
|
||||||
required: False
|
- If only C(instance_id) is specified, that is what is removed.
|
||||||
default: "present"
|
choices: [ absent, present ]
|
||||||
|
default: present
|
||||||
'''
|
'''
|
||||||
|
|
||||||
EXAMPLES = '''
|
EXAMPLES = '''
|
||||||
# Create instance.
|
- name: Create instance
|
||||||
gcspanner:
|
gcspanner:
|
||||||
instance_id: "{{ instance_id }}"
|
instance_id: '{{ instance_id }}'
|
||||||
configuration: "{{ configuration }}"
|
configuration: '{{ configuration }}'
|
||||||
state: present
|
state: present
|
||||||
node_count: 1
|
node_count: 1
|
||||||
|
|
||||||
# Create database.
|
- name: Create database
|
||||||
gcspanner:
|
gcspanner:
|
||||||
instance_id: "{{ instance_id }}"
|
instance_id: '{{ instance_id }}'
|
||||||
configuration: "{{ configuration }}"
|
configuration: '{{ configuration }}'
|
||||||
database_name: "{{ database_name }}"
|
database_name: '{{ database_name }}'
|
||||||
state: present
|
state: present
|
||||||
|
|
||||||
# Delete instance (and all databases)
|
- name: Delete instance (and all databases)
|
||||||
gcspanner:
|
- gcspanner:
|
||||||
instance_id: "{{ instance_id }}"
|
instance_id: '{{ instance_id }}'
|
||||||
configuration: "{{ configuration }}"
|
configuration: '{{ configuration }}'
|
||||||
state: absent
|
state: absent
|
||||||
force_instance_delete: yes
|
force_instance_delete: yes
|
||||||
'''
|
'''
|
||||||
|
@ -136,6 +138,7 @@ CLOUD_CLIENT = 'google-cloud-spanner'
|
||||||
CLOUD_CLIENT_MINIMUM_VERSION = '0.23.0'
|
CLOUD_CLIENT_MINIMUM_VERSION = '0.23.0'
|
||||||
CLOUD_CLIENT_USER_AGENT = 'ansible-spanner-0.1'
|
CLOUD_CLIENT_USER_AGENT = 'ansible-spanner-0.1'
|
||||||
|
|
||||||
|
|
||||||
def get_spanner_configuration_name(config_name, project_name):
|
def get_spanner_configuration_name(config_name, project_name):
|
||||||
config_name = 'projects/%s/instanceConfigs/regional-%s' % (project_name,
|
config_name = 'projects/%s/instanceConfigs/regional-%s' % (project_name,
|
||||||
config_name)
|
config_name)
|
||||||
|
@ -177,17 +180,20 @@ def instance_update(instance):
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
module = AnsibleModule(argument_spec=dict(
|
module = AnsibleModule(
|
||||||
|
argument_spec=dict(
|
||||||
instance_id=dict(type='str', required=True),
|
instance_id=dict(type='str', required=True),
|
||||||
state=dict(choices=['absent', 'present'], default='present'),
|
state=dict(type='str', default='present', choices=['absent', 'present']),
|
||||||
database_name=dict(type='str', default=None),
|
database_name=dict(type='str'),
|
||||||
configuration=dict(type='str', required=True),
|
configuration=dict(type='str', required=True),
|
||||||
node_count=dict(type='int'),
|
node_count=dict(type='int', default=1),
|
||||||
instance_display_name=dict(type='str', default=None),
|
instance_display_name=dict(type='str'),
|
||||||
force_instance_delete=dict(type='bool', default=False),
|
force_instance_delete=dict(type='bool', default=False),
|
||||||
service_account_email=dict(),
|
service_account_email=dict(type='str'),
|
||||||
credentials_file=dict(),
|
credentials_file=dict(type='str'),
|
||||||
project_id=dict(), ), )
|
project_id=dict(type='str'),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
if not HAS_PYTHON26:
|
if not HAS_PYTHON26:
|
||||||
module.fail_json(
|
module.fail_json(
|
||||||
|
|
|
@ -65,9 +65,6 @@ lib/ansible/modules/cloud/docker/docker_network.py
|
||||||
lib/ansible/modules/cloud/google/gc_storage.py
|
lib/ansible/modules/cloud/google/gc_storage.py
|
||||||
lib/ansible/modules/cloud/google/gcdns_record.py
|
lib/ansible/modules/cloud/google/gcdns_record.py
|
||||||
lib/ansible/modules/cloud/google/gcdns_zone.py
|
lib/ansible/modules/cloud/google/gcdns_zone.py
|
||||||
lib/ansible/modules/cloud/google/gce_tag.py
|
|
||||||
lib/ansible/modules/cloud/google/gcpubsub.py
|
|
||||||
lib/ansible/modules/cloud/google/gcspanner.py
|
|
||||||
lib/ansible/modules/cloud/lxc/lxc_container.py
|
lib/ansible/modules/cloud/lxc/lxc_container.py
|
||||||
lib/ansible/modules/cloud/lxd/lxd_container.py
|
lib/ansible/modules/cloud/lxd/lxd_container.py
|
||||||
lib/ansible/modules/cloud/misc/rhevm.py
|
lib/ansible/modules/cloud/misc/rhevm.py
|
||||||
|
|
Loading…
Reference in a new issue