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


Python hookenv.ERROR属性代码示例

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


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

示例1: mount_device

# 需要导入模块: from charmhelpers.core import hookenv [as 别名]
# 或者: from charmhelpers.core.hookenv import ERROR [as 别名]
def mount_device(device: Device, mount_point: str) -> Result:
    """
    mount a device at a mount point
    :param device: Device.
    :param mount_point: str.  Place to mount to.
    :return: Result with Ok or Err
    """
    arg_list = []
    if device.id:
        arg_list.append("-U")
        arg_list.append(str(device.id))
    else:
        arg_list.append("/dev/{}".format(device.name))

    arg_list.append(mount_point)

    cmd = ["mount"]
    cmd.extend(arg_list)
    try:
        output = subprocess.check_output(cmd, stderr=subprocess.PIPE)
        return Ok(output.decode('utf-8'))
    except subprocess.CalledProcessError as e:
        log("subprocess failed stdout: {} stderr: {} returncode: {}".format(
            e.stdout, e.stderr, e.returncode), ERROR)
        return Err(e.output) 
开发者ID:openstack,项目名称:charm-glusterfs,代码行数:27,代码来源:block.py

示例2: quota_list

# 需要导入模块: from charmhelpers.core import hookenv [as 别名]
# 或者: from charmhelpers.core.hookenv import ERROR [as 别名]
def quota_list(vol_name: str) -> Result:
    """
    Return a list of quotas on the volume if any
    Enable bitrot detection and remediation on the volume
    volume: String.  The volume to operate on.
    :return: List of Quota's on the volume
    :raises: GlusterError if the command fails to run
    """
    cmd = ["gluster", "volume", "quota", vol_name, "list", "--xml"]
    try:
        output = subprocess.check_output(cmd, stderr=subprocess.PIPE)
        quota_list_result = parse_quota_list(output.decode('utf-8'))
        return quota_list_result
    except subprocess.CalledProcessError as e:
        log("subprocess failed stdout: {} stderr: {} returncode: {}".format(
            e.stdout, e.stderr, e.returncode), ERROR)
        return Err("Volume quota list command failed with error: {}".format(
            e.stderr)) 
开发者ID:openstack,项目名称:charm-glusterfs,代码行数:20,代码来源:volume.py

示例3: configure_designate_full

# 需要导入模块: from charmhelpers.core import hookenv [as 别名]
# 或者: from charmhelpers.core.hookenv import ERROR [as 别名]
def configure_designate_full(*args):
    """Write out all designate config include bootstrap domain info"""
    # If cluster relation is available it needs to passed in
    cluster = reactive.RelationBase.from_state('cluster.available')
    if cluster is not None:
        args = args + (cluster, )
    dns_backend = reactive.RelationBase.from_state('dns-backend.available')
    if dns_backend is not None:
        args = args + (dns_backend, )
    with provide_charm_instance() as instance:
        instance.upgrade_if_available(args)
        instance.configure_ssl()
        instance.render_full_config(args)
        try:
            # the following function should only run once for the leader.
            instance.create_initial_servers_and_domains()
            _render_sink_configs(instance, args)
            instance.render_rndc_keys()
            instance.update_pools()
        except subprocess.CalledProcessError as e:
            hookenv.log("ensure_api_responding() errored out: {}"
                        .format(str(e)),
                        level=hookenv.ERROR) 
开发者ID:openstack,项目名称:charm-designate,代码行数:25,代码来源:designate_handlers.py

示例4: vol_set

# 需要导入模块: from charmhelpers.core import hookenv [as 别名]
# 或者: from charmhelpers.core.hookenv import ERROR [as 别名]
def vol_set(vol_name: str, options: Dict[str, str]) -> None:
    """
    :param vol_name: String. Volume name to set the option on
    :param options: GlusterOption
    :return: Result.  Return code and output of cmd
    """
    try:
        volume.optset(volname=vol_name, opts=options)
    except GlusterCmdException as e:
        log("volume.optset failed: {}".format(e), ERROR)
        raise 
开发者ID:openstack,项目名称:charm-glusterfs,代码行数:13,代码来源:volume.py

示例5: fuse_relation_joined

# 需要导入模块: from charmhelpers.core import hookenv [as 别名]
# 或者: from charmhelpers.core.hookenv import ERROR [as 别名]
def fuse_relation_joined():
    # Fuse clients only need one ip address and they can discover the rest
    """

    """
    public_addr = unit_public_ip()
    volumes = volume_list()
    if volumes.is_err():
        log("volume list is empty.  Unable to complete fuse relation", ERROR)
        return
    data = {"gluster-public-address": public_addr,
            "volumes": " ".join(volumes.value)}
    relation_set(relation_settings=data) 
开发者ID:openstack,项目名称:charm-glusterfs,代码行数:15,代码来源:fuse_relation_joined.py

示例6: add_node

# 需要导入模块: from charmhelpers.core import hookenv [as 别名]
# 或者: from charmhelpers.core.hookenv import ERROR [as 别名]
def add_node(self, host, executors, labels=()):
        """Add a slave node with the given host name."""
        self.wait()

        client = self._make_client()

        @retry_on_exception(3, 3, exc_type=RETRIABLE)
        def _add_node():
            if client.node_exists(host):
                hookenv.log("Node exists - not adding")
                return

            hookenv.log("Adding node '%s' to Jenkins master" % host)

            # See the "Launch slave agent headlessly" section of the Jenkins
            # wiki page about distributed builds:
            #
            # https://wiki.jenkins-ci.org/display/JENKINS/Distributed+builds
            launcher = jenkins.LAUNCHER_JNLP

            client.create_node(
                host, int(executors), host, labels=labels, launcher=launcher)

            if not client.node_exists(host):
                hookenv.log(
                    "Failed to create node '%s'" % host, level=ERROR)

        return _add_node() 
开发者ID:jenkinsci,项目名称:jenkins-charm,代码行数:30,代码来源:api.py

示例7: render_rndc_keys

# 需要导入模块: from charmhelpers.core import hookenv [as 别名]
# 或者: from charmhelpers.core.hookenv import ERROR [as 别名]
def render_rndc_keys(self):
        """Render the rndc keys supplied via user config

        @returns None
        """
        slaves = hookenv.config('dns-slaves') or ''
        try:
            for entry in slaves.split():
                address, port, key = entry.split(':')
                unit_name = address.replace('.', '_')
                self.write_key_file(unit_name, key)
        except ValueError as e:
            hookenv.log("Problem with 'dns-slaves' config: {}"
                        .format(str(e)), level=hookenv.ERROR) 
开发者ID:openstack,项目名称:charm-designate,代码行数:16,代码来源:designate.py

示例8: test_logs_messages_with_alternative_levels

# 需要导入模块: from charmhelpers.core import hookenv [as 别名]
# 或者: from charmhelpers.core.hookenv import ERROR [as 别名]
def test_logs_messages_with_alternative_levels(self, mock_call):
        alternative_levels = [
            hookenv.CRITICAL,
            hookenv.ERROR,
            hookenv.WARNING,
            hookenv.INFO,
        ]

        for level in alternative_levels:
            hookenv.log('foo', level)
            mock_call.assert_called_with(['juju-log', '-l', level, 'foo']) 
开发者ID:juju,项目名称:charm-helpers,代码行数:13,代码来源:test_hookenv.py

示例9: render

# 需要导入模块: from charmhelpers.core import hookenv [as 别名]
# 或者: from charmhelpers.core.hookenv import ERROR [as 别名]
def render(source, target, context, owner='root', group='root',
           perms=0o444, templates_dir=None, encoding='UTF-8', template_loader=None):
    """
    Render a template.

    The `source` path, if not absolute, is relative to the `templates_dir`.

    The `target` path should be absolute.  It can also be `None`, in which
    case no file will be written.

    The context should be a dict containing the values to be replaced in the
    template.

    The `owner`, `group`, and `perms` options will be passed to `write_file`.

    If omitted, `templates_dir` defaults to the `templates` folder in the charm.

    The rendered template will be written to the file as well as being returned
    as a string.

    Note: Using this requires python-jinja2; if it is not installed, calling
    this will attempt to use charmhelpers.fetch.apt_install to install it.
    """
    try:
        from jinja2 import FileSystemLoader, Environment, exceptions
    except ImportError:
        try:
            from charmhelpers.fetch import apt_install
        except ImportError:
            hookenv.log('Could not import jinja2, and could not import '
                        'charmhelpers.fetch to install it',
                        level=hookenv.ERROR)
            raise
        apt_install('python-jinja2', fatal=True)
        from jinja2 import FileSystemLoader, Environment, exceptions

    if template_loader:
        template_env = Environment(loader=template_loader)
    else:
        if templates_dir is None:
            templates_dir = os.path.join(hookenv.charm_dir(), 'templates')
        template_env = Environment(loader=FileSystemLoader(templates_dir))
    try:
        source = source
        template = template_env.get_template(source)
    except exceptions.TemplateNotFound as e:
        hookenv.log('Could not load template %s from %s.' %
                    (source, templates_dir),
                    level=hookenv.ERROR)
        raise e
    content = template.render(context)
    if target is not None:
        target_dir = os.path.dirname(target)
        if not os.path.exists(target_dir):
            # This is a terrible default directory permission, as the file
            # or its siblings will often contain secrets.
            host.mkdir(os.path.dirname(target), owner, group, perms=0o755)
        host.write_file(target, content.encode(encoding), owner, group, perms)
    return content 
