예제 #1
0
    def execute(self):
        node = self.args["--node"]
        if not node:
            utils.log_info("Using Default Node : pve")
            node = "pve"

        interface = self.args['--interface']
        if not interface:
            utils.log_err("Set Your Interface")
            exit()

        data = network_lib.get_interface_details(node, interface)
        detail_interface = list()
        if not data:
            utils.log_err("Data Not Found")
            exit()
        detail_interface.append(data)
        headers = {
            'exists': "Exists",
            'type': 'Type',
            'method': 'Method',
            'method6': 'Method6',
            'priority': "Priority",
            'families': "Families"
        }
        print(tabulate(detail_interface, headers=headers, tablefmt='grid'))
예제 #2
0
def initialize(node, manifest_fie):
    if not node:
        node = "pve"
    init = list()
    utils.log_info("Initialization....")
    key = utils.do_deploy_dir(manifest_fie)

    for stack in utils.initdir(key):
        for project in key["stack"][stack]:
            try:
                parameters = key["data"][stack][project]["parameters"]
            except:
                parameters = None

            dest = "{}/{}/{}".format(key["deploy_dir"], stack, project)
            utils.log_info("Build {} {} template".format(project, stack))
            utils.log_info("Done...")
            """ Stack init dict """
            stack_init = {}
            stack_init["dir"] = dest
            stack_init["project"] = project
            stack_init["stack"] = stack
            stack_init["node"] = node
            stack_init["template"] = key["data"][stack][project]['template']
            stack_init["env_file"] = False

            if not utils.check_folder(dest):
                utils.create_folder(dest)

            if parameters:
                utils.log_info("Create {} {} environment file".format(
                    project, stack))
                data_path = {"parameters": parameters}
                utils.yaml_create(data_path, "{}/env.yml".format(dest))
                utils.log_info("Done...")
                stack_init["env_file"] = "{}/env.yml".format(dest)

            init.append(stack_init)
    """ Reformat squences deploy """
    if utils.check_key(key["data"], "deploy"):
        if len(key["data"]["deploy"]) > 0:
            set_sequence = list()
            for deploy in key["data"]["deploy"]:
                set_deploy = deploy.split(".")
                set_stack = set_deploy[0]
                set_project = set_deploy[1]
                set_sequence.append([
                    new_init for new_init in init
                    if (new_init["stack"] == set_stack) and (
                        new_init["project"] == set_project)
                ][0])
            init = set_sequence
    utils.yaml_create(init, "{}/deploy.yml".format(key["deploy_dir"]))
    return init
예제 #3
0
    def execute(self):
        node = self.args["--node"]
        if not node:
            utils.log_info("Using Default Node : pve")
            node = "pve"

        if self.args['content']:
            storage = self.args['--storage']
            if not storage:
                utils.log_err("Set Your Storage")
                exit()

            storage = self.args['--storage']
            if not storage:
                utils.log_err("Set Your Storage")
                exit()

            content = self.args['--content']
            if not content:
                content_storage = node_lib.get_node_storage_content(
                    node, storage)
                content_list = list()
                print(
                    tabulate(content_storage, headers="keys", tablefmt="grid"))
                exit()
            content_list = node_lib.get_os_template(node, storage, content)
            print(tabulate(content_list, headers="keys", tablefmt="grid"))
            exit()

        storage = self.args['--storage']
        if not storage:
            utils.log_err("Set Your Storage")
            exit()
        detail_storage = node_lib.get_storage_detail(node, storage)
        headers = {
            'storage': "Name Storage",
            'type': "Type",
            'total': "Total",
            'used': "Used",
            'avail': "Available",
            'shared': "Shared",
            'active': "Status",
            'enabled': "Enable",
            'content': "Content"
        }
        print(tabulate(detail_storage, headers=headers, tablefmt='grid'))
