1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

update_attr should wait for the full wait timeout before checking for a missing IP addres

This commit is contained in:
Bryan Larsen 2013-07-11 14:05:26 -04:00
parent 848b38fc7f
commit cea812c3a7

View file

@ -189,19 +189,13 @@ class Droplet(JsonfyMixIn):
def is_powered_on(self):
return self.status == 'active'
def update_attr(self, attrs=None, times=5):
def update_attr(self, attrs=None):
if attrs:
for k, v in attrs.iteritems():
setattr(self, k, v)
else:
json = self.manager.show_droplet(self.id)
if not json['ip_address']:
if times > 0:
time.sleep(2)
self.update_attr(times=times-1)
else:
raise TimeoutError('No ip is found.', self.id)
else:
if json['ip_address']:
self.update_attr(json)
def power_on(self):
@ -221,6 +215,8 @@ class Droplet(JsonfyMixIn):
time.sleep(min(20, end_time-time.time()))
self.update_attr()
if self.is_powered_on():
if not self.ip_address:
raise TimeoutError('No ip is found.', self.id)
return
raise TimeoutError('Wait for droplet running timeout', self.id)