<s> import json <EOL> import logging <EOL> import re <EOL> import SoftLayer <EOL> from jumpgate . common import config <EOL> from jumpgate . common import error_handling <EOL> from jumpgate . common import utils <EOL> LOG = logging . getLogger ( __name__ ) <EOL> OPENSTACK_POWER_MAP = { <EOL> "<STR_LIT>" : <NUM_LIT:0> , <EOL> "<STR_LIT>" : <NUM_LIT:1> , <EOL> "<STR_LIT>" : <NUM_LIT:2> , <EOL> "<STR_LIT>" : <NUM_LIT:3> , <EOL> "<STR_LIT>" : <NUM_LIT:4> , <EOL> "<STR_LIT>" : <NUM_LIT:5> , <EOL> "<STR_LIT>" : <NUM_LIT:6> , <EOL> "<STR_LIT>" : <NUM_LIT:7> , <EOL> } <EOL> class ServerActionV2 ( object ) : <EOL> def __init__ ( self , app , flavors ) : <EOL> self . app = app <EOL> self . flavors = flavors <EOL> def on_post ( self , req , resp , tenant_id , instance_id ) : <EOL> body = json . loads ( req . stream . read ( ) . decode ( ) ) <EOL> if len ( body ) == <NUM_LIT:0> : <EOL> return error_handling . bad_request ( resp , <EOL> message = "<STR_LIT>" ) <EOL> vg_client = req . env [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> cci = SoftLayer . CCIManager ( req . env [ '<STR_LIT>' ] ) <EOL> try : <EOL> instance_id = int ( instance_id ) <EOL> except Exception : <EOL> return error_handling . not_found ( resp , <EOL> "<STR_LIT>" ) <EOL> instance = cci . get_instance ( instance_id ) <EOL> if '<STR_LIT>' in body or '<STR_LIT>' in body : <EOL> try : <EOL> vg_client . pause ( id = instance_id ) <EOL> except SoftLayer . SoftLayerAPIError as e : <EOL> if '<STR_LIT>' in e . faultString : <EOL> return error_handling . duplicate ( resp , e . faultString ) <EOL> raise <EOL> resp . status = <NUM_LIT> <EOL> return <EOL> elif '<STR_LIT>' in body or '<STR_LIT>' in body : <EOL> vg_client . resume ( id = instance_id ) <EOL> resp . status = <NUM_LIT> <EOL> return <EOL> elif '<STR_LIT>' in body : <EOL> if body [ '<STR_LIT>' ] . get ( '<STR_LIT:type>' ) == '<STR_LIT>' : <EOL> vg_client . rebootSoft ( id = instance_id ) <EOL> elif body [ '<STR_LIT>' ] . get ( '<STR_LIT:type>' ) == '<STR_LIT>' : <EOL> vg_client . rebootHard ( id = instance_id ) <EOL> else : <EOL> vg_client . rebootDefault ( id = instance_id ) <EOL> resp . status = <NUM_LIT> <EOL> return <EOL> elif '<STR_LIT>' in body : <EOL> vg_client . powerOff ( id = instance_id ) <EOL> resp . status = <NUM_LIT> <EOL> return <EOL> elif '<STR_LIT>' in body : <EOL> vg_client . powerOn ( id = instance_id ) <EOL> resp . status = <NUM_LIT> <EOL> return <EOL> elif '<STR_LIT>' in body : <EOL> image_name = body [ '<STR_LIT>' ] [ '<STR_LIT:name>' ] <EOL> disks = [ ] <EOL> for disk in filter ( lambda x : x [ '<STR_LIT>' ] == '<STR_LIT:0>' , <EOL> instance [ '<STR_LIT>' ] ) : <EOL> disks . append ( disk ) <EOL> try : <EOL> vg_client . createArchiveTransaction ( <EOL> image_name , <EOL> disks , <EOL> "<STR_LIT>" , <EOL> id = instance_id , <EOL> ) <EOL> cci . wait_for_transaction ( instance_id , <NUM_LIT> ) <EOL> _filter = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:name>' : { '<STR_LIT>' : image_name } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ { '<STR_LIT:name>' : '<STR_LIT>' , '<STR_LIT:value>' : [ '<STR_LIT>' ] } ] , <EOL> } <EOL> } } <EOL> acct = req . env [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> matching_image = acct . getPrivateBlockDeviceTemplateGroups ( <EOL> mask = '<STR_LIT>' , filter = _filter , limit = <NUM_LIT:1> ) <EOL> image_guid = matching_image . get ( '<STR_LIT>' ) <EOL> url = self . app . get_endpoint_url ( '<STR_LIT:image>' , req , '<STR_LIT>' , <EOL> image_guid = image_guid ) <EOL> resp . status = <NUM_LIT> <EOL> resp . set_header ( '<STR_LIT:location>' , url ) <EOL> except SoftLayer . SoftLayerAPIError as e : <EOL> error_handling . compute_fault ( resp , e . faultString ) <EOL> return <EOL> elif '<STR_LIT>' in body : <EOL> resp . status = <NUM_LIT> <EOL> return <EOL> elif '<STR_LIT>' in body : <EOL> flavor_id = int ( body [ '<STR_LIT>' ] . get ( '<STR_LIT>' ) ) <EOL> for flavor in self . flavors : <EOL> if str ( flavor_id ) == flavor [ '<STR_LIT:id>' ] : <EOL> vg_client . setTags ( '<STR_LIT>' + str ( flavor_id ) + '<STR_LIT:}>' , <EOL> id = instance_id ) <EOL> cci . upgrade ( instance_id , cpus = flavor [ '<STR_LIT>' ] , <EOL> memory = flavor [ '<STR_LIT>' ] / <NUM_LIT> ) <EOL> resp . status = <NUM_LIT> <EOL> return <EOL> return error_handling . bad_request ( resp , message = "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> elif '<STR_LIT>' in body : <EOL> resp . status = <NUM_LIT> <EOL> return <EOL> return error_handling . bad_request ( <EOL> resp , <EOL> message = "<STR_LIT>" % list ( body . keys ( ) ) , <EOL> code = <NUM_LIT> ) <EOL> class ServersV2 ( object ) : <EOL> def __init__ ( self , app , flavors ) : <EOL> self . app = app <EOL> self . flavors = flavors <EOL> def on_get ( self , req , resp , tenant_id ) : <EOL> client = req . env [ '<STR_LIT>' ] <EOL> cci = SoftLayer . CCIManager ( client ) <EOL> params = get_list_params ( req ) <EOL> sl_instances = cci . list_instances ( ** params ) <EOL> if not isinstance ( sl_instances , list ) : <EOL> sl_instances = [ sl_instances ] <EOL> results = [ ] <EOL> for instance in sl_instances : <EOL> results . append ( { <EOL> '<STR_LIT:id>' : instance [ '<STR_LIT:id>' ] , <EOL> '<STR_LIT>' : [ <EOL> { <EOL> '<STR_LIT>' : self . app . get_endpoint_url ( <EOL> '<STR_LIT>' , req , '<STR_LIT>' , server_id = id ) , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> ] , <EOL> '<STR_LIT:name>' : instance [ '<STR_LIT>' ] , <EOL> } ) <EOL> resp . status = <NUM_LIT:200> <EOL> resp . body = { '<STR_LIT>' : results } <EOL> def on_post ( self , req , resp , tenant_id ) : <EOL> payload = { } <EOL> client = req . env [ '<STR_LIT>' ] <EOL> body = json . loads ( req . stream . read ( ) . decode ( ) ) <EOL> payload [ '<STR_LIT>' ] = body [ '<STR_LIT>' ] [ '<STR_LIT:name>' ] <EOL> payload [ '<STR_LIT>' ] = config . CONF [ '<STR_LIT>' ] or '<STR_LIT>' <EOL> payload [ '<STR_LIT>' ] = body [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> payload [ '<STR_LIT>' ] = True <EOL> networks = utils . lookup ( body , '<STR_LIT>' , '<STR_LIT>' ) <EOL> cci = SoftLayer . CCIManager ( client ) <EOL> try : <EOL> self . _handle_flavor ( payload , body ) <EOL> self . _handle_sshkeys ( payload , body , client ) <EOL> self . _handle_user_data ( payload , body ) <EOL> self . _handle_datacenter ( payload , body ) <EOL> if networks : <EOL> self . _handle_network ( payload , client , networks ) <EOL> new_instance = cci . create_instance ( ** payload ) <EOL> except Exception as e : <EOL> return error_handling . bad_request ( resp , message = str ( e ) ) <EOL> try : <EOL> flavor_id = int ( body [ '<STR_LIT>' ] . get ( '<STR_LIT>' ) ) <EOL> vs = client [ '<STR_LIT>' ] <EOL> vs . setTags ( '<STR_LIT>' + str ( flavor_id ) + '<STR_LIT:}>' , <EOL> id = new_instance [ '<STR_LIT:id>' ] ) <EOL> except Exception : <EOL> pass <EOL> resp . set_header ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> resp . status = <NUM_LIT> <EOL> resp . body = { '<STR_LIT>' : { <EOL> '<STR_LIT:id>' : str ( new_instance [ '<STR_LIT:id>' ] ) , <EOL> '<STR_LIT>' : [ { <EOL> '<STR_LIT>' : self . app . get_endpoint_url ( <EOL> '<STR_LIT>' , req , '<STR_LIT>' , <EOL> instance_id = new_instance [ '<STR_LIT:id>' ] ) , <EOL> '<STR_LIT>' : '<STR_LIT>' } ] , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ ] <EOL> } } <EOL> def _handle_flavor ( self , payload , body ) : <EOL> flavor_id = int ( body [ '<STR_LIT>' ] . get ( '<STR_LIT>' ) ) <EOL> for flavor in self . flavors : <EOL> if str ( flavor_id ) == flavor [ '<STR_LIT:id>' ] : <EOL> payload [ '<STR_LIT>' ] = flavor [ '<STR_LIT>' ] <EOL> payload [ '<STR_LIT>' ] = flavor [ '<STR_LIT>' ] <EOL> payload [ '<STR_LIT>' ] = ( False if flavor [ '<STR_LIT>' ] == '<STR_LIT>' <EOL> else True ) <EOL> try : <EOL> port_speed = flavor [ '<STR_LIT>' ] <EOL> payload [ '<STR_LIT>' ] = port_speed <EOL> except Exception : <EOL> pass <EOL> return <EOL> raise Exception ( '<STR_LIT>' ) <EOL> def _handle_sshkeys ( self , payload , body , client ) : <EOL> ssh_keys = [ ] <EOL> key_name = body [ '<STR_LIT>' ] . get ( '<STR_LIT>' ) <EOL> if key_name : <EOL> sshkey_mgr = SoftLayer . SshKeyManager ( client ) <EOL> keys = sshkey_mgr . list_keys ( label = key_name ) <EOL> if len ( keys ) == <NUM_LIT:0> : <EOL> raise Exception ( '<STR_LIT>' ) <EOL> ssh_keys . append ( keys [ <NUM_LIT:0> ] [ '<STR_LIT:id>' ] ) <EOL> payload [ '<STR_LIT>' ] = ssh_keys <EOL> def _handle_user_data ( self , payload , body ) : <EOL> user_data = { } <EOL> if utils . lookup ( body , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> user_data [ '<STR_LIT>' ] = utils . lookup ( body , '<STR_LIT>' , '<STR_LIT>' ) <EOL> if utils . lookup ( body , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> user_data [ '<STR_LIT>' ] = utils . lookup ( body , '<STR_LIT>' , '<STR_LIT>' ) <EOL> if utils . lookup ( body , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> user_data [ '<STR_LIT>' ] = utils . lookup ( body , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> payload [ '<STR_LIT>' ] = json . dumps ( user_data ) <EOL> def _handle_datacenter ( self , payload , body ) : <EOL> datacenter = ( utils . lookup ( body , '<STR_LIT>' , '<STR_LIT>' ) <EOL> or config . CONF [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> if not datacenter : <EOL> raise Exception ( '<STR_LIT>' ) <EOL> payload [ '<STR_LIT>' ] = datacenter <EOL> def _handle_network ( self , payload , client , networks ) : <EOL> """<STR_LIT>""" <EOL> if len ( networks ) > <NUM_LIT:2> : <EOL> raise Exception ( '<STR_LIT>' ) <EOL> if networks [ <NUM_LIT:0> ] [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> if len ( networks ) > <NUM_LIT:1> : <EOL> raise Exception ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> payload [ '<STR_LIT>' ] = False <EOL> return <EOL> elif networks [ <NUM_LIT:0> ] [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> if len ( networks ) > <NUM_LIT:1> : <EOL> raise Exception ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> payload [ '<STR_LIT>' ] = True <EOL> return <EOL> private_network_only = True <EOL> try : <EOL> _filter = { <EOL> '<STR_LIT>' : { '<STR_LIT:id>' : { '<STR_LIT>' : int ( networks [ <NUM_LIT:0> ] [ '<STR_LIT>' ] ) } } <EOL> } <EOL> except Exception : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> priv_id_valid = ( <EOL> client [ '<STR_LIT>' ] . getPrivateNetworkVlans ( filter = _filter ) ) <EOL> if priv_id_valid : <EOL> payload [ '<STR_LIT>' ] = int ( networks [ <NUM_LIT:0> ] [ '<STR_LIT>' ] ) <EOL> else : <EOL> raise Exception ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> if len ( networks ) == <NUM_LIT:2> : <EOL> try : <EOL> _filter = { <EOL> '<STR_LIT>' : { '<STR_LIT:id>' : { '<STR_LIT>' : <EOL> int ( networks [ <NUM_LIT:1> ] [ '<STR_LIT>' ] ) } } <EOL> } <EOL> except Exception : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> pub_id_valid = ( <EOL> client [ '<STR_LIT>' ] . getPublicNetworkVlans ( filter = _filter ) ) <EOL> if pub_id_valid : <EOL> payload [ '<STR_LIT>' ] = int ( networks [ <NUM_LIT:1> ] [ '<STR_LIT>' ] ) <EOL> private_network_only = False <EOL> else : <EOL> raise Exception ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> payload [ '<STR_LIT>' ] = private_network_only <EOL> def get_list_params ( req ) : <EOL> _filter = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ { '<STR_LIT:name>' : '<STR_LIT>' , '<STR_LIT:value>' : [ '<STR_LIT>' ] } ] , <EOL> } <EOL> } <EOL> } <EOL> if req . get_param ( '<STR_LIT>' ) is not None : <EOL> _filter [ '<STR_LIT>' ] [ '<STR_LIT:id>' ] = { <EOL> '<STR_LIT>' : '<STR_LIT>' % req . get_param ( '<STR_LIT>' ) <EOL> } <EOL> if req . get_param ( '<STR_LIT:image>' ) is not None : <EOL> pass <EOL> if req . get_param ( '<STR_LIT>' ) is not None : <EOL> pass <EOL> if req . get_param ( '<STR_LIT:status>' ) is not None : <EOL> pass <EOL> if req . get_param ( '<STR_LIT>' ) is not None : <EOL> pass <EOL> if req . get_param ( '<STR_LIT>' ) is not None : <EOL> _filter [ '<STR_LIT>' ] [ '<STR_LIT>' ] = { <EOL> '<STR_LIT>' : req . get_param ( '<STR_LIT>' ) <EOL> } <EOL> if req . get_param ( '<STR_LIT>' ) is not None : <EOL> pass <EOL> name = req . get_param ( '<STR_LIT:name>' ) or req . get_param ( '<STR_LIT>' ) <EOL> if name is not None : <EOL> _filter [ '<STR_LIT>' ] [ '<STR_LIT>' ] = { '<STR_LIT>' : '<STR_LIT>' % name } <EOL> limit = None <EOL> if req . get_param ( '<STR_LIT>' ) is not None : <EOL> try : <EOL> limit = int ( req . get_param ( '<STR_LIT>' ) ) <EOL> except ValueError : <EOL> pass <EOL> return { <EOL> '<STR_LIT>' : limit , <EOL> '<STR_LIT>' : _filter , <EOL> '<STR_LIT>' : get_virtual_guest_mask ( ) , <EOL> } <EOL> class ServersDetailV2 ( object ) : <EOL> def __init__ ( self , app ) : <EOL> self . app = app <EOL> def on_get ( self , req , resp , tenant_id = None ) : <EOL> client = req . env [ '<STR_LIT>' ] <EOL> cci = SoftLayer . CCIManager ( client ) <EOL> params = get_list_params ( req ) <EOL> sl_instances = cci . list_instances ( ** params ) <EOL> if not isinstance ( sl_instances , list ) : <EOL> sl_instances = [ sl_instances ] <EOL> results = [ ] <EOL> for instance in sl_instances : <EOL> results . append ( <EOL> get_server_details_dict ( self . app , req , instance , False ) ) <EOL> resp . status = <NUM_LIT:200> <EOL> resp . body = { '<STR_LIT>' : results } <EOL> class ServerV2 ( object ) : <EOL> def __init__ ( self , app ) : <EOL> self . app = app <EOL> def on_get ( self , req , resp , tenant_id , server_id ) : <EOL> client = req . env [ '<STR_LIT>' ] <EOL> cci = SoftLayer . CCIManager ( client ) <EOL> instance = cci . get_instance ( server_id , <EOL> mask = get_virtual_guest_mask ( ) ) <EOL> results = get_server_details_dict ( self . app , req , instance , True ) <EOL> resp . body = { '<STR_LIT>' : results } <EOL> def on_delete ( self , req , resp , tenant_id , server_id ) : <EOL> client = req . env [ '<STR_LIT>' ] <EOL> cci = SoftLayer . CCIManager ( client ) <EOL> try : <EOL> cci . cancel_instance ( server_id ) <EOL> except SoftLayer . SoftLayerAPIError as e : <EOL> if '<STR_LIT>' in e . faultString : <EOL> return error_handling . bad_request ( <EOL> resp , <EOL> message = '<STR_LIT>' <EOL> '<STR_LIT>' , code = <NUM_LIT> ) <EOL> raise <EOL> resp . status = <NUM_LIT> <EOL> def on_put ( self , req , resp , tenant_id , server_id ) : <EOL> client = req . env [ '<STR_LIT>' ] <EOL> cci = SoftLayer . CCIManager ( client ) <EOL> body = json . loads ( req . stream . read ( ) . decode ( ) ) <EOL> if '<STR_LIT:name>' in utils . lookup ( body , '<STR_LIT>' ) : <EOL> if utils . lookup ( body , '<STR_LIT>' , '<STR_LIT:name>' ) . strip ( ) == '<STR_LIT>' : <EOL> return error_handling . bad_request ( <EOL> resp , message = '<STR_LIT>' ) <EOL> cci . edit ( server_id , hostname = utils . lookup ( body , '<STR_LIT>' , '<STR_LIT:name>' ) ) <EOL> instance = cci . get_instance ( server_id , <EOL> mask = get_virtual_guest_mask ( ) ) <EOL> results = get_server_details_dict ( self . app , req , instance , False ) <EOL> resp . body = { '<STR_LIT>' : results } <EOL> def get_server_details_dict ( app , req , instance , is_list ) : <EOL> image_id = utils . lookup ( instance , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> tenant_id = str ( instance [ '<STR_LIT>' ] ) <EOL> client = req . env [ '<STR_LIT>' ] <EOL> vs = client [ '<STR_LIT>' ] <EOL> flavor_url = None <EOL> flavor_id = <NUM_LIT:1> <EOL> if is_list : <EOL> tags = vs . getTagReferences ( id = instance [ '<STR_LIT:id>' ] ) <EOL> for tag in tags : <EOL> if '<STR_LIT>' in tag [ '<STR_LIT>' ] [ '<STR_LIT:name>' ] : <EOL> try : <EOL> tag_string = tag [ '<STR_LIT>' ] [ '<STR_LIT:name>' ] <EOL> flavor_id = int ( re . search ( r'<STR_LIT>' , tag_string ) . group ( ) ) <EOL> flavor_url = app . get_endpoint_url ( <EOL> '<STR_LIT>' , req , '<STR_LIT>' , flavor_id = flavor_id ) <EOL> except Exception : <EOL> pass <EOL> if not flavor_url : <EOL> flavor_url = app . get_endpoint_url ( <EOL> '<STR_LIT>' , req , '<STR_LIT>' , flavor_id = <NUM_LIT:1> ) <EOL> server_url = app . get_endpoint_url ( <EOL> '<STR_LIT>' , req , '<STR_LIT>' , server_id = instance [ '<STR_LIT:id>' ] ) <EOL> task_state = None <EOL> transaction = utils . lookup ( instance , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT:name>' ) <EOL> if transaction and any ( [ '<STR_LIT>' in transaction , <EOL> '<STR_LIT>' in transaction ] ) : <EOL> task_state = '<STR_LIT>' <EOL> else : <EOL> task_state = transaction <EOL> power_state = <NUM_LIT:0> <EOL> status = '<STR_LIT>' <EOL> sl_power_state = instance [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> if sl_power_state == '<STR_LIT>' : <EOL> if transaction or not instance . get ( '<STR_LIT>' ) : <EOL> status = '<STR_LIT>' <EOL> power_state = OPENSTACK_POWER_MAP [ '<STR_LIT>' ] <EOL> else : <EOL> status = '<STR_LIT>' <EOL> power_state = OPENSTACK_POWER_MAP [ '<STR_LIT>' ] <EOL> elif sl_power_state == '<STR_LIT>' : <EOL> status = '<STR_LIT>' <EOL> power_state = OPENSTACK_POWER_MAP [ '<STR_LIT>' ] <EOL> elif sl_power_state in OPENSTACK_POWER_MAP : <EOL> power_state = OPENSTACK_POWER_MAP [ sl_power_state ] <EOL> elif sl_power_state == '<STR_LIT>' and instance . get ( '<STR_LIT>' ) : <EOL> status = '<STR_LIT>' <EOL> power_state = OPENSTACK_POWER_MAP [ '<STR_LIT>' ] <EOL> elif sl_power_state == '<STR_LIT>' : <EOL> status = '<STR_LIT>' <EOL> power_state = OPENSTACK_POWER_MAP [ '<STR_LIT>' ] <EOL> addresses = { } <EOL> if instance . get ( '<STR_LIT>' ) : <EOL> addresses [ '<STR_LIT>' ] = [ { <EOL> '<STR_LIT>' : instance . get ( '<STR_LIT>' ) , <EOL> '<STR_LIT:version>' : <NUM_LIT:4> , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } ] <EOL> if instance . get ( '<STR_LIT>' ) : <EOL> addresses [ '<STR_LIT>' ] = [ { <EOL> '<STR_LIT>' : instance . get ( '<STR_LIT>' ) , <EOL> '<STR_LIT:version>' : <NUM_LIT:4> , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } ] <EOL> image_name = '<STR_LIT>' <EOL> uid = str ( utils . lookup ( instance , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) ) <EOL> if not uid : <EOL> uid = '<STR_LIT>' <EOL> zone = str ( utils . lookup ( instance , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT:id>' ) ) <EOL> if not zone : <EOL> zone = '<STR_LIT>' <EOL> results = { <EOL> '<STR_LIT:id>' : str ( instance [ '<STR_LIT:id>' ] ) , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : addresses , <EOL> '<STR_LIT>' : instance [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:id>' : str ( flavor_id ) , <EOL> '<STR_LIT>' : [ <EOL> { <EOL> '<STR_LIT>' : flavor_url , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } , <EOL> ] , <EOL> } , <EOL> '<STR_LIT>' : str ( instance [ '<STR_LIT:id>' ] ) , <EOL> '<STR_LIT>' : [ <EOL> { <EOL> '<STR_LIT>' : server_url , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> ] , <EOL> '<STR_LIT:name>' : instance [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : zone , <EOL> '<STR_LIT>' : power_state , <EOL> '<STR_LIT>' : task_state , <EOL> '<STR_LIT>' : instance [ '<STR_LIT:status>' ] [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : [ { '<STR_LIT:name>' : '<STR_LIT:default>' } ] , <EOL> '<STR_LIT:status>' : status , <EOL> '<STR_LIT>' : tenant_id , <EOL> '<STR_LIT>' : uid , <EOL> '<STR_LIT>' : instance [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : image_name , <EOL> '<STR_LIT>' : { } <EOL> } <EOL> if instance [ '<STR_LIT>' ] : <EOL> results [ '<STR_LIT>' ] = instance [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT:label>' ] <EOL> if image_id : <EOL> results [ '<STR_LIT:image>' ] = { <EOL> '<STR_LIT:id>' : image_id , <EOL> '<STR_LIT>' : [ <EOL> { <EOL> '<STR_LIT>' : app . get_endpoint_url ( <EOL> '<STR_LIT>' , req , '<STR_LIT>' , image_id = image_id ) , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } , <EOL> ] , <EOL> } <EOL> return results <EOL> def get_virtual_guest_mask ( ) : <EOL> mask = [ <EOL> '<STR_LIT:id>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT:status>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ] <EOL> return '<STR_LIT>' % '<STR_LIT:U+002C>' . join ( mask ) </s>
