示例#1
0
    def __init__(self):

        https.client.conpaas_init_ssl_ctx('/etc/cpsdirector/certs', 'director')

        init('/var/log/cpsdirector/debugging.log')
        self._logger = create_logger(__name__)
        self._logger.setLevel(logging.DEBUG)

        self._force_terminate_lock = Lock()

        self._created_nodes = []
        self._partially_created_nodes = []

        self._available_clouds = []
        self._default_cloud = None
        self.role = ""
示例#2
0
    def __init__(self):
        Thread.__init__(self)
        self.event = Event()
        self.unit = 1
        self.charging_unit = 60
        # self.credit_step = 1
        self.credit_step = 5
        self.sanity_step = 15

        self.count = 0
        self.daemon = True

        self.controller = Controller()
        self.controller.setup_default()

        init('/var/log/cpsdirector/debugging.log')
        self._logger = create_logger(__name__)
        self._logger.setLevel(logging.DEBUG)
示例#3
0
    def __init__(self, server_address, config_parser, role, **kwargs):
        log.init(config_parser.get(role, 'LOG_FILE'))
        self.config_parser = config_parser
        self.callback_dict = {'GET': {}, 'POST': {}, 'UPLOAD': {}}

        if role == 'manager':
            services = manager_services
        else:
            services = agent_services

        # Instantiate the requested service class
        service_type = config_parser.get(role, 'TYPE')
        try:
            module = __import__(services[service_type]['module'], globals(),
                                locals(), ['*'])
        except ImportError:
            raise Exception(
                'Could not import module containing service class "%(module)s"'
                % services[service_type])

        # Get the appropriate class for this service
        service_class = services[service_type]['class']
        try:
            instance_class = getattr(module, service_class)
        except AttributeError:
            raise Exception('Could not get service class %s from module %s' %
                            (service_class, module))

        # Create an instance of the service class
        self.instance = instance_class(config_parser, **kwargs)

        # Register the callable functions
        self.callback_dict = {'GET': {}, 'POST': {}, 'UPLOAD': {}}
        for http_method in exposed_functions:
            for func_name in exposed_functions[http_method]:
                self._register_method(
                    http_method, func_name,
                    exposed_functions[http_method][func_name])

        # Start the HTTPS server
        ctx = self._conpaas_init_ssl_ctx(role,
                                         config_parser.get(role, 'CERT_DIR'),
                                         SSL.SSLv23_METHOD)
        HTTPSServer.__init__(self, server_address, ConpaasRequestHandler, ctx)
示例#4
0
    def __init__(self, server_address, config_parser, role, **kwargs):
        log.init(config_parser.get(role, 'LOG_FILE'))
        self.instances = {}
        self.config_parser = config_parser
        self.callback_dict = {'GET': {}, 'POST': {}, 'UPLOAD': {}}

        if role == 'manager':
            from conpaas.core.manager import ApplicationManager
            service_instance = ApplicationManager(self, config_parser, **kwargs)
            # services = manager_services
        else:
            services = agent_services

            # Instantiate the requested service class
            service_type = config_parser.get(role, 'TYPE')
            try:
                module = __import__(services[service_type]['module'], globals(), locals(), ['*'])
            except ImportError:
                raise Exception('Could not import module containing service class "%(module)s"' %
                    services[service_type])

            # Get the appropriate class for this service
            service_class = services[service_type]['class']
            try:
                instance_class = getattr(module, service_class)
            except AttributeError:
                raise Exception('Could not get service class %s from module %s' % (service_class, module))

            # Create an instance of the service class
            service_instance = instance_class(config_parser, **kwargs)

        self.instances[0] = service_instance

        handler_exposed_functions = service_instance.get_exposed_methods()


        for http_method in handler_exposed_functions:
            for func_name in handler_exposed_functions[http_method]:
                self._register_method(http_method, 0, func_name, handler_exposed_functions[http_method][func_name])

        # Start the HTTPS server
        ctx = self._conpaas_init_ssl_ctx(role, config_parser.get(role, 'CERT_DIR'), SSL.SSLv23_METHOD)
        HTTPSServer.__init__(self, server_address, ConpaasRequestHandler, ctx)
示例#5
0
    def __init__(self, config_parser, **kwargs):
        # TODO: retrieve this file name from the director.cfg configuration file & create the log file if it is not yet present
        init('/var/log/cpsdirector/debugging.log')
        self.__logger = create_logger(__name__)
        self.__logger.setLevel(logging.DEBUG)
        # Params for director callback
        self.__conpaas_name = config_parser.get('manager',
                                                'DEPLOYMENT_NAME')
        self.__conpaas_creditUrl = config_parser.get('manager',
                                                'CREDIT_URL')
        self.__conpaas_terminateUrl = config_parser.get('manager',
                                                   'TERMINATE_URL')
        self.__conpaas_service_id = config_parser.get('manager',
                                                 'SERVICE_ID')
        self.__conpaas_user_id = config_parser.get('manager',
                                              'USER_ID')
        self.__conpaas_app_id = config_parser.get('manager',
                                              'APP_ID')
        self.__conpaas_caUrl = config_parser.get('manager',
                                            'CA_URL')

        # Set the CA URL as IPOP's base namespace
        self.__ipop_base_namespace = self.__conpaas_caUrl

        if config_parser.has_option('manager', 'IPOP_BASE_IP'):
            # Application-level network
            self.__ipop_base_ip = config_parser.get('manager', 'IPOP_BASE_IP')
        else:
            self.__ipop_base_ip = None

        if config_parser.has_option('manager', 'IPOP_NETMASK'):
            # Application-level netmask
            self.__ipop_netmask = config_parser.get('manager', 'IPOP_NETMASK')
        else:
            self.__ipop_netmask = None

        if config_parser.has_option('manager', 'IPOP_BOOTSTRAP_NODES'):
            # Application-level network's bootstrap nodes
            self.__ipop_bootstrap_nodes = config_parser.get('manager', 'IPOP_BOOTSTRAP_NODES')
        else:
            self.__ipop_bootstrap_nodes = None

        if config_parser.has_option('manager', 'IPOP_SUBNET'):
            # Only import from netaddr if IPOP has to be started
            from netaddr import IPNetwork

            # Subnet assigned to this service by the director
            self.__ipop_subnet = IPNetwork(
                config_parser.get('manager', 'IPOP_SUBNET'))
        else:
            self.__ipop_subnet = None

        # For crediting system
        self.__reservation_logger = create_logger('ReservationTimer')
        self.__reservation_map = {'manager': ReservationTimer(['manager'],
                                  55 * 60,  # 55mins
                                  self.__deduct_and_check_credit,
                                  self.__reservation_logger)}
        self.__reservation_map['manager'].start()
        self.__force_terminate_lock = Lock()

        self.config_parser = config_parser
        self.__created_nodes = []
        self.__partially_created_nodes = []

        self.__available_clouds = []
        self.__default_cloud = None
        if config_parser.has_option('iaas', 'DRIVER'):
            self.__default_cloud = iaas.get_cloud_instance(
                'iaas',
                config_parser.get('iaas', 'DRIVER').lower(),
                config_parser)
            self.__available_clouds.append(self.__default_cloud)

        if config_parser.has_option('iaas', 'OTHER_CLOUDS'):
            self.__logger.debug("attempt iaas.get_clouds()")
            try:
                self.__available_clouds.extend(iaas.get_clouds(config_parser))
            except Exception as e:
                self.__logger.debug("failed iaas.get_clouds()")
                self.__reservation_map['manager'].stop()
                raise e
            self.__logger.debug("succeeded iaas.get_clouds()")

        # Setting VM role
        self.role = 'agent'