当前位置: 首页>>代码示例>>Python>>正文


Python Printer.Printer类代码示例

本文整理汇总了Python中cloudmesh_client.common.Printer.Printer的典型用法代码示例。如果您正苦于以下问题:Python Printer类的具体用法?Python Printer怎么用?Python Printer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Printer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: details

    def details(self, kind, category, id, format="table"):

        from cloudmesh_client.db.CloudmeshDatabase import CloudmeshDatabase

        cm = CloudmeshDatabase()

        try:
            if kind not in self.kind:
                raise ValueError('{} not defined'.format(kind))

            elements = None
            for idkey in ["cm_id", "name", "uuid", "id", "cm_id"]:
                s = {idkey: id}
                try:
                    elements = cm.find(kind=kind, category=category, **s)
                except:
                    pass
                if elements is not None:
                    break

            if elements is None:
                return None

            if len(elements) > 0:
                element = elements[0]
                if format == "table":
                    return Printer.attribute(element)
                else:
                    return Printer.write(element,
                                         output=format)
            else:
                return None

        except Exception as ex:
            Console.error(ex.message)
开发者ID:arpiagariu,项目名称:client,代码行数:35,代码来源:CloudProviderBase.py

示例2: export

        def export(host, output):
            config = ConfigDict("cloudmesh.yaml")
            credentials = dict(
                config["cloudmesh"]["clouds"][host]["credentials"])

            if not arguments["--password"]:
                credentials["OS_PASSWORD"] = "********"

            if output is None:
                for attribute, value in credentials.items():
                    print("export {}={}".format(attribute, value))
            elif output == "table":
                print(Printer.attribute(credentials))
            else:
                print(Printer.write(credentials, output=output))
开发者ID:cloudmesh,项目名称:client,代码行数:15,代码来源:RegisterCommand.py

示例3: list

 def list(self, format='dict', sort_keys=True, order=None):
     if order is None:
         order = self.order
     return Printer.write(self.data,
                          order=order,
                          output=format,
                          sort_keys=sort_keys)
开发者ID:arpiagariu,项目名称:client,代码行数:7,代码来源:inventory.py

示例4: get_info

    def get_info(cls, category="general", name=None, output="table"):
        """
        Method to get info about a group
        :param cloud:
        :param name:
        :param output:
        :return:
        """

        try:
            cloud = category or Default.cloud

            args = {
                "category": category
            }

            if name is not None:
                args["name"] = name

            group = cls.cm.find(kind="group", output="dict", **args)

            return Printer.write(group,
                                 order=cls.order,
                                 output=output)
        except Exception as ex:
            Console.error(ex.message)
开发者ID:arpiagariu,项目名称:client,代码行数:26,代码来源:group.py

示例5: list

    def list(cls,
             order=None,
             header=None,
             output='table'):
        """
        lists the default values in the specified format.
        TODO: This method has a bug as it uses format and output,
        only one should be used.

        :param category: the category of the default value. If general is used
                      it is a special category that is used for global values.
        :param format: json, table, yaml, dict, csv
        :param order: The order in which the attributes are returned
        :param output: The output format.
        :return:
        """
        if order is None:
            order, header = None, None
            # order, header = Attributes(cls.__kind__, provider=cls.__provider__)
        try:
            result = cls.cm.all(provider=cls.__provider__, kind=cls.__kind__)

            return (Printer.write(result,
                                  order=order,
                                  output=output))
        except Exception as e:
            Console.error("Error creating list", traceflag=False)
            Console.error(e.message)
            return None
开发者ID:arpiagariu,项目名称:client,代码行数:29,代码来源:var.py

示例6: dict_choice

def dict_choice(d):
    if d is None:
        return None

    elements = dict(d)
    i = 1
    for e in d:
        elements[e]["id"] = i
        i += 1
    #   pprint(d)
    if elements != {}:
        # noinspection PyPep8
        print(Printer.write(elements,
                            order=["id",
                                  "name",
                                  "comment",
                                  "uri",
                                  "fingerprint",
                                  "source"],
                            output="table",
                            sort_keys=True))
    else:
        print("ERROR: No keys in the database")
        return

    n = num_choice(i - 1, tries=10) + 1
    element = None
    for e in elements:
        if str(elements[e]["id"]) is str(n):
            element = elements[e]
            break
    return element
