예제 #1
0
class DftOperator(ObjectOperator):
    _instance = None

    def __new__(cls, **kwargs):
        if cls._instance is None:
            cls._instance = super().__new__(cls)
            cls.__init__(cls, **kwargs)
        return cls._instance

    def __init__(self, **kwargs):
        logger.info(kwargs)
        self.store = OprStore()
        config.load_incluster_config()
        self.obj_api = client.CustomObjectsApi()

    def query_existing_dfts(self):
        def list_dft_obj_fn(name, spec, plurals):
            logger.info("Bootstrapped dft {}".format(name))
            dft = Dft(name, self.obj_api, self.store, spec)
            if dft.status == OBJ_STATUS.obj_status_provisioned:
                self.store.update_obj(dft)

        kube_list_obj(self.obj_api, RESOURCES.dfts, list_dft_obj_fn)
        self.bootstrapped = True

    def get_stored_obj(self, name, spec):
        return Dft(name, self.obj_api, self.store, spec)

    def create_default_dft(self):
        if self.store.get_obj(OBJ_DEFAULTS.default_dft, KIND.dft):
            return
        dft = Dft(OBJ_DEFAULTS.default_dft, self.obj_api, self.store)
        dft.numchains = OBJ_DEFAULTS.default_n_chains
        dft.numchainreplicas = OBJ_DEFAULTS.default_n_replicas
        dft.maglev_table = MaglevTable(OBJ_DEFAULTS.default_maglev_table_size)
        dft.create_obj()
예제 #2
0
class ObjectOperator(object):
    def __init__(self, **kwargs):
        logger.info(kwargs)
        self.store = OprStore()

    def store_get_obj(self, name, kind, spec):
        obj = self.store.get_obj(name, kind)
        if not obj:
            logger.info("{} of type {} not found in store".format(name, kind))
            return None
        obj.set_obj_spec(spec)
        return obj

    def store_update_obj(self, obj):
        self.store.update_obj(obj)
        obj.update_obj()

    def store_delete_obj(self, obj):
        self.store.delete_obj(obj.name, obj.kind)
        obj.delete_obj()

    def set_object_provisioned(self, obj):
        obj.set_status(OBJ_STATUS.obj_status_provisioned)
        self.store_update_obj(obj)