• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python gettextutils._函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: image_valid_on_flavor_validator

    def image_valid_on_flavor_validator(config, clients, task):
        flavor_id = types.FlavorResourceType.transform(
            clients=clients,
            resource_config=config.get("args", {}).get(flavor_name))
        try:
            flavor = clients.nova().flavors.get(flavor=flavor_id)
        except nova_exc.NotFound:
            message = _("Flavor with id '%s' not found") % flavor_id
            return ValidationResult(False, message)

        image_id = types.ImageResourceType.transform(
            clients=clients,
            resource_config=config.get("args", {}).get(image_name))
        try:
            image = clients.glance().images.get(image=image_id)
        except glance_exc.HTTPNotFound:
            message = _("Image with id '%s' not found") % image_id
            return ValidationResult(False, message)

        if flavor.ram < (image.min_ram or 0):
            message = _("The memory size for flavor '%s' is too small "
                        "for requested image '%s'") % (flavor_id, image_id)
            return ValidationResult(False, message)

        if flavor.disk:
            if (image.size or 0) > flavor.disk * (1024 ** 3):
                message = _("The disk size for flavor '%s' is too small "
                            "for requested image '%s'") % (flavor_id, image_id)
                return ValidationResult(False, message)

            if (image.min_disk or 0) > flavor.disk:
                message = _("The disk size for flavor '%s' is too small "
                            "for requested image '%s'") % (flavor_id, image_id)
                return ValidationResult(False, message)
        return ValidationResult()
开发者ID:slashk,项目名称:rally,代码行数:35,代码来源:validation.py


示例2: to_bytes

def to_bytes(text, default=0):
    """Converts a string into an integer of bytes.

    Looks at the last characters of the text to determine
    what conversion is needed to turn the input text into a byte number.
    Supports "B, K(B), M(B), G(B), and T(B)". (case insensitive)

    :param text: String input for bytes size conversion.
    :param default: Default return value when text is blank.

    """
    match = BYTE_REGEX.search(text)
    if match:
        magnitude = int(match.group(1))
        mult_key_org = match.group(2)
        if not mult_key_org:
            return magnitude
    elif text:
        msg = _("Invalid string format: %s") % text
        raise TypeError(msg)
    else:
        return default
    mult_key = mult_key_org.lower().replace("b", "", 1)
    multiplier = BYTE_MULTIPLIERS.get(mult_key)
    if multiplier is None:
        msg = _("Unknown byte multiplier: %s") % mult_key_org
        raise TypeError(msg)
    return magnitude * multiplier
开发者ID:pombredanne,项目名称:rally,代码行数:28,代码来源:strutils.py


示例3: wrapper

 def wrapper(self, *args, **kwargs):
     params = {"msg": msg % kw, "obj_name": obj.title(),
               "uuid": getattr(self, obj)["uuid"]}
     log(_("%(obj_name)s %(uuid)s | Starting:  %(msg)s") % params)
     result = f(self, *args, **kwargs)
     log(_("%(obj_name)s %(uuid)s | Completed: %(msg)s") % params)
     return result
开发者ID:Frostman,项目名称:rally,代码行数:7,代码来源:utils.py


示例4: _load_img

 def _load_img(self):
     cirros_url = ('http://download.cirros-cloud.net/%s/%s' %
                   (CONF.image.cirros_version,
                    CONF.image.cirros_image))
     try:
         response = requests.get(cirros_url, stream=True)
     except requests.ConnectionError as err:
         msg = _('Error on downloading cirros image, possibly'
                 ' no connection to Internet with message %s') % str(err)
         raise TempestConfigCreationFailure(msg)
     if response.status_code == 200:
         with open(self.img_path + '.tmp', 'wb') as img_file:
             for chunk in response.iter_content(chunk_size=1024):
                 if chunk:   # filter out keep-alive new chunks
                     img_file.write(chunk)
                     img_file.flush()
         os.rename(self.img_path + '.tmp', self.img_path)
     else:
         if response.status_code == 404:
             msg = _('Error on downloading cirros image, possibly'
                     'invalid cirros_version or cirros_image in rally.conf')
         else:
             msg = _('Error on downloading cirros image, '
                     'HTTP error code %s') % response.getcode()
         raise TempestConfigCreationFailure(msg)
开发者ID:itskewpie,项目名称:rally,代码行数:25,代码来源:config.py


