本文整理匯總了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)