<s> from __future__ import absolute_import <EOL> import itertools <EOL> import logging <EOL> import thread <EOL> import urlparse <EOL> from django . conf import settings <EOL> import glanceclient as glance_client <EOL> from openstack_dashboard . api import base <EOL> LOG = logging . getLogger ( __name__ ) <EOL> def glanceclient ( request ) : <EOL> o = urlparse . urlparse ( base . url_for ( request , '<STR_LIT:image>' ) ) <EOL> url = "<STR_LIT>" . join ( ( o . scheme , o . netloc ) ) <EOL> insecure = getattr ( settings , '<STR_LIT>' , False ) <EOL> cacert = getattr ( settings , '<STR_LIT>' , None ) <EOL> LOG . debug ( '<STR_LIT>' <EOL> % ( request . user . token . id , url ) ) <EOL> return glance_client . Client ( '<STR_LIT:1>' , url , token = request . user . token . id , <EOL> insecure = insecure , cacert = cacert ) <EOL> def image_delete ( request , image_id ) : <EOL> return glanceclient ( request ) . images . delete ( image_id ) <EOL> def image_get ( request , image_id ) : <EOL> """<STR_LIT>""" <EOL> return glanceclient ( request ) . images . get ( image_id ) <EOL> def image_list_detailed ( request , marker = None , filters = None , paginate = False ) : <EOL> limit = getattr ( settings , '<STR_LIT>' , <NUM_LIT:1000> ) <EOL> page_size = request . session . get ( '<STR_LIT>' , <EOL> getattr ( settings , '<STR_LIT>' , <EOL> <NUM_LIT:20> ) ) <EOL> if paginate : <EOL> request_size = page_size + <NUM_LIT:1> <EOL> else : <EOL> request_size = limit <EOL> kwargs = { '<STR_LIT>' : filters or { } } <EOL> if marker : <EOL> kwargs [ '<STR_LIT>' ] = marker <EOL> images_iter = glanceclient ( request ) . images . list ( page_size = request_size , <EOL> limit = limit , <EOL> ** kwargs ) <EOL> has_more_data = False <EOL> if paginate : <EOL> images = list ( itertools . islice ( images_iter , request_size ) ) <EOL> if len ( images ) > page_size : <EOL> images . pop ( - <NUM_LIT:1> ) <EOL> has_more_data = True <EOL> else : <EOL> images = list ( images_iter ) <EOL> return ( images , has_more_data ) <EOL> def image_update ( request , image_id , ** kwargs ) : <EOL> return glanceclient ( request ) . images . update ( image_id , ** kwargs ) <EOL> def image_create ( request , ** kwargs ) : <EOL> copy_from = None <EOL> if kwargs . get ( '<STR_LIT>' ) : <EOL> copy_from = kwargs . pop ( '<STR_LIT>' ) <EOL> image = glanceclient ( request ) . images . create ( ** kwargs ) <EOL> if copy_from : <EOL> thread . start_new_thread ( image_update , <EOL> ( request , image . id ) , <EOL> { '<STR_LIT>' : copy_from } ) <EOL> return image </s>
