begin_unit
comment|'# Copyright 2010 OpenStack Foundation'
nl|'\n'
comment|'# Copyright 2011 Piston Cloud Computing, Inc'
nl|'\n'
comment|'# All Rights Reserved.'
nl|'\n'
comment|'#'
nl|'\n'
comment|'#    Licensed under the Apache License, Version 2.0 (the "License"); you may'
nl|'\n'
comment|'#    not use this file except in compliance with the License. You may obtain'
nl|'\n'
comment|'#    a copy of the License at'
nl|'\n'
comment|'#'
nl|'\n'
comment|'#         http://www.apache.org/licenses/LICENSE-2.0'
nl|'\n'
comment|'#'
nl|'\n'
comment|'#    Unless required by applicable law or agreed to in writing, software'
nl|'\n'
comment|'#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT'
nl|'\n'
comment|'#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the'
nl|'\n'
comment|'#    License for the specific language governing permissions and limitations'
nl|'\n'
comment|'#    under the License.'
nl|'\n'
nl|'\n'
name|'import'
name|'base64'
newline|'\n'
name|'import'
name|'re'
newline|'\n'
name|'import'
name|'sys'
newline|'\n'
nl|'\n'
name|'from'
name|'oslo_log'
name|'import'
name|'log'
name|'as'
name|'logging'
newline|'\n'
name|'import'
name|'oslo_messaging'
name|'as'
name|'messaging'
newline|'\n'
name|'from'
name|'oslo_utils'
name|'import'
name|'netutils'
newline|'\n'
name|'from'
name|'oslo_utils'
name|'import'
name|'strutils'
newline|'\n'
name|'from'
name|'oslo_utils'
name|'import'
name|'timeutils'
newline|'\n'
name|'from'
name|'oslo_utils'
name|'import'
name|'uuidutils'
newline|'\n'
name|'import'
name|'six'
newline|'\n'
name|'import'
name|'webob'
newline|'\n'
name|'from'
name|'webob'
name|'import'
name|'exc'
newline|'\n'
nl|'\n'
name|'from'
name|'nova'
op|'.'
name|'api'
op|'.'
name|'openstack'
name|'import'
name|'common'
newline|'\n'
name|'from'
name|'nova'
op|'.'
name|'api'
op|'.'
name|'openstack'
op|'.'
name|'compute'
op|'.'
name|'views'
name|'import'
name|'servers'
name|'as'
name|'views_servers'
newline|'\n'
name|'from'
name|'nova'
op|'.'
name|'api'
op|'.'
name|'openstack'
name|'import'
name|'wsgi'
newline|'\n'
name|'from'
name|'nova'
name|'import'
name|'block_device'
newline|'\n'
name|'from'
name|'nova'
name|'import'
name|'compute'
newline|'\n'
name|'from'
name|'nova'
op|'.'
name|'compute'
name|'import'
name|'flavors'
newline|'\n'
name|'import'
name|'nova'
op|'.'
name|'conf'
newline|'\n'
name|'from'
name|'nova'
name|'import'
name|'exception'
newline|'\n'
name|'from'
name|'nova'
op|'.'
name|'i18n'
name|'import'
name|'_'
newline|'\n'
name|'from'
name|'nova'
name|'import'
name|'objects'
newline|'\n'
name|'from'
name|'nova'
name|'import'
name|'policy'
newline|'\n'
name|'from'
name|'nova'
name|'import'
name|'utils'
newline|'\n'
nl|'\n'
nl|'\n'
DECL|variable|CONF
name|'CONF'
op|'='
name|'nova'
op|'.'
name|'conf'
op|'.'
name|'CONF'
newline|'\n'
nl|'\n'
DECL|variable|LOG
name|'LOG'
op|'='
name|'logging'
op|'.'
name|'getLogger'
op|'('
name|'__name__'
op|')'
newline|'\n'
nl|'\n'
DECL|variable|CREATE_EXCEPTIONS
name|'CREATE_EXCEPTIONS'
op|'='
op|'{'
nl|'\n'
name|'exception'
op|'.'
name|'InvalidMetadataSize'
op|':'
name|'exc'
op|'.'
name|'HTTPRequestEntityTooLarge'
op|','
nl|'\n'
name|'exception'
op|'.'
name|'ImageNotFound'
op|':'
name|'exc'
op|'.'
name|'HTTPBadRequest'
op|','
nl|'\n'
name|'exception'
op|'.'
name|'FlavorNotFound'
op|':'
name|'exc'
op|'.'
name|'HTTPBadRequest'
op|','
nl|'\n'
name|'exception'
op|'.'
name|'KeypairNotFound'
op|':'
name|'exc'
op|'.'
name|'HTTPBadRequest'
op|','
nl|'\n'
name|'exception'
op|'.'
name|'ConfigDriveInvalidValue'
op|':'
name|'exc'
op|'.'
name|'HTTPBadRequest'
op|','
nl|'\n'
name|'exception'
op|'.'
name|'ImageNotActive'
op|':'
name|'exc'
op|'.'
name|'HTTPBadRequest'
op|','
nl|'\n'
name|'exception'
op|'.'
name|'FlavorDiskTooSmall'
op|':'
name|'exc'
op|'.'
name|'HTTPBadRequest'
op|','
nl|'\n'
name|'exception'
op|'.'
name|'FlavorMemoryTooSmall'
op|':'
name|'exc'
op|'.'
name|'HTTPBadRequest'
op|','
nl|'\n'
name|'exception'
op|'.'
name|'NetworkNotFound'
op|':'
name|'exc'
op|'.'
name|'HTTPBadRequest'
op|','
nl|'\n'
name|'exception'
op|'.'
name|'PortNotFound'
op|':'
name|'exc'
op|'.'
name|'HTTPBadRequest'
op|','
nl|'\n'
name|'exception'
op|'.'
name|'FixedIpAlreadyInUse'
op|':'
name|'exc'
op|'.'
name|'HTTPBadRequest'
op|','
nl|'\n'
name|'exception'
op|'.'
name|'SecurityGroupNotFound'
op|':'
name|'exc'
op|'.'
name|'HTTPBadRequest'
op|','
nl|'\n'
name|'exception'
op|'.'
name|'InstanceUserDataTooLarge'
op|':'
name|'exc'
op|'.'
name|'HTTPBadRequest'
op|','
nl|'\n'
name|'exception'
op|'.'
name|'InstanceUserDataMalformed'
op|':'
name|'exc'
op|'.'
name|'HTTPBadRequest'
op|','
nl|'\n'
name|'exception'
op|'.'
name|'ImageNUMATopologyIncomplete'
op|':'
name|'exc'
op|'.'
name|'HTTPBadRequest'
op|','
nl|'\n'
name|'exception'
op|'.'
name|'ImageNUMATopologyForbidden'
op|':'
name|'exc'
op|'.'
name|'HTTPBadRequest'
op|','
nl|'\n'
name|'exception'
op|'.'
name|'ImageNUMATopologyAsymmetric'
op|':'
name|'exc'
op|'.'
name|'HTTPBadRequest'
op|','
nl|'\n'
name|'exception'
op|'.'
name|'ImageNUMATopologyCPUOutOfRange'
op|':'
name|'exc'
op|'.'
name|'HTTPBadRequest'
op|','
nl|'\n'
name|'exception'
op|'.'
name|'ImageNUMATopologyCPUDuplicates'
op|':'
name|'exc'
op|'.'
name|'HTTPBadRequest'
op|','
nl|'\n'
name|'exception'
op|'.'
name|'ImageNUMATopologyCPUsUnassigned'
op|':'
name|'exc'
op|'.'
name|'HTTPBadRequest'
op|','
nl|'\n'
name|'exception'
op|'.'
name|'ImageNUMATopologyMemoryOutOfRange'
op|':'
name|'exc'
op|'.'
name|'HTTPBadRequest'
op|','
nl|'\n'
name|'exception'
op|'.'
name|'PortInUse'
op|':'
name|'exc'
op|'.'
name|'HTTPConflict'
op|','
nl|'\n'
name|'exception'
op|'.'
name|'InstanceExists'
op|':'
name|'exc'
op|'.'
name|'HTTPConflict'
op|','
nl|'\n'
name|'exception'
op|'.'
name|'NoUniqueMatch'
op|':'
name|'exc'
op|'.'
name|'HTTPConflict'
op|','
nl|'\n'
name|'exception'
op|'.'
name|'Invalid'
op|':'
name|'exc'
op|'.'
name|'HTTPBadRequest'
op|','
nl|'\n'
name|'exception'
op|'.'
name|'InstanceGroupNotFound'
op|':'
name|'exc'
op|'.'
name|'HTTPBadRequest'
op|','
nl|'\n'
op|'}'
newline|'\n'
nl|'\n'
DECL|variable|CREATE_EXCEPTIONS_MSGS
name|'CREATE_EXCEPTIONS_MSGS'
op|'='
op|'{'
nl|'\n'
name|'exception'
op|'.'
name|'ImageNotFound'
op|':'
name|'_'
op|'('
string|'"Can not find requested image"'
op|')'
op|','
nl|'\n'
name|'exception'
op|'.'
name|'FlavorNotFound'
op|':'
name|'_'
op|'('
string|'"Invalid flavorRef provided."'
op|')'
op|','
nl|'\n'
name|'exception'
op|'.'
name|'KeypairNotFound'
op|':'
name|'_'
op|'('
string|'"Invalid key_name provided."'
op|')'
op|','
nl|'\n'
name|'exception'
op|'.'
name|'ConfigDriveInvalidValue'
op|':'
name|'_'
op|'('
string|'"Invalid config_drive provided."'
op|')'
op|','
nl|'\n'
op|'}'
newline|'\n'
nl|'\n'
nl|'\n'
DECL|class|Controller
name|'class'
name|'Controller'
op|'('
name|'wsgi'
op|'.'
name|'Controller'
op|')'
op|':'
newline|'\n'
indent|'    '
string|'"""The Server API base controller class for the OpenStack API."""'
newline|'\n'
nl|'\n'
DECL|variable|_view_builder_class
name|'_view_builder_class'
op|'='
name|'views_servers'
op|'.'
name|'ViewBuilder'
newline|'\n'
nl|'\n'
op|'@'
name|'staticmethod'
newline|'\n'
DECL|member|_add_location
name|'def'
name|'_add_location'
op|'('
name|'robj'
op|')'
op|':'
newline|'\n'
comment|'# Just in case...'
nl|'\n'
indent|'        '
name|'if'
string|"'server'"
name|'not'
name|'in'
name|'robj'
op|'.'
name|'obj'
op|':'
newline|'\n'
indent|'            '
name|'return'
name|'robj'
newline|'\n'
nl|'\n'
dedent|''
name|'link'
op|'='
op|'['
name|'l'
name|'for'
name|'l'
name|'in'
name|'robj'
op|'.'
name|'obj'
op|'['
string|"'server'"
op|']'
op|'['
string|"'links'"
op|']'
name|'if'
name|'l'
op|'['
string|"'rel'"
op|']'
op|'=='
string|"'self'"
op|']'
newline|'\n'
name|'if'
name|'link'
op|':'
newline|'\n'
indent|'            '
name|'robj'
op|'['
string|"'Location'"
op|']'
op|'='
name|'utils'
op|'.'
name|'utf8'
op|'('
name|'link'
op|'['
number|'0'
op|']'
op|'['
string|"'href'"
op|']'
op|')'
newline|'\n'
nl|'\n'
comment|'# Convenience return'
nl|'\n'
dedent|''
name|'return'
name|'robj'
newline|'\n'
nl|'\n'
DECL|member|__init__
dedent|''
name|'def'
name|'__init__'
op|'('
name|'self'
op|','
name|'ext_mgr'
op|'='
name|'None'
op|','
op|'**'
name|'kwargs'
op|')'
op|':'
newline|'\n'
indent|'        '
name|'super'
op|'('
name|'Controller'
op|','
name|'self'
op|')'
op|'.'
name|'__init__'
op|'('
op|'**'
name|'kwargs'
op|')'
newline|'\n'
name|'self'
op|'.'
name|'compute_api'
op|'='
name|'compute'
op|'.'
name|'API'
op|'('
op|')'
newline|'\n'
name|'self'
op|'.'
name|'ext_mgr'
op|'='
name|'ext_mgr'
newline|'\n'
nl|'\n'
DECL|member|index
dedent|''
name|'def'
name|'index'
op|'('
name|'self'
op|','
name|'req'
op|')'
op|':'
newline|'\n'
indent|'        '
string|'"""Returns a list of server names and ids for a given user."""'
newline|'\n'
name|'try'
op|':'
newline|'\n'
indent|'            '
name|'servers'
op|'='
name|'self'
op|'.'
name|'_get_servers'
op|'('
name|'req'
op|','
name|'is_detail'
op|'='
name|'False'
op|')'
newline|'\n'
dedent|''
name|'except'
name|'exception'
op|'.'
name|'Invalid'
name|'as'
name|'err'
op|':'
newline|'\n'
indent|'            '
name|'raise'
name|'exc'
op|'.'
name|'HTTPBadRequest'
op|'('
name|'explanation'
op|'='
name|'err'
op|'.'
name|'format_message'
op|'('
op|')'
op|')'
newline|'\n'
dedent|''
name|'return'
name|'servers'
newline|'\n'
nl|'\n'
DECL|member|detail
dedent|''
name|'def'
name|'detail'
op|'('
name|'self'
op|','
name|'req'
op|')'
op|':'
newline|'\n'
indent|'        '
string|'"""Returns a list of server details for a given user."""'
newline|'\n'
name|'try'
op|':'
newline|'\n'
indent|'            '
name|'servers'
op|'='
name|'self'
op|'.'
name|'_get_servers'
op|'('
name|'req'
op|','
name|'is_detail'
op|'='
name|'True'
op|')'
newline|'\n'
dedent|''
name|'except'
name|'exception'
op|'.'
name|'Invalid'
name|'as'
name|'err'
op|':'
newline|'\n'
indent|'            '
name|'raise'
name|'exc'
op|'.'
name|'HTTPBadRequest'
op|'('
name|'explanation'
op|'='
name|'err'
op|'.'
name|'format_message'
op|'('
op|')'
op|')'
newline|'\n'
dedent|''
name|'return'
name|'servers'
newline|'\n'
nl|'\n'
DECL|member|_get_servers
dedent|''
name|'def'
name|'_get_servers'
op|'('
name|'self'
op|','
name|'req'
op|','
name|'is_detail'
op|')'
op|':'
newline|'\n'
indent|'        '
string|'"""Returns a list of servers, based on any search options specified."""'
newline|'\n'
nl|'\n'
name|'search_opts'
op|'='
op|'{'
op|'}'
newline|'\n'
name|'search_opts'
op|'.'
name|'update'
op|'('
name|'req'
op|'.'
name|'GET'
op|')'
newline|'\n'
nl|'\n'
name|'context'
op|'='
name|'req'
op|'.'
name|'environ'
op|'['
string|"'nova.context'"
op|']'
newline|'\n'
name|'remove_invalid_options'
op|'('
name|'context'
op|','
name|'search_opts'
op|','
nl|'\n'
name|'self'
op|'.'
name|'_get_server_search_options'
op|'('
op|')'
op|')'
newline|'\n'
nl|'\n'
comment|"# Verify search by 'status' contains a valid status."
nl|'\n'
comment|'# Convert it to filter by vm_state or task_state for compute_api.'
nl|'\n'
name|'search_opts'
op|'.'
name|'pop'
op|'('
string|"'status'"
op|','
name|'None'
op|')'
newline|'\n'
name|'if'
string|"'status'"
name|'in'
name|'req'
op|'.'
name|'GET'
op|'.'
name|'keys'
op|'('
op|')'
op|':'
newline|'\n'
indent|'            '
name|'statuses'
op|'='
name|'req'
op|'.'
name|'GET'
op|'.'
name|'getall'
op|'('
string|"'status'"
op|')'
newline|'\n'
name|'states'
op|'='
name|'common'
op|'.'
name|'task_and_vm_state_from_status'
op|'('
name|'statuses'
op|')'
newline|'\n'
name|'vm_state'
op|','
name|'task_state'
op|'='
name|'states'
newline|'\n'
name|'if'
name|'not'
name|'vm_state'
name|'and'
name|'not'
name|'task_state'
op|':'
newline|'\n'
indent|'                '
name|'return'
op|'{'
string|"'servers'"
op|':'
op|'['
op|']'
op|'}'
newline|'\n'
dedent|''
name|'search_opts'
op|'['
string|"'vm_state'"
op|']'
op|'='
name|'vm_state'
newline|'\n'
comment|"# When we search by vm state, task state will return 'default'."
nl|'\n'
comment|"# So we don't need task_state search_opt."
nl|'\n'
name|'if'
string|"'default'"
name|'not'
name|'in'
name|'task_state'
op|':'
newline|'\n'
indent|'                '
name|'search_opts'
op|'['
string|"'task_state'"
op|']'
op|'='
name|'task_state'
newline|'\n'
nl|'\n'
dedent|''
dedent|''
name|'if'
string|"'changes-since'"
name|'in'
name|'search_opts'
op|':'
newline|'\n'
indent|'            '
name|'try'
op|':'
newline|'\n'
indent|'                '
name|'parsed'
op|'='
name|'timeutils'
op|'.'
name|'parse_isotime'
op|'('
name|'search_opts'
op|'['
string|"'changes-since'"
op|']'
op|')'
newline|'\n'
dedent|''
name|'except'
name|'ValueError'
op|':'
newline|'\n'
indent|'                '
name|'msg'
op|'='
name|'_'
op|'('
string|"'Invalid changes-since value'"
op|')'
newline|'\n'
name|'raise'
name|'exc'
op|'.'
name|'HTTPBadRequest'
op|'('
name|'explanation'
op|'='
name|'msg'
op|')'
newline|'\n'
dedent|''
name|'search_opts'
op|'['
string|"'changes-since'"
op|']'
op|'='
name|'parsed'
newline|'\n'
nl|'\n'
comment|"# By default, compute's get_all() will return deleted instances."
nl|'\n'
comment|"# If an admin hasn't specified a 'deleted' search option, we need"
nl|'\n'
comment|'# to filter out deleted instances by setting the filter ourselves.'
nl|'\n'
comment|"# ... Unless 'changes-since' is specified, because 'changes-since'"
nl|'\n'
comment|'# should return recently deleted images according to the API spec.'
nl|'\n'
nl|'\n'
dedent|''
name|'if'
string|"'deleted'"
name|'not'
name|'in'
name|'search_opts'
op|':'
newline|'\n'
indent|'            '
name|'if'
string|"'changes-since'"
name|'not'
name|'in'
name|'search_opts'
op|':'
newline|'\n'
comment|"# No 'changes-since', so we only want non-deleted servers"
nl|'\n'
indent|'                '
name|'search_opts'
op|'['
string|"'deleted'"
op|']'
op|'='
name|'False'
newline|'\n'
dedent|''
dedent|''
name|'else'
op|':'
newline|'\n'
comment|'# Convert deleted filter value to a valid boolean.'
nl|'\n'
comment|'# Return non-deleted servers if an invalid value'
nl|'\n'
comment|'# is passed with deleted filter.'
nl|'\n'
indent|'            '
name|'search_opts'
op|'['
string|"'deleted'"
op|']'
op|'='
name|'strutils'
op|'.'
name|'bool_from_string'
op|'('
nl|'\n'
name|'search_opts'
op|'['
string|"'deleted'"
op|']'
op|','
name|'default'
op|'='
name|'False'
op|')'
newline|'\n'
nl|'\n'
dedent|''
name|'if'
name|'search_opts'
op|'.'
name|'get'
op|'('
string|'"vm_state"'
op|')'
op|'=='
op|'['
string|"'deleted'"
op|']'
op|':'
newline|'\n'
indent|'            '
name|'if'
name|'context'
op|'.'
name|'is_admin'
op|':'
newline|'\n'
indent|'                '
name|'search_opts'
op|'['
string|"'deleted'"
op|']'
op|'='
name|'True'
newline|'\n'
dedent|''
name|'else'
op|':'
newline|'\n'
indent|'                '
name|'msg'
op|'='
name|'_'
op|'('
string|'"Only administrators may list deleted instances"'
op|')'
newline|'\n'
name|'raise'
name|'exc'
op|'.'
name|'HTTPForbidden'
op|'('
name|'explanation'
op|'='
name|'msg'
op|')'
newline|'\n'
nl|'\n'
dedent|''
dedent|''
name|'all_tenants'
op|'='
name|'common'
op|'.'
name|'is_all_tenants'
op|'('
name|'search_opts'
op|')'
newline|'\n'
comment|'# use the boolean from here on out so remove the entry from search_opts'
nl|'\n'
comment|"# if it's present"
nl|'\n'
name|'search_opts'
op|'.'
name|'pop'
op|'('
string|"'all_tenants'"
op|','
name|'None'
op|')'
newline|'\n'
nl|'\n'
name|'elevated'
op|'='
name|'None'
newline|'\n'
name|'if'
name|'all_tenants'
op|':'
newline|'\n'
indent|'            '
name|'policy'
op|'.'
name|'enforce'
op|'('
name|'context'
op|','
string|"'compute:get_all_tenants'"
op|','
nl|'\n'
op|'{'
string|"'project_id'"
op|':'
name|'context'
op|'.'
name|'project_id'
op|','
nl|'\n'
string|"'user_id'"
op|':'
name|'context'
op|'.'
name|'user_id'
op|'}'
op|')'
newline|'\n'
name|'elevated'
op|'='
name|'context'
op|'.'
name|'elevated'
op|'('
op|')'
newline|'\n'
dedent|''
name|'else'
op|':'
newline|'\n'
indent|'            '
name|'if'
name|'context'
op|'.'
name|'project_id'
op|':'
newline|'\n'
indent|'                '
name|'search_opts'
op|'['
string|"'project_id'"
op|']'
op|'='
name|'context'
op|'.'
name|'project_id'
newline|'\n'
dedent|''
name|'else'
op|':'
newline|'\n'
indent|'                '
name|'search_opts'
op|'['
string|"'user_id'"
op|']'
op|'='
name|'context'
op|'.'
name|'user_id'
newline|'\n'
nl|'\n'
dedent|''
dedent|''
name|'limit'
op|','
name|'marker'
op|'='
name|'common'
op|'.'
name|'get_limit_and_marker'
op|'('
name|'req'
op|')'
newline|'\n'
comment|'# Sorting by multiple keys and directions is conditionally enabled'
nl|'\n'
name|'sort_keys'
op|','
name|'sort_dirs'
op|'='
name|'None'
op|','
name|'None'
newline|'\n'
name|'if'
name|'self'
op|'.'
name|'ext_mgr'
op|'.'
name|'is_loaded'
op|'('
string|"'os-server-sort-keys'"
op|')'
op|':'
newline|'\n'
indent|'            '
name|'sort_keys'
op|','
name|'sort_dirs'
op|'='
name|'common'
op|'.'
name|'get_sort_params'
op|'('
name|'req'
op|'.'
name|'params'
op|')'
newline|'\n'
nl|'\n'
dedent|''
name|'expected_attrs'
op|'='
name|'None'
newline|'\n'
name|'if'
name|'is_detail'
op|':'
newline|'\n'
comment|'# merge our expected attrs with what the view builder needs for'
nl|'\n'
comment|'# showing details'
nl|'\n'
indent|'            '
name|'expected_attrs'
op|'='
name|'self'
op|'.'
name|'_view_builder'
op|'.'
name|'get_show_expected_attrs'
op|'('
nl|'\n'
name|'expected_attrs'
op|')'
newline|'\n'
nl|'\n'
dedent|''
name|'try'
op|':'
newline|'\n'
indent|'            '
name|'instance_list'
op|'='
name|'self'
op|'.'
name|'compute_api'
op|'.'
name|'get_all'
op|'('
name|'elevated'
name|'or'
name|'context'
op|','
nl|'\n'
name|'search_opts'
op|'='
name|'search_opts'
op|','
name|'limit'
op|'='
name|'limit'
op|','
name|'marker'
op|'='
name|'marker'
op|','
nl|'\n'
name|'want_objects'
op|'='
name|'True'
op|','
name|'expected_attrs'
op|'='
name|'expected_attrs'
op|','
nl|'\n'
name|'sort_keys'
op|'='
name|'sort_keys'
op|','
name|'sort_dirs'
op|'='
name|'sort_dirs'
op|')'
newline|'\n'
dedent|''
name|'except'
name|'exception'
op|'.'
name|'MarkerNotFound'
op|':'
newline|'\n'
indent|'            '
name|'msg'
op|'='
name|'_'
op|'('
string|"'marker [%s] not found'"
op|')'
op|'%'
name|'marker'
newline|'\n'
name|'raise'
name|'exc'
op|'.'
name|'HTTPBadRequest'
op|'('
name|'explanation'
op|'='
name|'msg'
op|')'
newline|'\n'
dedent|''
name|'except'
name|'exception'
op|'.'
name|'FlavorNotFound'
op|':'
newline|'\n'
indent|'            '
name|'LOG'
op|'.'
name|'debug'
op|'('
string|'"Flavor \'%s\' could not be found"'
op|','
name|'search_opts'
op|'['
string|"'flavor'"
op|']'
op|')'
newline|'\n'
name|'instance_list'
op|'='
name|'objects'
op|'.'
name|'InstanceList'
op|'('
op|')'
newline|'\n'
nl|'\n'
dedent|''
name|'if'
name|'is_detail'
op|':'
newline|'\n'
indent|'            '
name|'instance_list'
op|'.'
name|'_context'
op|'='
name|'context'
newline|'\n'
name|'instance_list'
op|'.'
name|'fill_faults'
op|'('
op|')'
newline|'\n'
name|'response'
op|'='
name|'self'
op|'.'
name|'_view_builder'
op|'.'
name|'detail'
op|'('
name|'req'
op|','
name|'instance_list'
op|')'
newline|'\n'
dedent|''
name|'else'
op|':'
newline|'\n'
indent|'            '
name|'response'
op|'='
name|'self'
op|'.'
name|'_view_builder'
op|'.'
name|'index'
op|'('
name|'req'
op|','
name|'instance_list'
op|')'
newline|'\n'
dedent|''
name|'req'
op|'.'
name|'cache_db_instances'
op|'('
name|'instance_list'
op|')'
newline|'\n'
name|'return'
name|'response'
newline|'\n'
nl|'\n'
DECL|member|_get_server
dedent|''
name|'def'
name|'_get_server'
op|'('
name|'self'
op|','
name|'context'
op|','
name|'req'
op|','
name|'instance_uuid'
op|','
name|'is_detail'
op|'='
name|'False'
op|')'
op|':'
newline|'\n'
indent|'        '
string|'"""Utility function for looking up an instance by uuid.\n\n        :param context: request context for auth\n        :param req: HTTP request. The instance is cached in this request.\n        :param instance_uuid: UUID of the server instance to get\n        :param is_detail: True if you plan on showing the details of the\n            instance in the response, False otherwise.\n        """'
newline|'\n'
name|'expected_attrs'
op|'='
op|'['
string|"'flavor'"
op|']'
newline|'\n'
name|'if'
name|'is_detail'
op|':'
newline|'\n'
indent|'            '
name|'expected_attrs'
op|'='
name|'self'
op|'.'
name|'_view_builder'
op|'.'
name|'get_show_expected_attrs'
op|'('
nl|'\n'
name|'expected_attrs'
op|')'
newline|'\n'
dedent|''
name|'instance'
op|'='
name|'common'
op|'.'
name|'get_instance'
op|'('
name|'self'
op|'.'
name|'compute_api'
op|','
name|'context'
op|','
nl|'\n'
name|'instance_uuid'
op|','
nl|'\n'
name|'expected_attrs'
op|'='
name|'expected_attrs'
op|')'
newline|'\n'
name|'req'
op|'.'
name|'cache_db_instance'
op|'('
name|'instance'
op|')'
newline|'\n'
name|'return'
name|'instance'
newline|'\n'
nl|'\n'
DECL|member|_check_string_length
dedent|''
name|'def'
name|'_check_string_length'
op|'('
name|'self'
op|','
name|'value'
op|','
name|'name'
op|','
name|'max_length'
op|'='
name|'None'
op|')'
op|':'
newline|'\n'
indent|'        '
name|'try'
op|':'
newline|'\n'
indent|'            '
name|'if'
name|'isinstance'
op|'('
name|'value'
op|','
name|'six'
op|'.'
name|'string_types'
op|')'
op|':'
newline|'\n'
indent|'                '
name|'value'
op|'='
name|'value'
op|'.'
name|'strip'
op|'('
op|')'
newline|'\n'
dedent|''
name|'utils'
op|'.'
name|'check_string_length'
op|'('
name|'value'
op|','
name|'name'
op|','
name|'min_length'
op|'='
number|'1'
op|','
nl|'\n'
name|'max_length'
op|'='
name|'max_length'
op|')'
newline|'\n'
dedent|''
name|'except'
name|'exception'
op|'.'
name|'InvalidInput'
name|'as'
name|'e'
op|':'
newline|'\n'
indent|'            '
name|'raise'
name|'exc'
op|'.'
name|'HTTPBadRequest'
op|'('
name|'explanation'
op|'='
name|'e'
op|'.'
name|'format_message'
op|'('
op|')'
op|')'
newline|'\n'
nl|'\n'
DECL|member|_validate_server_name
dedent|''
dedent|''
name|'def'
name|'_validate_server_name'
op|'('
name|'self'
op|','
name|'value'
op|')'
op|':'
newline|'\n'
indent|'        '
name|'self'
op|'.'
name|'_check_string_length'
op|'('
name|'value'
op|','
string|"'Server name'"
op|','
name|'max_length'
op|'='
number|'255'
op|')'
newline|'\n'
nl|'\n'
DECL|member|_get_injected_files
dedent|''
name|'def'
name|'_get_injected_files'
op|'('
name|'self'
op|','
name|'personality'
op|')'
op|':'
newline|'\n'
indent|'        '
string|'"""Create a list of injected files from the personality attribute.\n\n        At this time, injected_files must be formatted as a list of\n        (file_path, file_content) pairs for compatibility with the\n        underlying compute service.\n        """'
newline|'\n'
name|'injected_files'
op|'='
op|'['
op|']'
newline|'\n'
nl|'\n'
name|'for'
name|'item'
name|'in'
name|'personality'
op|':'
newline|'\n'
indent|'            '
name|'try'
op|':'
newline|'\n'
indent|'                '
name|'path'
op|'='
name|'item'
op|'['
string|"'path'"
op|']'
newline|'\n'
name|'contents'
op|'='
name|'item'
op|'['
string|"'contents'"
op|']'
newline|'\n'
dedent|''
name|'except'
name|'KeyError'
name|'as'
name|'key'
op|':'
newline|'\n'
indent|'                '
name|'expl'
op|'='
name|'_'
op|'('
string|"'Bad personality format: missing %s'"
op|')'
op|'%'
name|'key'
newline|'\n'
name|'raise'
name|'exc'
op|'.'
name|'HTTPBadRequest'
op|'('
name|'explanation'
op|'='
name|'expl'
op|')'
newline|'\n'
dedent|''
name|'except'
name|'TypeError'
op|':'
newline|'\n'
indent|'                '
name|'expl'
op|'='
name|'_'
op|'('
string|"'Bad personality format'"
op|')'
newline|'\n'
name|'raise'
name|'exc'
op|'.'
name|'HTTPBadRequest'
op|'('
name|'explanation'
op|'='
name|'expl'
op|')'
newline|'\n'
dedent|''
name|'if'
name|'self'
op|'.'
name|'_decode_base64'
op|'('
name|'contents'
op|')'
name|'is'
name|'None'
op|':'
newline|'\n'
indent|'                '
name|'expl'
op|'='
name|'_'
op|'('
string|"'Personality content for %s cannot be decoded'"
op|')'
op|'%'
name|'path'
newline|'\n'
name|'raise'
name|'exc'
op|'.'
name|'HTTPBadRequest'
op|'('
name|'explanation'
op|'='
name|'expl'
op|')'
newline|'\n'
dedent|''
name|'injected_files'
op|'.'
name|'append'
op|'('
op|'('
name|'path'
op|','
name|'contents'
op|')'
op|')'
newline|'\n'
dedent|''
name|'return'
name|'injected_files'
newline|'\n'
nl|'\n'
DECL|member|_get_requested_networks
dedent|''
name|'def'
name|'_get_requested_networks'
op|'('
name|'self'
op|','
name|'requested_networks'
op|')'
op|':'
newline|'\n'
indent|'        '
string|'"""Create a list of requested networks from the networks attribute."""'
newline|'\n'
name|'networks'
op|'='
op|'['
op|']'
newline|'\n'
name|'network_uuids'
op|'='
op|'['
op|']'
newline|'\n'
name|'for'
name|'network'
name|'in'
name|'requested_networks'
op|':'
newline|'\n'
indent|'            '
name|'request'
op|'='
name|'objects'
op|'.'
name|'NetworkRequest'
op|'('
op|')'
newline|'\n'
name|'try'
op|':'
newline|'\n'
indent|'                '
name|'try'
op|':'
newline|'\n'
indent|'                    '
name|'request'
op|'.'
name|'port_id'
op|'='
name|'network'
op|'.'
name|'get'
op|'('
string|"'port'"
op|','
name|'None'
op|')'
newline|'\n'
dedent|''
name|'except'
name|'ValueError'
op|':'
newline|'\n'
indent|'                    '
name|'msg'
op|'='
name|'_'
op|'('
string|'"Bad port format: port uuid is "'
nl|'\n'
string|'"not in proper format "'
nl|'\n'
string|'"(%s)"'
op|')'
op|'%'
name|'network'
op|'.'
name|'get'
op|'('
string|"'port'"
op|')'
newline|'\n'
name|'raise'
name|'exc'
op|'.'
name|'HTTPBadRequest'
op|'('
name|'explanation'
op|'='
name|'msg'
op|')'
newline|'\n'
dedent|''
name|'if'
name|'request'
op|'.'
name|'port_id'
op|':'
newline|'\n'
indent|'                    '
name|'request'
op|'.'
name|'network_id'
op|'='
name|'None'
newline|'\n'
name|'if'
name|'not'
name|'utils'
op|'.'
name|'is_neutron'
op|'('
op|')'
op|':'
newline|'\n'
comment|'# port parameter is only for neutron v2.0'
nl|'\n'
indent|'                        '
name|'msg'
op|'='
name|'_'
op|'('
string|'"Unknown argument : port"'
op|')'
newline|'\n'
name|'raise'
name|'exc'
op|'.'
name|'HTTPBadRequest'
op|'('
name|'explanation'
op|'='
name|'msg'
op|')'
newline|'\n'
dedent|''
dedent|''
name|'else'
op|':'
newline|'\n'
indent|'                    '
name|'request'
op|'.'
name|'network_id'
op|'='
name|'network'
op|'['
string|"'uuid'"
op|']'
newline|'\n'
nl|'\n'
dedent|''
name|'if'
op|'('
name|'not'
name|'request'
op|'.'
name|'port_id'
name|'and'
name|'not'
nl|'\n'
name|'uuidutils'
op|'.'
name|'is_uuid_like'
op|'('
name|'request'
op|'.'
name|'network_id'
op|')'
op|')'
op|':'
newline|'\n'
indent|'                    '
name|'br_uuid'
op|'='
name|'request'
op|'.'
name|'network_id'
op|'.'
name|'split'
op|'('
string|"'-'"
op|','
number|'1'
op|')'
op|'['
op|'-'
number|'1'
op|']'
newline|'\n'
name|'if'
name|'not'
name|'uuidutils'
op|'.'
name|'is_uuid_like'
op|'('
name|'br_uuid'
op|')'
op|':'
newline|'\n'
indent|'                        '
name|'msg'
op|'='
name|'_'
op|'('
string|'"Bad networks format: network uuid is "'
nl|'\n'
string|'"not in proper format "'
nl|'\n'
string|'"(%s)"'
op|')'
op|'%'
name|'request'
op|'.'
name|'network_id'
newline|'\n'
name|'raise'
name|'exc'
op|'.'
name|'HTTPBadRequest'
op|'('
name|'explanation'
op|'='
name|'msg'
op|')'
newline|'\n'
nl|'\n'
comment|'# fixed IP address is optional'
nl|'\n'
comment|'# if the fixed IP address is not provided then'
nl|'\n'
comment|'# it will use one of the available IP address from the network'
nl|'\n'
dedent|''
dedent|''
name|'try'
op|':'
newline|'\n'
indent|'                    '
name|'request'
op|'.'
name|'address'
op|'='
name|'network'
op|'.'
name|'get'
op|'('
string|"'fixed_ip'"
op|','
name|'None'
op|')'
newline|'\n'
dedent|''
name|'except'
name|'ValueError'
op|':'
newline|'\n'
indent|'                    '
name|'msg'
op|'='
op|'('
name|'_'
op|'('
string|'"Invalid fixed IP address (%s)"'
op|')'
op|'%'
nl|'\n'
name|'network'
op|'.'
name|'get'
op|'('
string|"'fixed_ip'"
op|')'
op|')'
newline|'\n'
name|'raise'
name|'exc'
op|'.'
name|'HTTPBadRequest'
op|'('
name|'explanation'
op|'='
name|'msg'
op|')'
newline|'\n'
nl|'\n'
comment|'# duplicate networks are allowed only for neutron v2.0'
nl|'\n'
dedent|''
name|'if'
op|'('
name|'not'
name|'utils'
op|'.'
name|'is_neutron'
op|'('
op|')'
name|'and'
name|'request'
op|'.'
name|'network_id'
name|'and'
nl|'\n'
name|'request'
op|'.'
name|'network_id'
name|'in'
name|'network_uuids'
op|')'
op|':'
newline|'\n'
indent|'                    '
name|'expl'
op|'='
op|'('
name|'_'
op|'('
string|'"Duplicate networks"'
nl|'\n'
string|'" (%s) are not allowed"'
op|')'
op|'%'
nl|'\n'
name|'request'
op|'.'
name|'network_id'
op|')'
newline|'\n'
name|'raise'
name|'exc'
op|'.'
name|'HTTPBadRequest'
op|'('
name|'explanation'
op|'='
name|'expl'
op|')'
newline|'\n'
dedent|''
name|'network_uuids'
op|'.'
name|'append'
op|'('
name|'request'
op|'.'
name|'network_id'
op|')'
newline|'\n'
name|'networks'
op|'.'
name|'append'
op|'('
name|'request'
op|')'
newline|'\n'
dedent|''
name|'except'
name|'KeyError'
name|'as'
name|'key'
op|':'
newline|'\n'
indent|'                '
name|'expl'
op|'='
name|'_'
op|'('
string|"'Bad network format: missing %s'"
op|')'
op|'%'
name|'key'
newline|'\n'
name|'raise'
name|'exc'
op|'.'
name|'HTTPBadRequest'
op|'('
name|'explanation'
op|'='
name|'expl'
op|')'
newline|'\n'
dedent|''
name|'except'
name|'TypeError'
op|':'
newline|'\n'
indent|'                '
name|'expl'
op|'='
name|'_'
op|'('
string|"'Bad networks format'"
op|')'
newline|'\n'
name|'raise'
name|'exc'
op|'.'
name|'HTTPBadRequest'
op|'('
name|'explanation'
op|'='
name|'expl'
op|')'
newline|'\n'
nl|'\n'
dedent|''
dedent|''
name|'return'
name|'objects'
op|'.'
name|'NetworkRequestList'
op|'('
name|'objects'
op|'='
name|'networks'
op|')'
newline|'\n'
nl|'\n'
comment|'# NOTE(vish): Without this regex, b64decode will happily'
nl|'\n'
comment|'#             ignore illegal bytes in the base64 encoded'
nl|'\n'
comment|'#             data.'
nl|'\n'
DECL|variable|B64_REGEX
dedent|''
name|'B64_REGEX'
op|'='
name|'re'
op|'.'
name|'compile'
op|'('
string|"'^(?:[A-Za-z0-9+\\/]{4})*'"
nl|'\n'
string|"'(?:[A-Za-z0-9+\\/]{2}=='"
nl|'\n'
string|"'|[A-Za-z0-9+\\/]{3}=)?$'"
op|')'
newline|'\n'
nl|'\n'
DECL|member|_decode_base64
name|'def'
name|'_decode_base64'
op|'('
name|'self'
op|','
name|'data'
op|')'
op|':'
newline|'\n'
indent|'        '
name|'if'
name|'isinstance'
op|'('
name|'data'
op|','
name|'six'
op|'.'
name|'binary_type'
op|')'
name|'and'
name|'hasattr'
op|'('
name|'data'
op|','
string|'"decode"'
op|')'
op|':'
newline|'\n'
indent|'            '
name|'try'
op|':'
newline|'\n'
indent|'                '
name|'data'
op|'='
name|'data'
op|'.'
name|'decode'
op|'('
string|'"utf-8"'
op|')'
newline|'\n'
dedent|''
name|'except'
name|'UnicodeDecodeError'
op|':'
newline|'\n'
indent|'                '
name|'return'
name|'None'
newline|'\n'
dedent|''
dedent|''
name|'data'
op|'='
name|'re'
op|'.'
name|'sub'
op|'('
string|"r'\\s'"
op|','
string|"''"
op|','
name|'data'
op|')'
newline|'\n'
name|'if'
name|'not'
name|'self'
op|'.'
name|'B64_REGEX'
op|'.'
name|'match'
op|'('
name|'data'
op|')'
op|':'
newline|'\n'
indent|'            '
name|'return'
name|'None'
newline|'\n'
dedent|''
name|'try'
op|':'
newline|'\n'
indent|'            '
name|'return'
name|'base64'
op|'.'
name|'b64decode'
op|'('
name|'data'
op|')'
newline|'\n'
dedent|''
name|'except'
name|'TypeError'
op|':'
newline|'\n'
indent|'            '
name|'return'
name|'None'
newline|'\n'
nl|'\n'
DECL|member|_validate_access_ipv4
dedent|''
dedent|''
name|'def'
name|'_validate_access_ipv4'
op|'('
name|'self'
op|','
name|'address'
op|')'
op|':'
newline|'\n'
indent|'        '
name|'if'
name|'not'
name|'netutils'
op|'.'
name|'is_valid_ipv4'
op|'('
name|'address'
op|')'
op|':'
newline|'\n'
indent|'            '
name|'expl'
op|'='
name|'_'
op|'('
string|"'accessIPv4 is not proper IPv4 format'"
op|')'
newline|'\n'
name|'raise'
name|'exc'
op|'.'
name|'HTTPBadRequest'
op|'('
name|'explanation'
op|'='
name|'expl'
op|')'
newline|'\n'
nl|'\n'
DECL|member|_validate_access_ipv6
dedent|''
dedent|''
name|'def'
name|'_validate_access_ipv6'
op|'('
name|'self'
op|','
name|'address'
op|')'
op|':'
newline|'\n'
indent|'        '
name|'if'
name|'not'
name|'netutils'
op|'.'
name|'is_valid_ipv6'
op|'('
name|'address'
op|')'
op|':'
newline|'\n'
indent|'            '
name|'expl'
op|'='
name|'_'
op|'('
string|"'accessIPv6 is not proper IPv6 format'"
op|')'
newline|'\n'
name|'raise'
name|'exc'
op|'.'
name|'HTTPBadRequest'
op|'('
name|'explanation'
op|'='
name|'expl'
op|')'
newline|'\n'
nl|'\n'
DECL|member|show
dedent|''
dedent|''
name|'def'
name|'show'
op|'('
name|'self'
op|','
name|'req'
op|','
name|'id'
op|')'
op|':'
newline|'\n'
indent|'        '
string|'"""Returns server details by server id."""'
newline|'\n'
name|'context'
op|'='
name|'req'
op|'.'
name|'environ'
op|'['
string|"'nova.context'"
op|']'
newline|'\n'
name|'instance'
op|'='
name|'self'
op|'.'
name|'_get_server'
op|'('
name|'context'
op|','
name|'req'
op|','
name|'id'
op|','
name|'is_detail'
op|'='
name|'True'
op|')'
newline|'\n'
name|'return'
name|'self'
op|'.'
name|'_view_builder'
op|'.'
name|'show'
op|'('
name|'req'
op|','
name|'instance'
op|')'
newline|'\n'
nl|'\n'
DECL|member|_extract
dedent|''
name|'def'
name|'_extract'
op|'('
name|'self'
op|','
name|'server_dict'
op|','
name|'ext_name'
op|','
name|'key'
op|')'
op|':'
newline|'\n'
indent|'        '
name|'if'
name|'self'
op|'.'
name|'ext_mgr'
op|'.'
name|'is_loaded'
op|'('
name|'ext_name'
op|')'
op|':'
newline|'\n'
indent|'            '
name|'return'
name|'server_dict'
op|'.'
name|'get'
op|'('
name|'key'
op|')'
newline|'\n'
dedent|''
name|'return'
name|'None'
newline|'\n'
nl|'\n'
DECL|member|_validate_user_data
dedent|''
name|'def'
name|'_validate_user_data'
op|'('
name|'self'
op|','
name|'user_data'
op|')'
op|':'
newline|'\n'
indent|'        '
name|'if'
name|'user_data'
name|'and'
name|'self'
op|'.'
name|'_decode_base64'
op|'('
name|'user_data'
op|')'
name|'is'
name|'None'
op|':'
newline|'\n'
indent|'            '
name|'expl'
op|'='
name|'_'
op|'('
string|"'Userdata content cannot be decoded'"
op|')'
newline|'\n'
name|'raise'
name|'exc'
op|'.'
name|'HTTPBadRequest'
op|'('
name|'explanation'
op|'='
name|'expl'
op|')'
newline|'\n'
dedent|''
name|'return'
name|'user_data'
newline|'\n'
nl|'\n'
DECL|member|_extract_bdm
dedent|''
name|'def'
name|'_extract_bdm'
op|'('
name|'self'
op|','
name|'server_dict'
op|','
name|'image_uuid_specified'
op|')'
op|':'
newline|'\n'
indent|'        '
name|'legacy_bdm'
op|'='
name|'True'
newline|'\n'
name|'block_device_mapping_v2'
op|'='
name|'None'
newline|'\n'
name|'if'
name|'not'
name|'self'
op|'.'
name|'ext_mgr'
op|'.'
name|'is_loaded'
op|'('
string|"'os-volumes'"
op|')'
op|':'
newline|'\n'
indent|'            '
name|'return'
name|'legacy_bdm'
op|','
name|'None'
newline|'\n'
dedent|''
name|'block_device_mapping'
op|'='
name|'server_dict'
op|'.'
name|'get'
op|'('
string|"'block_device_mapping'"
op|','
op|'['
op|']'
op|')'
newline|'\n'
name|'if'
name|'not'
name|'isinstance'
op|'('
name|'block_device_mapping'
op|','
name|'list'
op|')'
op|':'
newline|'\n'
indent|'            '
name|'msg'
op|'='
name|'_'
op|'('
string|"'block_device_mapping must be a list'"
op|')'
newline|'\n'
name|'raise'
name|'exc'
op|'.'
name|'HTTPBadRequest'
op|'('
name|'explanation'
op|'='
name|'msg'
op|')'
newline|'\n'
dedent|''
name|'for'
name|'bdm'
name|'in'
name|'block_device_mapping'
op|':'
newline|'\n'
indent|'            '
name|'try'
op|':'
newline|'\n'
indent|'                '
name|'block_device'
op|'.'
name|'validate_device_name'
op|'('
name|'bdm'
op|'.'
name|'get'
op|'('
string|'"device_name"'
op|')'
op|')'
newline|'\n'
name|'block_device'
op|'.'
name|'validate_and_default_volume_size'
op|'('
name|'bdm'
op|')'
newline|'\n'
dedent|''
name|'except'
name|'exception'
op|'.'
name|'InvalidBDMFormat'
name|'as'
name|'e'
op|':'
newline|'\n'
indent|'                '
name|'raise'
name|'exc'
op|'.'
name|'HTTPBadRequest'
op|'('
name|'explanation'
op|'='
name|'e'
op|'.'
name|'format_message'
op|'('
op|')'
op|')'
newline|'\n'
nl|'\n'
dedent|''
name|'if'
string|"'delete_on_termination'"
name|'in'
name|'bdm'
op|':'
newline|'\n'
indent|'                '
name|'bdm'
op|'['
string|"'delete_on_termination'"
op|']'
op|'='
name|'strutils'
op|'.'
name|'bool_from_string'
op|'('
nl|'\n'
name|'bdm'
op|'['
string|"'delete_on_termination'"
op|']'
op|')'
newline|'\n'
nl|'\n'
dedent|''
dedent|''
name|'if'
name|'self'
op|'.'
name|'ext_mgr'
op|'.'
name|'is_loaded'
op|'('
string|"'os-block-device-mapping-v2-boot'"
op|')'
op|':'
newline|'\n'
comment|'# Consider the new data format for block device mapping'
nl|'\n'
indent|'            '
name|'block_device_mapping_v2'
op|'='
name|'server_dict'
op|'.'
name|'get'
op|'('
nl|'\n'
string|"'block_device_mapping_v2'"
op|','
op|'['
op|']'
op|')'
newline|'\n'
comment|'# NOTE (ndipanov):  Disable usage of both legacy and new'
nl|'\n'
comment|'#                   block device format in the same request'
nl|'\n'
name|'if'
name|'block_device_mapping'
name|'and'
name|'block_device_mapping_v2'
op|':'
newline|'\n'
indent|'                '
name|'expl'
op|'='
name|'_'
op|'('
string|"'Using different block_device_mapping syntaxes '"
nl|'\n'
string|"'is not allowed in the same request.'"
op|')'
newline|'\n'
name|'raise'
name|'exc'
op|'.'
name|'HTTPBadRequest'
op|'('
name|'explanation'
op|'='
name|'expl'
op|')'
newline|'\n'
nl|'\n'
dedent|''
name|'if'
name|'not'
name|'isinstance'
op|'('
name|'block_device_mapping_v2'
op|','
name|'list'
op|')'
op|':'
newline|'\n'
indent|'                '
name|'msg'
op|'='
name|'_'
op|'('
string|"'block_device_mapping_v2 must be a list'"
op|')'
newline|'\n'
name|'raise'
name|'exc'
op|'.'
name|'HTTPBadRequest'
op|'('
name|'explanation'
op|'='
name|'msg'
op|')'
newline|'\n'
nl|'\n'
comment|'# Assume legacy format'
nl|'\n'
dedent|''
name|'legacy_bdm'
op|'='
name|'not'
name|'bool'
op|'('
name|'block_device_mapping_v2'
op|')'
newline|'\n'
nl|'\n'
name|'try'
op|':'
newline|'\n'
indent|'                '
name|'block_device_mapping_v2'
op|'='
op|'['
nl|'\n'
name|'block_device'
op|'.'
name|'BlockDeviceDict'
op|'.'
name|'from_api'
op|'('
name|'bdm_dict'
op|','
nl|'\n'
name|'image_uuid_specified'
op|')'
nl|'\n'
name|'for'
name|'bdm_dict'
name|'in'
name|'block_device_mapping_v2'
op|']'
newline|'\n'
dedent|''
name|'except'
name|'exception'
op|'.'
name|'InvalidBDMFormat'
name|'as'
name|'e'
op|':'
newline|'\n'
indent|'                '
name|'raise'
name|'exc'
op|'.'
name|'HTTPBadRequest'
op|'('
name|'explanation'
op|'='
name|'e'
op|'.'
name|'format_message'
op|'('
op|')'
op|')'
newline|'\n'
nl|'\n'
dedent|''
dedent|''
name|'bdm'
op|'='
op|'('
name|'block_device_mapping'
name|'or'
name|'block_device_mapping_v2'
op|')'
newline|'\n'
name|'return'
name|'legacy_bdm'
op|','
name|'bdm'
newline|'\n'
nl|'\n'
dedent|''
op|'@'
name|'staticmethod'
newline|'\n'
DECL|member|_resolve_exception
name|'def'
name|'_resolve_exception'
op|'('
name|'matches'
op|')'
op|':'
newline|'\n'
indent|'        '
string|'"""We want the most specific exception class."""'
newline|'\n'
name|'while'
name|'len'
op|'('
name|'matches'
op|')'
op|'>'
number|'1'
op|':'
newline|'\n'
indent|'            '
name|'first'
op|'='
name|'matches'
op|'['
number|'0'
op|']'
newline|'\n'
name|'second'
op|'='
name|'matches'
op|'['
number|'1'
op|']'
newline|'\n'
name|'if'
name|'issubclass'
op|'('
name|'first'
op|','
name|'second'
op|')'
op|':'
newline|'\n'
indent|'                '
name|'del'
name|'matches'
op|'['
number|'1'
op|']'
newline|'\n'
dedent|''
name|'else'
op|':'
newline|'\n'
indent|'                '
name|'del'
name|'matches'
op|'['
number|'0'
op|']'
newline|'\n'
dedent|''
dedent|''
name|'return'
name|'matches'
op|'['
number|'0'
op|']'
newline|'\n'
nl|'\n'
dedent|''
op|'@'
name|'staticmethod'
newline|'\n'
DECL|member|_handle_create_exception
name|'def'
name|'_handle_create_exception'
op|'('
op|'*'
name|'exc_info'
op|')'
op|':'
newline|'\n'
indent|'        '
string|'"""The `CREATE_EXCEPTIONS` dict containing the relationships between\n        the nova exceptions and the webob exception classes to be raised is\n        defined at the top of this file.\n        """'
newline|'\n'
name|'error'
op|'='
name|'exc_info'
op|'['
number|'1'
op|']'
newline|'\n'
name|'err_cls'
op|'='
name|'error'
op|'.'
name|'__class__'
newline|'\n'
name|'cls_to_raise'
op|'='
name|'CREATE_EXCEPTIONS'
op|'.'
name|'get'
op|'('
name|'err_cls'
op|')'
newline|'\n'
name|'if'
name|'cls_to_raise'
name|'is'
name|'None'
op|':'
newline|'\n'
comment|'# The error is a subclass of one of the dict keys'
nl|'\n'
indent|'            '
name|'to_raise'
op|'='
op|'['
name|'val'
name|'for'
name|'key'
op|','
name|'val'
name|'in'
name|'CREATE_EXCEPTIONS'
op|'.'
name|'items'
op|'('
op|')'
nl|'\n'
name|'if'
name|'isinstance'
op|'('
name|'error'
op|','
name|'key'
op|')'
op|']'
newline|'\n'
name|'if'
name|'len'
op|'('
name|'to_raise'
op|')'
op|'>'
number|'1'
op|':'
newline|'\n'
indent|'                '
name|'cls_to_raise'
op|'='
name|'Controller'
op|'.'
name|'_resolve_exception'
op|'('
name|'to_raise'
op|')'
newline|'\n'
dedent|''
name|'elif'
name|'not'
name|'to_raise'
op|':'
newline|'\n'
comment|'# Not any of the expected exceptions, so re-raise'
nl|'\n'
indent|'                '
name|'six'
op|'.'
name|'reraise'
op|'('
op|'*'
name|'exc_info'
op|')'
newline|'\n'
dedent|''
name|'else'
op|':'
newline|'\n'
indent|'                '
name|'cls_to_raise'
op|'='
name|'to_raise'
op|'['
number|'0'
op|']'
newline|'\n'
nl|'\n'
dedent|''
dedent|''
name|'for'
name|'key'
op|','
name|'val'
name|'in'
name|'CREATE_EXCEPTIONS_MSGS'
op|'.'
name|'items'
op|'('
op|')'
op|':'
newline|'\n'
indent|'            '
name|'if'
name|'isinstance'
op|'('
name|'error'
op|','
name|'key'
op|')'
op|':'
newline|'\n'
indent|'                '
name|'raise'
name|'cls_to_raise'
op|'('
name|'explanation'
op|'='
name|'CREATE_EXCEPTIONS_MSGS'
op|'['
name|'key'
op|']'
op|')'
newline|'\n'
dedent|''
dedent|''
name|'raise'
name|'cls_to_raise'
op|'('
name|'explanation'
op|'='
name|'error'
op|'.'
name|'format_message'
op|'('
op|')'
op|')'
newline|'\n'
nl|'\n'
DECL|member|_determine_requested_networks
dedent|''
name|'def'
name|'_determine_requested_networks'
op|'('
name|'self'
op|','
name|'server_dict'
op|')'
op|':'
newline|'\n'
indent|'        '
name|'requested_networks'
op|'='
name|'None'
newline|'\n'
name|'if'
op|'('
name|'self'
op|'.'
name|'ext_mgr'
op|'.'
name|'is_loaded'
op|'('
string|"'os-networks'"
op|')'
nl|'\n'
name|'or'
name|'utils'
op|'.'
name|'is_neutron'
op|'('
op|')'
op|')'
op|':'
newline|'\n'
indent|'            '
name|'requested_networks'
op|'='
name|'server_dict'
op|'.'
name|'get'
op|'('
string|"'networks'"
op|')'
newline|'\n'
nl|'\n'
dedent|''
name|'if'
name|'requested_networks'
name|'is'
name|'not'
name|'None'
op|':'
newline|'\n'
indent|'            '
name|'if'
name|'not'
name|'isinstance'
op|'('
name|'requested_networks'
op|','
name|'list'
op|')'
op|':'
newline|'\n'
indent|'                '
name|'expl'
op|'='
name|'_'
op|'('
string|"'Bad networks format'"
op|')'
newline|'\n'
name|'raise'
name|'exc'
op|'.'
name|'HTTPBadRequest'
op|'('
name|'explanation'
op|'='
name|'expl'
op|')'
newline|'\n'
dedent|''
name|'requested_networks'
op|'='
name|'self'
op|'.'
name|'_get_requested_networks'
op|'('
nl|'\n'
name|'requested_networks'
op|')'
newline|'\n'
dedent|''
name|'return'
name|'requested_networks'
newline|'\n'
nl|'\n'
dedent|''
op|'@'
name|'wsgi'
op|'.'
name|'response'
op|'('
number|'202'
op|')'
newline|'\n'
DECL|member|create
name|'def'
name|'create'
op|'('
name|'self'
op|','
name|'req'
op|','
name|'body'
op|')'
op|':'
newline|'\n'
indent|'        '
string|'"""Creates a new server for a given user."""'
newline|'\n'
name|'if'
name|'not'
name|'self'
op|'.'
name|'is_valid_body'
op|'('
name|'body'
op|','
string|"'server'"
op|')'
op|':'
newline|'\n'
indent|'            '
name|'raise'
name|'exc'
op|'.'
name|'HTTPUnprocessableEntity'
op|'('
op|')'
newline|'\n'
nl|'\n'
dedent|''
name|'context'
op|'='
name|'req'
op|'.'
name|'environ'
op|'['
string|"'nova.context'"
op|']'
newline|'\n'
name|'server_dict'
op|'='
name|'body'
op|'['
string|"'server'"
op|']'
newline|'\n'
name|'password'
op|'='
name|'self'
op|'.'
name|'_get_server_admin_password'
op|'('
name|'server_dict'
op|')'
newline|'\n'
nl|'\n'
name|'if'
string|"'name'"
name|'not'
name|'in'
name|'server_dict'
op|':'
newline|'\n'
indent|'            '
name|'msg'
op|'='
name|'_'
op|'('
string|'"Server name is not defined"'
op|')'
newline|'\n'
name|'raise'
name|'exc'
op|'.'
name|'HTTPBadRequest'
op|'('
name|'explanation'
op|'='
name|'msg'
op|')'
newline|'\n'
nl|'\n'
dedent|''
name|'name'
op|'='
name|'server_dict'
op|'['
string|"'name'"
op|']'
newline|'\n'
name|'self'
op|'.'
name|'_validate_server_name'
op|'('
name|'name'
op|')'
newline|'\n'
name|'name'
op|'='
name|'name'
op|'.'
name|'strip'
op|'('
op|')'
newline|'\n'
nl|'\n'
name|'image_uuid'
op|'='
name|'self'
op|'.'
name|'_image_from_req_data'
op|'('
name|'body'
op|')'
newline|'\n'
nl|'\n'
name|'personality'
op|'='
name|'server_dict'
op|'.'
name|'get'
op|'('
string|"'personality'"
op|')'
newline|'\n'
name|'config_drive'
op|'='
name|'None'
newline|'\n'
name|'if'
name|'self'
op|'.'
name|'ext_mgr'
op|'.'
name|'is_loaded'
op|'('
string|"'os-config-drive'"
op|')'
op|':'
newline|'\n'
indent|'            '
name|'config_drive'
op|'='
name|'server_dict'
op|'.'
name|'get'
op|'('
string|"'config_drive'"
op|')'
newline|'\n'
nl|'\n'
dedent|''
name|'injected_files'
op|'='
op|'['
op|']'
newline|'\n'
name|'if'
name|'personality'
op|':'
newline|'\n'
indent|'            '
name|'injected_files'
op|'='
name|'self'
op|'.'
name|'_get_injected_files'
op|'('
name|'personality'
op|')'
newline|'\n'
nl|'\n'
dedent|''
name|'sg_names'
op|'='
op|'['
op|']'
newline|'\n'
name|'if'
name|'self'
op|'.'
name|'ext_mgr'
op|'.'
name|'is_loaded'
op|'('
string|"'os-security-groups'"
op|')'
op|':'
newline|'\n'
indent|'            '
name|'security_groups'
op|'='
name|'server_dict'
op|'.'
name|'get'
op|'('
string|"'security_groups'"
op|')'
newline|'\n'
name|'if'
name|'security_groups'
name|'is'
name|'not'
name|'None'
op|':'
newline|'\n'
indent|'                '
name|'try'
op|':'
newline|'\n'
indent|'                    '
name|'sg_names'
op|'='
op|'['
name|'sg'
op|'['
string|"'name'"
op|']'
name|'for'
name|'sg'
name|'in'
name|'security_groups'
nl|'\n'
name|'if'
name|'sg'
op|'.'
name|'get'
op|'('
string|"'name'"
op|')'
op|']'
newline|'\n'
dedent|''
name|'except'
name|'AttributeError'
op|':'
newline|'\n'
indent|'                    '
name|'msg'
op|'='
name|'_'
op|'('
string|'"Invalid input for field/attribute %(path)s."'
nl|'\n'
string|'" Value: %(value)s. %(message)s"'
op|')'
op|'%'
op|'{'
nl|'\n'
string|"'path'"
op|':'
string|"'security_groups'"
op|','
nl|'\n'
string|"'value'"
op|':'
name|'security_groups'
op|','
nl|'\n'
string|"'message'"
op|':'
string|"''"
nl|'\n'
op|'}'
newline|'\n'
name|'raise'
name|'exc'
op|'.'
name|'HTTPBadRequest'
op|'('
name|'explanation'
op|'='
name|'msg'
op|')'
newline|'\n'
dedent|''
dedent|''
dedent|''
name|'if'
name|'not'
name|'sg_names'
op|':'
newline|'\n'
indent|'            '
name|'sg_names'
op|'.'
name|'append'
op|'('
string|"'default'"
op|')'
newline|'\n'
nl|'\n'
dedent|''
name|'sg_names'
op|'='
name|'list'
op|'('
name|'set'
op|'('
name|'sg_names'
op|')'
op|')'
newline|'\n'
nl|'\n'
name|'requested_networks'
op|'='
name|'self'
op|'.'
name|'_determine_requested_networks'
op|'('
name|'server_dict'
op|')'
newline|'\n'
nl|'\n'
op|'('
name|'access_ip_v4'
op|','
op|')'
op|'='
name|'server_dict'
op|'.'
name|'get'
op|'('
string|"'accessIPv4'"
op|')'
op|','
newline|'\n'
name|'if'
name|'access_ip_v4'
name|'is'
name|'not'
name|'None'
op|':'
newline|'\n'
indent|'            '
name|'self'
op|'.'
name|'_validate_access_ipv4'
op|'('
name|'access_ip_v4'
op|')'
newline|'\n'
nl|'\n'
dedent|''
op|'('
name|'access_ip_v6'
op|','
op|')'
op|'='
name|'server_dict'
op|'.'
name|'get'
op|'('
string|"'accessIPv6'"
op|')'
op|','
newline|'\n'
name|'if'
name|'access_ip_v6'
name|'is'
name|'not'
name|'None'
op|':'
newline|'\n'
indent|'            '
name|'self'
op|'.'
name|'_validate_access_ipv6'
op|'('
name|'access_ip_v6'
op|')'
newline|'\n'
nl|'\n'
dedent|''
name|'flavor_id'
op|'='
name|'self'
op|'.'
name|'_flavor_id_from_req_data'
op|'('
name|'body'
op|')'
newline|'\n'
nl|'\n'
comment|'# optional openstack extensions:'
nl|'\n'
name|'key_name'
op|'='
name|'self'
op|'.'
name|'_extract'
op|'('
name|'server_dict'
op|','
string|"'os-keypairs'"
op|','
string|"'key_name'"
op|')'
newline|'\n'
name|'availability_zone'
op|'='
name|'self'
op|'.'
name|'_extract'
op|'('
name|'server_dict'
op|','
string|"'os-availability-zone'"
op|','
nl|'\n'
string|"'availability_zone'"
op|')'
newline|'\n'
name|'user_data'
op|'='
name|'self'
op|'.'
name|'_extract'
op|'('
name|'server_dict'
op|','
string|"'os-user-data'"
op|','
string|"'user_data'"
op|')'
newline|'\n'
name|'self'
op|'.'
name|'_validate_user_data'
op|'('
name|'user_data'
op|')'
newline|'\n'
nl|'\n'
name|'image_uuid_specified'
op|'='
name|'bool'
op|'('
name|'image_uuid'
op|')'
newline|'\n'
name|'legacy_bdm'
op|','
name|'block_device_mapping'
op|'='
name|'self'
op|'.'
name|'_extract_bdm'
op|'('
name|'server_dict'
op|','
nl|'\n'
name|'image_uuid_specified'
op|')'
newline|'\n'
nl|'\n'
name|'ret_resv_id'
op|'='
name|'False'
newline|'\n'
comment|'# min_count and max_count are optional.  If they exist, they may come'
nl|'\n'
comment|'# in as strings.  Verify that they are valid integers and > 0.'
nl|'\n'
comment|"# Also, we want to default 'min_count' to 1, and default"
nl|'\n'
comment|"# 'max_count' to be 'min_count'."
nl|'\n'
name|'min_count'
op|'='
number|'1'
newline|'\n'
name|'max_count'
op|'='
number|'1'
newline|'\n'
name|'if'
name|'self'
op|'.'
name|'ext_mgr'
op|'.'
name|'is_loaded'
op|'('
string|"'os-multiple-create'"
op|')'
op|':'
newline|'\n'
indent|'            '
name|'ret_resv_id'
op|'='
name|'server_dict'
op|'.'
name|'get'
op|'('
string|"'return_reservation_id'"
op|','
name|'False'
op|')'
newline|'\n'
name|'min_count'
op|'='
name|'server_dict'
op|'.'
name|'get'
op|'('
string|"'min_count'"
op|','
number|'1'
op|')'
newline|'\n'
name|'max_count'
op|'='
name|'server_dict'
op|'.'
name|'get'
op|'('
string|"'max_count'"
op|','
name|'min_count'
op|')'
newline|'\n'
nl|'\n'
dedent|''
name|'try'
op|':'
newline|'\n'
indent|'            '
name|'min_count'
op|'='
name|'utils'
op|'.'
name|'validate_integer'
op|'('
nl|'\n'
name|'min_count'
op|','
string|'"min_count"'
op|','
name|'min_value'
op|'='
number|'1'
op|')'
newline|'\n'
name|'max_count'
op|'='
name|'utils'
op|'.'
name|'validate_integer'
op|'('
nl|'\n'
name|'max_count'
op|','
string|'"max_count"'
op|','
name|'min_value'
op|'='
number|'1'
op|')'
newline|'\n'
dedent|''
name|'except'
name|'exception'
op|'.'
name|'InvalidInput'
name|'as'
name|'e'
op|':'
newline|'\n'
indent|'            '
name|'raise'
name|'exc'
op|'.'
name|'HTTPBadRequest'
op|'('
name|'explanation'
op|'='
name|'e'
op|'.'
name|'format_message'
op|'('
op|')'
op|')'
newline|'\n'
nl|'\n'
dedent|''
name|'if'
name|'min_count'
op|'>'
name|'max_count'
op|':'
newline|'\n'
indent|'            '
name|'msg'
op|'='
name|'_'
op|'('
string|"'min_count must be <= max_count'"
op|')'
newline|'\n'
name|'raise'
name|'exc'
op|'.'
name|'HTTPBadRequest'
op|'('
name|'explanation'
op|'='
name|'msg'
op|')'
newline|'\n'
nl|'\n'
dedent|''
name|'auto_disk_config'
op|'='
name|'False'
newline|'\n'
name|'if'
name|'self'
op|'.'
name|'ext_mgr'
op|'.'
name|'is_loaded'
op|'('
string|"'OS-DCF'"
op|')'
op|':'
newline|'\n'
indent|'            '
name|'auto_disk_config'
op|'='
name|'server_dict'
op|'.'
name|'get'
op|'('
string|"'auto_disk_config'"
op|')'
newline|'\n'
nl|'\n'
dedent|''
name|'scheduler_hints'
op|'='
op|'{'
op|'}'
newline|'\n'
name|'if'
name|'self'
op|'.'
name|'ext_mgr'
op|'.'
name|'is_loaded'
op|'('
string|"'OS-SCH-HNT'"
op|')'
op|':'
newline|'\n'
indent|'            '
name|'scheduler_hints'
op|'='
name|'server_dict'
op|'.'
name|'get'
op|'('
string|"'scheduler_hints'"
op|','
op|'{'
op|'}'
op|')'
newline|'\n'
dedent|''
name|'parse_az'
op|'='
name|'self'
op|'.'
name|'compute_api'
op|'.'
name|'parse_availability_zone'
newline|'\n'
name|'availability_zone'
op|','
name|'host'
op|','
name|'node'
op|'='
name|'parse_az'
op|'('
name|'context'
op|','
name|'availability_zone'
op|')'
newline|'\n'
nl|'\n'
name|'check_server_group_quota'
op|'='
name|'self'
op|'.'
name|'ext_mgr'
op|'.'
name|'is_loaded'
op|'('
nl|'\n'
string|"'os-server-group-quotas'"
op|')'
newline|'\n'
name|'try'
op|':'
newline|'\n'
indent|'            '
name|'_get_inst_type'
op|'='
name|'flavors'
op|'.'
name|'get_flavor_by_flavor_id'
newline|'\n'
name|'inst_type'
op|'='
name|'_get_inst_type'
op|'('
name|'flavor_id'
op|','
name|'ctxt'
op|'='
name|'context'
op|','
nl|'\n'
name|'read_deleted'
op|'='
string|'"no"'
op|')'
newline|'\n'
nl|'\n'
op|'('
name|'instances'
op|','
name|'resv_id'
op|')'
op|'='
name|'self'
op|'.'
name|'compute_api'
op|'.'
name|'create'
op|'('
name|'context'
op|','
nl|'\n'
name|'inst_type'
op|','
nl|'\n'
name|'image_uuid'
op|','
nl|'\n'
name|'display_name'
op|'='
name|'name'
op|','
nl|'\n'
name|'display_description'
op|'='
name|'name'
op|','
nl|'\n'
name|'key_name'
op|'='
name|'key_name'
op|','
nl|'\n'
name|'metadata'
op|'='
name|'server_dict'
op|'.'
name|'get'
op|'('
string|"'metadata'"
op|','
op|'{'
op|'}'
op|')'
op|','
nl|'\n'
name|'access_ip_v4'
op|'='
name|'access_ip_v4'
op|','
nl|'\n'
name|'access_ip_v6'
op|'='
name|'access_ip_v6'
op|','
nl|'\n'
name|'injected_files'
op|'='
name|'injected_files'
op|','
nl|'\n'
name|'admin_password'
op|'='
name|'password'
op|','
nl|'\n'
name|'min_count'
op|'='
name|'min_count'
op|','
nl|'\n'
name|'max_count'
op|'='
name|'max_count'
op|','
nl|'\n'
name|'requested_networks'
op|'='
name|'requested_networks'
op|','
nl|'\n'
name|'security_group'
op|'='
name|'sg_names'
op|','
nl|'\n'
name|'user_data'
op|'='
name|'user_data'
op|','
nl|'\n'
name|'availability_zone'
op|'='
name|'availability_zone'
op|','
nl|'\n'
name|'forced_host'
op|'='
name|'host'
op|','
name|'forced_node'
op|'='
name|'node'
op|','
nl|'\n'
name|'config_drive'
op|'='
name|'config_drive'
op|','
nl|'\n'
name|'block_device_mapping'
op|'='
name|'block_device_mapping'
op|','
nl|'\n'
name|'auto_disk_config'
op|'='
name|'auto_disk_config'
op|','
nl|'\n'
name|'scheduler_hints'
op|'='
name|'scheduler_hints'
op|','
nl|'\n'
name|'legacy_bdm'
op|'='
name|'legacy_bdm'
op|','
nl|'\n'
name|'check_server_group_quota'
op|'='
name|'check_server_group_quota'
op|')'
newline|'\n'
dedent|''
name|'except'
op|'('
name|'exception'
op|'.'
name|'QuotaError'
op|','
nl|'\n'
name|'exception'
op|'.'
name|'PortLimitExceeded'
op|')'
name|'as'
name|'error'
op|':'
newline|'\n'
indent|'            '
name|'raise'
name|'exc'
op|'.'
name|'HTTPForbidden'
op|'('
nl|'\n'
name|'explanation'
op|'='
name|'error'
op|'.'
name|'format_message'
op|'('
op|')'
op|')'
newline|'\n'
dedent|''
name|'except'
name|'messaging'
op|'.'
name|'RemoteError'
name|'as'
name|'err'
op|':'
newline|'\n'
indent|'            '
name|'msg'
op|'='
string|'"%(err_type)s: %(err_msg)s"'
op|'%'
op|'{'
string|"'err_type'"
op|':'
name|'err'
op|'.'
name|'exc_type'
op|','
nl|'\n'
string|"'err_msg'"
op|':'
name|'err'
op|'.'
name|'value'
op|'}'
newline|'\n'
name|'raise'
name|'exc'
op|'.'
name|'HTTPBadRequest'
op|'('
name|'explanation'
op|'='
name|'msg'
op|')'
newline|'\n'
dedent|''
name|'except'
name|'UnicodeDecodeError'
name|'as'
name|'error'
op|':'
newline|'\n'
indent|'            '
name|'msg'
op|'='
string|'"UnicodeError: %s"'
op|'%'
name|'error'
newline|'\n'
name|'raise'
name|'exc'
op|'.'
name|'HTTPBadRequest'
op|'('
name|'explanation'
op|'='
name|'msg'
op|')'
newline|'\n'
dedent|''
name|'except'
name|'Exception'
op|':'
newline|'\n'
comment|'# The remaining cases can be handled in a standard fashion.'
nl|'\n'
indent|'            '
name|'self'
op|'.'
name|'_handle_create_exception'
op|'('
op|'*'
name|'sys'
op|'.'
name|'exc_info'
op|'('
op|')'
op|')'
newline|'\n'
nl|'\n'
comment|'# If the caller wanted a reservation_id, return it'
nl|'\n'
dedent|''
name|'if'
name|'ret_resv_id'
op|':'
newline|'\n'
indent|'            '
name|'return'
name|'wsgi'
op|'.'
name|'ResponseObject'
op|'('
op|'{'
string|"'reservation_id'"
op|':'
name|'resv_id'
op|'}'
op|')'
newline|'\n'
nl|'\n'
dedent|''
name|'req'
op|'.'
name|'cache_db_instances'
op|'('
name|'instances'
op|')'
newline|'\n'
name|'server'
op|'='
name|'self'
op|'.'
name|'_view_builder'
op|'.'
name|'create'
op|'('
name|'req'
op|','
name|'instances'
op|'['
number|'0'
op|']'
op|')'
newline|'\n'
nl|'\n'
name|'if'
name|'CONF'
op|'.'
name|'enable_instance_password'
op|':'
newline|'\n'
indent|'            '
name|'server'
op|'['
string|"'server'"
op|']'
op|'['
string|"'adminPass'"
op|']'
op|'='
name|'password'
newline|'\n'
nl|'\n'
dedent|''
name|'robj'
op|'='
name|'wsgi'
op|'.'
name|'ResponseObject'
op|'('
name|'server'
op|')'
newline|'\n'
nl|'\n'
name|'return'
name|'self'
op|'.'
name|'_add_location'
op|'('
name|'robj'
op|')'
newline|'\n'
nl|'\n'
DECL|member|_delete
dedent|''
name|'def'
name|'_delete'
op|'('
name|'self'
op|','
name|'context'
op|','
name|'req'
op|','
name|'instance_uuid'
op|')'
op|':'
newline|'\n'
indent|'        '
name|'instance'
op|'='
name|'self'
op|'.'
name|'_get_server'
op|'('
name|'context'
op|','
name|'req'
op|','
name|'instance_uuid'
op|')'
newline|'\n'
name|'if'
name|'CONF'
op|'.'
name|'reclaim_instance_interval'
op|':'
newline|'\n'
indent|'            '
name|'try'
op|':'
newline|'\n'
indent|'                '
name|'self'
op|'.'
name|'compute_api'
op|'.'
name|'soft_delete'
op|'('
name|'context'
op|','
name|'instance'
op|')'
newline|'\n'
dedent|''
name|'except'
name|'exception'
op|'.'
name|'InstanceInvalidState'
op|':'
newline|'\n'
comment|'# Note(yufang521247): instance which has never been active'
nl|'\n'
comment|'# is not allowed to be soft_deleted. Thus we have to call'
nl|'\n'
comment|'# delete() to clean up the instance.'
nl|'\n'
indent|'                '
name|'self'
op|'.'
name|'compute_api'
op|'.'
name|'delete'
op|'('
name|'context'
op|','
name|'instance'
op|')'
newline|'\n'
dedent|''
dedent|''
name|'else'
op|':'
newline|'\n'
indent|'            '
name|'self'
op|'.'
name|'compute_api'
op|'.'
name|'delete'
op|'('
name|'context'
op|','
name|'instance'
op|')'
newline|'\n'
nl|'\n'
DECL|member|update
dedent|''
dedent|''
name|'def'
name|'update'
op|'('
name|'self'
op|','
name|'req'
op|','
name|'id'
op|','
name|'body'
op|')'
op|':'
newline|'\n'
indent|'        '
string|'"""Update server then pass on to version-specific controller."""'
newline|'\n'
name|'if'
name|'not'
name|'self'
op|'.'
name|'is_valid_body'
op|'('
name|'body'
op|','
string|"'server'"
op|')'
op|':'
newline|'\n'
indent|'            '
name|'raise'
name|'exc'
op|'.'
name|'HTTPUnprocessableEntity'
op|'('
op|')'
newline|'\n'
nl|'\n'
dedent|''
name|'ctxt'
op|'='
name|'req'
op|'.'
name|'environ'
op|'['
string|"'nova.context'"
op|']'
newline|'\n'
name|'update_dict'
op|'='
op|'{'
op|'}'
newline|'\n'
nl|'\n'
name|'if'
string|"'name'"
name|'in'
name|'body'
op|'['
string|"'server'"
op|']'
op|':'
newline|'\n'
indent|'            '
name|'name'
op|'='
name|'body'
op|'['
string|"'server'"
op|']'
op|'['
string|"'name'"
op|']'
newline|'\n'
name|'self'
op|'.'
name|'_validate_server_name'
op|'('
name|'name'
op|')'
newline|'\n'
name|'update_dict'
op|'['
string|"'display_name'"
op|']'
op|'='
name|'name'
op|'.'
name|'strip'
op|'('
op|')'
newline|'\n'
nl|'\n'
dedent|''
name|'if'
string|"'accessIPv4'"
name|'in'
name|'body'
op|'['
string|"'server'"
op|']'
op|':'
newline|'\n'
indent|'            '
name|'access_ipv4'
op|'='
name|'body'
op|'['
string|"'server'"
op|']'
op|'['
string|"'accessIPv4'"
op|']'
newline|'\n'
name|'if'
name|'access_ipv4'
op|':'
newline|'\n'
indent|'                '
name|'self'
op|'.'
name|'_validate_access_ipv4'
op|'('
name|'access_ipv4'
op|')'
newline|'\n'
dedent|''
name|'update_dict'
op|'['
string|"'access_ip_v4'"
op|']'
op|'='
op|'('
nl|'\n'
name|'access_ipv4'
name|'and'
name|'access_ipv4'
op|'.'
name|'strip'
op|'('
op|')'
name|'or'
name|'None'
op|')'
newline|'\n'
nl|'\n'
dedent|''
name|'if'
string|"'accessIPv6'"
name|'in'
name|'body'
op|'['
string|"'server'"
op|']'
op|':'
newline|'\n'
indent|'            '
name|'access_ipv6'
op|'='
name|'body'
op|'['
string|"'server'"
op|']'
op|'['
string|"'accessIPv6'"
op|']'
newline|'\n'
name|'if'
name|'access_ipv6'
op|':'
newline|'\n'
indent|'                '
name|'self'
op|'.'
name|'_validate_access_ipv6'
op|'('
name|'access_ipv6'
op|')'
newline|'\n'
dedent|''
name|'update_dict'
op|'['
string|"'access_ip_v6'"
op|']'
op|'='
op|'('
nl|'\n'
name|'access_ipv6'
name|'and'
name|'access_ipv6'
op|'.'
name|'strip'
op|'('
op|')'
name|'or'
name|'None'
op|')'
newline|'\n'
nl|'\n'
dedent|''
name|'if'
string|"'auto_disk_config'"
name|'in'
name|'body'
op|'['
string|"'server'"
op|']'
op|':'
newline|'\n'
indent|'            '
name|'auto_disk_config'
op|'='
name|'strutils'
op|'.'
name|'bool_from_string'
op|'('
nl|'\n'
name|'body'
op|'['
string|"'server'"
op|']'
op|'['
string|"'auto_disk_config'"
op|']'
op|')'
newline|'\n'
name|'update_dict'
op|'['
string|"'auto_disk_config'"
op|']'
op|'='
name|'auto_disk_config'
newline|'\n'
nl|'\n'
dedent|''
name|'if'
string|"'hostId'"
name|'in'
name|'body'
op|'['
string|"'server'"
op|']'
op|':'
newline|'\n'
indent|'            '
name|'msg'
op|'='
name|'_'
op|'('
string|'"HostId cannot be updated."'
op|')'
newline|'\n'
name|'raise'
name|'exc'
op|'.'
name|'HTTPBadRequest'
op|'('
name|'explanation'
op|'='
name|'msg'
op|')'
newline|'\n'
nl|'\n'
dedent|''
name|'if'
string|"'personality'"
name|'in'
name|'body'
op|'['
string|"'server'"
op|']'
op|':'
newline|'\n'
indent|'            '
name|'msg'
op|'='
name|'_'
op|'('
string|'"Personality cannot be updated."'
op|')'
newline|'\n'
name|'raise'
name|'exc'
op|'.'
name|'HTTPBadRequest'
op|'('
name|'explanation'
op|'='
name|'msg'
op|')'
newline|'\n'
nl|'\n'
dedent|''
name|'instance'
op|'='
name|'self'
op|'.'
name|'_get_server'
op|'('
name|'ctxt'
op|','
name|'req'
op|','
name|'id'
op|','
name|'is_detail'
op|'='
name|'True'
op|')'
newline|'\n'
name|'try'
op|':'
newline|'\n'
indent|'            '
name|'policy'
op|'.'
name|'enforce'
op|'('
name|'ctxt'
op|','
string|"'compute:update'"
op|','
name|'instance'
op|')'
newline|'\n'
name|'instance'
op|'.'
name|'update'
op|'('
name|'update_dict'
op|')'
newline|'\n'
comment|'# Note instance.save can throw a NotFound exception'
nl|'\n'
name|'instance'
op|'.'
name|'save'
op|'('
op|')'
newline|'\n'
dedent|''
name|'except'
name|'exception'
op|'.'
name|'NotFound'
op|':'
newline|'\n'
indent|'            '
name|'msg'
op|'='
name|'_'
op|'('
string|'"Instance could not be found"'
op|')'
newline|'\n'
name|'raise'
name|'exc'
op|'.'
name|'HTTPNotFound'
op|'('
name|'explanation'
op|'='
name|'msg'
op|')'
newline|'\n'
nl|'\n'
dedent|''
name|'return'
name|'self'
op|'.'
name|'_view_builder'
op|'.'
name|'show'
op|'('
name|'req'
op|','
name|'instance'
op|')'
newline|'\n'
nl|'\n'
dedent|''
op|'@'
name|'wsgi'
op|'.'
name|'response'
op|'('
number|'204'
op|')'
newline|'\n'
op|'@'
name|'wsgi'
op|'.'
name|'action'
op|'('
string|"'confirmResize'"
op|')'
newline|'\n'
DECL|member|_action_confirm_resize
name|'def'
name|'_action_confirm_resize'
op|'('
name|'self'
op|','
name|'req'
op|','
name|'id'
op|','
name|'body'
op|')'
op|':'
newline|'\n'
indent|'        '
name|'context'
op|'='
name|'req'
op|'.'
name|'environ'
op|'['
string|"'nova.context'"
op|']'
newline|'\n'
name|'instance'
op|'='
name|'self'
op|'.'
name|'_get_server'
op|'('
name|'context'
op|','
name|'req'
op|','
name|'id'
op|')'
newline|'\n'
name|'try'
op|':'
newline|'\n'
indent|'            '
name|'self'
op|'.'
name|'compute_api'
op|'.'
name|'confirm_resize'
op|'('
name|'context'
op|','
name|'instance'
op|')'
newline|'\n'
dedent|''
name|'except'
name|'exception'
op|'.'
name|'MigrationNotFound'
op|':'
newline|'\n'
indent|'            '
name|'msg'
op|'='
name|'_'
op|'('
string|'"Instance has not been resized."'
op|')'
newline|'\n'
name|'raise'
name|'exc'
op|'.'
name|'HTTPBadRequest'
op|'('
name|'explanation'
op|'='
name|'msg'
op|')'
newline|'\n'
dedent|''
name|'except'
name|'exception'
op|'.'
name|'InstanceIsLocked'
name|'as'
name|'e'
op|':'
newline|'\n'
indent|'            '
name|'raise'
name|'exc'
op|'.'
name|'HTTPConflict'
op|'('
name|'explanation'
op|'='
name|'e'
op|'.'
name|'format_message'
op|'('
op|')'
op|')'
newline|'\n'
dedent|''
name|'except'
name|'exception'
op|'.'
name|'InstanceInvalidState'
name|'as'
name|'state_error'
op|':'
newline|'\n'
indent|'            '
name|'common'
op|'.'
name|'raise_http_conflict_for_instance_invalid_state'
op|'('
name|'state_error'
op|','
nl|'\n'
string|"'confirmResize'"
op|','
name|'id'
op|')'
newline|'\n'
nl|'\n'
dedent|''
dedent|''
op|'@'
name|'wsgi'
op|'.'
name|'response'
op|'('
number|'202'
op|')'
newline|'\n'
op|'@'
name|'wsgi'
op|'.'
name|'action'
op|'('
string|"'revertResize'"
op|')'
newline|'\n'
DECL|member|_action_revert_resize
name|'def'
name|'_action_revert_resize'
op|'('
name|'self'
op|','
name|'req'
op|','
name|'id'
op|','
name|'body'
op|')'
op|':'
newline|'\n'
indent|'        '
name|'context'
op|'='
name|'req'
op|'.'
name|'environ'
op|'['
string|"'nova.context'"
op|']'
newline|'\n'
name|'instance'
op|'='
name|'self'
op|'.'
name|'_get_server'
op|'('
name|'context'
op|','
name|'req'
op|','
name|'id'
op|')'
newline|'\n'
name|'try'
op|':'
newline|'\n'
indent|'            '
name|'self'
op|'.'
name|'compute_api'
op|'.'
name|'revert_resize'
op|'('
name|'context'
op|','
name|'instance'
op|')'
newline|'\n'
dedent|''
name|'except'
name|'exception'
op|'.'
name|'MigrationNotFound'
op|':'
newline|'\n'
indent|'            '
name|'msg'
op|'='
name|'_'
op|'('
string|'"Instance has not been resized."'
op|')'
newline|'\n'
name|'raise'
name|'exc'
op|'.'
name|'HTTPBadRequest'
op|'('
name|'explanation'
op|'='
name|'msg'
op|')'
newline|'\n'
dedent|''
name|'except'
name|'exception'
op|'.'
name|'FlavorNotFound'
op|':'
newline|'\n'
indent|'            '
name|'msg'
op|'='
name|'_'
op|'('
string|'"Flavor used by the instance could not be found."'
op|')'
newline|'\n'
name|'raise'
name|'exc'
op|'.'
name|'HTTPBadRequest'
op|'('
name|'explanation'
op|'='
name|'msg'
op|')'
newline|'\n'
dedent|''
name|'except'
name|'exception'
op|'.'
name|'InstanceIsLocked'
name|'as'
name|'e'
op|':'
newline|'\n'
indent|'            '
name|'raise'
name|'exc'
op|'.'
name|'HTTPConflict'
op|'('
name|'explanation'
op|'='
name|'e'
op|'.'
name|'format_message'
op|'('
op|')'
op|')'
newline|'\n'
dedent|''
name|'except'
name|'exception'
op|'.'
name|'InstanceInvalidState'
name|'as'
name|'state_error'
op|':'
newline|'\n'
indent|'            '
name|'common'
op|'.'
name|'raise_http_conflict_for_instance_invalid_state'
op|'('
name|'state_error'
op|','
nl|'\n'
string|"'revertResize'"
op|','
name|'id'
op|')'
newline|'\n'
dedent|''
name|'return'
name|'webob'
op|'.'
name|'Response'
op|'('
name|'status_int'
op|'='
number|'202'
op|')'
newline|'\n'
nl|'\n'
dedent|''
op|'@'
name|'wsgi'
op|'.'
name|'response'
op|'('
number|'202'
op|')'
newline|'\n'
op|'@'
name|'wsgi'
op|'.'
name|'action'
op|'('
string|"'reboot'"
op|')'
newline|'\n'
DECL|member|_action_reboot
name|'def'
name|'_action_reboot'
op|'('
name|'self'
op|','
name|'req'
op|','
name|'id'
op|','
name|'body'
op|')'
op|':'
newline|'\n'
indent|'        '
name|'if'
string|"'reboot'"
name|'in'
name|'body'
name|'and'
string|"'type'"
name|'in'
name|'body'
op|'['
string|"'reboot'"
op|']'
op|':'
newline|'\n'
indent|'            '
name|'if'
name|'not'
name|'isinstance'
op|'('
name|'body'
op|'['
string|"'reboot'"
op|']'
op|'['
string|"'type'"
op|']'
op|','
name|'six'
op|'.'
name|'string_types'
op|')'
op|':'
newline|'\n'
indent|'                '
name|'msg'
op|'='
name|'_'
op|'('
string|'"Argument \'type\' for reboot must be a string"'
op|')'
newline|'\n'
name|'LOG'
op|'.'
name|'error'
op|'('
name|'msg'
op|')'
newline|'\n'
name|'raise'
name|'exc'
op|'.'
name|'HTTPBadRequest'
op|'('
name|'explanation'
op|'='
name|'msg'
op|')'
newline|'\n'
dedent|''
name|'valid_reboot_types'
op|'='
op|'['
string|"'HARD'"
op|','
string|"'SOFT'"
op|']'
newline|'\n'
name|'reboot_type'
op|'='
name|'body'
op|'['
string|"'reboot'"
op|']'
op|'['
string|"'type'"
op|']'
op|'.'
name|'upper'
op|'('
op|')'
newline|'\n'
name|'if'
name|'not'
name|'valid_reboot_types'
op|'.'
name|'count'
op|'('
name|'reboot_type'
op|')'
op|':'
newline|'\n'
indent|'                '
name|'msg'
op|'='
name|'_'
op|'('
string|'"Argument \'type\' for reboot is not HARD or SOFT"'
op|')'
newline|'\n'
name|'LOG'
op|'.'
name|'error'
op|'('
name|'msg'
op|')'
newline|'\n'
name|'raise'
name|'exc'
op|'.'
name|'HTTPBadRequest'
op|'('
name|'explanation'
op|'='
name|'msg'
op|')'
newline|'\n'
dedent|''
dedent|''
name|'else'
op|':'
newline|'\n'
indent|'            '
name|'msg'
op|'='
name|'_'
op|'('
string|'"Missing argument \'type\' for reboot"'
op|')'
newline|'\n'
name|'LOG'
op|'.'
name|'error'
op|'('
name|'msg'
op|')'
newline|'\n'
name|'raise'
name|'exc'
op|'.'
name|'HTTPBadRequest'
op|'('
name|'explanation'
op|'='
name|'msg'
op|')'
newline|'\n'
nl|'\n'
dedent|''
name|'context'
op|'='
name|'req'
op|'.'
name|'environ'
op|'['
string|"'nova.context'"
op|']'
newline|'\n'
name|'instance'
op|'='
name|'self'
op|'.'
name|'_get_server'
op|'('
name|'context'
op|','
name|'req'
op|','
name|'id'
op|')'
newline|'\n'
nl|'\n'
name|'try'
op|':'
newline|'\n'
indent|'            '
name|'self'
op|'.'
name|'compute_api'
op|'.'
name|'reboot'
op|'('
name|'context'
op|','
name|'instance'
op|','
name|'reboot_type'
op|')'
newline|'\n'
dedent|''
name|'except'
name|'exception'
op|'.'
name|'InstanceIsLocked'
name|'as'
name|'e'
op|':'
newline|'\n'
indent|'            '
name|'raise'
name|'exc'
op|'.'
name|'HTTPConflict'
op|'('
name|'explanation'
op|'='
name|'e'
op|'.'
name|'format_message'
op|'('
op|')'
op|')'
newline|'\n'
dedent|''
name|'except'
name|'exception'
op|'.'
name|'InstanceInvalidState'
name|'as'
name|'state_error'
op|':'
newline|'\n'
indent|'            '
name|'common'
op|'.'
name|'raise_http_conflict_for_instance_invalid_state'
op|'('
name|'state_error'
op|','
nl|'\n'
string|"'reboot'"
op|','
name|'id'
op|')'
newline|'\n'
dedent|''
name|'return'
name|'webob'
op|'.'
name|'Response'
op|'('
name|'status_int'
op|'='
number|'202'
op|')'
newline|'\n'
nl|'\n'
DECL|member|_resize
dedent|''
name|'def'
name|'_resize'
op|'('
name|'self'
op|','
name|'req'
op|','
name|'instance_id'
op|','
name|'flavor_id'
op|','
op|'**'
name|'kwargs'
op|')'
op|':'
newline|'\n'
indent|'        '
string|'"""Begin the resize process with given instance/flavor."""'
newline|'\n'
name|'context'
op|'='
name|'req'
op|'.'
name|'environ'
op|'['
string|'"nova.context"'
op|']'
newline|'\n'
name|'instance'
op|'='
name|'self'
op|'.'
name|'_get_server'
op|'('
name|'context'
op|','
name|'req'
op|','
name|'instance_id'
op|')'
newline|'\n'
name|'try'
op|':'
newline|'\n'
indent|'            '
name|'self'
op|'.'
name|'compute_api'
op|'.'
name|'resize'
op|'('
name|'context'
op|','
name|'instance'
op|','
name|'flavor_id'
op|','
op|'**'
name|'kwargs'
op|')'
newline|'\n'
dedent|''
name|'except'
name|'exception'
op|'.'
name|'QuotaError'
name|'as'
name|'error'
op|':'
newline|'\n'
indent|'            '
name|'raise'
name|'exc'
op|'.'
name|'HTTPForbidden'
op|'('
nl|'\n'
name|'explanation'
op|'='
name|'error'
op|'.'
name|'format_message'
op|'('
op|')'
op|')'
newline|'\n'
dedent|''
name|'except'
name|'exception'
op|'.'
name|'FlavorNotFound'
op|':'
newline|'\n'
indent|'            '
name|'msg'
op|'='
name|'_'
op|'('
string|'"Unable to locate requested flavor."'
op|')'
newline|'\n'
name|'raise'
name|'exc'
op|'.'
name|'HTTPBadRequest'
op|'('
name|'explanation'
op|'='
name|'msg'
op|')'
newline|'\n'
dedent|''
name|'except'
name|'exception'
op|'.'
name|'CannotResizeToSameFlavor'
op|':'
newline|'\n'
indent|'            '
name|'msg'
op|'='
name|'_'
op|'('
string|'"Resize requires a flavor change."'
op|')'
newline|'\n'
name|'raise'
name|'exc'
op|'.'
name|'HTTPBadRequest'
op|'('
name|'explanation'
op|'='
name|'msg'
op|')'
newline|'\n'
dedent|''
name|'except'
name|'exception'
op|'.'
name|'CannotResizeDisk'
name|'as'
name|'e'
op|':'
newline|'\n'
indent|'            '
name|'raise'
name|'exc'
op|'.'
name|'HTTPBadRequest'
op|'('
name|'explanation'
op|'='
name|'e'
op|'.'
name|'format_message'
op|'('
op|')'
op|')'
newline|'\n'
dedent|''
name|'except'
name|'exception'
op|'.'
name|'InstanceIsLocked'
name|'as'
name|'e'
op|':'
newline|'\n'
indent|'            '
name|'raise'
name|'exc'
op|'.'
name|'HTTPConflict'
op|'('
name|'explanation'
op|'='
name|'e'
op|'.'
name|'format_message'
op|'('
op|')'
op|')'
newline|'\n'
dedent|''
name|'except'
name|'exception'
op|'.'
name|'InstanceInvalidState'
name|'as'
name|'state_error'
op|':'
newline|'\n'
indent|'            '
name|'common'
op|'.'
name|'raise_http_conflict_for_instance_invalid_state'
op|'('
name|'state_error'
op|','
nl|'\n'
string|"'resize'"
op|','
name|'instance_id'
op|')'
newline|'\n'
dedent|''
name|'except'
name|'exception'
op|'.'
name|'ImageNotAuthorized'
op|':'
newline|'\n'
indent|'            '
name|'msg'
op|'='
name|'_'
op|'('
string|'"You are not authorized to access the image "'
nl|'\n'
string|'"the instance was started with."'
op|')'
newline|'\n'
name|'raise'
name|'exc'
op|'.'
name|'HTTPUnauthorized'
op|'('
name|'explanation'
op|'='
name|'msg'
op|')'
newline|'\n'
dedent|''
name|'except'
name|'exception'
op|'.'
name|'ImageNotFound'
op|':'
newline|'\n'
indent|'            '
name|'msg'
op|'='
name|'_'
op|'('
string|'"Image that the instance was started "'
nl|'\n'
string|'"with could not be found."'
op|')'
newline|'\n'
name|'raise'
name|'exc'
op|'.'
name|'HTTPBadRequest'
op|'('
name|'explanation'
op|'='
name|'msg'
op|')'
newline|'\n'
dedent|''
name|'except'
op|'('
name|'exception'
op|'.'
name|'NoValidHost'
op|','
nl|'\n'
name|'exception'
op|'.'
name|'AutoDiskConfigDisabledByImage'
op|')'
name|'as'
name|'e'
op|':'
newline|'\n'
indent|'            '
name|'raise'
name|'exc'
op|'.'
name|'HTTPBadRequest'
op|'('
name|'explanation'
op|'='
name|'e'
op|'.'
name|'format_message'
op|'('
op|')'
op|')'
newline|'\n'
dedent|''
name|'except'
name|'exception'
op|'.'
name|'Invalid'
op|':'
newline|'\n'
indent|'            '
name|'msg'
op|'='
name|'_'
op|'('
string|'"Invalid instance image."'
op|')'
newline|'\n'
name|'raise'
name|'exc'
op|'.'
name|'HTTPBadRequest'
op|'('
name|'explanation'
op|'='
name|'msg'
op|')'
newline|'\n'
nl|'\n'
dedent|''
name|'return'
name|'webob'
op|'.'
name|'Response'
op|'('
name|'status_int'
op|'='
number|'202'
op|')'
newline|'\n'
nl|'\n'
dedent|''
op|'@'
name|'wsgi'
op|'.'
name|'response'
op|'('
number|'204'
op|')'
newline|'\n'
DECL|member|delete
name|'def'
name|'delete'
op|'('
name|'self'
op|','
name|'req'
op|','
name|'id'
op|')'
op|':'
newline|'\n'
indent|'        '
string|'"""Destroys a server."""'
newline|'\n'
name|'try'
op|':'
newline|'\n'
indent|'            '
name|'self'
op|'.'
name|'_delete'
op|'('
name|'req'
op|'.'
name|'environ'
op|'['
string|"'nova.context'"
op|']'
op|','
name|'req'
op|','
name|'id'
op|')'
newline|'\n'
dedent|''
name|'except'
name|'exception'
op|'.'
name|'NotFound'
op|':'
newline|'\n'
indent|'            '
name|'msg'
op|'='
name|'_'
op|'('
string|'"Instance could not be found"'
op|')'
newline|'\n'
name|'raise'
name|'exc'
op|'.'
name|'HTTPNotFound'
op|'('
name|'explanation'
op|'='
name|'msg'
op|')'
newline|'\n'
dedent|''
name|'except'
name|'exception'
op|'.'
name|'InstanceIsLocked'
name|'as'
name|'e'
op|':'
newline|'\n'
indent|'            '
name|'raise'
name|'exc'
op|'.'
name|'HTTPConflict'
op|'('
name|'explanation'
op|'='
name|'e'
op|'.'
name|'format_message'
op|'('
op|')'
op|')'
newline|'\n'
dedent|''
name|'except'
name|'exception'
op|'.'
name|'InstanceInvalidState'
name|'as'
name|'state_error'
op|':'
newline|'\n'
indent|'            '
name|'common'
op|'.'
name|'raise_http_conflict_for_instance_invalid_state'
op|'('
name|'state_error'
op|','
nl|'\n'
string|"'delete'"
op|','
name|'id'
op|')'
newline|'\n'
nl|'\n'
DECL|member|_image_ref_from_req_data
dedent|''
dedent|''
name|'def'
name|'_image_ref_from_req_data'
op|'('
name|'self'
op|','
name|'data'
op|')'
op|':'
newline|'\n'
indent|'        '
name|'try'
op|':'
newline|'\n'
indent|'            '
name|'return'
name|'six'
op|'.'
name|'text_type'
op|'('
name|'data'
op|'['
string|"'server'"
op|']'
op|'['
string|"'imageRef'"
op|']'
op|')'
newline|'\n'
dedent|''
name|'except'
op|'('
name|'TypeError'
op|','
name|'KeyError'
op|')'
op|':'
newline|'\n'
indent|'            '
name|'msg'
op|'='
name|'_'
op|'('
string|'"Missing imageRef attribute"'
op|')'
newline|'\n'
name|'raise'
name|'exc'
op|'.'
name|'HTTPBadRequest'
op|'('
name|'explanation'
op|'='
name|'msg'
op|')'
newline|'\n'
nl|'\n'
DECL|member|_image_from_req_data
dedent|''
dedent|''
name|'def'
name|'_image_from_req_data'
op|'('
name|'self'
op|','
name|'data'
op|')'
op|':'
newline|'\n'
indent|'        '
string|'"""Get image data from the request or raise appropriate\n        exceptions\n\n        If no image is supplied - checks to see if there is\n        block devices set and proper extesions loaded.\n        """'
newline|'\n'
name|'image_ref'
op|'='
name|'data'
op|'['
string|"'server'"
op|']'
op|'.'
name|'get'
op|'('
string|"'imageRef'"
op|')'
newline|'\n'
name|'bdm'
op|'='
name|'data'
op|'['
string|"'server'"
op|']'
op|'.'
name|'get'
op|'('
string|"'block_device_mapping'"
op|')'
newline|'\n'
name|'bdm_v2'
op|'='
name|'data'
op|'['
string|"'server'"
op|']'
op|'.'
name|'get'
op|'('
string|"'block_device_mapping_v2'"
op|')'
newline|'\n'
nl|'\n'
name|'if'
op|'('
name|'not'
name|'image_ref'
name|'and'
op|'('
nl|'\n'
op|'('
name|'bdm'
name|'and'
name|'self'
op|'.'
name|'ext_mgr'
op|'.'
name|'is_loaded'
op|'('
string|"'os-volumes'"
op|')'
op|')'
name|'or'
nl|'\n'
op|'('
name|'bdm_v2'
name|'and'
nl|'\n'
name|'self'
op|'.'
name|'ext_mgr'
op|'.'
name|'is_loaded'
op|'('
string|"'os-block-device-mapping-v2-boot'"
op|')'
op|')'
op|')'
op|')'
op|':'
newline|'\n'
indent|'            '
name|'return'
string|"''"
newline|'\n'
dedent|''
name|'else'
op|':'
newline|'\n'
indent|'            '
name|'image_href'
op|'='
name|'self'
op|'.'
name|'_image_ref_from_req_data'
op|'('
name|'data'
op|')'
newline|'\n'
name|'image_uuid'
op|'='
name|'common'
op|'.'
name|'image_uuid_from_href'
op|'('
name|'image_href'
op|','
string|"'imageRef'"
op|')'
newline|'\n'
name|'return'
name|'image_uuid'
newline|'\n'
nl|'\n'
DECL|member|_flavor_id_from_req_data
dedent|''
dedent|''
name|'def'
name|'_flavor_id_from_req_data'
op|'('
name|'self'
op|','
name|'data'
op|')'
op|':'
newline|'\n'
indent|'        '
name|'try'
op|':'
newline|'\n'
indent|'            '
name|'flavor_ref'
op|'='
name|'data'
op|'['
string|"'server'"
op|']'
op|'['
string|"'flavorRef'"
op|']'
newline|'\n'
dedent|''
name|'except'
op|'('
name|'TypeError'
op|','
name|'KeyError'
op|')'
op|':'
newline|'\n'
indent|'            '
name|'msg'
op|'='
name|'_'
op|'('
string|'"Missing flavorRef attribute"'
op|')'
newline|'\n'
name|'raise'
name|'exc'
op|'.'
name|'HTTPBadRequest'
op|'('
name|'explanation'
op|'='
name|'msg'
op|')'
newline|'\n'
dedent|''
name|'try'
op|':'
newline|'\n'
indent|'            '
name|'return'
name|'common'
op|'.'
name|'get_id_from_href'
op|'('
name|'flavor_ref'
op|')'
newline|'\n'
dedent|''
name|'except'
name|'ValueError'
op|':'
newline|'\n'
indent|'            '
name|'msg'
op|'='
name|'_'
op|'('
string|'"Invalid flavorRef provided."'
op|')'
newline|'\n'
name|'raise'
name|'exc'
op|'.'
name|'HTTPBadRequest'
op|'('
name|'explanation'
op|'='
name|'msg'
op|')'
newline|'\n'
nl|'\n'
dedent|''
dedent|''
op|'@'
name|'wsgi'
op|'.'
name|'response'
op|'('
number|'202'
op|')'
newline|'\n'
op|'@'
name|'wsgi'
op|'.'
name|'action'
op|'('
string|"'changePassword'"
op|')'
newline|'\n'
DECL|member|_action_change_password
name|'def'
name|'_action_change_password'
op|'('
name|'self'
op|','
name|'req'
op|','
name|'id'
op|','
name|'body'
op|')'
op|':'
newline|'\n'
indent|'        '
name|'context'
op|'='
name|'req'
op|'.'
name|'environ'
op|'['
string|"'nova.context'"
op|']'
newline|'\n'
name|'if'
op|'('
name|'not'
name|'body'
op|'.'
name|'get'
op|'('
string|"'changePassword'"
op|')'
nl|'\n'
name|'or'
string|"'adminPass'"
name|'not'
name|'in'
name|'body'
op|'['
string|"'changePassword'"
op|']'
op|')'
op|':'
newline|'\n'
indent|'            '
name|'msg'
op|'='
name|'_'
op|'('
string|'"No adminPass was specified"'
op|')'
newline|'\n'
name|'raise'
name|'exc'
op|'.'
name|'HTTPBadRequest'
op|'('
name|'explanation'
op|'='
name|'msg'
op|')'
newline|'\n'
dedent|''
name|'password'
op|'='
name|'self'
op|'.'
name|'_get_server_admin_password'
op|'('
name|'body'
op|'['
string|"'changePassword'"
op|']'
op|')'
newline|'\n'
nl|'\n'
name|'server'
op|'='
name|'self'
op|'.'
name|'_get_server'
op|'('
name|'context'
op|','
name|'req'
op|','
name|'id'
op|')'
newline|'\n'
name|'try'
op|':'
newline|'\n'
indent|'            '
name|'self'
op|'.'
name|'compute_api'
op|'.'
name|'set_admin_password'
op|'('
name|'context'
op|','
name|'server'
op|','
name|'password'
op|')'
newline|'\n'
dedent|''
name|'except'
name|'exception'
op|'.'
name|'InstancePasswordSetFailed'
name|'as'
name|'e'
op|':'
newline|'\n'
indent|'            '
name|'raise'
name|'exc'
op|'.'
name|'HTTPConflict'
op|'('
name|'explanation'
op|'='
name|'e'
op|'.'
name|'format_message'
op|'('
op|')'
op|')'
newline|'\n'
dedent|''
name|'except'
name|'exception'
op|'.'
name|'InstanceInvalidState'
name|'as'
name|'e'
op|':'
newline|'\n'
indent|'            '
name|'raise'
name|'common'
op|'.'
name|'raise_http_conflict_for_instance_invalid_state'
op|'('
nl|'\n'
name|'e'
op|','
string|"'changePassword'"
op|','
name|'id'
op|')'
newline|'\n'
dedent|''
name|'except'
name|'NotImplementedError'
op|':'
newline|'\n'
indent|'            '
name|'msg'
op|'='
name|'_'
op|'('
string|'"Unable to set password on instance"'
op|')'
newline|'\n'
name|'raise'
name|'exc'
op|'.'
name|'HTTPNotImplemented'
op|'('
name|'explanation'
op|'='
name|'msg'
op|')'
newline|'\n'
dedent|''
name|'return'
name|'webob'
op|'.'
name|'Response'
op|'('
name|'status_int'
op|'='
number|'202'
op|')'
newline|'\n'
nl|'\n'
DECL|member|_validate_metadata
dedent|''
name|'def'
name|'_validate_metadata'
op|'('
name|'self'
op|','
name|'metadata'
op|')'
op|':'
newline|'\n'
indent|'        '
string|'"""Ensure that we can work with the metadata given."""'
newline|'\n'
name|'try'
op|':'
newline|'\n'
indent|'            '
name|'six'
op|'.'
name|'iteritems'
op|'('
name|'metadata'
op|')'
newline|'\n'
dedent|''
name|'except'
name|'AttributeError'
op|':'
newline|'\n'
indent|'            '
name|'msg'
op|'='
name|'_'
op|'('
string|'"Unable to parse metadata key/value pairs."'
op|')'
newline|'\n'
name|'LOG'
op|'.'
name|'debug'
op|'('
name|'msg'
op|')'
newline|'\n'
name|'raise'
name|'exc'
op|'.'
name|'HTTPBadRequest'
op|'('
name|'explanation'
op|'='
name|'msg'
op|')'
newline|'\n'
nl|'\n'
dedent|''
dedent|''
op|'@'
name|'wsgi'
op|'.'
name|'response'
op|'('
number|'202'
op|')'
newline|'\n'
op|'@'
name|'wsgi'
op|'.'
name|'action'
op|'('
string|"'resize'"
op|')'
newline|'\n'
DECL|member|_action_resize
name|'def'
name|'_action_resize'
op|'('
name|'self'
op|','
name|'req'
op|','
name|'id'
op|','
name|'body'
op|')'
op|':'
newline|'\n'
indent|'        '
string|'"""Resizes a given instance to the flavor size requested."""'
newline|'\n'
name|'try'
op|':'
newline|'\n'
indent|'            '
name|'flavor_ref'
op|'='
name|'str'
op|'('
name|'body'
op|'['
string|'"resize"'
op|']'
op|'['
string|'"flavorRef"'
op|']'
op|')'
newline|'\n'
name|'if'
name|'not'
name|'flavor_ref'
op|':'
newline|'\n'
indent|'                '
name|'msg'
op|'='
name|'_'
op|'('
string|'"Resize request has invalid \'flavorRef\' attribute."'
op|')'
newline|'\n'
name|'raise'
name|'exc'
op|'.'
name|'HTTPBadRequest'
op|'('
name|'explanation'
op|'='
name|'msg'
op|')'
newline|'\n'
dedent|''
dedent|''
name|'except'
op|'('
name|'KeyError'
op|','
name|'TypeError'
op|')'
op|':'
newline|'\n'
indent|'            '
name|'msg'
op|'='
name|'_'
op|'('
string|'"Resize requests require \'flavorRef\' attribute."'
op|')'
newline|'\n'
name|'raise'
name|'exc'
op|'.'
name|'HTTPBadRequest'
op|'('
name|'explanation'
op|'='
name|'msg'
op|')'
newline|'\n'
nl|'\n'
dedent|''
name|'kwargs'
op|'='
op|'{'
op|'}'
newline|'\n'
name|'if'
string|"'auto_disk_config'"
name|'in'
name|'body'
op|'['
string|"'resize'"
op|']'
op|':'
newline|'\n'
indent|'            '
name|'kwargs'
op|'['
string|"'auto_disk_config'"
op|']'
op|'='
name|'body'
op|'['
string|"'resize'"
op|']'
op|'['
string|"'auto_disk_config'"
op|']'
newline|'\n'
nl|'\n'
dedent|''
name|'return'
name|'self'
op|'.'
name|'_resize'
op|'('
name|'req'
op|','
name|'id'
op|','
name|'flavor_ref'
op|','
op|'**'
name|'kwargs'
op|')'
newline|'\n'
nl|'\n'
dedent|''
op|'@'
name|'wsgi'
op|'.'
name|'response'
op|'('
number|'202'
op|')'
newline|'\n'
op|'@'
name|'wsgi'
op|'.'
name|'action'
op|'('
string|"'rebuild'"
op|')'
newline|'\n'
DECL|member|_action_rebuild
name|'def'
name|'_action_rebuild'
op|'('
name|'self'
op|','
name|'req'
op|','
name|'id'
op|','
name|'body'
op|')'
op|':'
newline|'\n'
indent|'        '
string|'"""Rebuild an instance with the given attributes."""'
newline|'\n'
name|'body'
op|'='
name|'body'
op|'['
string|"'rebuild'"
op|']'
newline|'\n'
nl|'\n'
name|'try'
op|':'
newline|'\n'
indent|'            '
name|'image_href'
op|'='
name|'body'
op|'['
string|'"imageRef"'
op|']'
newline|'\n'
dedent|''
name|'except'
op|'('
name|'KeyError'
op|','
name|'TypeError'
op|')'
op|':'
newline|'\n'
indent|'            '
name|'msg'
op|'='
name|'_'
op|'('
string|'"Could not parse imageRef from request."'
op|')'
newline|'\n'
name|'raise'
name|'exc'
op|'.'
name|'HTTPBadRequest'
op|'('
name|'explanation'
op|'='
name|'msg'
op|')'
newline|'\n'
nl|'\n'
dedent|''
name|'image_href'
op|'='
name|'common'
op|'.'
name|'image_uuid_from_href'
op|'('
name|'image_href'
op|','
string|"'imageRef'"
op|')'
newline|'\n'
nl|'\n'
name|'password'
op|'='
name|'self'
op|'.'
name|'_get_server_admin_password'
op|'('
name|'body'
op|')'
newline|'\n'
nl|'\n'
name|'context'
op|'='
name|'req'
op|'.'
name|'environ'
op|'['
string|"'nova.context'"
op|']'
newline|'\n'
name|'instance'
op|'='
name|'self'
op|'.'
name|'_get_server'
op|'('
name|'context'
op|','
name|'req'
op|','
name|'id'
op|')'
newline|'\n'
nl|'\n'
name|'attr_map'
op|'='
op|'{'
nl|'\n'
string|"'personality'"
op|':'
string|"'files_to_inject'"
op|','
nl|'\n'
string|"'name'"
op|':'
string|"'display_name'"
op|','
nl|'\n'
string|"'accessIPv4'"
op|':'
string|"'access_ip_v4'"
op|','
nl|'\n'
string|"'accessIPv6'"
op|':'
string|"'access_ip_v6'"
op|','
nl|'\n'
string|"'metadata'"
op|':'
string|"'metadata'"
op|','
nl|'\n'
string|"'auto_disk_config'"
op|':'
string|"'auto_disk_config'"
op|','
nl|'\n'
op|'}'
newline|'\n'
nl|'\n'
name|'kwargs'
op|'='
op|'{'
op|'}'
newline|'\n'
nl|'\n'
comment|'# take the preserve_ephemeral value into account only when the'
nl|'\n'
comment|'# corresponding extension is active'
nl|'\n'
name|'if'
op|'('
name|'self'
op|'.'
name|'ext_mgr'
op|'.'
name|'is_loaded'
op|'('
string|"'os-preserve-ephemeral-rebuild'"
op|')'
nl|'\n'
name|'and'
string|"'preserve_ephemeral'"
name|'in'
name|'body'
op|')'
op|':'
newline|'\n'
indent|'            '
name|'kwargs'
op|'['
string|"'preserve_ephemeral'"
op|']'
op|'='
name|'strutils'
op|'.'
name|'bool_from_string'
op|'('
nl|'\n'
name|'body'
op|'['
string|"'preserve_ephemeral'"
op|']'
op|','
name|'strict'
op|'='
name|'True'
op|')'
newline|'\n'
nl|'\n'
dedent|''
name|'if'
string|"'accessIPv4'"
name|'in'
name|'body'
op|':'
newline|'\n'
indent|'            '
name|'self'
op|'.'
name|'_validate_access_ipv4'
op|'('
name|'body'
op|'['
string|"'accessIPv4'"
op|']'
op|')'
newline|'\n'
nl|'\n'
dedent|''
name|'if'
string|"'accessIPv6'"
name|'in'
name|'body'
op|':'
newline|'\n'
indent|'            '
name|'self'
op|'.'
name|'_validate_access_ipv6'
op|'('
name|'body'
op|'['
string|"'accessIPv6'"
op|']'
op|')'
newline|'\n'
nl|'\n'
dedent|''
name|'if'
string|"'name'"
name|'in'
name|'body'
op|':'
newline|'\n'
indent|'            '
name|'self'
op|'.'
name|'_validate_server_name'
op|'('
name|'body'
op|'['
string|"'name'"
op|']'
op|')'
newline|'\n'
nl|'\n'
dedent|''
name|'for'
name|'request_attribute'
op|','
name|'instance_attribute'
name|'in'
name|'attr_map'
op|'.'
name|'items'
op|'('
op|')'
op|':'
newline|'\n'
indent|'            '
name|'try'
op|':'
newline|'\n'
indent|'                '
name|'kwargs'
op|'['
name|'instance_attribute'
op|']'
op|'='
name|'body'
op|'['
name|'request_attribute'
op|']'
newline|'\n'
dedent|''
name|'except'
op|'('
name|'KeyError'
op|','
name|'TypeError'
op|')'
op|':'
newline|'\n'
indent|'                '
name|'pass'
newline|'\n'
nl|'\n'
dedent|''
dedent|''
name|'self'
op|'.'
name|'_validate_metadata'
op|'('
name|'kwargs'
op|'.'
name|'get'
op|'('
string|"'metadata'"
op|','
op|'{'
op|'}'
op|')'
op|')'
newline|'\n'
nl|'\n'
name|'if'
string|"'files_to_inject'"
name|'in'
name|'kwargs'
op|':'
newline|'\n'
indent|'            '
name|'personality'
op|'='
name|'kwargs'
op|'.'
name|'pop'
op|'('
string|"'files_to_inject'"
op|')'
newline|'\n'
name|'files_to_inject'
op|'='
name|'self'
op|'.'
name|'_get_injected_files'
op|'('
name|'personality'
op|')'
newline|'\n'
dedent|''
name|'else'
op|':'
newline|'\n'
indent|'            '
name|'files_to_inject'
op|'='
name|'None'
newline|'\n'
nl|'\n'
dedent|''
name|'try'
op|':'
newline|'\n'
indent|'            '
name|'self'
op|'.'
name|'compute_api'
op|'.'
name|'rebuild'
op|'('
name|'context'
op|','
nl|'\n'
name|'instance'
op|','
nl|'\n'
name|'image_href'
op|','
nl|'\n'
name|'password'
op|','
nl|'\n'
name|'files_to_inject'
op|'='
name|'files_to_inject'
op|','
nl|'\n'
op|'**'
name|'kwargs'
op|')'
newline|'\n'
dedent|''
name|'except'
name|'exception'
op|'.'
name|'InstanceIsLocked'
name|'as'
name|'e'
op|':'
newline|'\n'
indent|'            '
name|'raise'
name|'exc'
op|'.'
name|'HTTPConflict'
op|'('
name|'explanation'
op|'='
name|'e'
op|'.'
name|'format_message'
op|'('
op|')'
op|')'
newline|'\n'
dedent|''
name|'except'
name|'exception'
op|'.'
name|'InstanceInvalidState'
name|'as'
name|'state_error'
op|':'
newline|'\n'
indent|'            '
name|'common'
op|'.'
name|'raise_http_conflict_for_instance_invalid_state'
op|'('
name|'state_error'
op|','
nl|'\n'
string|"'rebuild'"
op|','
name|'id'
op|')'
newline|'\n'
dedent|''
name|'except'
name|'exception'
op|'.'
name|'InstanceNotFound'
op|':'
newline|'\n'
indent|'            '
name|'msg'
op|'='
name|'_'
op|'('
string|'"Instance could not be found"'
op|')'
newline|'\n'
name|'raise'
name|'exc'
op|'.'
name|'HTTPNotFound'
op|'('
name|'explanation'
op|'='
name|'msg'
op|')'
newline|'\n'
dedent|''
name|'except'
name|'exception'
op|'.'
name|'InvalidMetadataSize'
name|'as'
name|'error'
op|':'
newline|'\n'
indent|'            '
name|'raise'
name|'exc'
op|'.'
name|'HTTPRequestEntityTooLarge'
op|'('
nl|'\n'
name|'explanation'
op|'='
name|'error'
op|'.'
name|'format_message'
op|'('
op|')'
op|')'
newline|'\n'
dedent|''
name|'except'
name|'exception'
op|'.'
name|'ImageNotFound'
op|':'
newline|'\n'
indent|'            '
name|'msg'
op|'='
name|'_'
op|'('
string|'"Cannot find image for rebuild"'
op|')'
newline|'\n'
name|'raise'
name|'exc'
op|'.'
name|'HTTPBadRequest'
op|'('
name|'explanation'
op|'='
name|'msg'
op|')'
newline|'\n'
dedent|''
name|'except'
name|'exception'
op|'.'
name|'QuotaError'
name|'as'
name|'error'
op|':'
newline|'\n'
indent|'            '
name|'raise'
name|'exc'
op|'.'
name|'HTTPForbidden'
op|'('
name|'explanation'
op|'='
name|'error'
op|'.'
name|'format_message'
op|'('
op|')'
op|')'
newline|'\n'
dedent|''
name|'except'
op|'('
name|'exception'
op|'.'
name|'ImageNotActive'
op|','
nl|'\n'
name|'exception'
op|'.'
name|'FlavorDiskTooSmall'
op|','
nl|'\n'
name|'exception'
op|'.'
name|'FlavorMemoryTooSmall'
op|','
nl|'\n'
name|'exception'
op|'.'
name|'InvalidMetadata'
op|','
nl|'\n'
name|'exception'
op|'.'
name|'AutoDiskConfigDisabledByImage'
op|')'
name|'as'
name|'error'
op|':'
newline|'\n'
indent|'            '
name|'raise'
name|'exc'
op|'.'
name|'HTTPBadRequest'
op|'('
name|'explanation'
op|'='
name|'error'
op|'.'
name|'format_message'
op|'('
op|')'
op|')'
newline|'\n'
nl|'\n'
dedent|''
name|'instance'
op|'='
name|'self'
op|'.'
name|'_get_server'
op|'('
name|'context'
op|','
name|'req'
op|','
name|'id'
op|','
name|'is_detail'
op|'='
name|'True'
op|')'
newline|'\n'
nl|'\n'
name|'view'
op|'='
name|'self'
op|'.'
name|'_view_builder'
op|'.'
name|'show'
op|'('
name|'req'
op|','
name|'instance'
op|')'
newline|'\n'
nl|'\n'
comment|"# Add on the adminPass attribute since the view doesn't do it"
nl|'\n'
comment|'# unless instance passwords are disabled'
nl|'\n'
name|'if'
name|'CONF'
op|'.'
name|'enable_instance_password'
op|':'
newline|'\n'
indent|'            '
name|'view'
op|'['
string|"'server'"
op|']'
op|'['
string|"'adminPass'"
op|']'
op|'='
name|'password'
newline|'\n'
nl|'\n'
dedent|''
name|'robj'
op|'='
name|'wsgi'
op|'.'
name|'ResponseObject'
op|'('
name|'view'
op|')'
newline|'\n'
name|'return'
name|'self'
op|'.'
name|'_add_location'
op|'('
name|'robj'
op|')'
newline|'\n'
nl|'\n'
dedent|''
op|'@'
name|'wsgi'
op|'.'
name|'response'
op|'('
number|'202'
op|')'
newline|'\n'
op|'@'
name|'wsgi'
op|'.'
name|'action'
op|'('
string|"'createImage'"
op|')'
newline|'\n'
op|'@'
name|'common'
op|'.'
name|'check_snapshots_enabled'
newline|'\n'
DECL|member|_action_create_image
name|'def'
name|'_action_create_image'
op|'('
name|'self'
op|','
name|'req'
op|','
name|'id'
op|','
name|'body'
op|')'
op|':'
newline|'\n'
indent|'        '
string|'"""Snapshot a server instance."""'
newline|'\n'
name|'context'
op|'='
name|'req'
op|'.'
name|'environ'
op|'['
string|"'nova.context'"
op|']'
newline|'\n'
name|'entity'
op|'='
name|'body'
op|'.'
name|'get'
op|'('
string|'"createImage"'
op|','
op|'{'
op|'}'
op|')'
newline|'\n'
nl|'\n'
name|'image_name'
op|'='
name|'entity'
op|'.'
name|'get'
op|'('
string|'"name"'
op|')'
newline|'\n'
nl|'\n'
name|'if'
name|'not'
name|'image_name'
op|':'
newline|'\n'
indent|'            '
name|'msg'
op|'='
name|'_'
op|'('
string|'"createImage entity requires name attribute"'
op|')'
newline|'\n'
name|'raise'
name|'exc'
op|'.'
name|'HTTPBadRequest'
op|'('
name|'explanation'
op|'='
name|'msg'
op|')'
newline|'\n'
nl|'\n'
dedent|''
name|'props'
op|'='
op|'{'
op|'}'
newline|'\n'
name|'metadata'
op|'='
name|'entity'
op|'.'
name|'get'
op|'('
string|"'metadata'"
op|','
op|'{'
op|'}'
op|')'
newline|'\n'
name|'common'
op|'.'
name|'check_img_metadata_properties_quota'
op|'('
name|'context'
op|','
name|'metadata'
op|')'
newline|'\n'
name|'try'
op|':'
newline|'\n'
indent|'            '
name|'props'
op|'.'
name|'update'
op|'('
name|'metadata'
op|')'
newline|'\n'
dedent|''
name|'except'
name|'ValueError'
op|':'
newline|'\n'
indent|'            '
name|'msg'
op|'='
name|'_'
op|'('
string|'"Invalid metadata"'
op|')'
newline|'\n'
name|'raise'
name|'exc'
op|'.'
name|'HTTPBadRequest'
op|'('
name|'explanation'
op|'='
name|'msg'
op|')'
newline|'\n'
nl|'\n'
dedent|''
name|'instance'
op|'='
name|'self'
op|'.'
name|'_get_server'
op|'('
name|'context'
op|','
name|'req'
op|','
name|'id'
op|')'
newline|'\n'
nl|'\n'
name|'bdms'
op|'='
name|'objects'
op|'.'
name|'BlockDeviceMappingList'
op|'.'
name|'get_by_instance_uuid'
op|'('
nl|'\n'
name|'context'
op|','
name|'instance'
op|'.'
name|'uuid'
op|')'
newline|'\n'
nl|'\n'
name|'try'
op|':'
newline|'\n'
indent|'            '
name|'if'
name|'self'
op|'.'
name|'compute_api'
op|'.'
name|'is_volume_backed_instance'
op|'('
name|'context'
op|','
name|'instance'
op|','
nl|'\n'
name|'bdms'
op|')'
op|':'
newline|'\n'
indent|'                '
name|'policy'
op|'.'
name|'enforce'
op|'('
name|'context'
op|','
nl|'\n'
string|"'compute:snapshot_volume_backed'"
op|','
nl|'\n'
op|'{'
string|"'project_id'"
op|':'
name|'context'
op|'.'
name|'project_id'
op|','
nl|'\n'
string|"'user_id'"
op|':'
name|'context'
op|'.'
name|'user_id'
op|'}'
op|')'
newline|'\n'
name|'image'
op|'='
name|'self'
op|'.'
name|'compute_api'
op|'.'
name|'snapshot_volume_backed'
op|'('
nl|'\n'
name|'context'
op|','
nl|'\n'
name|'instance'
op|','
nl|'\n'
name|'image_name'
op|','
nl|'\n'
name|'extra_properties'
op|'='
name|'props'
op|')'
newline|'\n'
dedent|''
name|'else'
op|':'
newline|'\n'
indent|'                '
name|'image'
op|'='
name|'self'
op|'.'
name|'compute_api'
op|'.'
name|'snapshot'
op|'('
name|'context'
op|','
nl|'\n'
name|'instance'
op|','
nl|'\n'
name|'image_name'
op|','
nl|'\n'
name|'extra_properties'
op|'='
name|'props'
op|')'
newline|'\n'
dedent|''
dedent|''
name|'except'
name|'exception'
op|'.'
name|'InstanceInvalidState'
name|'as'
name|'state_error'
op|':'
newline|'\n'
indent|'            '
name|'common'
op|'.'
name|'raise_http_conflict_for_instance_invalid_state'
op|'('
name|'state_error'
op|','
nl|'\n'
string|"'createImage'"
op|','
name|'id'
op|')'
newline|'\n'
dedent|''
name|'except'
name|'exception'
op|'.'
name|'Invalid'
name|'as'
name|'err'
op|':'
newline|'\n'
indent|'            '
name|'raise'
name|'exc'
op|'.'
name|'HTTPBadRequest'
op|'('
name|'explanation'
op|'='
name|'err'
op|'.'
name|'format_message'
op|'('
op|')'
op|')'
newline|'\n'
nl|'\n'
comment|'# build location of newly-created image entity'
nl|'\n'
dedent|''
name|'image_id'
op|'='
name|'str'
op|'('
name|'image'
op|'['
string|"'id'"
op|']'
op|')'
newline|'\n'
name|'url_prefix'
op|'='
name|'self'
op|'.'
name|'_view_builder'
op|'.'
name|'_update_glance_link_prefix'
op|'('
nl|'\n'
name|'req'
op|'.'
name|'application_url'
op|')'
newline|'\n'
name|'image_ref'
op|'='
name|'common'
op|'.'
name|'url_join'
op|'('
name|'url_prefix'
op|','
nl|'\n'
name|'context'
op|'.'
name|'project_id'
op|','
nl|'\n'
string|"'images'"
op|','
nl|'\n'
name|'image_id'
op|')'
newline|'\n'
nl|'\n'
name|'resp'
op|'='
name|'webob'
op|'.'
name|'Response'
op|'('
name|'status_int'
op|'='
number|'202'
op|')'
newline|'\n'
name|'resp'
op|'.'
name|'headers'
op|'['
string|"'Location'"
op|']'
op|'='
name|'image_ref'
newline|'\n'
name|'return'
name|'resp'
newline|'\n'
nl|'\n'
DECL|member|_get_server_admin_password
dedent|''
name|'def'
name|'_get_server_admin_password'
op|'('
name|'self'
op|','
name|'server'
op|')'
op|':'
newline|'\n'
indent|'        '
string|'"""Determine the admin password for a server on creation."""'
newline|'\n'
name|'try'
op|':'
newline|'\n'
indent|'            '
name|'password'
op|'='
name|'server'
op|'['
string|"'adminPass'"
op|']'
newline|'\n'
name|'self'
op|'.'
name|'_validate_admin_password'
op|'('
name|'password'
op|')'
newline|'\n'
dedent|''
name|'except'
name|'KeyError'
op|':'
newline|'\n'
indent|'            '
name|'password'
op|'='
name|'utils'
op|'.'
name|'generate_password'
op|'('
op|')'
newline|'\n'
dedent|''
name|'except'
name|'ValueError'
op|':'
newline|'\n'
indent|'            '
name|'raise'
name|'exc'
op|'.'
name|'HTTPBadRequest'
op|'('
name|'explanation'
op|'='
name|'_'
op|'('
string|'"Invalid adminPass"'
op|')'
op|')'
newline|'\n'
nl|'\n'
dedent|''
name|'return'
name|'password'
newline|'\n'
nl|'\n'
DECL|member|_validate_admin_password
dedent|''
name|'def'
name|'_validate_admin_password'
op|'('
name|'self'
op|','
name|'password'
op|')'
op|':'
newline|'\n'
indent|'        '
name|'if'
name|'not'
name|'isinstance'
op|'('
name|'password'
op|','
name|'six'
op|'.'
name|'string_types'
op|')'
op|':'
newline|'\n'
indent|'            '
name|'raise'
name|'ValueError'
op|'('
op|')'
newline|'\n'
nl|'\n'
DECL|member|_get_server_search_options
dedent|''
dedent|''
name|'def'
name|'_get_server_search_options'
op|'('
name|'self'
op|')'
op|':'
newline|'\n'
indent|'        '
string|'"""Return server search options allowed by non-admin."""'
newline|'\n'
name|'return'
op|'('
string|"'reservation_id'"
op|','
string|"'name'"
op|','
string|"'status'"
op|','
string|"'image'"
op|','
string|"'flavor'"
op|','
nl|'\n'
string|"'ip'"
op|','
string|"'changes-since'"
op|','
string|"'all_tenants'"
op|')'
newline|'\n'
nl|'\n'
nl|'\n'
DECL|function|create_resource
dedent|''
dedent|''
name|'def'
name|'create_resource'
op|'('
name|'ext_mgr'
op|')'
op|':'
newline|'\n'
indent|'    '
name|'return'
name|'wsgi'
op|'.'
name|'Resource'
op|'('
name|'Controller'
op|'('
name|'ext_mgr'
op|')'
op|')'
newline|'\n'
nl|'\n'
nl|'\n'
DECL|function|remove_invalid_options
dedent|''
name|'def'
name|'remove_invalid_options'
op|'('
name|'context'
op|','
name|'search_options'
op|','
name|'allowed_search_options'
op|')'
op|':'
newline|'\n'
indent|'    '
string|'"""Remove search options that are not valid for non-admin API/context."""'
newline|'\n'
name|'if'
name|'context'
op|'.'
name|'is_admin'
op|':'
newline|'\n'
comment|'# Only remove parameters for sorting and pagination'
nl|'\n'
indent|'        '
name|'for'
name|'key'
name|'in'
op|'('
string|"'sort_key'"
op|','
string|"'sort_dir'"
op|','
string|"'limit'"
op|','
string|"'marker'"
op|')'
op|':'
newline|'\n'
indent|'            '
name|'search_options'
op|'.'
name|'pop'
op|'('
name|'key'
op|','
name|'None'
op|')'
newline|'\n'
dedent|''
name|'return'
newline|'\n'
comment|'# Otherwise, strip out all unknown options'
nl|'\n'
dedent|''
name|'unknown_options'
op|'='
op|'['
name|'opt'
name|'for'
name|'opt'
name|'in'
name|'search_options'
nl|'\n'
name|'if'
name|'opt'
name|'not'
name|'in'
name|'allowed_search_options'
op|']'
newline|'\n'
name|'LOG'
op|'.'
name|'debug'
op|'('
string|'"Removing options \'%s\' from query"'
op|','
nl|'\n'
string|'", "'
op|'.'
name|'join'
op|'('
name|'unknown_options'
op|')'
op|')'
newline|'\n'
name|'for'
name|'opt'
name|'in'
name|'unknown_options'
op|':'
newline|'\n'
indent|'        '
name|'search_options'
op|'.'
name|'pop'
op|'('
name|'opt'
op|','
name|'None'
op|')'
newline|'\n'
dedent|''
dedent|''
endmarker|''
end_unit