예제 #4
0
    def execute(self):
        node = self.args["--node"]
        if not node:
            utils.log_info("Using Default Node : pve")
            node = "pve"

        if self.args['vm']:
            vmid = self.args['--vmid']
            if vmid:
                # WITH ARGUMEN VM ID
                print("RM WITH ARGUMEN"+ vmid)
                # code here
                exit()

            # No Argumen VM ID
            print("RM VM")
            # Code Here
            # check prox.yml to data vmid
            exit()
        
        # rm command
        # code here
        # check yaml to data action
예제 #5
0
파일: vm.py 프로젝트: sofyan48/prox-cli
    def execute(self):
        node = self.args["--node"]
        if not node:
            utils.log_info("Using Default Node : pve")
            node = "pve"

        vm_id = self.args["--vmid"]

        if self.args['info']:
            if not vm_id:
                utils.log_err("Set VM_ID : -i VM_ID")
                exit()
            data = vm_lib.get_vm_status(node, vm_id)
            action = self.args['--action']
            if action:
                details_status = list()
                for i in data:
                    if i == action:
                        if type(data[i]) == dict:
                            details_status.append(data[i])
                            break
                        else:
                            utils.log_info(i + " " + str(data[i]))
                            exit()
                print(tabulate(details_status, headers="keys",
                               tablefmt="grid"))
                exit()

            list_data = list()
            for i in data:
                if type(data[i]) != dict:
                    list_data.append({"action": i})
                else:
                    list_data.append({"action": i})
            print(tabulate(list_data, headers="keys", tablefmt="grid"))
            exit()

        if self.args['rrd']:
            # not complete no representing data in process
            if not vm_id:
                utils.log_err("Set VM_ID : -i VM_ID")
                exit()
            data = vm_lib.get_vm_rrd(node, vm_id)
            utils.log_info("Coming soon")
            exit()

        if self.args['start']:
            cur_dir = os.getcwd()
            manifest_file = None

            if utils.read_file(cur_dir + "/prox.yml"):
                vm_id = None
                node = None
                manifest_file = utils.yaml_parser_file(cur_dir + "/prox.yml")
                for i in manifest_file['instances']:
                    node = manifest_file['instances'][i]['node']
                    vm_id = manifest_file['instances'][i]['parameters']['vmid']
                    vm_data = vm_lib.start_vm(node, vm_id)
            else:
                vm_id = self.args["--vmid"]
                if not vm_id:
                    utils.log_err("Set VM_ID : -i VM_ID")
                    exit()
            vm_data = vm_lib.start_vm(node, vm_id)
            utils.log_info(vm_data)
            exit()
        if self.args['stop']:
            cur_dir = os.getcwd()
            manifest_file = None
            if utils.read_file(cur_dir + "/prox.yml"):
                vm_id = None
                node = None
                manifest_file = utils.yaml_parser_file(cur_dir + "/prox.yml")
                for i in manifest_file['instances']:
                    node = manifest_file['instances'][i]['node']
                    vm_id = manifest_file['instances'][i]['parameters']['vmid']
            else:
                vm_id = self.args["--vmid"]
                if not vm_id:
                    utils.log_err("Set VM_ID : -i VM_ID")
                    exit()
            vm_data = vm_lib.stop_vm(node, vm_id)
            utils.log_info(vm_data)
            exit()
        if self.args['reboot']:
            cur_dir = os.getcwd()
            manifest_file = None
            if utils.read_file(cur_dir + "/prox.yml"):
                vm_id = None
                node = None
                manifest_file = utils.yaml_parser_file(cur_dir + "/prox.yml")
                for i in manifest_file['instances']:
                    node = manifest_file['instances'][i]['node']
                    vm_id = manifest_file['instances'][i]['parameters']['vmid']
            else:
                vm_id = self.args["--vmid"]
                if not vm_id:
                    utils.log_err("Set VM_ID : -i VM_ID")
                    exit()
            vm_data = vm_lib.reset_vm(node, vm_id)
            utils.log_info(vm_data)
            exit()
        if self.args['suspend']:
            cur_dir = os.getcwd()
            manifest_file = None
            if utils.read_file(cur_dir + "/prox.yml"):
                vm_id = None
                node = None
                manifest_file = utils.yaml_parser_file(cur_dir + "/prox.yml")
                for i in manifest_file['instances']:
                    node = manifest_file['instances'][i]['node']
                    vm_id = manifest_file['instances'][i]['parameters']['vmid']
            else:
                vm_id = self.args["--vmid"]
                if not vm_id:
                    utils.log_err("Set VM_ID : -i VM_ID")
                    exit()
            vm_data = vm_lib.suspesn_vm(node, vm_id)
            utils.log_info(vm_data)
            exit()
        if self.args['poweroff']:
            cur_dir = os.getcwd()
            manifest_file = None
            if utils.read_file(cur_dir + "/prox.yml"):
                vm_id = None
                node = None
                manifest_file = utils.yaml_parser_file(cur_dir + "/prox.yml")
                for i in manifest_file['instances']:
                    node = manifest_file['instances'][i]['node']
                    vm_id = manifest_file['instances'][i]['parameters']['vmid']
            else:
                vm_id = self.args["--vmid"]
                if not vm_id:
                    utils.log_err("Set VM_ID : -i VM_ID")
                    exit()
            vm_data = vm_lib.shutdown_vm(node, vm_id)
            utils.log_info(vm_data)
            exit()
        if self.args['remote']:
            cur_dir = os.getcwd()
            manifest_file = None
            if utils.read_file(cur_dir + "/prox.yml"):
                vm_id = None
                node = None
                manifest_file = utils.yaml_parser_file(cur_dir + "/prox.yml")
                for i in manifest_file['instances']:
                    node = manifest_file['instances'][i]['node']
                    vm_id = manifest_file['instances'][i]['parameters']['vmid']
            else:
                vm_id = self.args["--vmid"]
                if not vm_id:
                    utils.log_err("Set VM_ID : -i VM_ID")
                    exit()
            vm_data = vm_lib.vnc_vm(node, vm_id)
            utils.log_info(vm_data)
            exit()

        action = self.args['--action']
        if not action:
            data_vm = vm_lib.get_vm_detail(node, vm_id)
            headers = {"subdir": "Action"}
            print(tabulate(data_vm, headers=headers, tablefmt="grid"))
            exit()

        if action:
            if not vm_id:
                utils.log_err("Set VM_ID : -i VM_ID")
                exit()
            # Not Fix in View Error detecting tabulate
            data_vm = vm_lib.get_vm_detail(node, vm_id)
            # list_data_vm = list()
            for i in data_vm:
                if action == i['subdir']:
                    data_action = vm_lib.get_vm_action(node, vm_id,
                                                       i['subdir'])
                    if type(data_action) == dict:
                        for key in data_action:
                            # data = {
                            #     key : data_action[key]
                            # }
                            #
                            # list_data_vm.append(data)
                            utils.log_info(
                                str(key) + " | " + str(data_action[key]))
                        break
                    else:
                        utils.log_info(i + " " + str(i['subdir']))
                        exit
            # print(tabulate(data_vm_fix, headers="keys", tablefmt="grid"))
            exit()
