<s> import webob <EOL> import webob . exc <EOL> from nova . api . openstack import extensions <EOL> from nova import exception <EOL> from nova . i18n import _ <EOL> from nova import objects <EOL> authorize = extensions . extension_authorizer ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> class FixedIPController ( object ) : <EOL> def show ( self , req , id ) : <EOL> """<STR_LIT>""" <EOL> context = req . environ [ '<STR_LIT>' ] <EOL> authorize ( context ) <EOL> attrs = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> try : <EOL> fixed_ip = objects . FixedIP . get_by_address ( context , id , <EOL> expected_attrs = attrs ) <EOL> except exception . FixedIpNotFoundForAddress as ex : <EOL> raise webob . exc . HTTPNotFound ( explanation = ex . format_message ( ) ) <EOL> except exception . FixedIpInvalid as ex : <EOL> raise webob . exc . HTTPBadRequest ( explanation = ex . format_message ( ) ) <EOL> fixed_ip_info = { "<STR_LIT>" : { } } <EOL> if fixed_ip is None : <EOL> msg = _ ( "<STR_LIT>" ) % id <EOL> raise webob . exc . HTTPNotFound ( explanation = msg ) <EOL> fixed_ip_info [ '<STR_LIT>' ] [ '<STR_LIT>' ] = str ( fixed_ip . network . cidr ) <EOL> fixed_ip_info [ '<STR_LIT>' ] [ '<STR_LIT:address>' ] = str ( fixed_ip . address ) <EOL> if fixed_ip . instance : <EOL> fixed_ip_info [ '<STR_LIT>' ] [ '<STR_LIT>' ] = fixed_ip . instance . hostname <EOL> fixed_ip_info [ '<STR_LIT>' ] [ '<STR_LIT:host>' ] = fixed_ip . instance . host <EOL> else : <EOL> fixed_ip_info [ '<STR_LIT>' ] [ '<STR_LIT>' ] = None <EOL> fixed_ip_info [ '<STR_LIT>' ] [ '<STR_LIT:host>' ] = None <EOL> return fixed_ip_info <EOL> def action ( self , req , id , body ) : <EOL> context = req . environ [ '<STR_LIT>' ] <EOL> authorize ( context ) <EOL> if '<STR_LIT>' in body : <EOL> return self . _set_reserved ( context , id , True ) <EOL> elif '<STR_LIT>' in body : <EOL> return self . _set_reserved ( context , id , False ) <EOL> else : <EOL> raise webob . exc . HTTPBadRequest ( <EOL> explanation = "<STR_LIT>" ) <EOL> def _set_reserved ( self , context , address , reserved ) : <EOL> try : <EOL> fixed_ip = objects . FixedIP . get_by_address ( context , address ) <EOL> fixed_ip . reserved = reserved <EOL> fixed_ip . save ( ) <EOL> except exception . FixedIpNotFoundForAddress : <EOL> msg = _ ( "<STR_LIT>" ) % address <EOL> raise webob . exc . HTTPNotFound ( explanation = msg ) <EOL> except exception . FixedIpInvalid as ex : <EOL> raise webob . exc . HTTPBadRequest ( explanation = ex . format_message ( ) ) <EOL> return webob . Response ( status_int = <NUM_LIT> ) <EOL> class Fixed_ips ( extensions . ExtensionDescriptor ) : <EOL> """<STR_LIT>""" <EOL> name = "<STR_LIT>" <EOL> alias = "<STR_LIT>" <EOL> namespace = "<STR_LIT>" <EOL> updated = "<STR_LIT>" <EOL> def get_resources ( self ) : <EOL> member_actions = { '<STR_LIT:action>' : '<STR_LIT:POST>' } <EOL> resources = [ ] <EOL> resource = extensions . ResourceExtension ( '<STR_LIT>' , <EOL> FixedIPController ( ) , <EOL> member_actions = member_actions ) <EOL> resources . append ( resource ) <EOL> return resources </s>
