示例#1
0
文件: update.py 项目: sdmoko/neo-cli
    def execute(self):
        headers = ["ID", "Name", "Status", "Created", "Updated"]

        set_file = self.args["--file"]
        default_file = orch.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 neo.yml manifest file!")
            exit()

        deploy_init = orch.initialize(default_file)
        try:
            orch.do_update(deploy_init)
        except:
            utils.log_err("Update Stack failed...")
            exit()

        projects = utils.get_project(default_file)

        project_list = list()
        for project in projects:
            proj = orch.get_stack(project)
            if proj:
                project_list.append(proj)

        if len(project_list) > 0:
            print(tabulate(project_list, headers=headers, tablefmt="grid"))
示例#2
0
文件: ls.py 项目: nofriiza/neo-cli
    def execute(self):
        headers = ["ID", "Name", "Status", "Created", "Updated"]
        if self.args["stack"]:
            print(tabulate(orch.get_list(), headers=headers, tablefmt="grid"))
            exit()

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

        if self.args["vm"]:
            try:
                data_instance = list()
                for instance in vm_lib.get_list():
                    pre_instance = [
                        instance.id, instance.name, instance.key_name
                    ]
                    pre_instance.append(
                        image.detail(instance.image["id"]).name)
                    flavors = vm_lib.detail_flavor(instance.flavor["id"])
                    flavors_name = flavors.name
                    flavors_vcpu = flavors.vcpus
                    flavors_ram = bitmath.MiB(
                        flavors.ram).to_GiB().best_prefix()
                    pre_instance.append(flavors_name)
                    pre_instance.append(flavors_ram)
                    pre_instance.append(flavors_vcpu)

                    # Address
                    addr = list()
                    addr_objs = utils.get_index(instance.addresses)
                    if len(addr_objs) > 0:
                        for addr_obj in addr_objs:
                            addr.append("network : {}".format(addr_obj))
                            for addr_ip in instance.addresses[addr_obj]:
                                addr_meta = "{} IP : {}".format(
                                    addr_ip["OS-EXT-IPS:type"],
                                    addr_ip["addr"])
                                addr.append(addr_meta)
                    if len(addr) > 0:
                        pre_instance.append("\n".join(addr))
                    else:
                        pre_instance.append("")

                    pre_instance.append(instance.status)
                    data_instance.append(pre_instance)

                if len(data_instance) == 0:
                    utils.log_err("No Data...")
                    print(self.__doc__)

            except Exception as e:
                utils.log_err(e)
                exit()
            print(
                tabulate(
                    data_instance,
                    headers=[
                        "ID",
                        "Name",
                        "Key Pair",
                        "Image",
                        "Flavor",
                        "RAM (GiB)",
                        "vCPU",
                        "Addresses",
                        "Status",
                    ],
                    tablefmt="grid",
                ))
            exit()

        if self.args["network"]:
            data_network = [[
                network["id"], network["name"], network["status"]
            ] for network in network_lib.get_list()]
            if len(data_network) == 0:
                utils.log_err("No Data...")
                print(self.__doc__)
                exit()
            print(
                tabulate(data_network,
                         headers=["ID", "Name", "Status"],
                         tablefmt="grid"))
            exit()

        if self.args["floatingips"]:
            data_floatingips = [[
                floatingips["floating_ip_address"],
                floatingips["created_at"],
                floatingips["status"],
            ] for floatingips in network_lib.get_floatingips()]
            if len(data_floatingips) == 0:
                utils.log_err("No Data...")
                print(self.__doc__)
                exit()
            print(
                tabulate(
                    data_floatingips,
                    headers=["IP Address", "Created at", "Status"],
                    tablefmt="grid",
                ))
            exit()

        if self.args["--outputs"]:
            stack_name = self.args["--outputs"].split(".")
            if len(stack_name) is 1:
                for meta in orch.get_meta_stack(stack_name[0]):
                    print(meta["output_key"], " :")
                    print(meta["output_value"])
                    print("")
            if len(stack_name) is 2:
                print(orch.get_metadata(stack_name[0], stack_name[1]))
            exit()

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

        if not default_file:
            utils.log_err("Oops!! Can't find neo.yml manifest file!")
            print(self.__doc__)
            exit()

        projects = utils.get_project(default_file)

        project_list = list()
        for project in projects:
            proj = orch.get_stack(project)
            if proj:
                project_list.append(proj)

        if len(project_list) > 0:
            print(tabulate(project_list, headers=headers, tablefmt="grid"))
        else:
            utils.log_err("No Data...")
            print(self.__doc__)
