Пример #1
0
def subcmd_storage_add(args):
    """ Adds the subcommand arguments back to main CLI tool """
    data = storage_add_data(args)

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

        cmd = [utils.KUBECTL_CMD, "create", "-f", tempfile_path]
        resp = utils.execute(cmd)
        print("Storage add request sent successfully")
        print(resp.stdout)
        print()
        print("Storage Yaml file for your reference:")
        print(yaml.dump(data))
        print()
    except utils.CommandError as err:
        print("Error while running the following command", file=sys.stderr)
        print("$ " + " ".join(cmd), file=sys.stderr)
        print("", file=sys.stderr)
        print(err.stderr, file=sys.stderr)
        sys.exit(1)
    finally:
        os.remove(tempfile_path)
Пример #2
0
def subcmd_install(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 = [utils.KUBECTL_CMD, "apply", "-f", operator_file]
        print("Executing '%s'" % cmd)
        resp = utils.execute(cmd)
        print("Kadalu operator create request sent successfully")
        print(resp.stdout)
        print()
    #noqa #pylint : disable=R0801
    except utils.CommandError as err:
        print("Error while running the following command", file=sys.stderr)
        print("$ " + " ".join(cmd), file=sys.stderr)
        print("", file=sys.stderr)
        print(err.stderr, file=sys.stderr)
        sys.exit(1)
Пример #3
0
def get_kube_nodes():
    """ gets all nodes  """
    try:
        #cmd = ["kubectl", "get", "nodes", "--no-headers", "-o", "custom-columns=':metadata.name'"]
        # above returns <none>
        cmd = ["kubectl", "get", "nodes"]
        resp = utils.execute(cmd)
        print("The following nodes are available")
        print(resp.stdout)
        nodes = []
        for line in resp.stdout.split("\n"):
            # The last line is empty thus ignore as otherwise we get an
            # IndexError: list index out of range
            line = line.strip()
            if not line:
                continue
            nodename = line.split()[0]
            if nodename != "NAME":
                nodes.append(nodename)
        return nodes
    except utils.CommandError as err:
        print("Error while running the following command", file=sys.stderr)
        print("$ " + " ".join(cmd), file=sys.stderr)
        print("", file=sys.stderr)
        print(err.stderr, file=sys.stderr)
        sys.exit(1)