예제 #1
0
def run(args):
    """ perform install subcommand """
    operator_file = args.local_yaml
    if not operator_file:
        file_url = "https://raw.githubusercontent.com/kadalu/kadalu/master/manifests"
        version = ""
        insttype = ""

        if args.version and args.version != "latest":
            version = "-%s" % args.version

            if args.type and args.type == "openshift":
                insttype = "-openshift"

        operator_file = "%s/kadalu-operator%s%s.yaml" % (file_url, insttype,
                                                         version)

    try:
        cmd = [args.kubectl_cmd, "apply", "-f", operator_file]
        print("Executing '%s'" % " ".join(cmd))
        if args.dry_run:
            return

        resp = utils.execute(cmd)
        print("Kadalu operator create request sent successfully")
        print(resp.stdout)
        print()
    except utils.CommandError as err:
        utils.command_error(cmd, err.stderr)
    except FileNotFoundError:
        utils.kubectl_cmd_help(args.kubectl_cmd)
예제 #2
0
def get_configmap_data(args):
    """
    Get storage info data from kadalu configmap
    """

    cmd = utils.kubectl_cmd(args) + ["get", "configmap", "kadalu-info", "-nkadalu", "-ojson"]

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

        volname = args.name
        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 utils.CommandError as err:
        utils.command_error(cmd, err.stderr)
        return None

    except KeyError:
        # Validate method expects None when 'storage' not found.
        return None
예제 #3
0
파일: __main__.py 프로젝트: leelavg/kadalu
def get_kadalu_version_in_pod(pod):
    """ Get kadalu version from pods inside kadalu-namespace by exec """

    try:

        cmd = [
            "kubectl", "exec", "-nkadalu", pod, "--", "bash", "-c",
            "echo $KADALU_VERSION"
        ]

        if "nodeplugin" in pod or "provisioner" in pod:
            version_container = "kadalu-nodeplugin"
            if "provisioner" in pod:
                version_container = "kadalu-provisioner"
            cmd.insert(3, "-c")
            cmd.insert(4, version_container)

        version_resp = utils.execute(cmd)
        version = version_resp.stdout.strip()

        return version

    except utils.CommandError as err:
        utils.command_error(cmd, err.stderr)
        return None
예제 #4
0
def run(args):
    """ perform log subcommand """

    try:

        pods, container = [args.podname], "--all-containers=true"

        if args.container:
            container = '-c' + args.container

        if not args.podname:
            cmd = utils.kubectl_cmd(args) + [
                "get", "pods", "-nkadalu", "-oname"
            ]
            resp = utils.execute(cmd)
            # Remove empty lines(pod-names) from command response
            pods = resp.stdout.split()

        for pod in pods:
            log_cmd = utils.kubectl_cmd(args) + [
                "logs", "-nkadalu", pod, container
            ]
            log_resp = utils.execute(log_cmd)
            print("----- (Kadalu Namespace) %s -----" % pod)
            print(log_resp.stdout)
            print()

    except utils.CommandError as err:
        utils.command_error(cmd, err.stderr)
    except FileNotFoundError:
        utils.kubectl_cmd_help(args.kubectl_cmd)
예제 #5
0
파일: install.py 프로젝트: vatsa287/kadalu
def run(args):
    """ perform install subcommand """

    # Check if kadalu operator is present already.
    try:
        cmd = utils.kubectl_cmd(args) + [
            "get", "deployments", "-nkadalu", "-ojson"
        ]
        resp = utils.execute(cmd)
        data = json.loads(resp.stdout)
        items = data["items"]

        if items:
            operator = items[0]["metadata"].get("name")
            namespace = items[0]["metadata"].get("namespace")

            if operator is not None and namespace is not None:
                print("Kadalu operator already installed")
                return

    except utils.CommandError as err:
        utils.command_error(cmd, err.stderr)
    except FileNotFoundError:
        utils.kubectl_cmd_help(args.kubectl_cmd)

    operator_file = args.local_yaml
    if not operator_file:
        file_url = ""
        insttype = ""

        if args.version and args.version == "devel":
            file_url = "https://raw.githubusercontent.com/kadalu/kadalu/devel/manifests"
        elif args.version:
            file_url = "https://github.com/kadalu/kadalu/releases/download/%s" % args.version

        if args.type and args.type != "kubernetes":
            insttype = "-%s" % args.type

        operator_file = "%s/kadalu-operator%s.yaml" % (file_url, insttype)

    try:
        cmd = utils.kubectl_cmd(args) + ["apply", "-f", operator_file]
        print("Executing '%s'" % " ".join(cmd))
        if args.dry_run:
            return

        resp = utils.execute(cmd)
        print("Kadalu operator create request sent successfully")
        print(resp.stdout)
        print()
    except utils.CommandError as err:
        utils.command_error(cmd, err.stderr)
    except FileNotFoundError:
        utils.kubectl_cmd_help(args.kubectl_cmd)