示例#3
0
文件: ls.py 项目: sdmoko/neo-cli
    def execute(self):
        headers = ["ID", "Name", "Status", "Created", "Updated"]
        if self.args["stack"]:
            print(tabulate(orch.get_list(), headers=headers, tablefmt="grid"))
            exit()

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

        if self.args["vm"]:
            data_instance = list()
            for instance in vm_lib.get_list():
                pre_instance = [instance.id, instance.name]
                pre_instance.append(image.detail(instance.image["id"]).name)
                flavors = vm_lib.detail_flavor(instance.flavor["id"])
                flavors_name = flavors.name
                flavors_vcpu = flavors.vcpus
                flavors_ram = bitmath.MiB(flavors.ram).to_GiB().best_prefix()
                pre_instance.append(flavors_name)
                pre_instance.append(flavors_ram)
                pre_instance.append(flavors_vcpu)

                # Address
                addr = list()
                addr_objs = utils.get_index(instance.addresses)
                if len(addr_objs) > 0:
                    for addr_obj in addr_objs:
                        addr.append("network : {}".format(addr_obj))
                        for addr_ip in instance.addresses[addr_obj]:
                            addr_meta = "{} IP : {}".format(
                                addr_ip["OS-EXT-IPS:type"], addr_ip["addr"])
                            addr.append(addr_meta)
                if len(addr) > 0:
                    pre_instance.append("\n".join(addr))
                else:
                    pre_instance.append("")

                pre_instance.append(instance.status)
                data_instance.append(pre_instance)

            if len(data_instance) == 0:
                utils.log_err("No Data...")
                print(self.__doc__)
                exit()
            print(
                tabulate(
                    data_instance,
                    headers=[
                        "ID", "Name", "Image", "Flavor", "RAM (GiB)", "vCPU",
                        "Addresses", "Status"
                    ],
                    tablefmt="grid"))
            exit()

        if self.args["network"]:
            data_network = [[
                network['id'], network['name'], network['status']
            ] for network in network_lib.get_list()]
            if len(data_network) == 0:
                utils.log_err("No Data...")
                print(self.__doc__)
                exit()
            print(
                tabulate(
                    data_network,
                    headers=["ID", "Name", "Status"],
                    tablefmt="grid"))
            exit()

        if self.args["--outputs"]:
            stack_name = self.args["--outputs"].split(".")
            if len(stack_name) is 1:
                for meta in orch.get_meta_stack(stack_name[0]):
                    print(meta["output_key"], " :")
                    print(meta["output_value"])
                    print("")
            if len(stack_name) is 2:
                print(orch.get_metadata(stack_name[0], stack_name[1]))
            exit()

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

        if not default_file:
            utils.log_err("Oops!! Can't find neo.yml manifest file!")
            print(self.__doc__)
            exit()

        projects = utils.get_project(default_file)

        project_list = list()
        for project in projects:
            proj = orch.get_stack(project)
            if proj:
                project_list.append(proj)

        if len(project_list) > 0:
            print(tabulate(project_list, headers=headers, tablefmt="grid"))
        else:
            utils.log_err("No Data...")
            print(self.__doc__)
示例#4
0
    def execute(self):
        if self.args["--template"]:
            if self.args["--template"] in ("clusters", "instances", "networks"):
                tmpl = self.args["--template"]

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

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

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

        headers = ["ID", "Name", "Status", "Created", "Updated"]

        set_file = self.args["--file"]
        default_file = orch.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 neo.yml manifest file!")
            q_stack = utils.question("Do you want to generate neo.yml manifest? ")

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

        deploy_init = orch.initialize(default_file)
        try:
            orch.do_create(deploy_init)
        except Exception as e:
            utils.log_err(e)
            utils.log_err("Deploying Stack failed...")
            exit()

        projects = utils.get_project(default_file)

        project_list = list()
        for project in projects:
            proj = orch.get_stack(project)
            if proj:
                project_list.append(proj)

        if len(project_list) > 0:
            print(tabulate(project_list, headers=headers, tablefmt="grid"))
示例#5
0
文件: create.py 项目: sdmoko/neo-cli
    def execute(self):
        if self.args["--template"]:
            if self.args["--template"] in ('clusters', 'instances',
                                           'networks'):
                tmpl = self.args["--template"]

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

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

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

        headers = ["ID", "Name", "Status", "Created", "Updated"]

        set_file = self.args["--file"]
        default_file = orch.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 neo.yml manifest file!")
            q_stack = utils.question(
                "Do you want to generate neo.yml manifest? ")

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

        deploy_init = orch.initialize(default_file)
        try:
            orch.do_create(deploy_init)
        except Exception as e:
            utils.log_err(e)
            utils.log_err("Deploying Stack failed...")
            exit()

        projects = utils.get_project(default_file)

        project_list = list()
        for project in projects:
            proj = orch.get_stack(project)
            if proj:
                project_list.append(proj)

        if len(project_list) > 0:
            print(tabulate(project_list, headers=headers, tablefmt="grid"))