Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcleanup.py
More file actions
Latest commit
35 lines (31 loc) · 1.25 KB
/
Copy pathcleanup.py
File metadata and controls
35 lines (31 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
importdatetime
importos
importsys
importtime
# Clenup scirpt which will delete VM which is living longer than 1day
fromnovaclient.v1_1importclient
USER=os.environ.get('OS_USERNAME', '')
PASS=os.environ.get('OS_PASSWORD', '')
TENANT=os.environ.get('OS_TENANT_NAME', '')
AUTH_URL=os.environ.get('OS_AUTH_URL', '')
REGION_NAME=os.environ.get('OS_REGION_NAME', '')
client=client.Client(USER, PASS, TENANT, AUTH_URL,
endpoint_type="adminURL",
region_name=REGION_NAME)
now=datetime.datetime.now()
oneday=datetime.timedelta(days=1)
forserverinclient.servers.list(True, {'all_tenants':True}):
delta=now-datetime.datetime.strptime(server.created,
"%Y-%m-%dT%H:%M:%SZ")
ifdelta>oneday:
print"server_id:%s\ttenant_id:%s deleted"% (server.id,
server.tenant_id)
try:
server.delete()
time.sleep(1)
print"server_id:%s\ttenant_id:%s deleted"% (server.id,
server.tenant_id)
except:
print"[ERROR] failed to delete server_id:%s\ttenant_id:%s"% (
server.id,
server.tenant_id)