<s> import base64 <EOL> import re <EOL> import sys <EOL> from oslo_config import cfg <EOL> from oslo_log import log as logging <EOL> import oslo_messaging as messaging <EOL> from oslo_utils import netutils <EOL> from oslo_utils import strutils <EOL> from oslo_utils import timeutils <EOL> from oslo_utils import uuidutils <EOL> import six <EOL> import webob <EOL> from webob import exc <EOL> from nova . api . openstack import common <EOL> from nova . api . openstack . compute . views import servers as views_servers <EOL> from nova . api . openstack import wsgi <EOL> from nova import block_device <EOL> from nova import compute <EOL> from nova . compute import flavors <EOL> import nova . conf <EOL> from nova import exception <EOL> from nova . i18n import _ <EOL> from nova import objects <EOL> from nova import policy <EOL> from nova import utils <EOL> server_opts = [ <EOL> cfg . BoolOpt ( '<STR_LIT>' , <EOL> default = True , <EOL> help = '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) , <EOL> ] <EOL> CONF = nova . conf . CONF <EOL> CONF . register_opts ( server_opts ) <EOL> LOG = logging . getLogger ( __name__ ) <EOL> CREATE_EXCEPTIONS = { <EOL> exception . InvalidMetadataSize : exc . HTTPRequestEntityTooLarge , <EOL> exception . ImageNotFound : exc . HTTPBadRequest , <EOL> exception . FlavorNotFound : exc . HTTPBadRequest , <EOL> exception . KeypairNotFound : exc . HTTPBadRequest , <EOL> exception . ConfigDriveInvalidValue : exc . HTTPBadRequest , <EOL> exception . ImageNotActive : exc . HTTPBadRequest , <EOL> exception . FlavorDiskTooSmall : exc . HTTPBadRequest , <EOL> exception . FlavorMemoryTooSmall : exc . HTTPBadRequest , <EOL> exception . NetworkNotFound : exc . HTTPBadRequest , <EOL> exception . PortNotFound : exc . HTTPBadRequest , <EOL> exception . FixedIpAlreadyInUse : exc . HTTPBadRequest , <EOL> exception . SecurityGroupNotFound : exc . HTTPBadRequest , <EOL> exception . InstanceUserDataTooLarge : exc . HTTPBadRequest , <EOL> exception . InstanceUserDataMalformed : exc . HTTPBadRequest , <EOL> exception . ImageNUMATopologyIncomplete : exc . HTTPBadRequest , <EOL> exception . ImageNUMATopologyForbidden : exc . HTTPBadRequest , <EOL> exception . ImageNUMATopologyAsymmetric : exc . HTTPBadRequest , <EOL> exception . ImageNUMATopologyCPUOutOfRange : exc . HTTPBadRequest , <EOL> exception . ImageNUMATopologyCPUDuplicates : exc . HTTPBadRequest , <EOL> exception . ImageNUMATopologyCPUsUnassigned : exc . HTTPBadRequest , <EOL> exception . ImageNUMATopologyMemoryOutOfRange : exc . HTTPBadRequest , <EOL> exception . PortInUse : exc . HTTPConflict , <EOL> exception . InstanceExists : exc . HTTPConflict , <EOL> exception . NoUniqueMatch : exc . HTTPConflict , <EOL> exception . Invalid : exc . HTTPBadRequest , <EOL> exception . InstanceGroupNotFound : exc . HTTPBadRequest , <EOL> } <EOL> CREATE_EXCEPTIONS_MSGS = { <EOL> exception . ImageNotFound : _ ( "<STR_LIT>" ) , <EOL> exception . FlavorNotFound : _ ( "<STR_LIT>" ) , <EOL> exception . KeypairNotFound : _ ( "<STR_LIT>" ) , <EOL> exception . ConfigDriveInvalidValue : _ ( "<STR_LIT>" ) , <EOL> } <EOL> class Controller ( wsgi . Controller ) : <EOL> """<STR_LIT>""" <EOL> _view_builder_class = views_servers . ViewBuilder <EOL> @ staticmethod <EOL> def _add_location ( robj ) : <EOL> if '<STR_LIT>' not in robj . obj : <EOL> return robj <EOL> link = [ l for l in robj . obj [ '<STR_LIT>' ] [ '<STR_LIT>' ] if l [ '<STR_LIT>' ] == '<STR_LIT>' ] <EOL> if link : <EOL> robj [ '<STR_LIT>' ] = utils . utf8 ( link [ <NUM_LIT:0> ] [ '<STR_LIT>' ] ) <EOL> return robj <EOL> def __init__ ( self , ext_mgr = None , ** kwargs ) : <EOL> super ( Controller , self ) . __init__ ( ** kwargs ) <EOL> self . compute_api = compute . API ( ) <EOL> self . ext_mgr = ext_mgr <EOL> def index ( self , req ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> servers = self . _get_servers ( req , is_detail = False ) <EOL> except exception . Invalid as err : <EOL> raise exc . HTTPBadRequest ( explanation = err . format_message ( ) ) <EOL> return servers <EOL> def detail ( self , req ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> servers = self . _get_servers ( req , is_detail = True ) <EOL> except exception . Invalid as err : <EOL> raise exc . HTTPBadRequest ( explanation = err . format_message ( ) ) <EOL> return servers <EOL> def _get_servers ( self , req , is_detail ) : <EOL> """<STR_LIT>""" <EOL> search_opts = { } <EOL> search_opts . update ( req . GET ) <EOL> context = req . environ [ '<STR_LIT>' ] <EOL> remove_invalid_options ( context , search_opts , <EOL> self . _get_server_search_options ( ) ) <EOL> search_opts . pop ( '<STR_LIT:status>' , None ) <EOL> if '<STR_LIT:status>' in req . GET . keys ( ) : <EOL> statuses = req . GET . getall ( '<STR_LIT:status>' ) <EOL> states = common . task_and_vm_state_from_status ( statuses ) <EOL> vm_state , task_state = states <EOL> if not vm_state and not task_state : <EOL> return { '<STR_LIT>' : [ ] } <EOL> search_opts [ '<STR_LIT>' ] = vm_state <EOL> if '<STR_LIT:default>' not in task_state : <EOL> search_opts [ '<STR_LIT>' ] = task_state <EOL> if '<STR_LIT>' in search_opts : <EOL> try : <EOL> parsed = timeutils . parse_isotime ( search_opts [ '<STR_LIT>' ] ) <EOL> except ValueError : <EOL> msg = _ ( '<STR_LIT>' ) <EOL> raise exc . HTTPBadRequest ( explanation = msg ) <EOL> search_opts [ '<STR_LIT>' ] = parsed <EOL> if '<STR_LIT>' not in search_opts : <EOL> if '<STR_LIT>' not in search_opts : <EOL> search_opts [ '<STR_LIT>' ] = False <EOL> else : <EOL> search_opts [ '<STR_LIT>' ] = strutils . bool_from_string ( <EOL> search_opts [ '<STR_LIT>' ] , default = False ) <EOL> if search_opts . get ( "<STR_LIT>" ) == [ '<STR_LIT>' ] : <EOL> if context . is_admin : <EOL> search_opts [ '<STR_LIT>' ] = True <EOL> else : <EOL> msg = _ ( "<STR_LIT>" ) <EOL> raise exc . HTTPForbidden ( explanation = msg ) <EOL> all_tenants = common . is_all_tenants ( search_opts ) <EOL> search_opts . pop ( '<STR_LIT>' , None ) <EOL> elevated = None <EOL> if all_tenants : <EOL> policy . enforce ( context , '<STR_LIT>' , <EOL> { '<STR_LIT>' : context . project_id , <EOL> '<STR_LIT>' : context . user_id } ) <EOL> elevated = context . elevated ( ) <EOL> else : <EOL> if context . project_id : <EOL> search_opts [ '<STR_LIT>' ] = context . project_id <EOL> else : <EOL> search_opts [ '<STR_LIT>' ] = context . user_id <EOL> limit , marker = common . get_limit_and_marker ( req ) <EOL> sort_keys , sort_dirs = None , None <EOL> if self . ext_mgr . is_loaded ( '<STR_LIT>' ) : <EOL> sort_keys , sort_dirs = common . get_sort_params ( req . params ) <EOL> expected_attrs = None <EOL> if is_detail : <EOL> expected_attrs = self . _view_builder . get_show_expected_attrs ( <EOL> expected_attrs ) <EOL> try : <EOL> instance_list = self . compute_api . get_all ( elevated or context , <EOL> search_opts = search_opts , limit = limit , marker = marker , <EOL> want_objects = True , expected_attrs = expected_attrs , <EOL> sort_keys = sort_keys , sort_dirs = sort_dirs ) <EOL> except exception . MarkerNotFound : <EOL> msg = _ ( '<STR_LIT>' ) % marker <EOL> raise exc . HTTPBadRequest ( explanation = msg ) <EOL> except exception . FlavorNotFound : <EOL> LOG . debug ( "<STR_LIT>" , search_opts [ '<STR_LIT>' ] ) <EOL> instance_list = objects . InstanceList ( ) <EOL> if is_detail : <EOL> instance_list . _context = context <EOL> instance_list . fill_faults ( ) <EOL> response = self . _view_builder . detail ( req , instance_list ) <EOL> else : <EOL> response = self . _view_builder . index ( req , instance_list ) <EOL> req . cache_db_instances ( instance_list ) <EOL> return response <EOL> def _get_server ( self , context , req , instance_uuid , is_detail = False ) : <EOL> """<STR_LIT>""" <EOL> expected_attrs = [ '<STR_LIT>' ] <EOL> if is_detail : <EOL> expected_attrs = self . _view_builder . get_show_expected_attrs ( <EOL> expected_attrs ) <EOL> instance = common . get_instance ( self . compute_api , context , <EOL> instance_uuid , <EOL> expected_attrs = expected_attrs ) <EOL> req . cache_db_instance ( instance ) <EOL> return instance <EOL> def _check_string_length ( self , value , name , max_length = None ) : <EOL> try : <EOL> if isinstance ( value , six . string_types ) : <EOL> value = value . strip ( ) <EOL> utils . check_string_length ( value , name , min_length = <NUM_LIT:1> , <EOL> max_length = max_length ) <EOL> except exception . InvalidInput as e : <EOL> raise exc . HTTPBadRequest ( explanation = e . format_message ( ) ) <EOL> def _validate_server_name ( self , value ) : <EOL> self . _check_string_length ( value , '<STR_LIT>' , max_length = <NUM_LIT:255> ) <EOL> def _get_injected_files ( self , personality ) : <EOL> """<STR_LIT>""" <EOL> injected_files = [ ] <EOL> for item in personality : <EOL> try : <EOL> path = item [ '<STR_LIT:path>' ] <EOL> contents = item [ '<STR_LIT>' ] <EOL> except KeyError as key : <EOL> expl = _ ( '<STR_LIT>' ) % key <EOL> raise exc . HTTPBadRequest ( explanation = expl ) <EOL> except TypeError : <EOL> expl = _ ( '<STR_LIT>' ) <EOL> raise exc . HTTPBadRequest ( explanation = expl ) <EOL> if self . _decode_base64 ( contents ) is None : <EOL> expl = _ ( '<STR_LIT>' ) % path <EOL> raise exc . HTTPBadRequest ( explanation = expl ) <EOL> injected_files . append ( ( path , contents ) ) <EOL> return injected_files <EOL> def _get_requested_networks ( self , requested_networks ) : <EOL> """<STR_LIT>""" <EOL> networks = [ ] <EOL> network_uuids = [ ] <EOL> for network in requested_networks : <EOL> request = objects . NetworkRequest ( ) <EOL> try : <EOL> try : <EOL> request . port_id = network . get ( '<STR_LIT:port>' , None ) <EOL> except ValueError : <EOL> msg = _ ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) % network . get ( '<STR_LIT:port>' ) <EOL> raise exc . HTTPBadRequest ( explanation = msg ) <EOL> if request . port_id : <EOL> request . network_id = None <EOL> if not utils . is_neutron ( ) : <EOL> msg = _ ( "<STR_LIT>" ) <EOL> raise exc . HTTPBadRequest ( explanation = msg ) <EOL> else : <EOL> request . network_id = network [ '<STR_LIT>' ] <EOL> if ( not request . port_id and not <EOL> uuidutils . is_uuid_like ( request . network_id ) ) : <EOL> br_uuid = request . network_id . split ( '<STR_LIT:->' , <NUM_LIT:1> ) [ - <NUM_LIT:1> ] <EOL> if not uuidutils . is_uuid_like ( br_uuid ) : <EOL> msg = _ ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) % request . network_id <EOL> raise exc . HTTPBadRequest ( explanation = msg ) <EOL> try : <EOL> request . address = network . get ( '<STR_LIT>' , None ) <EOL> except ValueError : <EOL> msg = ( _ ( "<STR_LIT>" ) % <EOL> network . get ( '<STR_LIT>' ) ) <EOL> raise exc . HTTPBadRequest ( explanation = msg ) <EOL> if ( not utils . is_neutron ( ) and request . network_id and <EOL> request . network_id in network_uuids ) : <EOL> expl = ( _ ( "<STR_LIT>" <EOL> "<STR_LIT>" ) % <EOL> request . network_id ) <EOL> raise exc . HTTPBadRequest ( explanation = expl ) <EOL> network_uuids . append ( request . network_id ) <EOL> networks . append ( request ) <EOL> except KeyError as key : <EOL> expl = _ ( '<STR_LIT>' ) % key <EOL> raise exc . HTTPBadRequest ( explanation = expl ) <EOL> except TypeError : <EOL> expl = _ ( '<STR_LIT>' ) <EOL> raise exc . HTTPBadRequest ( explanation = expl ) <EOL> return objects . NetworkRequestList ( objects = networks ) <EOL> B64_REGEX = re . compile ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> def _decode_base64 ( self , data ) : <EOL> if isinstance ( data , six . binary_type ) and hasattr ( data , "<STR_LIT>" ) : <EOL> try : <EOL> data = data . decode ( "<STR_LIT:utf-8>" ) <EOL> except UnicodeDecodeError : <EOL> return None <EOL> data = re . sub ( r'<STR_LIT>' , '<STR_LIT>' , data ) <EOL> if not self . B64_REGEX . match ( data ) : <EOL> return None <EOL> try : <EOL> return base64 . b64decode ( data ) <EOL> except TypeError : <EOL> return None <EOL> def _validate_access_ipv4 ( self , address ) : <EOL> if not netutils . is_valid_ipv4 ( address ) : <EOL> expl = _ ( '<STR_LIT>' ) <EOL> raise exc . HTTPBadRequest ( explanation = expl ) <EOL> def _validate_access_ipv6 ( self , address ) : <EOL> if not netutils . is_valid_ipv6 ( address ) : <EOL> expl = _ ( '<STR_LIT>' ) <EOL> raise exc . HTTPBadRequest ( explanation = expl ) <EOL> def show ( self , req , id ) : <EOL> """<STR_LIT>""" <EOL> context = req . environ [ '<STR_LIT>' ] <EOL> instance = self . _get_server ( context , req , id , is_detail = True ) <EOL> return self . _view_builder . show ( req , instance ) <EOL> def _extract ( self , server_dict , ext_name , key ) : <EOL> if self . ext_mgr . is_loaded ( ext_name ) : <EOL> return server_dict . get ( key ) <EOL> return None <EOL> def _validate_user_data ( self , user_data ) : <EOL> if user_data and self . _decode_base64 ( user_data ) is None : <EOL> expl = _ ( '<STR_LIT>' ) <EOL> raise exc . HTTPBadRequest ( explanation = expl ) <EOL> return user_data <EOL> def _extract_bdm ( self , server_dict , image_uuid_specified ) : <EOL> legacy_bdm = True <EOL> block_device_mapping_v2 = None <EOL> if not self . ext_mgr . is_loaded ( '<STR_LIT>' ) : <EOL> return legacy_bdm , None <EOL> block_device_mapping = server_dict . get ( '<STR_LIT>' , [ ] ) <EOL> if not isinstance ( block_device_mapping , list ) : <EOL> msg = _ ( '<STR_LIT>' ) <EOL> raise exc . HTTPBadRequest ( explanation = msg ) <EOL> for bdm in block_device_mapping : <EOL> try : <EOL> block_device . validate_device_name ( bdm . get ( "<STR_LIT>" ) ) <EOL> block_device . validate_and_default_volume_size ( bdm ) <EOL> except exception . InvalidBDMFormat as e : <EOL> raise exc . HTTPBadRequest ( explanation = e . format_message ( ) ) <EOL> if '<STR_LIT>' in bdm : <EOL> bdm [ '<STR_LIT>' ] = strutils . bool_from_string ( <EOL> bdm [ '<STR_LIT>' ] ) <EOL> if self . ext_mgr . is_loaded ( '<STR_LIT>' ) : <EOL> block_device_mapping_v2 = server_dict . get ( <EOL> '<STR_LIT>' , [ ] ) <EOL> if block_device_mapping and block_device_mapping_v2 : <EOL> expl = _ ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> raise exc . HTTPBadRequest ( explanation = expl ) <EOL> if not isinstance ( block_device_mapping_v2 , list ) : <EOL> msg = _ ( '<STR_LIT>' ) <EOL> raise exc . HTTPBadRequest ( explanation = msg ) <EOL> legacy_bdm = not bool ( block_device_mapping_v2 ) <EOL> try : <EOL> block_device_mapping_v2 = [ <EOL> block_device . BlockDeviceDict . from_api ( bdm_dict , <EOL> image_uuid_specified ) <EOL> for bdm_dict in block_device_mapping_v2 ] <EOL> except exception . InvalidBDMFormat as e : <EOL> raise exc . HTTPBadRequest ( explanation = e . format_message ( ) ) <EOL> bdm = ( block_device_mapping or block_device_mapping_v2 ) <EOL> return legacy_bdm , bdm <EOL> @ staticmethod <EOL> def _resolve_exception ( matches ) : <EOL> """<STR_LIT>""" <EOL> while len ( matches ) > <NUM_LIT:1> : <EOL> first = matches [ <NUM_LIT:0> ] <EOL> second = matches [ <NUM_LIT:1> ] <EOL> if issubclass ( first , second ) : <EOL> del matches [ <NUM_LIT:1> ] <EOL> else : <EOL> del matches [ <NUM_LIT:0> ] <EOL> return matches [ <NUM_LIT:0> ] <EOL> @ staticmethod <EOL> def _handle_create_exception ( * exc_info ) : <EOL> """<STR_LIT>""" <EOL> error = exc_info [ <NUM_LIT:1> ] <EOL> err_cls = error . __class__ <EOL> cls_to_raise = CREATE_EXCEPTIONS . get ( err_cls ) <EOL> if cls_to_raise is None : <EOL> to_raise = [ val for key , val in CREATE_EXCEPTIONS . items ( ) <EOL> if isinstance ( error , key ) ] <EOL> if len ( to_raise ) > <NUM_LIT:1> : <EOL> cls_to_raise = Controller . _resolve_exception ( to_raise ) <EOL> elif not to_raise : <EOL> six . reraise ( * exc_info ) <EOL> else : <EOL> cls_to_raise = to_raise [ <NUM_LIT:0> ] <EOL> for key , val in CREATE_EXCEPTIONS_MSGS . items ( ) : <EOL> if isinstance ( error , key ) : <EOL> raise cls_to_raise ( explanation = CREATE_EXCEPTIONS_MSGS [ key ] ) <EOL> raise cls_to_raise ( explanation = error . format_message ( ) ) <EOL> def _determine_requested_networks ( self , server_dict ) : <EOL> requested_networks = None <EOL> if ( self . ext_mgr . is_loaded ( '<STR_LIT>' ) <EOL> or utils . is_neutron ( ) ) : <EOL> requested_networks = server_dict . get ( '<STR_LIT>' ) <EOL> if requested_networks is not None : <EOL> if not isinstance ( requested_networks , list ) : <EOL> expl = _ ( '<STR_LIT>' ) <EOL> raise exc . HTTPBadRequest ( explanation = expl ) <EOL> requested_networks = self . _get_requested_networks ( <EOL> requested_networks ) <EOL> return requested_networks <EOL> @ wsgi . response ( <NUM_LIT> ) <EOL> def create ( self , req , body ) : <EOL> """<STR_LIT>""" <EOL> if not self . is_valid_body ( body , '<STR_LIT>' ) : <EOL> raise exc . HTTPUnprocessableEntity ( ) <EOL> context = req . environ [ '<STR_LIT>' ] <EOL> server_dict = body [ '<STR_LIT>' ] <EOL> password = self . _get_server_admin_password ( server_dict ) <EOL> if '<STR_LIT:name>' not in server_dict : <EOL> msg = _ ( "<STR_LIT>" ) <EOL> raise exc . HTTPBadRequest ( explanation = msg ) <EOL> name = server_dict [ '<STR_LIT:name>' ] <EOL> self . _validate_server_name ( name ) <EOL> name = name . strip ( ) <EOL> image_uuid = self . _image_from_req_data ( body ) <EOL> personality = server_dict . get ( '<STR_LIT>' ) <EOL> config_drive = None <EOL> if self . ext_mgr . is_loaded ( '<STR_LIT>' ) : <EOL> config_drive = server_dict . get ( '<STR_LIT>' ) <EOL> injected_files = [ ] <EOL> if personality : <EOL> injected_files = self . _get_injected_files ( personality ) <EOL> sg_names = [ ] <EOL> if self . ext_mgr . is_loaded ( '<STR_LIT>' ) : <EOL> security_groups = server_dict . get ( '<STR_LIT>' ) <EOL> if security_groups is not None : <EOL> try : <EOL> sg_names = [ sg [ '<STR_LIT:name>' ] for sg in security_groups <EOL> if sg . get ( '<STR_LIT:name>' ) ] <EOL> except AttributeError : <EOL> msg = _ ( "<STR_LIT>" <EOL> "<STR_LIT>" ) % { <EOL> '<STR_LIT:path>' : '<STR_LIT>' , <EOL> '<STR_LIT:value>' : security_groups , <EOL> '<STR_LIT:message>' : '<STR_LIT>' <EOL> } <EOL> raise exc . HTTPBadRequest ( explanation = msg ) <EOL> if not sg_names : <EOL> sg_names . append ( '<STR_LIT:default>' ) <EOL> sg_names = list ( set ( sg_names ) ) <EOL> requested_networks = self . _determine_requested_networks ( server_dict ) <EOL> ( access_ip_v4 , ) = server_dict . get ( '<STR_LIT>' ) , <EOL> if access_ip_v4 is not None : <EOL> self . _validate_access_ipv4 ( access_ip_v4 ) <EOL> ( access_ip_v6 , ) = server_dict . get ( '<STR_LIT>' ) , <EOL> if access_ip_v6 is not None : <EOL> self . _validate_access_ipv6 ( access_ip_v6 ) <EOL> flavor_id = self . _flavor_id_from_req_data ( body ) <EOL> key_name = self . _extract ( server_dict , '<STR_LIT>' , '<STR_LIT>' ) <EOL> availability_zone = self . _extract ( server_dict , '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> user_data = self . _extract ( server_dict , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . _validate_user_data ( user_data ) <EOL> image_uuid_specified = bool ( image_uuid ) <EOL> legacy_bdm , block_device_mapping = self . _extract_bdm ( server_dict , <EOL> image_uuid_specified ) <EOL> ret_resv_id = False <EOL> min_count = <NUM_LIT:1> <EOL> max_count = <NUM_LIT:1> <EOL> if self . ext_mgr . is_loaded ( '<STR_LIT>' ) : <EOL> ret_resv_id = server_dict . get ( '<STR_LIT>' , False ) <EOL> min_count = server_dict . get ( '<STR_LIT>' , <NUM_LIT:1> ) <EOL> max_count = server_dict . get ( '<STR_LIT>' , min_count ) <EOL> try : <EOL> min_count = utils . validate_integer ( <EOL> min_count , "<STR_LIT>" , min_value = <NUM_LIT:1> ) <EOL> max_count = utils . validate_integer ( <EOL> max_count , "<STR_LIT>" , min_value = <NUM_LIT:1> ) <EOL> except exception . InvalidInput as e : <EOL> raise exc . HTTPBadRequest ( explanation = e . format_message ( ) ) <EOL> if min_count > max_count : <EOL> msg = _ ( '<STR_LIT>' ) <EOL> raise exc . HTTPBadRequest ( explanation = msg ) <EOL> auto_disk_config = False <EOL> if self . ext_mgr . is_loaded ( '<STR_LIT>' ) : <EOL> auto_disk_config = server_dict . get ( '<STR_LIT>' ) <EOL> scheduler_hints = { } <EOL> if self . ext_mgr . is_loaded ( '<STR_LIT>' ) : <EOL> scheduler_hints = server_dict . get ( '<STR_LIT>' , { } ) <EOL> parse_az = self . compute_api . parse_availability_zone <EOL> availability_zone , host , node = parse_az ( context , availability_zone ) <EOL> check_server_group_quota = self . ext_mgr . is_loaded ( <EOL> '<STR_LIT>' ) <EOL> try : <EOL> _get_inst_type = flavors . get_flavor_by_flavor_id <EOL> inst_type = _get_inst_type ( flavor_id , ctxt = context , <EOL> read_deleted = "<STR_LIT>" ) <EOL> ( instances , resv_id ) = self . compute_api . create ( context , <EOL> inst_type , <EOL> image_uuid , <EOL> display_name = name , <EOL> display_description = name , <EOL> key_name = key_name , <EOL> metadata = server_dict . get ( '<STR_LIT>' , { } ) , <EOL> access_ip_v4 = access_ip_v4 , <EOL> access_ip_v6 = access_ip_v6 , <EOL> injected_files = injected_files , <EOL> admin_password = password , <EOL> min_count = min_count , <EOL> max_count = max_count , <EOL> requested_networks = requested_networks , <EOL> security_group = sg_names , <EOL> user_data = user_data , <EOL> availability_zone = availability_zone , <EOL> forced_host = host , forced_node = node , <EOL> config_drive = config_drive , <EOL> block_device_mapping = block_device_mapping , <EOL> auto_disk_config = auto_disk_config , <EOL> scheduler_hints = scheduler_hints , <EOL> legacy_bdm = legacy_bdm , <EOL> check_server_group_quota = check_server_group_quota ) <EOL> except ( exception . QuotaError , <EOL> exception . PortLimitExceeded ) as error : <EOL> raise exc . HTTPForbidden ( <EOL> explanation = error . format_message ( ) ) <EOL> except messaging . RemoteError as err : <EOL> msg = "<STR_LIT>" % { '<STR_LIT>' : err . exc_type , <EOL> '<STR_LIT>' : err . value } <EOL> raise exc . HTTPBadRequest ( explanation = msg ) <EOL> except UnicodeDecodeError as error : <EOL> msg = "<STR_LIT>" % error <EOL> raise exc . HTTPBadRequest ( explanation = msg ) <EOL> except Exception : <EOL> self . _handle_create_exception ( * sys . exc_info ( ) ) <EOL> if ret_resv_id : <EOL> return wsgi . ResponseObject ( { '<STR_LIT>' : resv_id } ) <EOL> req . cache_db_instances ( instances ) <EOL> server = self . _view_builder . create ( req , instances [ <NUM_LIT:0> ] ) <EOL> if CONF . enable_instance_password : <EOL> server [ '<STR_LIT>' ] [ '<STR_LIT>' ] = password <EOL> robj = wsgi . ResponseObject ( server ) <EOL> return self . _add_location ( robj ) <EOL> def _delete ( self , context , req , instance_uuid ) : <EOL> instance = self . _get_server ( context , req , instance_uuid ) <EOL> if CONF . reclaim_instance_interval : <EOL> try : <EOL> self . compute_api . soft_delete ( context , instance ) <EOL> except exception . InstanceInvalidState : <EOL> self . compute_api . delete ( context , instance ) <EOL> else : <EOL> self . compute_api . delete ( context , instance ) <EOL> def update ( self , req , id , body ) : <EOL> """<STR_LIT>""" <EOL> if not self . is_valid_body ( body , '<STR_LIT>' ) : <EOL> raise exc . HTTPUnprocessableEntity ( ) <EOL> ctxt = req . environ [ '<STR_LIT>' ] <EOL> update_dict = { } <EOL> if '<STR_LIT:name>' in body [ '<STR_LIT>' ] : <EOL> name = body [ '<STR_LIT>' ] [ '<STR_LIT:name>' ] <EOL> self . _validate_server_name ( name ) <EOL> update_dict [ '<STR_LIT>' ] = name . strip ( ) <EOL> if '<STR_LIT>' in body [ '<STR_LIT>' ] : <EOL> access_ipv4 = body [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> if access_ipv4 : <EOL> self . _validate_access_ipv4 ( access_ipv4 ) <EOL> update_dict [ '<STR_LIT>' ] = ( <EOL> access_ipv4 and access_ipv4 . strip ( ) or None ) <EOL> if '<STR_LIT>' in body [ '<STR_LIT>' ] : <EOL> access_ipv6 = body [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> if access_ipv6 : <EOL> self . _validate_access_ipv6 ( access_ipv6 ) <EOL> update_dict [ '<STR_LIT>' ] = ( <EOL> access_ipv6 and access_ipv6 . strip ( ) or None ) <EOL> if '<STR_LIT>' in body [ '<STR_LIT>' ] : <EOL> auto_disk_config = strutils . bool_from_string ( <EOL> body [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> update_dict [ '<STR_LIT>' ] = auto_disk_config <EOL> if '<STR_LIT>' in body [ '<STR_LIT>' ] : <EOL> msg = _ ( "<STR_LIT>" ) <EOL> raise exc . HTTPBadRequest ( explanation = msg ) <EOL> if '<STR_LIT>' in body [ '<STR_LIT>' ] : <EOL> msg = _ ( "<STR_LIT>" ) <EOL> raise exc . HTTPBadRequest ( explanation = msg ) <EOL> instance = self . _get_server ( ctxt , req , id , is_detail = True ) <EOL> try : <EOL> policy . enforce ( ctxt , '<STR_LIT>' , instance ) <EOL> instance . update ( update_dict ) <EOL> instance . save ( ) <EOL> except exception . NotFound : <EOL> msg = _ ( "<STR_LIT>" ) <EOL> raise exc . HTTPNotFound ( explanation = msg ) <EOL> return self . _view_builder . show ( req , instance ) <EOL> @ wsgi . response ( <NUM_LIT> ) <EOL> @ wsgi . action ( '<STR_LIT>' ) <EOL> def _action_confirm_resize ( self , req , id , body ) : <EOL> context = req . environ [ '<STR_LIT>' ] <EOL> instance = self . _get_server ( context , req , id ) <EOL> try : <EOL> self . compute_api . confirm_resize ( context , instance ) <EOL> except exception . MigrationNotFound : <EOL> msg = _ ( "<STR_LIT>" ) <EOL> raise exc . HTTPBadRequest ( explanation = msg ) <EOL> except exception . InstanceIsLocked as e : <EOL> raise exc . HTTPConflict ( explanation = e . format_message ( ) ) <EOL> except exception . InstanceInvalidState as state_error : <EOL> common . raise_http_conflict_for_instance_invalid_state ( state_error , <EOL> '<STR_LIT>' , id ) <EOL> @ wsgi . response ( <NUM_LIT> ) <EOL> @ wsgi . action ( '<STR_LIT>' ) <EOL> def _action_revert_resize ( self , req , id , body ) : <EOL> context = req . environ [ '<STR_LIT>' ] <EOL> instance = self . _get_server ( context , req , id ) <EOL> try : <EOL> self . compute_api . revert_resize ( context , instance ) <EOL> except exception . MigrationNotFound : <EOL> msg = _ ( "<STR_LIT>" ) <EOL> raise exc . HTTPBadRequest ( explanation = msg ) <EOL> except exception . FlavorNotFound : <EOL> msg = _ ( "<STR_LIT>" ) <EOL> raise exc . HTTPBadRequest ( explanation = msg ) <EOL> except exception . InstanceIsLocked as e : <EOL> raise exc . HTTPConflict ( explanation = e . format_message ( ) ) <EOL> except exception . InstanceInvalidState as state_error : <EOL> common . raise_http_conflict_for_instance_invalid_state ( state_error , <EOL> '<STR_LIT>' , id ) <EOL> return webob . Response ( status_int = <NUM_LIT> ) <EOL> @ wsgi . response ( <NUM_LIT> ) <EOL> @ wsgi . action ( '<STR_LIT>' ) <EOL> def _action_reboot ( self , req , id , body ) : <EOL> if '<STR_LIT>' in body and '<STR_LIT:type>' in body [ '<STR_LIT>' ] : <EOL> if not isinstance ( body [ '<STR_LIT>' ] [ '<STR_LIT:type>' ] , six . string_types ) : <EOL> msg = _ ( "<STR_LIT>" ) <EOL> LOG . error ( msg ) <EOL> raise exc . HTTPBadRequest ( explanation = msg ) <EOL> valid_reboot_types = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> reboot_type = body [ '<STR_LIT>' ] [ '<STR_LIT:type>' ] . upper ( ) <EOL> if not valid_reboot_types . count ( reboot_type ) : <EOL> msg = _ ( "<STR_LIT>" ) <EOL> LOG . error ( msg ) <EOL> raise exc . HTTPBadRequest ( explanation = msg ) <EOL> else : <EOL> msg = _ ( "<STR_LIT>" ) <EOL> LOG . error ( msg ) <EOL> raise exc . HTTPBadRequest ( explanation = msg ) <EOL> context = req . environ [ '<STR_LIT>' ] <EOL> instance = self . _get_server ( context , req , id ) <EOL> try : <EOL> self . compute_api . reboot ( context , instance , reboot_type ) <EOL> except exception . InstanceIsLocked as e : <EOL> raise exc . HTTPConflict ( explanation = e . format_message ( ) ) <EOL> except exception . InstanceInvalidState as state_error : <EOL> common . raise_http_conflict_for_instance_invalid_state ( state_error , <EOL> '<STR_LIT>' , id ) <EOL> return webob . Response ( status_int = <NUM_LIT> ) <EOL> def _resize ( self , req , instance_id , flavor_id , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> context = req . environ [ "<STR_LIT>" ] <EOL> instance = self . _get_server ( context , req , instance_id ) <EOL> try : <EOL> self . compute_api . resize ( context , instance , flavor_id , ** kwargs ) <EOL> except exception . QuotaError as error : <EOL> raise exc . HTTPForbidden ( <EOL> explanation = error . format_message ( ) ) <EOL> except exception . FlavorNotFound : <EOL> msg = _ ( "<STR_LIT>" ) <EOL> raise exc . HTTPBadRequest ( explanation = msg ) <EOL> except exception . CannotResizeToSameFlavor : <EOL> msg = _ ( "<STR_LIT>" ) <EOL> raise exc . HTTPBadRequest ( explanation = msg ) <EOL> except exception . CannotResizeDisk as e : <EOL> raise exc . HTTPBadRequest ( explanation = e . format_message ( ) ) <EOL> except exception . InstanceIsLocked as e : <EOL> raise exc . HTTPConflict ( explanation = e . format_message ( ) ) <EOL> except exception . InstanceInvalidState as state_error : <EOL> common . raise_http_conflict_for_instance_invalid_state ( state_error , <EOL> '<STR_LIT>' , instance_id ) <EOL> except exception . ImageNotAuthorized : <EOL> msg = _ ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> raise exc . HTTPUnauthorized ( explanation = msg ) <EOL> except exception . ImageNotFound : <EOL> msg = _ ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> raise exc . HTTPBadRequest ( explanation = msg ) <EOL> except ( exception . NoValidHost , <EOL> exception . AutoDiskConfigDisabledByImage ) as e : <EOL> raise exc . HTTPBadRequest ( explanation = e . format_message ( ) ) <EOL> except exception . Invalid : <EOL> msg = _ ( "<STR_LIT>" ) <EOL> raise exc . HTTPBadRequest ( explanation = msg ) <EOL> return webob . Response ( status_int = <NUM_LIT> ) <EOL> @ wsgi . response ( <NUM_LIT> ) <EOL> def delete ( self , req , id ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> self . _delete ( req . environ [ '<STR_LIT>' ] , req , id ) <EOL> except exception . NotFound : <EOL> msg = _ ( "<STR_LIT>" ) <EOL> raise exc . HTTPNotFound ( explanation = msg ) <EOL> except exception . InstanceIsLocked as e : <EOL> raise exc . HTTPConflict ( explanation = e . format_message ( ) ) <EOL> except exception . InstanceInvalidState as state_error : <EOL> common . raise_http_conflict_for_instance_invalid_state ( state_error , <EOL> '<STR_LIT>' , id ) <EOL> def _image_ref_from_req_data ( self , data ) : <EOL> try : <EOL> return six . text_type ( data [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> except ( TypeError , KeyError ) : <EOL> msg = _ ( "<STR_LIT>" ) <EOL> raise exc . HTTPBadRequest ( explanation = msg ) <EOL> def _image_uuid_from_href ( self , image_href ) : <EOL> if not image_href : <EOL> msg = _ ( "<STR_LIT>" ) <EOL> raise exc . HTTPBadRequest ( explanation = msg ) <EOL> image_uuid = image_href . split ( '<STR_LIT:/>' ) . pop ( ) <EOL> if not uuidutils . is_uuid_like ( image_uuid ) : <EOL> msg = _ ( "<STR_LIT>" ) <EOL> raise exc . HTTPBadRequest ( explanation = msg ) <EOL> return image_uuid <EOL> def _image_from_req_data ( self , data ) : <EOL> """<STR_LIT>""" <EOL> image_ref = data [ '<STR_LIT>' ] . get ( '<STR_LIT>' ) <EOL> bdm = data [ '<STR_LIT>' ] . get ( '<STR_LIT>' ) <EOL> bdm_v2 = data [ '<STR_LIT>' ] . get ( '<STR_LIT>' ) <EOL> if ( not image_ref and ( <EOL> ( bdm and self . ext_mgr . is_loaded ( '<STR_LIT>' ) ) or <EOL> ( bdm_v2 and <EOL> self . ext_mgr . is_loaded ( '<STR_LIT>' ) ) ) ) : <EOL> return '<STR_LIT>' <EOL> else : <EOL> image_href = self . _image_ref_from_req_data ( data ) <EOL> image_uuid = self . _image_uuid_from_href ( image_href ) <EOL> return image_uuid <EOL> def _flavor_id_from_req_data ( self , data ) : <EOL> try : <EOL> flavor_ref = data [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> except ( TypeError , KeyError ) : <EOL> msg = _ ( "<STR_LIT>" ) <EOL> raise exc . HTTPBadRequest ( explanation = msg ) <EOL> try : <EOL> return common . get_id_from_href ( flavor_ref ) <EOL> except ValueError : <EOL> msg = _ ( "<STR_LIT>" ) <EOL> raise exc . HTTPBadRequest ( explanation = msg ) <EOL> @ wsgi . response ( <NUM_LIT> ) <EOL> @ wsgi . action ( '<STR_LIT>' ) <EOL> def _action_change_password ( self , req , id , body ) : <EOL> context = req . environ [ '<STR_LIT>' ] <EOL> if ( not body . get ( '<STR_LIT>' ) <EOL> or '<STR_LIT>' not in body [ '<STR_LIT>' ] ) : <EOL> msg = _ ( "<STR_LIT>" ) <EOL> raise exc . HTTPBadRequest ( explanation = msg ) <EOL> password = self . _get_server_admin_password ( body [ '<STR_LIT>' ] ) <EOL> server = self . _get_server ( context , req , id ) <EOL> try : <EOL> self . compute_api . set_admin_password ( context , server , password ) <EOL> except exception . InstancePasswordSetFailed as e : <EOL> raise exc . HTTPConflict ( explanation = e . format_message ( ) ) <EOL> except exception . InstanceInvalidState as e : <EOL> raise common . raise_http_conflict_for_instance_invalid_state ( <EOL> e , '<STR_LIT>' , id ) <EOL> except NotImplementedError : <EOL> msg = _ ( "<STR_LIT>" ) <EOL> raise exc . HTTPNotImplemented ( explanation = msg ) <EOL> return webob . Response ( status_int = <NUM_LIT> ) <EOL> def _validate_metadata ( self , metadata ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> six . iteritems ( metadata ) <EOL> except AttributeError : <EOL> msg = _ ( "<STR_LIT>" ) <EOL> LOG . debug ( msg ) <EOL> raise exc . HTTPBadRequest ( explanation = msg ) <EOL> @ wsgi . response ( <NUM_LIT> ) <EOL> @ wsgi . action ( '<STR_LIT>' ) <EOL> def _action_resize ( self , req , id , body ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> flavor_ref = str ( body [ "<STR_LIT>" ] [ "<STR_LIT>" ] ) <EOL> if not flavor_ref : <EOL> msg = _ ( "<STR_LIT>" ) <EOL> raise exc . HTTPBadRequest ( explanation = msg ) <EOL> except ( KeyError , TypeError ) : <EOL> msg = _ ( "<STR_LIT>" ) <EOL> raise exc . HTTPBadRequest ( explanation = msg ) <EOL> kwargs = { } <EOL> if '<STR_LIT>' in body [ '<STR_LIT>' ] : <EOL> kwargs [ '<STR_LIT>' ] = body [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> return self . _resize ( req , id , flavor_ref , ** kwargs ) <EOL> @ wsgi . response ( <NUM_LIT> ) <EOL> @ wsgi . action ( '<STR_LIT>' ) <EOL> def _action_rebuild ( self , req , id , body ) : <EOL> """<STR_LIT>""" <EOL> body = body [ '<STR_LIT>' ] <EOL> try : <EOL> image_href = body [ "<STR_LIT>" ] <EOL> except ( KeyError , TypeError ) : <EOL> msg = _ ( "<STR_LIT>" ) <EOL> raise exc . HTTPBadRequest ( explanation = msg ) <EOL> image_href = self . _image_uuid_from_href ( image_href ) <EOL> password = self . _get_server_admin_password ( body ) <EOL> context = req . environ [ '<STR_LIT>' ] <EOL> instance = self . _get_server ( context , req , id ) <EOL> attr_map = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> kwargs = { } <EOL> if ( self . ext_mgr . is_loaded ( '<STR_LIT>' ) <EOL> and '<STR_LIT>' in body ) : <EOL> kwargs [ '<STR_LIT>' ] = strutils . bool_from_string ( <EOL> body [ '<STR_LIT>' ] , strict = True ) <EOL> if '<STR_LIT>' in body : <EOL> self . _validate_access_ipv4 ( body [ '<STR_LIT>' ] ) <EOL> if '<STR_LIT>' in body : <EOL> self . _validate_access_ipv6 ( body [ '<STR_LIT>' ] ) <EOL> if '<STR_LIT:name>' in body : <EOL> self . _validate_server_name ( body [ '<STR_LIT:name>' ] ) <EOL> for request_attribute , instance_attribute in attr_map . items ( ) : <EOL> try : <EOL> kwargs [ instance_attribute ] = body [ request_attribute ] <EOL> except ( KeyError , TypeError ) : <EOL> pass <EOL> self . _validate_metadata ( kwargs . get ( '<STR_LIT>' , { } ) ) <EOL> if '<STR_LIT>' in kwargs : <EOL> personality = kwargs . pop ( '<STR_LIT>' ) <EOL> files_to_inject = self . _get_injected_files ( personality ) <EOL> else : <EOL> files_to_inject = None <EOL> try : <EOL> self . compute_api . rebuild ( context , <EOL> instance , <EOL> image_href , <EOL> password , <EOL> files_to_inject = files_to_inject , <EOL> ** kwargs ) <EOL> except exception . InstanceIsLocked as e : <EOL> raise exc . HTTPConflict ( explanation = e . format_message ( ) ) <EOL> except exception . InstanceInvalidState as state_error : <EOL> common . raise_http_conflict_for_instance_invalid_state ( state_error , <EOL> '<STR_LIT>' , id ) <EOL> except exception . InstanceNotFound : <EOL> msg = _ ( "<STR_LIT>" ) <EOL> raise exc . HTTPNotFound ( explanation = msg ) <EOL> except exception . InvalidMetadataSize as error : <EOL> raise exc . HTTPRequestEntityTooLarge ( <EOL> explanation = error . format_message ( ) ) <EOL> except exception . ImageNotFound : <EOL> msg = _ ( "<STR_LIT>" ) <EOL> raise exc . HTTPBadRequest ( explanation = msg ) <EOL> except exception . QuotaError as error : <EOL> raise exc . HTTPForbidden ( explanation = error . format_message ( ) ) <EOL> except ( exception . ImageNotActive , <EOL> exception . FlavorDiskTooSmall , <EOL> exception . FlavorMemoryTooSmall , <EOL> exception . InvalidMetadata , <EOL> exception . AutoDiskConfigDisabledByImage ) as error : <EOL> raise exc . HTTPBadRequest ( explanation = error . format_message ( ) ) <EOL> instance = self . _get_server ( context , req , id , is_detail = True ) <EOL> view = self . _view_builder . show ( req , instance ) <EOL> if CONF . enable_instance_password : <EOL> view [ '<STR_LIT>' ] [ '<STR_LIT>' ] = password <EOL> robj = wsgi . ResponseObject ( view ) <EOL> return self . _add_location ( robj ) <EOL> @ wsgi . response ( <NUM_LIT> ) <EOL> @ wsgi . action ( '<STR_LIT>' ) <EOL> @ common . check_snapshots_enabled <EOL> def _action_create_image ( self , req , id , body ) : <EOL> """<STR_LIT>""" <EOL> context = req . environ [ '<STR_LIT>' ] <EOL> entity = body . get ( "<STR_LIT>" , { } ) <EOL> image_name = entity . get ( "<STR_LIT:name>" ) <EOL> if not image_name : <EOL> msg = _ ( "<STR_LIT>" ) <EOL> raise exc . HTTPBadRequest ( explanation = msg ) <EOL> props = { } <EOL> metadata = entity . get ( '<STR_LIT>' , { } ) <EOL> common . check_img_metadata_properties_quota ( context , metadata ) <EOL> try : <EOL> props . update ( metadata ) <EOL> except ValueError : <EOL> msg = _ ( "<STR_LIT>" ) <EOL> raise exc . HTTPBadRequest ( explanation = msg ) <EOL> instance = self . _get_server ( context , req , id ) <EOL> bdms = objects . BlockDeviceMappingList . get_by_instance_uuid ( <EOL> context , instance . uuid ) <EOL> try : <EOL> if self . compute_api . is_volume_backed_instance ( context , instance , <EOL> bdms ) : <EOL> policy . enforce ( context , <EOL> '<STR_LIT>' , <EOL> { '<STR_LIT>' : context . project_id , <EOL> '<STR_LIT>' : context . user_id } ) <EOL> image = self . compute_api . snapshot_volume_backed ( <EOL> context , <EOL> instance , <EOL> image_name , <EOL> extra_properties = props ) <EOL> else : <EOL> image = self . compute_api . snapshot ( context , <EOL> instance , <EOL> image_name , <EOL> extra_properties = props ) <EOL> except exception . InstanceInvalidState as state_error : <EOL> common . raise_http_conflict_for_instance_invalid_state ( state_error , <EOL> '<STR_LIT>' , id ) <EOL> except exception . Invalid as err : <EOL> raise exc . HTTPBadRequest ( explanation = err . format_message ( ) ) <EOL> image_id = str ( image [ '<STR_LIT:id>' ] ) <EOL> url_prefix = self . _view_builder . _update_glance_link_prefix ( <EOL> req . application_url ) <EOL> image_ref = common . url_join ( url_prefix , <EOL> context . project_id , <EOL> '<STR_LIT>' , <EOL> image_id ) <EOL> resp = webob . Response ( status_int = <NUM_LIT> ) <EOL> resp . headers [ '<STR_LIT>' ] = image_ref <EOL> return resp <EOL> def _get_server_admin_password ( self , server ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> password = server [ '<STR_LIT>' ] <EOL> self . _validate_admin_password ( password ) <EOL> except KeyError : <EOL> password = utils . generate_password ( ) <EOL> except ValueError : <EOL> raise exc . HTTPBadRequest ( explanation = _ ( "<STR_LIT>" ) ) <EOL> return password <EOL> def _validate_admin_password ( self , password ) : <EOL> if not isinstance ( password , six . string_types ) : <EOL> raise ValueError ( ) <EOL> def _get_server_search_options ( self ) : <EOL> """<STR_LIT>""" <EOL> return ( '<STR_LIT>' , '<STR_LIT:name>' , '<STR_LIT:status>' , '<STR_LIT:image>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> def create_resource ( ext_mgr ) : <EOL> return wsgi . Resource ( Controller ( ext_mgr ) ) <EOL> def remove_invalid_options ( context , search_options , allowed_search_options ) : <EOL> """<STR_LIT>""" <EOL> if context . is_admin : <EOL> for key in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> search_options . pop ( key , None ) <EOL> return <EOL> unknown_options = [ opt for opt in search_options <EOL> if opt not in allowed_search_options ] <EOL> LOG . debug ( "<STR_LIT>" , <EOL> "<STR_LIT:U+002CU+0020>" . join ( unknown_options ) ) <EOL> for opt in unknown_options : <EOL> search_options . pop ( opt , None ) </s>
