1 # Copyright (c) 2019 Cisco and/or its affiliates.
2 # Licensed under the Apache License, Version 2.0 (the "License");
3 # you may not use this file except in compliance with the License.
4 # You may obtain a copy of the License at:
6 # http://www.apache.org/licenses/LICENSE-2.0
8 # Unless required by applicable law or agreed to in writing, software
9 # distributed under the License is distributed on an "AS IS" BASIS,
10 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 # See the License for the specific language governing permissions and
12 # limitations under the License.
14 """Linux sysctl library."""
16 from resources.libraries.python.ssh import exec_cmd_no_error
18 __all__ = ["SysctlUtil"]
21 class SysctlUtil(object):
22 """Class contains methods for getting or setting sysctl settings."""
25 def get_sysctl_value(node, key):
28 :param node: Node in the topology.
29 :param key: Key that will be set.
33 command = 'sysctl {key}'.format(key=key)
35 message = 'Node {host} failed to run: {command}'.\
36 format(host=node['host'], command=command)
38 exec_cmd_no_error(node, command, sudo=True, message=message)
41 def set_sysctl_value(node, key, value):
42 """Set sysctl key to specific value.
44 :param node: Node in the topology.
45 :param key: Key that will be set.
46 :param value: Value to set.
51 command = 'sysctl -w {key}={value}'.format(key=key, value=value)
53 message = 'Node {host} failed to run: {command}'.\
54 format(host=node['host'], command=command)
56 exec_cmd_no_error(node, command, sudo=True, message=message)