예제 #6
0
파일: ls.py 프로젝트: sofyan48/prox-cli
    def execute(self):
        if self.args['network']:
            node = self.args['--node']
            if not node:
                node = "pve"
                utils.log_warn("Using Default Node | -N node to set node")
            data = network_lib.get_interface(node)
            if not data:
                utils.log_err("Data Not Found")
                exit()
            list_interface = list()
            for i in data:
                data_interface = {
                    "interface": i['iface'],
                    "type": i['type'],
                }
                list_interface.append(data_interface)

            headers = {
                "interface": "Interface",
                "type": "Type",
            }
            print(tabulate(list_interface, headers=headers, tablefmt='grid'))
            exit()

        if self.args['cluster']:
            headers = {
                'nodeid': "NODE",
                'ip': "IP",
                'name': "Name",
                "type": "Type",
                "id": "ID",
                "online": "Online",
                "level": "Level",
                "local": "Local"
            }
            list_cluster = clusters_lib.list_cluster()["data"]
            print(tabulate(list_cluster, headers=headers, tablefmt='grid'))
            exit()

        if self.args['vm']:
            if self.args['--next']:
                cl_next = node_lib.vm_next()
                utils.log_info(cl_next)
                exit()

            try:
                node = self.args["--node"]
            except Exception:
                node = None
            if node:
                data = node_lib.list_vm_by_node(node)
                if not data:
                    utils.log_err("Data Not Found")
                    exit()
                list_vm = list()
                for key in data:
                    data_vm = {
                        "vmid": key['vmid'],
                        "name": key['name'],
                        "cpus": key['cpus'],
                        "memory": key['mem'],
                        "status": key['status']
                    }
                    list_vm.append(data_vm)
                headers = {
                    "vmid": "ID VM",
                    "name": "VM Name",
                    "cpus": "vCPUS",
                    "memory": "RAM",
                    "status": "Status"
                }
                print(tabulate(list_vm, headers=headers, tablefmt='grid'))
                exit()

            utils.log_warn("Using default node : pve ")
            data = node_lib.list_vm_by_node("pve")
            if not data:
                utils.log_err("Data Not Found")
                exit()
            list_vm = list()
            for key in data:
                data_vm = {
                    "vmid": key['vmid'],
                    "name": key['name'],
                    "cpus": key['cpus'],
                    "memory": key['mem'],
                    "status": key['status']
                }
                list_vm.append(data_vm)
            headers = {
                "vmid": "ID VM",
                "name": "VM Name",
                "cpus": "vCPUS",
                "memory": "RAM",
                "status": "Status"
            }
            print(tabulate(list_vm, headers=headers, tablefmt='grid'))
            exit()

        if self.args['container']:
            try:
                node = self.args["--node"]
            except Exception:
                node = None
            if node:
                data = node_lib.list_container_by_node("pve")
                if not data:
                    utils.log_err("Data Not Found")
                    exit()
                print("WIP: Not Data In Testing")
                exit()
            data = node_lib.list_container_by_node("pve")
            if not data:
                utils.log_err("Data Not Found")
                exit()
            print("WIP: Not Data In Testing")

        if self.args['storage']:
            node = self.args['--node']
            if not node:
                utils.log_warn("Using Default Node : pve")
                node = "pve"
            data = node_lib.get_storage(node)
            if not data:
                utils.log_err("Data Not Found")
                exit()
            list_storage = list()
            for i in data:
                storage = {
                    "storage": i['storage'],
                    "total": i["total"],
                    "used": i["used"],
                    "avail": i['avail']
                }
                list_storage.append(storage)
            headers = {
                "storage": "Name Storage",
                "total": "Total",
                "used": "Used",
                "avail": "Available"
            }
            print(tabulate(list_storage, headers=headers, tablefmt='grid'))
            exit()
