示例#1
0
    def factory(
        interface=constants.CEPHBLOCKPOOL,
        project=None,
        storageclass=None,
        size=None,
        custom_data=None,
        status=constants.STATUS_BOUND,
    ):
        """
        Args:
            interface (str): CephBlockPool or CephFileSystem. This decides
                whether a RBD based or CephFS resource is created.
                RBD is default.
            project (object): ocs_ci.ocs.resources.ocs.OCS instance
                of 'Project' kind.
            storageclass (object): ocs_ci.ocs.resources.ocs.OCS instance
                of 'StorageClass' kind.
            size (int): The requested size for the PVC
            custom_data (dict): If provided then PVC object is created
                by using these data. Parameters `project` and `storageclass`
                are not used but reference is set if provided.
            status (str): If provided then factory waits for object to reach
                desired state.

        Returns:
            object: helpers.create_pvc instance.
        """
        if custom_data:
            pvc_obj = PVC(**custom_data)
            pvc_obj.create(do_reload=False)
        else:
            project = project or project_factory()
            storageclass = storageclass or storageclass_factory(interface)
            pvc_size = f"{size}Gi" if size else None

            pvc_obj = helpers.create_pvc(sc_name=storageclass.name,
                                         namespace=project.namespace,
                                         size=pvc_size,
                                         wait=False)
            assert pvc_obj, "Failed to create PVC"
        if status:
            helpers.wait_for_resource_state(pvc_obj, status)
        pvc_obj.storageclass = storageclass
        pvc_obj.project = project

        instances.append(pvc_obj)
        return pvc_obj
示例#2
0
    def factory(interface=constants.CEPHBLOCKPOOL,
                project=None,
                storageclass=None,
                size=None,
                access_mode=constants.ACCESS_MODE_RWO,
                custom_data=None,
                status=constants.STATUS_BOUND,
                volume_mode=None):
        """
        Args:
            interface (str): CephBlockPool or CephFileSystem. This decides
                whether a RBD based or CephFS resource is created.
                RBD is default.
            project (object): ocs_ci.ocs.resources.ocs.OCS instance
                of 'Project' kind.
            storageclass (object): ocs_ci.ocs.resources.ocs.OCS instance
                of 'StorageClass' kind.
            size (int): The requested size for the PVC
            access_mode (str): ReadWriteOnce, ReadOnlyMany or ReadWriteMany.
                This decides the access mode to be used for the PVC.
                ReadWriteOnce is default.
            custom_data (dict): If provided then PVC object is created
                by using these data. Parameters `project` and `storageclass`
                are not used but reference is set if provided.
            status (str): If provided then factory waits for object to reach
                desired state.
            volume_mode (str): Volume mode for PVC.
                eg: volume_mode='Block' to create rbd `block` type volume

        Returns:
            object: helpers.create_pvc instance.
        """
        if custom_data:
            pvc_obj = PVC(**custom_data)
            pvc_obj.create(do_reload=False)
        else:
            nonlocal active_project
            nonlocal active_rbd_storageclass
            nonlocal active_cephfs_storageclass

            project = project or active_project or project_factory()
            active_project = project
            if interface == constants.CEPHBLOCKPOOL:
                storageclass = (storageclass or active_rbd_storageclass
                                or storageclass_factory(interface))
                active_rbd_storageclass = storageclass
            elif interface == constants.CEPHFILESYSTEM:
                storageclass = (storageclass or active_cephfs_storageclass
                                or storageclass_factory(interface))
                active_cephfs_storageclass = storageclass
            pvc_size = f"{size}Gi" if size else None

            pvc_obj = helpers.create_pvc(sc_name=storageclass.name,
                                         namespace=project.namespace,
                                         size=pvc_size,
                                         do_reload=False,
                                         access_mode=access_mode,
                                         volume_mode=volume_mode)
            assert pvc_obj, "Failed to create PVC"

        if status:
            helpers.wait_for_resource_state(pvc_obj, status)
        pvc_obj.storageclass = storageclass
        pvc_obj.project = project
        pvc_obj.access_mode = access_mode
        instances.append(pvc_obj)

        return pvc_obj