Merge pull request #883 from nabam/gcloud-external-ip

Allow to spawn instances without external ip in google cloud module
This commit is contained in:
Eric Johnson 2015-03-03 15:59:59 -08:00
commit bd8cfa2a24

View file

@ -122,6 +122,13 @@ options:
required: false required: false
default: "false" default: "false"
aliases: [] aliases: []
external_ip:
version_added: "1.9"
description:
- type of external ip, ephemeral by default
required: false
default: "ephemeral"
aliases: []
requirements: [ "libcloud" ] requirements: [ "libcloud" ]
notes: notes:
@ -230,6 +237,12 @@ def get_instance_info(inst):
key=lambda disk_info: disk_info['index'])] key=lambda disk_info: disk_info['index'])]
else: else:
disk_names = [] disk_names = []
if len(inst.public_ips) == 0:
public_ip = None
else:
public_ip = inst.public_ips[0]
return({ return({
'image': not inst.image is None and inst.image.split('/')[-1] or None, 'image': not inst.image is None and inst.image.split('/')[-1] or None,
'disks': disk_names, 'disks': disk_names,
@ -238,7 +251,7 @@ def get_instance_info(inst):
'name': inst.name, 'name': inst.name,
'network': netname, 'network': netname,
'private_ip': inst.private_ips[0], 'private_ip': inst.private_ips[0],
'public_ip': inst.public_ips[0], 'public_ip': public_ip,
'status': ('status' in inst.extra) and inst.extra['status'] or None, 'status': ('status' in inst.extra) and inst.extra['status'] or None,
'tags': ('tags' in inst.extra) and inst.extra['tags'] or [], 'tags': ('tags' in inst.extra) and inst.extra['tags'] or [],
'zone': ('zone' in inst.extra) and inst.extra['zone'].name or None, 'zone': ('zone' in inst.extra) and inst.extra['zone'].name or None,
@ -267,6 +280,10 @@ def create_instances(module, gce, instance_names):
tags = module.params.get('tags') tags = module.params.get('tags')
zone = module.params.get('zone') zone = module.params.get('zone')
ip_forward = module.params.get('ip_forward') ip_forward = module.params.get('ip_forward')
external_ip = module.params.get('external_ip')
if external_ip == "none":
external_ip = None
new_instances = [] new_instances = []
changed = False changed = False
@ -327,7 +344,8 @@ def create_instances(module, gce, instance_names):
try: try:
inst = gce.create_node(name, lc_machine_type, lc_image, inst = gce.create_node(name, lc_machine_type, lc_image,
location=lc_zone, ex_network=network, ex_tags=tags, location=lc_zone, ex_network=network, ex_tags=tags,
ex_metadata=metadata, ex_boot_disk=pd, ex_can_ip_forward=ip_forward) ex_metadata=metadata, ex_boot_disk=pd, ex_can_ip_forward=ip_forward,
external_ip=external_ip)
changed = True changed = True
except ResourceExistsError: except ResourceExistsError:
inst = gce.ex_get_node(name, lc_zone) inst = gce.ex_get_node(name, lc_zone)
@ -418,6 +436,8 @@ def main():
pem_file = dict(), pem_file = dict(),
project_id = dict(), project_id = dict(),
ip_forward = dict(type='bool', default=False), ip_forward = dict(type='bool', default=False),
external_ip = dict(choices=['ephemeral', 'none'],
default='ephemeral'),
) )
) )