예제 #7
0
파일: node.py 프로젝트: sofyan48/prox-cli
    def execute(self):
        node = self.args["--node"]
        if not node:
            utils.log_info("Using Default Node : pve")
            node = "pve"

        if self.args['task']:
            task_data = node_lib.get_finish_task(node)
            if not task_data:
                utils.log_err("Data not found")
                exit()

            total_task = task_data['total']
            utils.log_info("Total: " + str(total_task))
            task_list = list()
            vmid = self.args['--vmid']
            if vmid:
                for i in task_data['data']:
                    if i['id'] == vmid:
                        id = None
                        if i['id'] == "":
                            id = "master"
                        else:
                            id = i['id']

                        data = {
                            'id': id,
                            'type': i['type'],
                            'pstart': i['pstart'],
                            'pid': i['pid'],
                            'status': i['status']
                        }
                        task_list.append(data)
                headers = {
                    'pstart': 'PStart',
                    'id': 'ID',
                    'type': 'Type',
                    'pid': "PID",
                    'status': 'Status'
                }
                print(tabulate(task_list, headers=headers, tablefmt='grid'))
                exit()

            for i in task_data['data']:
                id = None
                if i['id'] == "":
                    id = "master"
                else:
                    id = i['id']

                data = {
                    'id': id,
                    'type': i['type'],
                    'pstart': i['pstart'],
                    'pid': i['pid'],
                    'status': i['status']
                }
                task_list.append(data)
            headers = {
                'pstart': 'PStart',
                'id': 'ID',
                'type': 'Type',
                'pid': "PID",
                'status': 'Status'
            }
            print(tabulate(task_list, headers=headers, tablefmt='grid'))
            exit()

        if self.args['dns']:
            data_dns = node_lib.get_node_dns(node)
            if not data_dns:
                utils.log_err("Data Not Found")
                exit()
            list_dns = list()
            list_dns.append(data_dns)
            print(tabulate(list_dns, headers="keys", tablefmt='grid'))
            exit()

        if self.args['status']:
            data_status = node_lib.get_node_status(node)
            if not data_status:
                utils.log_err("Data Not Found")
                exit()
            action = self.args['--action']
            if action:
                list_action = list()
                for i in data_status:
                    if i == action:
                        if type(data_status[i]) == dict:
                            list_action.append(data_status[i])
                        elif type(data_status[i]) == list:
                            for key in data_status[i]:
                                utils.log_info(key)
                        else:
                            utils.log_info(data_status[i])
                            exit()
                print(tabulate(list_action, headers="keys", tablefmt='grid'))
                exit()
            list_status = list()
            for i in data_status:
                list_status.append({"Status": i})
            print(tabulate(list_status, headers="keys", tablefmt='grid'))
            exit()

        if self.args['log']:
            data = node_lib.get_node_syslog(node)
            list_log = list()
            for i in data:
                data_log = {"row": i['n'], "desc": i['t']}
                list_log.append(data_log)
            headers = {"row": "No", "desc": "Description"}
            print(tabulate(list_log, headers=headers, tablefmt='grid'))
            exit()

        if self.args['rrd']:
            data = self.args['--action']
            if data:
                rrd_data = node_lib.get_node_rrd_data(node)
                print(rrd_data)
                exit()
            data = node_lib.get_node_rrd(node)
            print("Testing")
            exit()

        if self.args['beans']:
            data = node_lib.get_node_beans(node)
            print("Testing")
            exit()
