<commit_before>import os.path
import simplejson

from netaddr import IPNetwork

from conpaas.core.controller import Controller
from conpaas.core.misc import file_get_contents
from conpaas.core.node import ServiceNode
from conpaas.core.log import create_logger

from cpsdirector.x509cert import generate_certificate
from cpsdirector.common import config_parser, log
from cpsdirector.user import User
from cpsdirector import db

from flask import Blueprint
cloud_page = Blueprint('cloud_page', __name__)

class ManagerController(Controller):

    def __init__(self, service_name, service_id, user_id, cloud_name, app_id, vpn):
        self.config_parser = self.__get_config(str(service_id), str(user_id),
                                               str(app_id), service_name, vpn)

        Controller.__init__(self, self.config_parser)
        self.logger = create_logger(__name__)
        self.service_name = service_name
        self.service_id = service_id
        self.user_id = user_id
        self.cloud_name = cloud_name
        self.role = "manager"

    def _get_certificate(self, email, cn, org):
        user_id = self.config_parser.get("manager", "USER_ID")
        service_id = self.config_parser.get("manager", "SERVICE_ID")
        cert_dir = self.config_parser.get('conpaas', 'CERT_DIR')

        return generate_certificate(cert_dir, user_id, service_id,
                                    "manager", email, cn, org)

    def _get_context_file(self, service_name, cloud):
        """Override default _get_context_file. Here we generate the context
        file for managers rather than for agents."""
        conpaas_home = self.config_parser.get('conpaas', 'CONF_DIR')

        cloud_scripts_dir = os.path.join(conpaas_home, 'scripts', 'cloud')
        mngr_scripts_dir = os.path.join(conpaas_home, 'scripts', 'manager')
        mngr_cfg_dir = os.path.join(conpaas_home, 'config', 'manager')

        director = self.config_parser.get('director', 'DIRECTOR_URL')

        # Values to be passed to the context file template
        tmpl_values = {}

        # Get contextualization script for the cloud
        try:
            tmpl_values['cloud_script'] = file_get_contents(
                os.path.join(cloud_scripts_dir, cloud))
        except IOError:
            self.logger.info("No cloud configuration script found for '%s'" % cloud)
            tmpl_values['cloud_script'] = ''

        # Get manager setup file
        mngr_setup = file_get_contents(
            os.path.join(mngr_scripts_dir, 'manager-setup'))

        tmpl_values['mngr_setup'] = mngr_setup.replace('%DIRECTOR_URL%',
                                                       director)

        # Get cloud config values from director.cfg
        cloud_sections = ['iaas']
        if self.config_parser.has_option('iaas', 'OTHER_CLOUDS'):
            cloud_sections.extend(
                [cloud_name for cloud_name
                 in self.config_parser.get('iaas', 'OTHER_CLOUDS').split(',')
                 if self.config_parser.has_section(cloud_name)])

        def __extract_cloud_cfg(section_name):
            tmpl_values['cloud_cfg'] += "["+section_name+"]\n"<commit_msg>conpaas-director: remove useless logging statement in ManagerController<commit_after>import os.path
import simplejson

from netaddr import IPNetwork

from conpaas.core.controller import Controller
from conpaas.core.misc import file_get_contents
from conpaas.core.node import ServiceNode

from cpsdirector.x509cert import generate_certificate
from cpsdirector.common import config_parser, log
from cpsdirector.user import User
from cpsdirector import db

from flask import Blueprint
cloud_page = Blueprint('cloud_page', __name__)

class ManagerController(Controller):

    def __init__(self, service_name, service_id, user_id, cloud_name, app_id, vpn):
        self.config_parser = self.__get_config(str(service_id), str(user_id),
                                               str(app_id), service_name, vpn)

        Controller.__init__(self, self.config_parser)
        self.service_name = service_name
        self.service_id = service_id
        self.user_id = user_id
        self.cloud_name = cloud_name
        self.role = "manager"

    def _get_certificate(self, email, cn, org):
        user_id = self.config_parser.get("manager", "USER_ID")
        service_id = self.config_parser.get("manager", "SERVICE_ID")
        cert_dir = self.config_parser.get('conpaas', 'CERT_DIR')

        return generate_certificate(cert_dir, user_id, service_id,
                                    "manager", email, cn, org)

    def _get_context_file(self, service_name, cloud):
        """Override default _get_context_file. Here we generate the context
        file for managers rather than for agents."""
        conpaas_home = self.config_parser.get('conpaas', 'CONF_DIR')

        cloud_scripts_dir = os.path.join(conpaas_home, 'scripts', 'cloud')
        mngr_scripts_dir = os.path.join(conpaas_home, 'scripts', 'manager')
        mngr_cfg_dir = os.path.join(conpaas_home, 'config', 'manager')

        director = self.config_parser.get('director', 'DIRECTOR_URL')

        # Values to be passed to the context file template
        tmpl_values = {}

        # Get contextualization script for the cloud
        try:
            tmpl_values['cloud_script'] = file_get_contents(
                os.path.join(cloud_scripts_dir, cloud))
        except IOError:
            tmpl_values['cloud_script'] = ''

        # Get manager setup file
        mngr_setup = file_get_contents(
            os.path.join(mngr_scripts_dir, 'manager-setup'))

        tmpl_values['mngr_setup'] = mngr_setup.replace('%DIRECTOR_URL%',
                                                       director)

        # Get cloud config values from director.cfg
        cloud_sections = ['iaas']
        if self.config_parser.has_option('iaas', 'OTHER_CLOUDS'):
            cloud_sections.extend(
                [cloud_name for cloud_name
                 in self.config_parser.get('iaas', 'OTHER_CLOUDS').split(',')
                 if self.config_parser.has_section(cloud_name)])

        def __extract_cloud_cfg(section_name):
            tmpl_values['cloud_cfg'] += "["+section_name+"]\n"
{'fraction_non_alphanumeric': 0.0946119307248236, 'fraction_numerical': 0.0009621552277100705, 'mean_word_length': 2.764031382015691, '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': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '113571', 'n_tokens_mistral': 1851, 'n_tokens_neox': 1781, 'n_words': 399}