开发者ID:arpiagariu,项目名称:client,代码行数:32,代码来源:menu.py

示例7: list_unused_floating_ip

    def list_unused_floating_ip(cls, cloudname, output='table'):
        """
        Method to list unused floating ips
        These floating ips are not associated with any instance
        :param cloudname:
        :return: floating ip list
        """
        try:
            # fetch unused floating ips
            floating_ips = cls.get_unused_floating_ip_list(cloudname)

            # print the output
            return Printer.write(floating_ips,
                                 order=[
                                     "ip",
                                     "pool",
                                     "id",
                                     "cloud"
                                 ],
                                 header=[
                                     "floating_ip",
                                     "floating_ip_pool",
                                     "floating_ip_id",
                                     "cloud"
                                 ],
                                 output=output)
        except Exception as ex:
            Console.error(ex.message)

        return
开发者ID:arpiagariu,项目名称:client,代码行数:30,代码来源:network.py

示例8: list

    def list(cls,
             category=None,
             order=None,
             output='table'):
        """
        lists the default values in the specified format.
        TODO: This method has a bug as it uses format and output,
        only one should be used.

        :param category: the category of the default value. If general is used
                      it is a special category that is used for global values.
        :param order: The order in which the attributes are returned
        :param output: The output format. json, table, yaml, dict, csv
        :return:
        """

        # if order is None:
        #    # (order, header) = CloudProvider(category).get_attributes("default")
        try:
            if category is None:
                d = cls.cm.all("default")
            else:
                d = cls.cm.find('default', category=category)
            return (Printer.dict_printer(d,
                                         order=order,
                                         output=output))
        except:
            return None
开发者ID:ashwinir20,项目名称:client,代码行数:28,代码来源:ListResource.py

示例9: list

    def list(cls, name, live=False, format="table"):
        """
        This method lists all workflows of the cloud
        :param cloud: the cloud name
        """

        # Console.TODO("this method is not yet implemented")
        # return

        try:

            elements = cls.cm.find(kind="workflow", category='general')

            # pprint(elements)

            # (order, header) = CloudProvider(cloud).get_attributes("workflow")
            order = None
            header= None
            # Console.msg(elements)
            return Printer.write(elements,
                                 order=order,
                                 header=header,
                                 output=format)
        except Exception as ex:
            Console.error(ex.message)
开发者ID:ashwinir20,项目名称:client,代码行数:25,代码来源:workflow.py

示例10: get

    def get(cls, **kwargs):
        """
        This method queries the database to fetch group(s)
        with given name filtered by cloud.
        :param name:
        :param cloud:
        :return:
        """

        query = dict(kwargs)

        if 'output' in kwargs:
            for key, value in kwargs.items():
                if value is None:
                    query[key] = "None"
            del query['output']
        try:

            print("QQQ"), query
            group = cls.cm.find(kind="group", **query)
            print("gggg", group)
            if group is not None \
                    and "output" in kwargs:
                d = {"0": group}
                group = Printer.write(d)
            return group

        except Exception as ex:
            Console.error(ex.message)
开发者ID:arpiagariu,项目名称:client,代码行数:29,代码来源:group.py

示例11: list

    def list(cls, cloud=None, names=None, output='table', live=False):

        try:

            if live:
                cls.refresh(cloud)

            elements = cls.cm.find(kind="vm", category=cloud)
            result = []
            if "all" in names:
                for element in elements:
                    result.append(element)
            elif names is not None:
                for element in elements:
                    if element["name"] in names:
                        result.append(element)

            (order, header) = CloudProvider(cloud).get_attributes("ip")

            return Printer.write(result,
                                 order=order,
                                 header=header,
                                 output=output)
        except Exception as ex:
            Console.error(ex.message)
开发者ID:arpiagariu,项目名称:client,代码行数:25,代码来源:ip.py