예제 #8
0
    def execute(self):
        node = self.args["--node"]
        if not node:
            utils.log_info("Using Default Node : pve")
            node = "pve"

        if self.args["--template"]:
            if self.args["--template"] in ('pool', 'instances', 'network',
                                           "storage"):
                tmpl = self.args["--template"]

                if self.args["--interactive"]:
                    ncurses.init(node, stack=tmpl)
                else:
                    prompt.init(node, stack=tmpl)
            exit()

        if self.args["vm"]:
            if self.args["--interactive"]:
                print(ncurses.init(node, stack="instances", project="vm"))
            else:
                print(prompt.init(node, stack="instances", project="vm"))

        set_file = self.args["--file"]
        default_file = utils.check_manifest_file()

        if set_file:
            if os.path.exists(set_file):
                default_file = set_file
            else:
                utils.log_err("{} file is not exists!".format(set_file))
                exit()

        if not default_file:
            utils.log_err("Can't find prox.yml manifest file!")
            q_stack = utils.question(
                "Do you want to generate pro.yml manifest? ")

            if q_stack:
                if self.args["--interactive"]:
                    print(ncurses.init(node))
                else:
                    print(prompt.init(node))
                q_deploy = utils.question("Continue to deploy? ")
                if q_deploy:
                    default_file = "prox.yml"
                else:
                    exit()
            else:
                exit()
        else:
            q_deploy = utils.question("Continue to deploy? ")
            if q_deploy:
                default_file = "prox.yml"
            else:
                exit()

        deploy_init = create_libs.initialize(node, default_file)
        result = list()
        try:
            result = create_libs.do_create(deploy_init)
        except Exception as e:
            utils.log_err(e)
            utils.log_err("Deploying Stack failed...")
            exit()
        list_result = list()
        list_result.append(result)
        print(tabulate(list_result, tablefmt='grid'))