예제 #6
0
파일: __main__.py 프로젝트: leelavg/kadalu
def get_all_kadalu_pods():
    """ List of all pods in kadalu namespace """

    try:
        cmd = ["kubectl", "get", "pods", "-nkadalu", "-oname"]
        resp = utils.execute(cmd)
        # Remove empty lines(pod-names) from command response
        pods = resp.stdout.split()
        return pods
    except utils.CommandError as err:
        utils.command_error(cmd, err.stderr)
        return None
예제 #7
0
def run(args):
    """ perform log subcommand """

    try:
        cmd = utils.kubectl_cmd(args) + [
            "exec", "-nkadalu", "kadalu-csi-provisioner-0", "-c",
            "kadalu-provisioner", "--", "/kadalu/heal-info.sh"
        ]
        resp = utils.execute(cmd)
        print(resp.stdout)
        print()

    except utils.CommandError as err:
        utils.command_error(cmd, err.stderr)
    except FileNotFoundError:
        utils.kubectl_cmd_help(args.kubectl_cmd)
예제 #8
0
def run(args):
    """ Adds the subcommand arguments back to main CLI tool """

    yaml_content = Template(YAML_TEMPLATE).substitute(name=args.name)

    print("Storage Yaml file for your reference:\n")
    print(yaml_content)

    if args.dry_run:
        return

    if not args.script_mode:
        answer = ""
        valid_answers = ["yes", "no", "n", "y"]

        while answer not in valid_answers:
            answer = input("Is this correct?(Yes/No): ")
            answer = answer.strip().lower()

        if answer in ["n", "no"]:
            return

    config, tempfile_path = tempfile.mkstemp(prefix="kadalu")
    try:
        with os.fdopen(config, 'w') as tmp:
            tmp.write(yaml_content)

        cmd = utils.kubectl_cmd(args) + ["delete", "-f", tempfile_path]
        resp = utils.execute(cmd)
        print("Storage delete request sent successfully.\n")
        print(resp.stdout)
        print()

    except utils.CommandError as err:
        os.remove(tempfile_path)
        utils.command_error(cmd, err.stderr)

    except FileNotFoundError:
        os.remove(tempfile_path)
        utils.kubectl_cmd_help(args.kubectl_cmd)

    finally:
        if os.path.exists(tempfile_path):
            os.remove(tempfile_path)
예제 #9
0
def get_kube_nodes(args):
    """ gets all nodes  """
    if args.dry_run:
        return []

    cmd = [args.kubectl_cmd, "get", "nodes", "-ojson"]
    try:
        resp = utils.execute(cmd)
        data = json.loads(resp.stdout)
        nodes = []
        for nodedata in data["items"]:
            nodes.append(nodedata["metadata"]["name"])

        print("The following nodes are available:\n  %s" % ", ".join(nodes))
        print()
        return nodes
    except utils.CommandError as err:
        utils.command_error(cmd, err.stderr)
    except FileNotFoundError:
        utils.kubectl_cmd_help(args.kubectl_cmd)
예제 #10
0
def run(args):
    """Shows List of Storages"""
    cmd = [args.kubectl_cmd, "get", "configmap",
           "kadalu-info", "-nkadalu", "-ojson"]

    try:
        resp = utils.execute(cmd)
        storages = list_storages(resp.stdout, args)
        if args.status:
            if not fetch_status(storages, args):
                sys.exit(1)

        if args.detail:
            detailed_output(storages, args)
        else:
            summary_output(storages, args)
    except utils.CommandError as err:
        utils.command_error(cmd, err.stderr)
    except FileNotFoundError:
        utils.kubectl_cmd_help(args.kubectl_cmd)