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


Python Utils.get_singular_name方法代码示例

本文整理汇总了Python中utils.Utils.get_singular_name方法的典型用法代码示例。如果您正苦于以下问题:Python Utils.get_singular_name方法的具体用法?Python Utils.get_singular_name怎么用?Python Utils.get_singular_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在utils.Utils的用法示例。


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

示例1: objects

# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import get_singular_name [as 别名]
    def objects(cls, args):
        """ List all objects of the VSD

        """
        inspector = VSDKInspector(args.version)
        objects = []

        if args.parent:
            name = Utils.get_singular_name(args.parent)
            instance = inspector.get_vsdk_instance(name)

            objects = [Utils.get_plural_name(name) for name in instance.children_rest_names]
        else:
            objects = inspector.get_all_objects()

        if args.child:
            child = Utils.get_singular_name(args.child)
            parents = []
            for name in objects:
                singular_name = Utils.get_singular_name(name)
                instance = inspector.get_vsdk_instance(singular_name)

                if child in instance.children_rest_names:
                    parents.append(name)

            objects = parents

        if args.filter:
            objects = [name for name in objects if args.filter in name]

        objects.sort()

        if not args.json:
            Printer.success('%s objects found.' % len(objects))
        Printer.output(objects, json=args.json, headers={'Name'})
开发者ID:nuagenetworks,项目名称:vsdcli,代码行数:37,代码来源:commands.py

示例2: count

# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import get_singular_name [as 别名]
    def count(cls, args):
        """ Count all objects

        """
        inspector = VSDKInspector(args.version)
        name = Utils.get_singular_name(args.name)
        instance = inspector.get_vsdk_instance(name)
        session = inspector.get_user_session(args)
        parent = inspector.get_vsdk_parent(args.parent_infos, session.user)

        classname = instance.__class__.__name__[2:]
        plural_classname = Utils.get_plural_name(classname)
        fetcher_name = Utils.get_python_name(plural_classname)

        try:
            fetcher = getattr(parent, fetcher_name)
        except:

            if parent.rest_name == 'me':
                parent_name = 'Root'
                error_message = '%s failed to found children %s. Maybe you forgot to specify the parent using `--in [parent] [ID]` syntax ?' % (parent_name, fetcher_name)
            else:
                parent_name = parent.rest_name
                error_message = '%s failed to found children %s. You can use command `vsd objects -c %s` to list all possible parents' % (parent_name, fetcher_name, fetcher_name)

            Printer.raise_error(error_message)

        (fetcher, parent, count) = fetcher.count(filter=args.filter)

        if not args.json:
            Printer.success('%s %s have been retrieved' % (count, instance.rest_resource_name))
        Printer.output({instance.rest_resource_name: count}, fields=[instance.rest_resource_name], json=args.json)
开发者ID:nuagenetworks,项目名称:vsdcli,代码行数:34,代码来源:commands.py

示例3: delete

# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import get_singular_name [as 别名]
    def delete(cls, args):
        """ Delete an existing object


        """
        inspector = VSDKInspector(args.version)
        name = Utils.get_singular_name(args.name)
        instance = inspector.get_vsdk_instance(name)
        instance.id = args.id

        inspector.get_user_session(args)

        try:
            (instance, connection) = instance.delete()
        except Exception, e:
            Printer.raise_error('Could not delete %s with id `%s`. Activate verbose mode for more information:\n%s' % (name, args.id, e))
开发者ID:nuagenetworks,项目名称:vsdcli,代码行数:18,代码来源:commands.py

示例4: update

# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import get_singular_name [as 别名]
    def update(cls, args):
        """ Update an existing object


        """
        inspector = VSDKInspector(args.version)
        name = Utils.get_singular_name(args.name)
        instance = inspector.get_vsdk_instance(name)
        instance.id = args.id
        attributes = cls._get_attributes(args.params)

        inspector.get_user_session(args)

        try:
            (instance, connection) = instance.fetch()
        except Exception, e:
            Printer.raise_error('Could not find %s with id `%s`. Activate verbose mode for more information:\n%s' % (name, args.id, e))
开发者ID:nuagenetworks,项目名称:vsdcli,代码行数:19,代码来源:commands.py

示例5: create

# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import get_singular_name [as 别名]
    def create(cls, args):
        """ Create an object

        """
        inspector = VSDKInspector(args.version)
        name = Utils.get_singular_name(args.name)
        instance = inspector.get_vsdk_instance(name)
        session = inspector.get_user_session(args)
        parent = inspector.get_vsdk_parent(args.parent_infos, session.user)
        attributes = cls._get_attributes(args.params)

        cls._fill_instance_with_attributes(instance, attributes)

        try:
            (instance, connection) = parent.create_child(instance)
        except Exception, e:
            Printer.raise_error('Cannot create %s:\n%s' % (name, e))
开发者ID:nuagenetworks,项目名称:vsdcli,代码行数:19,代码来源:commands.py

示例6: _internal_assign

# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import get_singular_name [as 别名]
    def _internal_assign(cls, args, method):
        """ Execute method to list final assignation

            Returns:
                (nb_affected_objects, assigned_objects_name, assigned_objects_ids, parent_name, parent_id)
        """
        inspector = VSDKInspector(args.version)

        name = Utils.get_singular_name(args.name)
        object_class = inspector.get_vsdk_class(name)
        object_type = object_class()

        session = inspector.get_user_session(args)
        resource = inspector.get_vsdk_parent(args.parent_infos, session.user)

        classname = object_class.__name__[2:]
        plural_classname = Utils.get_plural_name(classname)
        fetcher_name = Utils.get_python_name(plural_classname)

        try:
            fetcher = getattr(resource, fetcher_name)
        except:

            if resource.rest_name == 'me':
                resource_name = 'Root'

            error_message = '%s failed to found children %s.' % (resource_name, fetcher_name)
            Printer.raise_error(error_message)

        (fetcher, resource, current_objects) = fetcher.fetch()

        if current_objects is None:
            current_objects = []

        (final_objects, nb_affected_objects) = method(object_class, args.ids, current_objects)

        try:
            (references, connection) = resource.assign(final_objects, object_class)
        except Exception, e:
            Printer.raise_error('Cannot assign %s:\n%s' % (name, e))
开发者ID:nuagenetworks,项目名称:vsdcli,代码行数:42,代码来源:commands.py

示例7: show

# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import get_singular_name [as 别名]
    def show(cls, args):
        """ Show object details

            Args:
                uuid: Identifier of the object to show
        """

        inspector = VSDKInspector(args.version)
        session = inspector.get_user_session(args)

        name = Utils.get_singular_name(args.name)
        instance = inspector.get_vsdk_instance(name)

        instance.id = args.id

        if args.id == "me":
            instance.id = session.user.id

        try:
            (instance, connection) = instance.fetch()
        except Exception, e:
            Printer.raise_error('Could not find %s with id `%s`. Activate verbose mode for more information:\n%s' % (name, args.id, e))
开发者ID:nuagenetworks,项目名称:vsdcli,代码行数:24,代码来源:commands.py


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