示例12: list

 def list(cls, category=None, live=False, output="table"):
     "this does not work only returns all ceys in the db"
     (order, header) = CloudProvider(category).get_attributes("key")
     d = cls.cm.find(kind="key", scope="all", output=output)
     return Printer.write(d,
                          order=order,
                          header=header,
                          output=output)
开发者ID:arpiagariu,项目名称:client,代码行数:8,代码来源:key.py

示例13: list

    def list(cls, cloud, start=None, end=None, tenant=None, format="table"):
        # set the environment variables
        set_os_environ(cloud)

        try:
            # execute the command
            args = ["usage"]
            if start is not None:
                args.extend(["--start", start])
            if end is not None:
                args.extend(["--end", end])
            if tenant is not None:
                args.extend(["--tenant", tenant])

            result = Shell.execute("nova", args)
            result = Nova.remove_subjectAltName_warning(result)

            lines = result.splitlines()
            dates = lines[0]

            # TODO: as stated below, nova returns additional lines,
            # on my pc, SecurityWarning is returned, so filtering..

            for l in lines[1:]:
                if l.__contains__("SecurityWarning"):
                    lines.remove(l)

            table = '\n'.join(lines[1:])

            dates = dates.replace("Usage from ", "").replace("to", "").replace(" +", " ")[:-1].split()

            #
            # TODO: for some reason the nova command has returned not the
            # first + char, so we could not ignore the line we may set - as
            # additional comment char, but that did not work
            #

            d = TableParser.convert(table, comment_chars="+#")

            # d["0"]["start"] = "start"
            # d["0"]["end"] = "end"

            d["0"]["start"] = dates[0]
            d["0"]["end"] = dates[1]

            # del d['0']

            return Printer.write(d,
                                 order=["start",
                                        "end",
                                        "servers",
                                        "cpu hours",
                                        "ram mb-hours",
                                        "disk gb-hours"],
                                 output=format)

        except Exception as e:
            return e
开发者ID:arpiagariu,项目名称:client,代码行数:58,代码来源:usage.py

示例14: details

 def details(cls, cloud, id, live=False, format="table"):
     elements = cls.cm.find(kind="workflow", category='general' ,cm_id =id)
     Console.msg(elements)
     order = None
     header= None
     # Console.TODO("this method is not yet implemented")
     return Printer.write(elements,
                              order=order,
                              header=header,
                              output=format)
开发者ID:ashwinir20,项目名称:client,代码行数:10,代码来源:workflow.py

示例15: boot_from_args

def boot_from_args(arg):
    arg.username = arg.username or Image.guess_username(arg.image)
    is_name_provided = arg.name is not None

    arg.user = Default.user

    for index in range(0, arg.count):
        vm_details = dotdict({
            "cloud": arg.cloud,
            "name": Vm.get_vm_name(arg.name, index),
            "image": arg.image,
            "flavor": arg.flavor,
            "key": arg.key,
            "secgroup": arg.secgroup,
            "group": arg.group,
            "username": arg.username,
            "user": arg.user
        })
        # correct the username
        vm_details.username = Image.guess_username_from_category(
            vm_details.cloud,
            vm_details.image,
            username=arg.username)
        try:

            if arg.dryrun:
                print(Printer.attribute(vm_details, output=arg.format))
                msg = "dryrun info. OK."
                Console.ok(msg)
            else:
                vm_id = Vm.boot(**vm_details)

                if vm_id is None:
                    msg = "info. failed."
                    Console.error(msg, traceflag=False)
                    return ""

                # set name and counter in defaults
                Default.set_vm(value=vm_details.name)
                if is_name_provided is False:
                    Default.incr_counter("name")

                # Add to group
                if vm_id is not None:
                    Group.add(name=vm_details.group,
                              species="vm",
                              member=vm_details.name,
                              category=vm_details.cloud)

                msg = "info. OK."
                Console.ok(msg)

        except Exception as e:
            Console.error("Problem booting instance {name}".format(**vm_details), traceflag=False)
开发者ID:pombredanne,项目名称:client-6,代码行数:54,代码来源:ClusterCommand.py


注:本文中的cloudmesh_client.common.Printer.Printer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。