<commit_before>from heat.common import exception
from heat.engine import clients
from heat.engine.resources.neutron import neutron
from heat.engine import properties

if clients.neutronclient is not None:
    from neutronclient.common.exceptions import NeutronClientException

from heat.openstack.common import log as logging

logger = logging.getLogger(__name__)


class AttachPolicy(neutron.NeutronResource):

    PROPERTIES = (
        NETWORK_ID, POLICY,
    ) = (
        'network_id', 'policy',
    )

    properties_schema = {
        NETWORK_ID: properties.Schema(
            properties.Schema.STRING,
            description=_('The network id'),
            required=True),
        POLICY: properties.Schema(
            properties.Schema.STRING,
            description=_('policy name FQ name notation'),
            required=True),
    }

    def handle_create(self):
        network_id = self.properties.get(self.NETWORK_ID)
        policies = self.neutron().show_network(network_id).get('network').get('contrail:policys')
        if not policies:
            policies = []
        policies.append(self.properties.get(self.POLICY).split(':'))
        self.neutron().update_network(network_id, {'network':
                                     {'contrail:policys': policies}})
        self.resource_id_set(
            '%s|%s' % (network_id, self.properties.get(self.POLICY)))

    def handle_delete(self):
        if not self.resource_id:
            return
        (network_id, policy) = self.resource_id.split('|')
        try:
            policies = self.neutron().show_network(
                network_id).get('network').get('contrail:policys', [])
            try:
                policies.remove(policy.split(':'))
            except ValueError:
                return
            self.neutron().update_network(network_id, {'network':
                                         {'contrail:policys': policies}})
        except NeutronClientException as ex:
            if ex.status_code != 404:
                raise ex


def resource_mapping():
    if clients.neutronclient is None:
        return {}

    return {<commit_msg>double commit I17e23731ec165c724b9c3ff612b12f5005fe234f to support heat in ubuntu/juno, these changes are specific to contrail-heat<commit_after>from heat.common import exception
from heat.engine.resources.neutron import neutron
from heat.engine import properties

from neutronclient.common.exceptions import NeutronClientException
from heat.openstack.common import log as logging

logger = logging.getLogger(__name__)


class AttachPolicy(neutron.NeutronResource):

    PROPERTIES = (
        NETWORK_ID, POLICY,
    ) = (
        'network_id', 'policy',
    )

    properties_schema = {
        NETWORK_ID: properties.Schema(
            properties.Schema.STRING,
            description=_('The network id'),
            required=True),
        POLICY: properties.Schema(
            properties.Schema.STRING,
            description=_('policy name FQ name notation'),
            required=True),
    }

    def handle_create(self):
        network_id = self.properties.get(self.NETWORK_ID)
        policies = self.neutron().show_network(network_id).get('network').get('contrail:policys')
        if not policies:
            policies = []
        policies.append(self.properties.get(self.POLICY).split(':'))
        self.neutron().update_network(network_id, {'network':
                                     {'contrail:policys': policies}})
        self.resource_id_set(
            '%s|%s' % (network_id, self.properties.get(self.POLICY)))

    def handle_delete(self):
        if not self.resource_id:
            return
        (network_id, policy) = self.resource_id.split('|')
        try:
            policies = self.neutron().show_network(
                network_id).get('network').get('contrail:policys', [])
            try:
                policies.remove(policy.split(':'))
            except ValueError:
                return
            self.neutron().update_network(network_id, {'network':
                                         {'contrail:policys': policies}})
        except NeutronClientException as ex:
            if ex.status_code != 404:
                raise ex


def resource_mapping():
    return {
{'fraction_non_alphanumeric': 0.10679156908665105, 'fraction_numerical': 0.007728337236533958, 'mean_word_length': 2.250380517503805, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5988030', 'n_tokens_mistral': 1195, 'n_tokens_neox': 1164, 'n_words': 229}