Ejemplo n.º 1
0
def get_num_pvs(storage_info_data):
    """
    Get number of PVs provisioned from
    volume requested for deletion
    through configmap.
    """

    volname = storage_info_data['volname']
    cmd = None
    if storage_info_data.get("type") == "External":
        # We can't access external cluster and so query existing PVs which are
        # using external storageclass
        volname = "kadalu." + volname
        jpath = ('jsonpath=\'{range .items[?(@.spec.storageClassName=="%s")]}'
                 '{.spec.storageClassName}{"\\n"}{end}\'' % volname)
        cmd = ["kubectl", "get", "pv", "-o", jpath]
    else:
        bricks = storage_info_data['bricks']
        dbpath = "/bricks/" + volname + "/data/brick/stat.db"
        query = ("select count(pvname) from pv_stats;")
        cmd = [
            "kubectl", "exec", "-i",
            bricks[0]['node'].replace("." + volname, ""), "-c", "server",
            "-nkadalu", "--", "sqlite3", dbpath, query
        ]

    try:
        resp = utils_execute(cmd)
        parts = resp.stdout.strip("'").split()
        if storage_info_data.get("type") == "External":
            return len(parts)
        pv_count = int(parts[0])
        return pv_count

    except CommandError as msg:
        # 1. If storage is created but no PV is carved then pv_stats table is not
        # created in SQLITE3
        # 2. If we fail to create 'server' pod then there'll be no 'server'
        # container (this'll be hit if supplied 'storageClass' is invalid)
        # 3. If 'server' pod does not have a host assigned,
        # TODO: find out root cause, repro - use incorrect device and edit with
        # correct device later
        if msg.stderr.find("no such table") != -1 or msg.stderr.find(
                "container not found") != -1 or msg.stderr.find(
                    "not have a host assigned") != -1:
            # We are good to delete server pods
            return 0
        logging.error(
            logf("Failed to get size details of the "
                 "storage \"%s\"" % volname,
                 error=msg))
        # Return error as its -1
        return -1
Ejemplo n.º 2
0
def csi_driver_object_api_version():
    """
    Return API Version of CSI Driver object"
    """

    cmd = ["kubectl", "get", "csidriver", "kadalu", "-ojson"]

    try:
        resp = utils_execute(cmd)
        csi_driver_data = json.loads(resp.stdout)
        version = csi_driver_data["apiVersion"]
        return version

    except CommandError as err:
        logging.error(
            logf("Failed to get version of csi driver object", error=err))
        return None
Ejemplo n.º 3
0
def get_num_pvs(storage_info_data):
    """
    Get number of PVs provisioned from
    volume requested for deletion
    through configmap.
    """

    volname = storage_info_data['volname']
    cmd = None
    if storage_info_data.get("type") == "External":
        # We can't access external cluster and so query existing PVs which are
        # using external storageclass
        volname = "kadalu.external." + volname
        jpath = ('jsonpath=\'{range .items[?(@.spec.storageClassName=="%s")]}'
                 '{.spec.storageClassName}{"\\n"}{end}\'' % volname)
        cmd = ["kubectl", "get", "pv", "-o", jpath]
    else:
        bricks = storage_info_data['bricks']
        dbpath = "/bricks/" + volname + "/data/brick/stat.db"
        query = ("select count(pvname) from pv_stats;")
        cmd = [
            "kubectl", "exec", "-i",
            bricks[0]['node'].replace("." + volname, ""), "-c", "server",
            "-nkadalu", "--", "sqlite3", dbpath, query
        ]

    try:
        resp = utils_execute(cmd)
        parts = resp.stdout.strip("'").split()
        if storage_info_data.get("type") == "External":
            return len(parts)
        pv_count = int(parts[0])
        return pv_count

    except CommandError as msg:
        logging.error(
            logf("Failed to get size details of the "
                 "storage \"%s\"" % volname,
                 error=msg))
        # Return error as its -1
        return -1
Ejemplo n.º 4
0
def get_configmap_data(volname):
    """
    Get storage info data from kadalu configmap
    """

    cmd = ["kubectl", "get", "configmap", "kadalu-info", "-nkadalu", "-ojson"]

    try:
        resp = utils_execute(cmd)
        config_data = json.loads(resp.stdout)

        data = config_data['data']
        storage_name = "%s.info" % volname
        storage_info_data = data[storage_name]

        # Return data in 'dict' format
        return json.loads(storage_info_data)

    except CommandError as err:
        logging.error(logf("Failed to get details from configmap", error=err))
        return None