summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Likins <alikins@redhat.com>2016-06-13 15:33:27 -0400
committerGitHub <noreply@github.com>2016-06-13 15:33:27 -0400
commit97ac3f2cc87d38e1179016351d3369efe51c8c13 (patch)
tree24d3eefaa1ba98d5dfd0f760100566c25b479623
parentec569ac89e5b7c48e9df5e360f44dc1a2198fec1 (diff)
parent8231a1afc89e79e615a9c851f3b45dbba2fba9f3 (diff)
downloadansible-modules-core-97ac3f2cc87d38e1179016351d3369efe51c8c13.tar.gz
Merge pull request #3701 from gillesgagniard/gce-subnetwork-dev
GCE : Add support for subnet networks
-rw-r--r--cloud/google/gce.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/cloud/google/gce.py b/cloud/google/gce.py
index bd6ea15c..8571b0fd 100644
--- a/cloud/google/gce.py
+++ b/cloud/google/gce.py
@@ -96,6 +96,12 @@ options:
- name of the network, 'default' will be used if not specified
required: false
default: "default"
+ subnetwork:
+ description:
+ - name of the subnetwork in which the instance should be created
+ required: false
+ default: null
+ version_added: "2.2"
persistent_boot_disk:
description:
- if set, create the instance with a persistent boot disk
@@ -285,6 +291,10 @@ def get_instance_info(inst):
netname = inst.extra['networkInterfaces'][0]['network'].split('/')[-1]
except:
netname = None
+ try:
+ subnetname = inst.extra['networkInterfaces'][0]['subnetwork'].split('/')[-1]
+ except:
+ subnetname = None
if 'disks' in inst.extra:
disk_names = [disk_info['source'].split('/')[-1]
for disk_info
@@ -305,6 +315,7 @@ def get_instance_info(inst):
'metadata': metadata,
'name': inst.name,
'network': netname,
+ 'subnetwork': subnetname,
'private_ip': inst.private_ips[0],
'public_ip': public_ip,
'status': ('status' in inst.extra) and inst.extra['status'] or None,
@@ -330,6 +341,7 @@ def create_instances(module, gce, instance_names):
machine_type = module.params.get('machine_type')
metadata = module.params.get('metadata')
network = module.params.get('network')
+ subnetwork = module.params.get('subnetwork')
persistent_boot_disk = module.params.get('persistent_boot_disk')
disks = module.params.get('disks')
state = module.params.get('state')
@@ -441,6 +453,8 @@ def create_instances(module, gce, instance_names):
)
if preemptible is not None:
gce_args['ex_preemptible'] = preemptible
+ if subnetwork is not None:
+ gce_args['ex_subnetwork'] = subnetwork
inst = None
try:
@@ -527,6 +541,7 @@ def main():
metadata = dict(),
name = dict(),
network = dict(default='default'),
+ subnetwork = dict(),
persistent_boot_disk = dict(type='bool', default=False),
disks = dict(type='list'),
state = dict(choices=['active', 'present', 'absent', 'deleted'],
@@ -558,6 +573,7 @@ def main():
metadata = module.params.get('metadata')
name = module.params.get('name')
network = module.params.get('network')
+ subnetwork = module.params.get('subnetwork')
persistent_boot_disk = module.params.get('persistent_boot_disk')
state = module.params.get('state')
tags = module.params.get('tags')
@@ -583,6 +599,10 @@ def main():
module.fail_json(msg="Apache Libcloud 0.20.0+ is required to use 'preemptible' option",
changed=False)
+ if subnetwork is not None and not hasattr(gce, 'ex_get_subnetwork'):
+ module.fail_json(msg="Apache Libcloud 1.0.0+ is required to use 'subnetwork' option",
+ changed=False)
+
json_output = {'zone': zone}
if state in ['absent', 'deleted']:
json_output['state'] = 'absent'