示例5: _validate_test_config

    def _validate_test_config(self, test_config):
        """Checks whether the given test config is valid and can be used during
        verification and benchmarking tests.

        :param test_config: Dictionary in the same format as for the __init__
                            method.

        :raises: Exception if the test config is not valid
        """
        task_uuid = self.task['uuid']
        # Perform schema validation
        try:
            jsonschema.validate(test_config, config.test_config_schema)
        except jsonschema.ValidationError as e:
            LOG.exception(_('Task %s: Error: %s') % (task_uuid, e.message))
            raise exceptions.InvalidConfigException(message=e.message)

        # Check for verification test names
        for test in test_config['verify']:
            if test not in self.verification_tests:
                LOG.exception(_('Task %s: Error: the specified '
                                'verification test does not exist: %s') %
                              (task_uuid, test))
                raise exceptions.NoSuchVerificationTest(test_name=test)
        # Check for benchmark scenario names
        benchmark_scenarios_set = set(self.benchmark_scenarios)
        for scenario in test_config['benchmark']:
            if scenario not in benchmark_scenarios_set:
                LOG.exception(_('Task %s: Error: the specified '
                                'benchmark scenario does not exist: %s') %
                              (task_uuid, scenario))
                raise exceptions.NoSuchScenario(name=scenario)
开发者ID:pombredanne,项目名称:rally,代码行数:32,代码来源:engine.py


示例6: _cleanup_users_resources

    def _cleanup_users_resources(self):
        for user in self.users:
            clients = osclients.Clients(user)
            admin_clients = osclients.Clients(self.admin)
            cleanup_methods = {
                "nova": functools.partial(utils.delete_nova_resources,
                                          clients.nova()),
                "glance": functools.partial(utils.delete_glance_resources,
                                            clients.glance(),
                                            clients.keystone().tenant_id),
                "cinder": functools.partial(utils.delete_cinder_resources,
                                            clients.cinder()),
                "quotas": functools.partial(utils.delete_quotas,
                                            admin_clients,
                                            clients.keystone().tenant_id)
            }

            for service in self.config:
                try:
                    cleanup_methods[service]()
                except Exception as e:
                    LOG.debug(_("Not all resources were cleaned."),
                              exc_info=sys.exc_info())
                    LOG.warning(_('Unable to fully cleanup the cloud: %s') %
                                (e.message))
开发者ID:Frostman,项目名称:rally,代码行数:25,代码来源:cleanup.py


示例7: setup

    def setup(self):
        self.verifier = tempest.Tempest(self.task.task.deployment_uuid)
        self.verifier.log_file = "/dev/null"

        try:
            if not self.verifier.is_installed():
                self.verifier.install()
            if not self.verifier.is_configured():
                self.verifier.generate_config_file()
        except exceptions.TempestSetupFailure:
            msg = _("Failing to install tempest.")
            LOG.error(msg)
            raise exceptions.BenchmarkSetupFailure(msg)
        except exceptions.TempestConfigCreationFailure:
            msg = _("Failing to configure tempest.")
            LOG.error(msg)
            raise exceptions.BenchmarkSetupFailure(msg)

        self.context["verifier"] = self.verifier

        # Create temporary directory for xml-results.
        self.results_dir = os.path.join(
            tempfile.gettempdir(), "%s-results" % self.task.task.uuid)
        os.mkdir(self.results_dir)
        self.context["tmp_results_dir"] = self.results_dir
开发者ID:RajalakshmiGanesan,项目名称:rally,代码行数:25,代码来源:tempest.py


示例8: get_image_uuid

    def get_image_uuid(self):
        """Get image uuid. Download image if necessary."""

        image_uuid = self.config['image'].get('uuid', None)
        if image_uuid:
            return image_uuid

        for image in self.glance.images.list():
            if image.checksum == self.config['image']['checksum']:
                LOG.info(_('Found image with appropriate checksum. Using it.'))
                return image.id

        LOG.info(_('Downloading new image %s') % self.config['image']['url'])
        image = self.glance.images.create(name=self.config['image']['name'])
        try:
            image.update(data=urllib2.urlopen(self.config['image']['url']),
                         disk_format=self.config['image']['format'],
                         container_format='bare')
        except urllib2.URLError:
            LOG.error(_('Unable to retrieve %s') % self.config['image']['url'])
            raise
        image.get()

        if image.checksum != self.config['image']['checksum']:
            raise exceptions.ChecksumMismatch(url=self.config['image']['url'])

        return image.id
开发者ID:hughsaunders,项目名称:rally,代码行数:27,代码来源:openstack.py


示例9: inner

 def inner(*args, **kwargs):
     try:
         with lock(name, lock_file_prefix, external, lock_path):
             LOG.debug(_('Got semaphore / lock "%(function)s"'), {"function": f.__name__})
             return f(*args, **kwargs)
     finally:
         LOG.debug(_('Semaphore / lock released "%(function)s"'), {"function": f.__name__})
开发者ID:RajalakshmiGanesan,项目名称:rally,代码行数:7,代码来源:lockutils.py


