<s> import collections <EOL> import logging <EOL> from glanceclient import exc as exceptions <EOL> LOG = logging . getLogger ( __name__ ) <EOL> def create_or_find_kernel_and_ramdisk ( glanceclient , kernel_name , ramdisk_name , <EOL> kernel_path = None , ramdisk_path = None , <EOL> skip_missing = False ) : <EOL> """<STR_LIT>""" <EOL> kernel_image = _upload_file ( glanceclient , kernel_name , kernel_path , <EOL> '<STR_LIT>' , '<STR_LIT>' , skip_missing = skip_missing ) <EOL> ramdisk_image = _upload_file ( glanceclient , ramdisk_name , ramdisk_path , <EOL> '<STR_LIT>' , '<STR_LIT>' , skip_missing = skip_missing ) <EOL> return { '<STR_LIT>' : kernel_image . id , '<STR_LIT>' : ramdisk_image . id } <EOL> def _upload_file ( glanceclient , name , path , disk_format , type_name , <EOL> skip_missing = False ) : <EOL> image_tuple = collections . namedtuple ( '<STR_LIT:image>' , [ '<STR_LIT:id>' ] ) <EOL> try : <EOL> image = glanceclient . images . find ( name = name , disk_format = disk_format ) <EOL> except exceptions . NotFound : <EOL> if path : <EOL> image = glanceclient . images . create ( <EOL> name = name , disk_format = disk_format , is_public = True , <EOL> data = open ( path , '<STR_LIT:rb>' ) ) <EOL> else : <EOL> if skip_missing : <EOL> image = image_tuple ( None ) <EOL> else : <EOL> raise ValueError ( "<STR_LIT>" <EOL> "<STR_LIT>" % type_name ) <EOL> return image </s>
