<s> from cloudify import ctx <EOL> from cloudify . decorators import operation <EOL> from cloudify . exceptions import NonRecoverableError <EOL> from openstack_plugin_common import ( <EOL> transform_resource_name , <EOL> with_neutron_client , <EOL> get_resource_id , <EOL> is_external_resource , <EOL> delete_resource_and_runtime_properties , <EOL> use_external_resource , <EOL> validate_resource , <EOL> OPENSTACK_ID_PROPERTY , <EOL> OPENSTACK_TYPE_PROPERTY , <EOL> OPENSTACK_NAME_PROPERTY , <EOL> COMMON_RUNTIME_PROPERTIES_KEYS <EOL> ) <EOL> NETWORK_OPENSTACK_TYPE = '<STR_LIT>' <EOL> RUNTIME_PROPERTIES_KEYS = COMMON_RUNTIME_PROPERTIES_KEYS <EOL> @ operation <EOL> @ with_neutron_client <EOL> def create ( neutron_client , args , ** kwargs ) : <EOL> if use_external_resource ( ctx , neutron_client , NETWORK_OPENSTACK_TYPE ) : <EOL> return <EOL> network = { <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT:name>' : get_resource_id ( ctx , NETWORK_OPENSTACK_TYPE ) , <EOL> } <EOL> network . update ( ctx . node . properties [ '<STR_LIT>' ] , ** args ) <EOL> transform_resource_name ( ctx , network ) <EOL> net = neutron_client . create_network ( { '<STR_LIT>' : network } ) [ '<STR_LIT>' ] <EOL> ctx . instance . runtime_properties [ OPENSTACK_ID_PROPERTY ] = net [ '<STR_LIT:id>' ] <EOL> ctx . instance . runtime_properties [ OPENSTACK_TYPE_PROPERTY ] = NETWORK_OPENSTACK_TYPE <EOL> ctx . instance . runtime_properties [ OPENSTACK_NAME_PROPERTY ] = net [ '<STR_LIT:name>' ] <EOL> @ operation <EOL> @ with_neutron_client <EOL> def start ( neutron_client , ** kwargs ) : <EOL> network_id = ctx . instance . runtime_properties [ OPENSTACK_ID_PROPERTY ] <EOL> if is_external_resource ( ctx ) : <EOL> ctx . logger . info ( '<STR_LIT>' ) <EOL> if not neutron_client . show_network ( <EOL> network_id ) [ '<STR_LIT>' ] [ '<STR_LIT>' ] : <EOL> raise NonRecoverableError ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' . format ( network_id ) ) <EOL> return <EOL> neutron_client . update_network ( <EOL> network_id , { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : True <EOL> } <EOL> } ) <EOL> @ operation <EOL> @ with_neutron_client <EOL> def stop ( neutron_client , ** kwargs ) : <EOL> if is_external_resource ( ctx ) : <EOL> ctx . logger . info ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> return <EOL> neutron_client . update_network ( <EOL> ctx . instance . runtime_properties [ OPENSTACK_ID_PROPERTY ] , { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : False <EOL> } <EOL> } ) <EOL> @ operation <EOL> @ with_neutron_client <EOL> def delete ( neutron_client , ** kwargs ) : <EOL> delete_resource_and_runtime_properties ( ctx , neutron_client , <EOL> RUNTIME_PROPERTIES_KEYS ) <EOL> @ operation <EOL> @ with_neutron_client <EOL> def creation_validation ( neutron_client , ** kwargs ) : <EOL> validate_resource ( ctx , neutron_client , NETWORK_OPENSTACK_TYPE ) </s>