示例10: _cleanup_users_resources

    def _cleanup_users_resources(self):
        def _init_services_to_cleanup(cleanup_methods):
            scenario_name = self.context.get('scenario_name')
            if scenario_name:
                cls_name, method_name = scenario_name.split(".", 1)
                scenario = scenario_base.Scenario.get_by_name(cls_name)()
                scenario_method = getattr(scenario, method_name)
                if hasattr(scenario_method, "cleanup_services"):
                    return getattr(scenario_method, "cleanup_services")
            return cleanup_methods.keys()

        if not self.users:
            return

        for user in self.users:
            clients = osclients.Clients(user)
            cleanup_methods = {
                "nova": functools.partial(utils.delete_nova_resources,
                                          clients.nova()),
                "glance": functools.partial(utils.delete_glance_resources,
                                            clients.glance(),
                                            clients.keystone()),
                "cinder": functools.partial(utils.delete_cinder_resources,
                                            clients.cinder())
            }

            for service in _init_services_to_cleanup(cleanup_methods):
                try:
                    cleanup_methods[service]()
                except Exception as e:
                    LOG.debug(_("Not all resources were cleaned."),
                              exc_info=sys.exc_info())
                    LOG.warning(_('Unable to fully cleanup the cloud: %s') %
                                (e.message))
开发者ID:dlenwell,项目名称:rally,代码行数:34,代码来源:cleaner.py


示例11: required_openstack

def required_openstack(config, clients, task, admin=False, users=False):
    """Validator that requires OpenStack admin or (and) users.

    This allows us to create 4 kind of benchmarks:
    1) not OpenStack related (validator is not specified)
    2) requires OpenStack admin
    3) requires OpenStack admin + users
    4) requires OpenStack users

    :param admin: requires OpenStack admin
    :param users: requires OpenStack users
    """

    if not (admin or users):
        return ValidationResult(False, _("You should specify admin=True or users=True or both."))

    deployment = objects.Deployment.get(task["deployment_uuid"])

    if deployment["admin"] and deployment["users"]:
        return ValidationResult()

    if deployment["admin"]:
        if users and not config.get("context", {}).get("users"):
            return ValidationResult(False, _("You should specify 'users' context"))
        return ValidationResult()

    if deployment["users"] and admin:
        return ValidationResult(False, _("Admin credentials required"))

    return ValidationResult()
开发者ID:javacruft,项目名称:rally,代码行数:30,代码来源:validation.py


示例12: image_valid_on_flavor

def image_valid_on_flavor(config, clients, task, flavor_name, image_name):
    """Returns validator for image could be used for current flavor

    :param flavor_name: defines which variable should be used
                       to get flavor id value.
    :param image_name: defines which variable should be used
                       to get image id value.

    """
    valid_result, flavor = _get_validated_flavor(config, clients, flavor_name)
    if not valid_result.is_valid:
        return valid_result

    valid_result, image = _get_validated_image(config, clients, image_name)
    if not valid_result.is_valid:
        return valid_result

    if flavor.ram < (image.min_ram or 0):
        message = _("The memory size for flavor '%s' is too small "
                    "for requested image '%s'") % (flavor.id, image.id)
        return ValidationResult(False, message)

    if flavor.disk:
        if (image.size or 0) > flavor.disk * (1024 ** 3):
            message = _("The disk size for flavor '%s' is too small "
                        "for requested image '%s'") % (flavor.id, image.id)
            return ValidationResult(False, message)

        if (image.min_disk or 0) > flavor.disk:
            message = _("The disk size for flavor '%s' is too small "
                        "for requested image '%s'") % (flavor.id, image.id)
            return ValidationResult(False, message)
    return ValidationResult()
开发者ID:bluejayKR,项目名称:rally,代码行数:33,代码来源:validation.py


示例13: _initialize_testr

 def _initialize_testr(self):
     if not os.path.isdir(os.path.join(self.tempest_path,
                                       ".testrepository")):
         msg = _("Test Repository initialization.")
         LOG.info(_("Starting: ") + msg)
         subprocess.check_call("%s testr init" % self.venv_wrapper,
                               shell=True, cwd=self.tempest_path)
         LOG.info(_("Completed: ") + msg)
开发者ID:KevinTsang,项目名称:rally,代码行数:8,代码来源:tempest.py


示例14: _cleanup_admin_resources

 def _cleanup_admin_resources(self):
     try:
         admin = osclients.Clients(self.admin)
         utils.delete_keystone_resources(admin.keystone())
     except Exception as e:
         LOG.debug(_("Not all resources were cleaned."),
                   exc_info=sys.exc_info())
         LOG.warning(_('Unable to fully cleanup keystone service: %s') %
                     (e.message))
开发者ID:Frostman,项目名称:rally,代码行数:9,代码来源:cleanup.py


示例15: wrapper

 def wrapper(*args, **kwargs):
     try:
         path = lock_path or os.environ.get("RALLY_LOCK_PATH")
         lock = lockfile.FileLock(os.path.join(path, lock_prefix))
         with lock:
             LOG.debug(_('Got lock "%s"') % f.__name__)
             return f(*args, **kwargs)
     finally:
         LOG.debug(_('Lock released "%s"') % f.__name__)
开发者ID:Ch00k,项目名称:rally,代码行数:9,代码来源:test_migrations.py


示例16: boot_runcommand_delete_server

    def boot_runcommand_delete_server(
        self,
        image_id,
        flavor_id,
        script,
        interpreter,
        network="private",
        username="ubuntu",
        ip_version=4,
        retries=60,
        port=22,
        **kwargs
    ):
        """Boot server, run a script that outputs JSON, delete server.

        Parameters:
        script: script to run on the server, must output JSON mapping metric
                names to values. See sample script below.
        network: Network to choose address to connect to instance from
        username: User to SSH to instance as
        ip_version: Version of ip protocol to use for connection

        returns: Dictionary containing two keys, data and errors. Data is JSON
                 data output by the script. Errors is raw data from the
                 script's standard error stream.


        Example Script in doc/samples/support/instance_dd_test.sh
        """
        server_name = self._generate_random_name(16)

        server = self._boot_server(server_name, image_id, flavor_id, key_name="rally_ssh_key", **kwargs)

        if network not in server.addresses:
            raise ValueError(
                "Can't find cloud network %(network)s, so cannot boot "
                "instance for Rally scenario boot-runcommand-delete. "
                "Available networks: %(networks)s" % (dict(network=network, networks=server.addresses.keys()))
            )
        server_ip = [ip for ip in server.addresses[network] if ip["version"] == ip_version][0]["addr"]
        ssh = sshutils.SSH(username, server_ip, port=port, pkey=self.clients("ssh_key_pair")["private"])
        ssh.wait()
        code, out, err = ssh.execute(interpreter, stdin=open(script, "rb"))
        if code:
            LOG.error(_("Error running script on instance via SSH. " "Error: %s") % err)
        try:
            out = json.loads(out)
        except ValueError:
            LOG.warning(_("Script %s did not output valid JSON. ") % script)

        self._delete_server(server)
        LOG.debug(
            _("Output streams from in-instance script execution: " "stdout: %(stdout)s, stderr: $(stderr)s")
            % dict(stdout=out, stderr=err)
        )
        return {"data": out, "errors": err}
开发者ID:ugvddm,项目名称:rally,代码行数:56,代码来源:servers.py


示例17: wait

 def wait(self, timeout=120, interval=1):
     """Wait for the host will be available via ssh."""
     start_time = time.time()
     while True:
         try:
             return self.execute('uname')
         except (socket.error, SSHError) as e:
             LOG.debug(_('Ssh is still unavailable: %r') % e)
             time.sleep(interval)
         if time.time() > (start_time + timeout):
             raise SSHTimeout(_('Timeout waiting for "%s"') % self.host)
开发者ID:mohitsethi,项目名称:rally,代码行数:11,代码来源:sshutils.py


示例18: required_services

def required_services(*args, **kwargs):
    """Check if specified services are available.

    :param args: list of servives names
    """
    available_services = kwargs.get("clients").services().values()
    for service in args:
        if service not in consts.Service:
            return ValidationResult(False, _("Unknown service: %s") % service)
        if service not in available_services:
            return ValidationResult(
                False, _("Service is not available: %s") % service)
开发者ID:KevinTsang,项目名称:rally,代码行数:12,代码来源:validation.py


示例19: required_services

def required_services(config, clients, task, *required_services):
    """Check if specified services are available.

    :param args: list of servives names
    """
    available_services = clients.services().values()
    for service in required_services:
        if service not in consts.Service:
            return ValidationResult(False, _("Unknown service: %s") % service)
        if service not in available_services:
            return ValidationResult(
                False, _("Service is not available: %s") % service)
开发者ID:slashk,项目名称:rally,代码行数:12,代码来源:validation.py


示例20: _cleanup_admin_resources

    def _cleanup_admin_resources(self):
        if not self.admin:
            return

        try:
            admin = utils.create_openstack_clients(self.admin)
            utils.delete_keystone_resources(admin["keystone"])
        except Exception as e:
            LOG.debug(_("Not all resources were cleaned."),
                      exc_info=sys.exc_info())
            LOG.warning(_('Unable to fully cleanup keystone service: %s') %
                        (e.message))
开发者ID:mohitsethi,项目名称:rally,代码行数:12,代码来源:cleaner.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python taskview.TaskView类代码示例发布时间:2022-05-26
下一篇:
Python db.deployment_list函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap