~smoser/simplestreams/sstream-tools

« back to all changes in this revision

Viewing changes to wipe-glance.py

  • Committer: Scott Moser
  • Date: 2013-04-08 20:35:02 UTC
  • Revision ID: smoser@ubuntu.com-20130408203502-sh8r1maqpsab0lpd
add prefix filter to wipe-glance

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 
3
3
from simplestreams import openstack
4
4
import glanceclient
 
5
import sys
5
6
 
6
7
def get_glanceclient(version='1', **kwargs):
7
8
    pt = ('endpoint', 'token', 'insecure', 'cacert')
11
12
kscreds = openstack.load_keystone_creds()
12
13
gcreds = openstack.get_service_conn_info(service='image', **kscreds)
13
14
gc = get_glanceclient(**gcreds)
 
15
prefix = None
 
16
if len(sys.argv) > 1:
 
17
   prefix = sys.argv[1]
 
18
 
14
19
for img in gc.images.list():
15
20
   if img.owner != gcreds['tenant_id']:
16
21
       continue
17
 
   print "wiping %s: %s" % (img.id, getattr(img, 'name'))
 
22
   name=getattr(img, 'name')
 
23
   if prefix is None or name.startswith(prefix):
 
24
       print "wiping %s: %s" % (img.id, name)
 
25
   else:
 
26
       print "skip   %s: %s" % (img.id, name)
 
27
       continue
18
28
   gc.images.delete(img.id)