mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
if vm state is not ACTIVE, associate floating ip to it will fail.So we should wait for state of vm is ACTIVE,then associate the assigned floating ip to it
This commit is contained in:
parent
0f2ec1e1db
commit
8e0a9864c5
1 changed files with 42 additions and 2 deletions
|
@ -705,8 +705,47 @@ def request_instance(vm_=None, call=None):
|
|||
break
|
||||
if floating_ip is None:
|
||||
floating_ip = conn.floating_ip_create(pool)['ip']
|
||||
|
||||
def __query_node_data(vm_):
|
||||
try:
|
||||
node = show_instance(vm_['name'], 'action')
|
||||
log.debug(
|
||||
'Loaded node data for {0}:\n{1}'.format(
|
||||
vm_['name'],
|
||||
pprint.pformat(node)
|
||||
)
|
||||
)
|
||||
except Exception as err:
|
||||
log.error(
|
||||
'Failed to get nodes list: {0}'.format(
|
||||
err
|
||||
),
|
||||
# Show the traceback if the debug logging level is enabled
|
||||
exc_info_on_loglevel=logging.DEBUG
|
||||
)
|
||||
# Trigger a failure in the wait for IP function
|
||||
return False
|
||||
return node['state'] == 'ACTIVE' or None
|
||||
|
||||
# if we associate the floating ip here,then we will fail.
|
||||
# As if we attempt to associate a floating IP before the Nova instance has completed building,
|
||||
# it will fail.So we should associate it after the Nova instance has completed building.
|
||||
try:
|
||||
conn.floating_ip_associate(kwargs['name'], floating_ip)
|
||||
salt.utils.cloud.wait_for_ip(
|
||||
__query_node_data,
|
||||
update_args = (vm_,)
|
||||
)
|
||||
except (SaltCloudExecutionTimeout, SaltCloudExecutionFailure) as exc:
|
||||
try:
|
||||
# It might be already up, let's destroy it!
|
||||
destroy(vm_['name'])
|
||||
except SaltCloudSystemExit:
|
||||
pass
|
||||
finally:
|
||||
raise SaltCloudSystemExit(str(exc))
|
||||
|
||||
try:
|
||||
conn.floating_ip_associate(vm_['name'], floating_ip)
|
||||
vm_['floating_ip'] = floating_ip
|
||||
except Exception as exc:
|
||||
raise SaltCloudSystemExit(
|
||||
|
@ -717,7 +756,8 @@ def request_instance(vm_=None, call=None):
|
|||
)
|
||||
)
|
||||
|
||||
vm_['password'] = data.extra.get('password', '')
|
||||
if not vm_.get('password', None):
|
||||
vm_['password'] = data.extra.get('password', '')
|
||||
|
||||
return data, vm_
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue