Exemplo n.º 1
0
    'none': ('', ''),
    '512': ('512', '512'),
    '1024': ('1024', '1024'),
    '2048': ('2048', '2048'),
    '4096': ('4096', '4096')
}

DEFAULT_CERT_VALIDITY = 1
DEFAULT_KEY_LENGTH = '2048'
DEFAULT_DIGEST_ALGORITHM = 'sha256'
CERT_KEYUSAGE_CRITICAL = False
CERT_KEYUSAGE_VALUE = 'digitalSignature, keyEncipherment'
CRL_PROTECTED = False

generalized_time = '%Y%m%d%H%M%SZ'
logger = get_logger(__name__)


def bytes_compat(string, encoding='utf-8'):
    if sys.version_info.major >= 3:
        if not isinstance(string, string_types):
            string = str(string)
        return bytes(string, encoding)
    else:
        return bytes(string)


def log_certificate_create(username, days=DEFAULT_CERT_VALIDITY):
    cert_file = get_config('system', 'certificate-log-file',
                           '/etc/softfire/certificate-create.log')
    try:
Exemplo n.º 2
0
from bottle import FileUpload
from grpc._channel import _Rendezvous
from toscaparser.tosca_template import ToscaTemplate

from eu.softfire.tub.core.calendar import CalendarManager
from eu.softfire.tub.entities import entities
from eu.softfire.tub.entities.entities import UsedResource, ManagerEndpoint, ResourceMetadata, Experimenter, \
    ResourceStatus
from eu.softfire.tub.entities.repositories import save, find, delete, get_user_info, find_by_element_value
from eu.softfire.tub.exceptions.exceptions import ExperimentValidationError, ManagerNotFound, RpcFailedCall, \
    ResourceNotFound, ExperimentNotFound
from eu.softfire.tub.messaging.grpc import messages_pb2_grpc, messages_pb2
from eu.softfire.tub.utils.utils import get_logger, ExceptionHandlerThread, TimerTerminationThread, get_config, \
    get_mapping_managers

logger = get_logger('eu.softfire.tub.core')

REFRESH_RES_NODE_TYPES = ["NfvImage"]

keys_to_pass = [
    "floatingIp",
    "floatingIpIp",
]

TESTBED_MAPPING = {
    'fokus': messages_pb2.FOKUS,
    'fokus-dev': messages_pb2.FOKUS_DEV,
    'ericsson': messages_pb2.ERICSSON,
    'ericsson-dev': messages_pb2.ERICSSON_DEV,
    'surrey': messages_pb2.SURREY,
    'surrey-dev': messages_pb2.SURREY_DEV,
Exemplo n.º 3
0
import os
import unittest
import urllib.request

from eu.softfire.tub.core.CoreManagers import Experiment
from eu.softfire.tub.utils.utils import get_logger

logger = get_logger("eu.softfire.tests")


class MyTestCase(unittest.TestCase):
    def test_csar(self):
        tempfile = "/tmp/example.csar"
        urllib.request.urlretrieve("http://docs.softfire.eu/etc/example.csar", tempfile)
        tpl = Experiment(tempfile).get_topology()
        os.remove(tempfile)
        self.assertIsNotNone(tpl)
        self.assertFalse(os.path.exists(tempfile))


if __name__ == '__main__':
    unittest.main()
Exemplo n.º 4
0
import bottle
import requests
from beaker.middleware import SessionMiddleware
from bottle import request, post, get, HTTPError, HTTPResponse, hook
from cork import Cork

import eu.softfire.tub.exceptions.exceptions as exceptions
from eu.softfire.tub.core import CoreManagers
from eu.softfire.tub.core.CoreManagers import get_resources_dict, Experiment, \
    get_experiment_dict, add_resource, get_other_resources
from eu.softfire.tub.core.calendar import CalendarManager
from eu.softfire.tub.core.certificate import CertificateGenerator, log_certificate_create
from eu.softfire.tub.utils.static_config import CONFIGURATION_FOLDER
from eu.softfire.tub.utils.utils import get_config, get_logger

logger = get_logger('eu.softfire.tub.api')
bottle.TEMPLATE_PATH = [get_config('api', 'view-path', '/etc/softfire/views')]
aaa = Cork(get_config("api", "cork-files-path", "/etc/softfire/users"))
authorize = aaa.make_auth_decorator(fail_redirect="/login")
create_user_thread = None
create_user_thread_pool = Pool(20)


@hook('after_request')
def maintenance():
    try:
        if request.environ.get(
                'bottle.raw_path'
        ) == '/login' or aaa.current_user.role == 'admin':
            return
    except:
import time
from concurrent import futures

import grpc

from eu.softfire.tub.core import CoreManagers
from eu.softfire.tub.core.CoreManagers import list_resources
from eu.softfire.tub.entities.entities import ManagerEndpoint, ResourceMetadata
from eu.softfire.tub.entities.repositories import save, find, delete, find_by_element_value
from eu.softfire.tub.messaging.grpc import messages_pb2
from eu.softfire.tub.messaging.grpc import messages_pb2_grpc
from eu.softfire.tub.utils.utils import get_logger, get_config, get_mapping_managers

logger = get_logger('eu.softfire.tub.messaging')
_ONE_DAY_IN_SECONDS = 60 * 60 * 24


def receive_forever():
    server = grpc.server(
        futures.ThreadPoolExecutor(
            max_workers=int(get_config('system', 'server_threads', 5))))
    messages_pb2_grpc.add_RegistrationServiceServicer_to_server(
        RegistrationAgent(), server)
    binding = '[::]:%s' % get_config('messaging', 'bind_port', 50051)
    logger.info("Binding rpc registration server to: %s" % binding)
    server.add_insecure_port(binding)
    server.start()
    try:
        while True:
            time.sleep(_ONE_DAY_IN_SECONDS)
    except KeyboardInterrupt:
import logging
import threading
from contextlib import contextmanager

from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker, scoped_session
from sqlalchemy.orm.exc import NoResultFound
from sqlalchemy.pool import StaticPool

from eu.softfire.tub.entities import entities
from eu.softfire.tub.entities.entities import Base
from eu.softfire.tub.messaging.grpc import messages_pb2
from eu.softfire.tub.utils.utils import get_config, get_logger

logger = get_logger('eu.softfire.tub.repository')

lock = threading.RLock()

db_url = get_config('database', 'url', "sqlite:////tmp/experiment-manager.db")
is_sqlite = db_url.startswith("sqlite:")
if is_sqlite:
    engine = create_engine(db_url,
                           poolclass=StaticPool,
                           connect_args={'check_same_thread': False})
else:
    engine = create_engine(db_url)
debug_echo = (logger.getEffectiveLevel() == logging.DEBUG) and get_config(
    'database', 'show_sql', False).lower() == 'true'
engine.echo = debug_echo
Base.metadata.create_all(engine)
if is_sqlite: