Allowing specifying ip by address
This commit is contained in:
parent
a757af0264
commit
44af735ac4
1 changed files with 14 additions and 2 deletions
|
@ -136,7 +136,7 @@ options:
|
||||||
external_ip:
|
external_ip:
|
||||||
version_added: "1.9"
|
version_added: "1.9"
|
||||||
description:
|
description:
|
||||||
- type of external ip, ephemeral by default; alternatively, a list of fixed gce ip names can be given (if there is not enough specified ip, 'ephemeral' will be used)
|
- type of external ip, ephemeral by default; alternatively, a list of fixed gce ips or ip names can be given (if there is not enough specified ip, 'ephemeral' will be used)
|
||||||
required: false
|
required: false
|
||||||
default: "ephemeral"
|
default: "ephemeral"
|
||||||
disk_auto_delete:
|
disk_auto_delete:
|
||||||
|
@ -242,12 +242,15 @@ EXAMPLES = '''
|
||||||
|
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
import socket
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import libcloud
|
import libcloud
|
||||||
from libcloud.compute.types import Provider
|
from libcloud.compute.types import Provider
|
||||||
from libcloud.compute.providers import get_driver
|
from libcloud.compute.providers import get_driver
|
||||||
from libcloud.common.google import GoogleBaseError, QuotaExceededError, \
|
from libcloud.common.google import GoogleBaseError, QuotaExceededError, \
|
||||||
ResourceExistsError, ResourceInUseError, ResourceNotFoundError
|
ResourceExistsError, ResourceInUseError, ResourceNotFoundError
|
||||||
|
from libcloud.compute.drivers.gce import GCEAddress
|
||||||
_ = Provider.GCE
|
_ = Provider.GCE
|
||||||
HAS_LIBCLOUD = True
|
HAS_LIBCLOUD = True
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
@ -334,7 +337,16 @@ def create_instances(module, gce, instance_names):
|
||||||
instance_external_ip = None
|
instance_external_ip = None
|
||||||
elif not isinstance(external_ip, basestring):
|
elif not isinstance(external_ip, basestring):
|
||||||
try:
|
try:
|
||||||
instance_external_ip = gce.ex_get_address(external_ip.pop(0) if len(external_ip) != 0 else 'ephemeral')
|
if len(external_ip) != 0:
|
||||||
|
instance_external_ip = external_ip.pop(0)
|
||||||
|
# check if instance_external_ip is an ip or a name
|
||||||
|
try:
|
||||||
|
socket.inet_aton(instance_external_ip)
|
||||||
|
instance_external_ip = GCEAddress(id='unknown', name='unknown', address=instance_external_ip, region='unknown', driver=gce)
|
||||||
|
except socket.error:
|
||||||
|
instance_external_ip = gce.ex_get_address(instance_external_ip)
|
||||||
|
else:
|
||||||
|
instance_external_ip = 'ephemeral'
|
||||||
except GoogleBaseError, e:
|
except GoogleBaseError, e:
|
||||||
module.fail_json(msg='Unexpected error attempting to get a static ip %s, error: %s' % (external_ip, e.value))
|
module.fail_json(msg='Unexpected error attempting to get a static ip %s, error: %s' % (external_ip, e.value))
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in a new issue