コード例 #1
0
ファイル: project.py プロジェクト: CCI-MOC/ABMI
from sqlalchemy import Column, Integer, String
from sqlalchemy.exc import SQLAlchemyError
from sqlalchemy.orm import relationship

import ims.exception.db_exceptions as db_exceptions
from ims.common.log import create_logger, log, trace
from ims.database.db_connection import DatabaseConnection

logger = create_logger(__name__)


# This class is responsible for doing CRUD operations on the Project Table in
# DB. This class was written as per the Repository Model which allows us to
# change the DB in the future without changing business code
class ProjectRepository:
    @trace
    def __init__(self, connection):
        self.connection = connection

    # inserts the arguments into the table
    # commits after insertion otherwise rollback occurs after which exception
    # is bubbled up
    @log
    def insert(self, name, provision_network, id=None):
        try:
            p = Project()
            p.name = name
            p.provision_network = provision_network
            if id is not None:
                p.id = id
            self.connection.session.add(p)
コード例 #2
0
ファイル: ceph.py プロジェクト: chemistry-sourabh/ims
#! /bin/python
import subprocess
from contextlib import contextmanager

import os
import rados
import rbd
import sh

import ims.common.constants as constants
import ims.exception.file_system_exceptions as file_system_exceptions
from ims.common.log import create_logger, log, trace

logger = create_logger(__name__)


# Need to think if there is a better way to reduce boilerplate exception
# handling code in methods
class RBD:
    @log
    def __init__(self, config, password):
        self.__validate(config)
        self.password = password
        self.cluster = self.__init_cluster()
        self.context = self.__init_context()
        self.rbd = rbd.RBD()

    # Validates the config arguments passed
    # If all are present then the values are copied to variables
    @trace
    def __validate(self, config):