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


Python host.mkdir方法代码示例

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


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

示例1: test_creates_a_directory_if_it_doesnt_exist

# 需要导入模块: from charmhelpers.core import host [as 别名]
# 或者: from charmhelpers.core.host import mkdir [as 别名]
def test_creates_a_directory_if_it_doesnt_exist(self, os_, log,
                                                    getgrnam, getpwnam):
        uid = 123
        gid = 234
        owner = 'some-user'
        group = 'some-group'
        path = '/some/other/path/from/link'
        realpath = '/some/path'
        path_exists = False
        perms = 0o644

        getpwnam.return_value.pw_uid = uid
        getgrnam.return_value.gr_gid = gid
        os_.path.abspath.return_value = realpath
        os_.path.exists.return_value = path_exists

        host.mkdir(path, owner=owner, group=group, perms=perms)

        getpwnam.assert_called_with('some-user')
        getgrnam.assert_called_with('some-group')
        os_.path.abspath.assert_called_with(path)
        os_.path.exists.assert_called_with(realpath)
        os_.makedirs.assert_called_with(realpath, perms)
        os_.chown.assert_called_with(realpath, uid, gid) 
开发者ID:juju,项目名称:charm-helpers,代码行数:26,代码来源:test_host.py

示例2: test_creates_a_directory_with_defaults

# 需要导入模块: from charmhelpers.core import host [as 别名]
# 或者: from charmhelpers.core.host import mkdir [as 别名]
def test_creates_a_directory_with_defaults(self, os_, log):
        uid = 0
        gid = 0
        path = '/some/other/path/from/link'
        realpath = '/some/path'
        path_exists = False
        perms = 0o555

        os_.path.abspath.return_value = realpath
        os_.path.exists.return_value = path_exists

        host.mkdir(path)

        os_.path.abspath.assert_called_with(path)
        os_.path.exists.assert_called_with(realpath)
        os_.makedirs.assert_called_with(realpath, perms)
        os_.chown.assert_called_with(realpath, uid, gid) 
开发者ID:juju,项目名称:charm-helpers,代码行数:19,代码来源:test_host.py

示例3: mount_volume

# 需要导入模块: from charmhelpers.core import host [as 别名]
# 或者: from charmhelpers.core.host import mkdir [as 别名]
def mount_volume(config):
    if os.path.exists(config['mountpoint']):
        if not os.path.isdir(config['mountpoint']):
            hookenv.log('Not a directory: {}'.format(config['mountpoint']))
            raise VolumeConfigurationError()
    else:
        host.mkdir(config['mountpoint'])
    if os.path.ismount(config['mountpoint']):
        unmount_volume(config)
    if not host.mount(config['device'], config['mountpoint'], persist=True):
        raise VolumeConfigurationError() 
开发者ID:openstack,项目名称:charm-swift-proxy,代码行数:13,代码来源:volumes.py

示例4: configure_ceph

# 需要导入模块: from charmhelpers.core import host [as 别名]
# 或者: from charmhelpers.core.host import mkdir [as 别名]
def configure_ceph(ceph):
    with charm.provide_charm_instance() as charm_class:
        # TODO(jamespage): refactor to avoid massaging helper
        ceph_helper.KEYRING = charm_class.ceph_keyring
        host.mkdir(os.path.dirname(charm_class.ceph_keyring))
        ceph_helper.ensure_ceph_keyring(service=hookenv.service_name(),
                                        key=ceph.key(),
                                        user=charm_class.gnocchi_user,
                                        group=charm_class.gnocchi_group) 
开发者ID:openstack,项目名称:charm-gnocchi,代码行数:11,代码来源:gnocchi_handlers.py

示例5: install

# 需要导入模块: from charmhelpers.core import host [as 别名]
# 或者: from charmhelpers.core.host import mkdir [as 别名]
def install(self, plugins):
        """Install the given plugins, optionally removing unlisted ones.

        @params plugins: A whitespace-separated list of plugins to install.
        """
        plugins = plugins or ""
        plugins = plugins.split()
        hookenv.log("Stopping jenkins for plugin update(s)")
        host.service_stop("jenkins")
        hookenv.log("Installing plugins (%s)" % " ".join(plugins))

        host.mkdir(
            paths.PLUGINS, owner="jenkins", group="jenkins", perms=0o0755)

        existing_plugins = set(glob.glob("%s/*.hpi" % paths.PLUGINS))
        try:
            installed_plugins = self._install_plugins(plugins)
        except:
            hookenv.log("Plugin installation failed, check logs for details")
            host.service_start("jenkins")  # Make sure we don't leave jenkins down
            raise

        unlisted_plugins = existing_plugins - installed_plugins
        if unlisted_plugins:
            if hookenv.config()["remove-unlisted-plugins"] == "yes":
                self._remove_plugins(unlisted_plugins)
            else:
                hookenv.log(
                    "Unlisted plugins: (%s) Not removed. Set "
                    "remove-unlisted-plugins to 'yes' to clear them "
                    "away." % ", ".join(unlisted_plugins))

        hookenv.log("Starting jenkins to pickup configuration changes")
        host.service_start("jenkins") 
