<commit_before># vim: ts=4 sw=4 et

# Standard
import json
import os

# Celery
from celery import task

# OpenStack
import keystoneclient.v2_0.client as ksclient
from neutronclient.neutron import client

# Cosmo
from cosmo.events import send_event

@task
def provision(__cloudify_id, router, **kwargs):
    neutron_client = _init_client()
    if _get_router_by_name(neutron_client, router['name']):
        raise RuntimeError("Can not provision router with name '{0}' because router with such name already exists"
                           .format(router['name']))

    rtr = neutron_client.create_router({
        'router': {
            'name': router['name'],
        }
    })['router']

    send_event(__cloudify_id, "rtr-" + router['name'], "router status", "state", "running")


@task
def add_gateway(router, network):
    neutron_client = _init_client()
    rtr = _get_router_by_name(neutron_client, router['name'])
    net = _get_network_by_name(neutron_client, network['name'])
    neutron_client.add_gateway_router(rtr['id'], {'network_id': net['id']})
    

@task<commit_msg>add_gateway() - add **kwargs<commit_after># vim: ts=4 sw=4 et

# Standard
import json
import os

# Celery
from celery import task

# OpenStack
import keystoneclient.v2_0.client as ksclient
from neutronclient.neutron import client

# Cosmo
from cosmo.events import send_event

@task
def provision(__cloudify_id, router, **kwargs):
    neutron_client = _init_client()
    if _get_router_by_name(neutron_client, router['name']):
        raise RuntimeError("Can not provision router with name '{0}' because router with such name already exists"
                           .format(router['name']))

    rtr = neutron_client.create_router({
        'router': {
            'name': router['name'],
        }
    })['router']

    send_event(__cloudify_id, "rtr-" + router['name'], "router status", "state", "running")


@task
def add_gateway(router, network, **kwargs):
    neutron_client = _init_client()
    rtr = _get_router_by_name(neutron_client, router['name'])
    net = _get_network_by_name(neutron_client, network['name'])
    neutron_client.add_gateway_router(rtr['id'], {'network_id': net['id']})
    

@task
{'fraction_non_alphanumeric': 0.12551159618008187, 'fraction_numerical': 0.004547521600727604, 'mean_word_length': 4.0, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1360694', 'n_tokens_mistral': 714, 'n_tokens_neox': 697, 'n_words': 170}