开发者ID:openstack,项目名称:charm-plumgrid-gateway,代码行数:61,代码来源:templating.py

示例10: get_config

# 需要导入模块: from charmhelpers.core import hookenv [as 别名]
# 或者: from charmhelpers.core.hookenv import ERROR [as 别名]
def get_config():
    '''Gather and sanity-check volume configuration data'''
    volume_config = {}
    config = hookenv.config()

    errors = False

    if config.get('volume-ephemeral') in (True, 'True', 'true', 'Yes', 'yes'):
        volume_config['ephemeral'] = True
    else:
        volume_config['ephemeral'] = False

    try:
        volume_map = yaml.safe_load(config.get('volume-map', '{}'))
    except yaml.YAMLError as e:
        hookenv.log("Error parsing YAML volume-map: {}".format(e),
                    hookenv.ERROR)
        errors = True
    if volume_map is None:
        # probably an empty string
        volume_map = {}
    elif not isinstance(volume_map, dict):
        hookenv.log("Volume-map should be a dictionary, not {}".format(
            type(volume_map)))
        errors = True

    volume_config['device'] = volume_map.get(os.environ['JUJU_UNIT_NAME'])
    if volume_config['device'] and volume_config['ephemeral']:
        # asked for ephemeral storage but also defined a volume ID
        hookenv.log('A volume is defined for this unit, but ephemeral '
                    'storage was requested', hookenv.ERROR)
        errors = True
    elif not volume_config['device'] and not volume_config['ephemeral']:
        # asked for permanent storage but did not define volume ID
        hookenv.log('Ephemeral storage was requested, but there is no volume '
                    'defined for this unit.', hookenv.ERROR)
        errors = True

    unit_mount_name = hookenv.local_unit().replace('/', '-')
    volume_config['mountpoint'] = os.path.join(MOUNT_BASE, unit_mount_name)

    if errors:
        return None
    return volume_config 
开发者ID:openstack,项目名称:charm-swift-proxy,代码行数:46,代码来源:volumes.py

示例11: check_for_upgrade

# 需要导入模块: from charmhelpers.core import hookenv [as 别名]
# 或者: from charmhelpers.core.hookenv import ERROR [as 别名]
def check_for_upgrade() -> Result:
    """
    If the config has changed this will initiated a rolling upgrade

    :return:
    """
    config = hookenv.config()
    if not config.changed("source"):
        # No upgrade requested
        log("No upgrade requested")
        return Ok(())

    log("Getting current_version")
    current_version = get_glusterfs_version()

    log("Adding new source line")
    source = config["source"]
    if not source:
        # No upgrade requested
        log("Source not set.  Cannot continue with upgrade")
        return Ok(())
    add_source(source)
    log("Calling apt update")
    apt_update()

    log("Getting proposed_version")
    apt_pkg.init_system()
    proposed_version = get_candidate_package_version("glusterfs-server")
    if proposed_version.is_err():
        return Err(proposed_version.value)
    version_compare = apt_pkg.version_compare(a=proposed_version.value,
                                              b=current_version)

    # Using semantic versioning if the new version is greater
    # than we allow the upgrade
    if version_compare > 0:
        log("current_version: {}".format(current_version))
        log("new_version: {}".format(proposed_version.value))
        log("{} to {} is a valid upgrade path.  Proceeding.".format(
            current_version, proposed_version.value))
        return roll_cluster(proposed_version.value)
    else:
        # Log a helpful error message
        log("Invalid upgrade path from {} to {}. The new version needs to be \
                            greater than the old version".format(
            current_version, proposed_version.value), ERROR)
        return Ok(()) 
开发者ID:openstack,项目名称:charm-glusterfs,代码行数:49,代码来源:upgrade.py


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