本文整理汇总了Python中dopy.manager.DoManager.destroy_droplet方法的典型用法代码示例。如果您正苦于以下问题:Python DoManager.destroy_droplet方法的具体用法?Python DoManager.destroy_droplet怎么用?Python DoManager.destroy_droplet使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dopy.manager.DoManager
的用法示例。
在下文中一共展示了DoManager.destroy_droplet方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: DoManager
# 需要导入模块: from dopy.manager import DoManager [as 别名]
# 或者: from dopy.manager.DoManager import destroy_droplet [as 别名]
except Exception as e:
print "Invalid format for DONT - %s" % e
sys.exit(1)
if __name__ == '__main__':
do = DoManager(client_id, api_key, api_version=api_version)
while True:
try:
droplets = do.all_active_droplets()
for droplet in droplets:
if droplet.get('id') in DONT:
# Don't kill meeeeee
print 'Not killing %s (%s) - part of the DONT' % (droplet.get('name'), droplet.get('id'))
continue
created = datetime.strptime(droplet.get('created_at'), "%Y-%m-%dT%H:%M:%SZ")
now = datetime.now()
diff = now - created
if diff.seconds > MAX_AGE:
print 'gonna destroy droplet - %s (%s: %s)' % (droplet.get('name'), droplet.get('id'), droplet.get('ip_address'))
do.destroy_droplet(droplet.get('id'))
print 'destroyed droplet - %s (%s: %s)' % (droplet.get('name'), droplet.get('id'), droplet.get('ip_address'))
else:
print 'droplet %s (%s: %s) is less than %s sec (age: %s sec)' % (droplet.get('name'), droplet.get('id'), droplet.get('ip_address'), MAX_AGE, diff.seconds)
print '.'
except Exception as e:
# Don't want to crash ! just wait and try again in 5 min
print 'Error: %s' % (e,)
# Sleep another 5 min and retry to kill
sleep(CHECK_FREQ)