<s> from suds . client import Client <EOL> from nova import exception <EOL> from nova import db <EOL> import logging <EOL> logging . getLogger ( '<STR_LIT>' ) . setLevel ( logging . INFO ) <EOL> def update_for_run_instance ( service_url , region_name , server_port1 , server_port2 , dpid1 , dpid2 ) : <EOL> client = Client ( service_url + "<STR_LIT>" ) <EOL> client . service . setServerPort ( dpid1 , server_port1 , region_name ) <EOL> client . service . setServerPort ( dpid2 , server_port2 , region_name ) <EOL> client . service . save ( ) <EOL> def update_for_terminate_instance ( service_url , region_name , server_port1 , server_port2 , dpid1 , dpid2 , vlan_id ) : <EOL> client = Client ( service_url + "<STR_LIT>" ) <EOL> client . service . clearServerPort ( dpid1 , server_port1 ) <EOL> client . service . clearServerPort ( dpid2 , server_port2 ) <EOL> client . service . save ( ) <EOL> dpid_datas = client . service . showSwitchDatapathId ( ) <EOL> for dpid_data in dpid_datas : <EOL> ports = client . service . showPorts ( dpid_data . dpid ) <EOL> for port in ports : <EOL> if port . type != "<STR_LIT>" : <EOL> continue <EOL> if port . regionName == region_name : <EOL> return <EOL> remove_region ( service_url , region_name , vlan_id ) <EOL> def create_region ( service_url , region_name , vlan_id ) : <EOL> client = Client ( service_url + "<STR_LIT>" ) <EOL> try : <EOL> client . service . createRegion ( region_name ) <EOL> client . service . save ( ) <EOL> except : <EOL> raise exception . OFCRegionCreationFailed ( region_name = region_name ) <EOL> try : <EOL> switches = db . switch_get_all ( None ) <EOL> for switch in switches : <EOL> client . service . setOuterPortAssociationSetting ( switch [ "<STR_LIT>" ] , switch [ "<STR_LIT>" ] , vlan_id , <NUM_LIT> , region_name ) <EOL> client . service . save ( ) <EOL> except : <EOL> client . service . destroyRegion ( region_name ) <EOL> client . service . save ( ) <EOL> raise exception . OFCRegionSettingOuterPortAssocFailed ( region_name = region_name , vlan_id = vlan_id ) <EOL> def remove_region ( service_url , region_name , vlan_id ) : <EOL> client = Client ( service_url + "<STR_LIT>" ) <EOL> try : <EOL> switches = db . switch_get_all ( None ) <EOL> for switch in switches : <EOL> client . service . clearOuterPortAssociationSetting ( switch [ "<STR_LIT>" ] , switch [ "<STR_LIT>" ] , vlan_id ) <EOL> client . service . save ( ) <EOL> except : <EOL> pass <EOL> client . service . destroyRegion ( region_name ) <EOL> client . service . save ( ) <EOL> def has_region ( service_url , region_name ) : <EOL> client = Client ( service_url + "<STR_LIT>" ) <EOL> return region_name in [ x . regionName for x in client . service . showRegion ( ) ] </s>