开发者ID:jenkinsci,项目名称:jenkins-charm,代码行数:36,代码来源:plugins.py

示例6: configure_cert

# 需要导入模块: from charmhelpers.core import host [as 别名]
# 或者: from charmhelpers.core.host import mkdir [as 别名]
def configure_cert(self, cert, key, cn=None):
        """Configure service SSL cert and key

        Write out service SSL certificate and key for Apache.

        @param cert string SSL Certificate
        @param key string SSL Key
        @param cn string Canonical name for service
        """
        if os_utils.snap_install_requested():
            ssl_dir = '/var/snap/{snap_name}/common/etc/nginx/ssl'.format(
                snap_name=self.primary_snap)
        else:
            ssl_dir = os.path.join('/etc/apache2/ssl/', self.name)

        if not cn:
            cn = os_ip.resolve_address(endpoint_type=os_ip.INTERNAL)
        ch_host.mkdir(path=ssl_dir)
        if cn:
            cert_filename = 'cert_{}'.format(cn)
            key_filename = 'key_{}'.format(cn)
        else:
            cert_filename = 'cert'
            key_filename = 'key'

        ch_host.write_file(path=os.path.join(ssl_dir, cert_filename),
                           content=cert.encode('utf-8'))
        ch_host.write_file(path=os.path.join(ssl_dir, key_filename),
                           content=key.encode('utf-8')) 
开发者ID:openstack,项目名称:charms.openstack,代码行数:31,代码来源:classes.py

示例7: install_snap_certs

# 需要导入模块: from charmhelpers.core import host [as 别名]
# 或者: from charmhelpers.core.host import mkdir [as 别名]
def install_snap_certs(self):
        """Install systems CA certificates for a snap

        Installs the aggregated host system ca-certificates.crt into
        $SNAP_COMMON/etc/ssl/certs for services running within a sandboxed
        snap to consume.

        Snaps should set the REQUESTS_CA_BUNDLE environment variable to
        ensure requests based API calls use the updated system certs.
        """
        if (os_utils.snap_install_requested() and
                os.path.exists(SYSTEM_CA_CERTS)):
            ca_certs = SNAP_CA_CERTS.format(self.primary_snap)
            ch_host.mkdir(os.path.dirname(ca_certs))
            shutil.copyfile(SYSTEM_CA_CERTS, ca_certs) 
开发者ID:openstack,项目名称:charms.openstack,代码行数:17,代码来源:classes.py

示例8: createFolders

# 需要导入模块: from charmhelpers.core import host [as 别名]
# 或者: from charmhelpers.core.host import mkdir [as 别名]
def createFolders():
    status_set('maintenance', 'Creating DC/OS Folders')
    mkdir(configdir)
    mkdir(configdir+'roles')
    mkdir(basedir)
    mkdir(configdir+'setup-flags')
    mkdir(basedir+'packages/dcos-config--setup_b3e41695178e35239659186b92f25820c610f961')
    mkdir(basedir+'packages/dcos-metadata--setup_b3e41695178e35239659186b92f25820c610f961')
    mkdir('/etc/profile.d')
    mkdir('/etc/systemd/journald.conf.d') 
开发者ID:spiculedata,项目名称:dcos-agent-charm,代码行数:12,代码来源:dcos_master.py

示例9: createSymlinks

# 需要导入模块: from charmhelpers.core import host [as 别名]
# 或者: from charmhelpers.core.host import mkdir [as 别名]
def createSymlinks():
    status_set('maintenance', 'Creating DC/OS symlinks')
    #Hack to make start scripts work
    os.symlink("/bin/mkdir", "/usr/bin/mkdir") 
开发者ID:spiculedata,项目名称:dcos-agent-charm,代码行数:6,代码来源:dcos_master.py

示例10: test_removes_file_with_same_path_before_mkdir

# 需要导入模块: from charmhelpers.core import host [as 别名]
# 或者: from charmhelpers.core.host import mkdir [as 别名]
def test_removes_file_with_same_path_before_mkdir(self, os_, log,
                                                      getgrnam, getpwnam):
        uid = 123
        gid = 234
        owner = 'some-user'
        group = 'some-group'
        path = '/some/other/path/from/link'
        realpath = '/some/path'
        path_exists = True
        force = True
        is_dir = False
        perms = 0o644

        getpwnam.return_value.pw_uid = uid
        getgrnam.return_value.gr_gid = gid
        os_.path.abspath.return_value = realpath
        os_.path.exists.return_value = path_exists
        os_.path.isdir.return_value = is_dir

        host.mkdir(path, owner=owner, group=group, perms=perms, force=force)

        getpwnam.assert_called_with('some-user')
        getgrnam.assert_called_with('some-group')
        os_.path.abspath.assert_called_with(path)
        os_.path.exists.assert_called_with(realpath)
        os_.unlink.assert_called_with(realpath)
        os_.makedirs.assert_called_with(realpath, perms)
        os_.chown.assert_called_with(realpath, uid, gid) 
开发者ID:juju,项目名称:charm-helpers,代码行数:30,代码来源:test_host.py

示例11: render

# 需要导入模块: from charmhelpers.core import host [as 别名]
# 或者: from charmhelpers.core.host import mkdir [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


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