本文整理汇总了Python中charmhelpers.core.sysctl.create方法的典型用法代码示例。如果您正苦于以下问题:Python sysctl.create方法的具体用法?Python sysctl.create怎么用?Python sysctl.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类charmhelpers.core.sysctl
的用法示例。
在下文中一共展示了sysctl.create方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: hugepage_support
# 需要导入模块: from charmhelpers.core import sysctl [as 别名]
# 或者: from charmhelpers.core.sysctl import create [as 别名]
def hugepage_support(user, group='hugetlb', nr_hugepages=256,
max_map_count=65536, mnt_point='/run/hugepages/kvm',
pagesize='2MB', mount=True, set_shmmax=False):
"""Enable hugepages on system.
Args:
user (str) -- Username to allow access to hugepages to
group (str) -- Group name to own hugepages
nr_hugepages (int) -- Number of pages to reserve
max_map_count (int) -- Number of Virtual Memory Areas a process can own
mnt_point (str) -- Directory to mount hugepages on
pagesize (str) -- Size of hugepages
mount (bool) -- Whether to Mount hugepages
"""
group_info = add_group(group)
gid = group_info.gr_gid
add_user_to_group(user, group)
if max_map_count < 2 * nr_hugepages:
max_map_count = 2 * nr_hugepages
sysctl_settings = {
'vm.nr_hugepages': nr_hugepages,
'vm.max_map_count': max_map_count,
'vm.hugetlb_shm_group': gid,
}
if set_shmmax:
shmmax_current = int(check_output(['sysctl', '-n', 'kernel.shmmax']))
shmmax_minsize = bytes_from_string(pagesize) * nr_hugepages
if shmmax_minsize > shmmax_current:
sysctl_settings['kernel.shmmax'] = shmmax_minsize
sysctl.create(yaml.dump(sysctl_settings), '/etc/sysctl.d/10-hugepage.conf')
mkdir(mnt_point, owner='root', group='root', perms=0o755, force=False)
lfstab = fstab.Fstab()
fstab_entry = lfstab.get_entry_by_attr('mountpoint', mnt_point)
if fstab_entry:
lfstab.remove_entry(fstab_entry)
entry = lfstab.Entry('nodev', mnt_point, 'hugetlbfs',
'mode=1770,gid={},pagesize={}'.format(gid, pagesize), 0, 0)
lfstab.add_entry(entry)
if mount:
fstab_mount(mnt_point)
示例2: test_create
# 需要导入模块: from charmhelpers.core import sysctl [as 别名]
# 或者: from charmhelpers.core.sysctl import create [as 别名]
def test_create(self, mock_open):
"""Test create sysctl method"""
_file = MagicMock(spec=io.FileIO)
mock_open.return_value = _file
create('{"kernel.max_pid": 1337}', "/etc/sysctl.d/test-sysctl.conf")
_file.__enter__().write.assert_called_with("kernel.max_pid=1337\n")
self.log.assert_called_with(
"Updating sysctl_file: /etc/sysctl.d/test-sysctl.conf"
" values: {'kernel.max_pid': 1337}",
level='DEBUG')
self.check_call.assert_called_with([
"sysctl", "-p",
"/etc/sysctl.d/test-sysctl.conf"])
示例3: create_gluster_volume
# 需要导入模块: from charmhelpers.core import sysctl [as 别名]
# 或者: from charmhelpers.core.sysctl import create [as 别名]
def create_gluster_volume(volume_name: str,
peers: Dict[str, Dict]) -> Result:
"""
Create a new gluster volume with a name and a list of peers
:param volume_name: str. Name of the volume to create
:param peers: List[Peer]. List of the peers to use in this volume
:return:
"""
create_vol = create_volume(peers, None)
if create_vol.is_ok():
if create_vol.value == Status.Created:
log("Create volume succeeded.", INFO)
status_set(workload_state="maintenance",
message="Create volume succeeded")
start_gluster_volume(volume_name)
# Poke the other peers to update their status
set_state("volume.started")
return Ok(Status.Created)
elif create_vol.value == Status.WaitForMorePeers:
log("Waiting for all peers to enter the Peer in Cluster status")
status_set(workload_state="maintenance",
message="Waiting for all peers to enter "
"the \"Peer in Cluster status\"")
return Ok(Status.WaitForMorePeers)
else:
# Status is failed
# What should I return here
return Ok(())
else:
log("Create volume failed with output: {}".format(create_vol.value),
ERROR)
status_set(workload_state="blocked",
message="Create volume failed. Please check "
"juju debug-log.")
return Err(create_vol.value)
示例4: check_for_sysctl
# 需要导入模块: from charmhelpers.core import sysctl [as 别名]
# 或者: from charmhelpers.core.sysctl import create [as 别名]
def check_for_sysctl() -> Result:
"""
Check to see if there's sysctl changes that need to be applied
:return: Result
"""
config = hookenv.config()
if config.changed("sysctl"):
config_path = os.path.join(os.sep, "etc", "sysctl.d",
"50-gluster-charm.conf")
sysctl_dict = config["sysctl"]
if sysctl_dict is not None:
sysctl.create(sysctl_dict, config_path)
return Ok(())