Exemplo n.º 1
0
 def check_pvc(self, namespace, name, service_api: CoreV1Api = None):
     try:
         claim = service_api.read_namespaced_persistent_volume_claim(
             name, namespace)
     except Exception as e:
         logger.error(e)
         return False
     return True
Exemplo n.º 2
0
 def delete_pvc(self, namespace, name, service_api: CoreV1Api = None):
     try:
         service_api.delete_namespaced_persistent_volume_claim(
             name, namespace)
     except Exception as e:
         logger.error(e)
         return -1
     return 2
Exemplo n.º 3
0
 def create_pvc(self, body, service_api: CoreV1Api = None):
     pvc = load_param_yaml(
         PVC_TEMPLATE,
         name=body.pvc_name,
         namespace=body.namespace,
         #accessModes="ReadWriteMany" if body.mode == "RWX" else "ReadWriteOnce",
         accessModes=body.mode,
         storage=body.disk,
         storageClassName=body.storage_class)
     try:
         service_api.create_namespaced_persistent_volume_claim(
             body.namespace, body=pvc)
     except Exception as e:
         logger.error(e)
         return -1
     return 2
Exemplo n.º 4
0
 def insert(pvc, service_api: Engine = None):
     try:
         db_session = sessionmaker(bind=service_api)
         session = db_session()
         session.add(pvc)
         yield
         # 提交即保存到数据库:
         session.commit()
         return True
     except Exception as e:
         session.rollback()
         logger.error(e)
     finally:
         if session is not None:
             # 关闭 session:
             session.close()
     return False
Exemplo n.º 5
0
 def query(namespace, module, ou_id, service_api: Engine = None):
     try:
         db_session = sessionmaker(bind=service_api)
         session = db_session()
         Base.to_dict = RmsPvc.to_dict
         conditions = [RmsPvc.is_delete == 0, RmsPvc.cre_user == ou_id]
         if namespace is not None:
             conditions.append(RmsPvc.namespace == namespace)
         if module is not None:
             conditions.append(RmsPvc.module == module)
         rows = session.query(RmsPvc).filter(*conditions).all()
         return [row.to_dict() for row in rows]
     except Exception as e:
         logger.error(e)
     finally:
         if session is not None:
             # 关闭 session:
             session.close
     return False
Exemplo n.º 6
0
 def delete(namespace, pvc_name, ou_id, service_api: Engine = None):
     try:
         db_session = sessionmaker(bind=service_api)
         session = db_session()
         rows = session.query(RmsPvc).filter(RmsPvc.namespace == namespace,
                                             RmsPvc.name == pvc_name,
                                             RmsPvc.is_delete == 0,
                                             RmsPvc.ou_id == ou_id).all()
         for row in rows:
             row.is_delete = 1
         yield
         session.commit()
         return True
     except Exception as e:
         session.rollback()
         logger.error(e)
     finally:
         if session is not None:
             # 关闭 session:
             session.close()
     return False