Exemplo n.º 1
0
 def create(self):
     spec = client.V1PersistentVolumeSpec(
         access_modes=[self.access_mode],
         capacity={"storage": "10Pi"},
         volume_mode="Filesystem",
         persistent_volume_reclaim_policy="Delete",
         mount_options=self.mount_options,
         csi=client.V1CSIPersistentVolumeSource(
             driver="csi.juicefs.com",
             fs_type="juicefs",
             volume_handle=self.volume_handle,
             node_publish_secret_ref=client.V1SecretReference(
                 name=self.secret_name,
                 namespace=self.secret_namespace
             ),
             volume_attributes=self.parameters,
         )
     )
     pv = client.V1PersistentVolume(
         api_version="v1",
         kind="PersistentVolume",
         metadata=client.V1ObjectMeta(name=self.name, labels={"pv": self.name}),
         spec=spec
     )
     client.CoreV1Api().create_persistent_volume(body=pv)
     PVs.append(self)
Exemplo n.º 2
0
def create_pv(pv_values, pv_name, created_objects, sc_name=""):
    """
    creates persistent volume

    Args:
        param1: pv_values - values required for creation of pv
        param2: pv_name - name of pv to be created
        param3: sc_name - name of storage class pv associated with

    Returns:
        None

    Raises:
        Raises an exception on kubernetes client api failure and asserts

    """
    api_instance = client.CoreV1Api()
    pv_metadata = client.V1ObjectMeta(name=pv_name)
    pv_csi = client.V1CSIPersistentVolumeSource(
        driver="spectrumscale.csi.ibm.com",
        volume_handle=pv_values["volumeHandle"])
    if pv_values["reclaim_policy"] == "Default":
        pv_spec = client.V1PersistentVolumeSpec(
            access_modes=[pv_values["access_modes"]],
            capacity={"storage": pv_values["storage"]},
            csi=pv_csi,
            storage_class_name=sc_name)
    else:
        pv_spec = client.V1PersistentVolumeSpec(
            access_modes=[pv_values["access_modes"]],
            capacity={"storage": pv_values["storage"]},
            csi=pv_csi,
            persistent_volume_reclaim_policy=pv_values["reclaim_policy"],
            storage_class_name=sc_name)

    pv_body = client.V1PersistentVolume(api_version="v1",
                                        kind="PersistentVolume",
                                        metadata=pv_metadata,
                                        spec=pv_spec)
    try:
        LOGGER.info(
            f'PV Create : Creating PV {pv_name} with {pv_values} parameter')
        api_response = api_instance.create_persistent_volume(body=pv_body,
                                                             pretty=True)
        LOGGER.debug(str(api_response))
        created_objects["pv"].append(pv_name)
    except ApiException as e:
        LOGGER.error(f'PV {pv_name} creation failed hence failing test case ')
        LOGGER.error(
            f"Exception when calling CoreV1Api->create_persistent_volume: {e}")
        cleanup.clean_with_created_objects(created_objects)
        assert False