本文整理汇总了Python中salt.modules.state_std函数的典型用法代码示例。如果您正苦于以下问题:Python state_std函数的具体用法?Python state_std怎么用?Python state_std使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了state_std函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: swapon
def swapon(name, priority=None, **kwargs):
'''
Activate a swap disk
CLI Example:
.. code-block:: bash
salt '*' mount.swapon /root/swapfile
'''
ret = {}
on_ = swaps()
if name in on_:
ret['stats'] = on_[name]
ret['new'] = False
return ret
cmd = 'swapon {0}'.format(name)
if priority:
cmd += ' -p {0}'.format(priority)
result = __salt__['cmd.run_stdall'](cmd)
state_std(kwargs, result)
on_ = swaps()
if name in on_:
ret['stats'] = on_[name]
ret['new'] = True
return ret
return ret
开发者ID:MadeiraCloud,项目名称:salt,代码行数:27,代码来源:mount.py
示例2: restart
def restart(name='all', user=None, conf_file=None, bin_env=None, **kwargs):
'''
Restart the named service.
Process group names should not include a trailing asterisk.
user
user to run supervisorctl as
conf_file
path to supervisorctl config file
bin_env
path to supervisorctl bin or path to virtualenv with supervisor
installed
CLI Example:
.. code-block:: bash
salt '*' supervisord.restart <service>
salt '*' supervisord.restart <group>:
'''
ret = __salt__['cmd.run_stdall'](
_ctl_cmd('restart', name, conf_file, bin_env), runas=user
)
state_std(kwargs, ret)
return _get_return(ret)
开发者ID:MadeiraCloud,项目名称:salt,代码行数:25,代码来源:supervisord.py
示例3: chhomephone
def chhomephone(name, homephone, **kwargs):
"""
Change the user's Home Phone
CLI Example:
.. code-block:: bash
salt '*' user.chhomephone foo "7735551234"
"""
homephone = str(homephone)
pre_info = _get_gecos(name)
if not pre_info:
return False
if homephone == pre_info["homephone"]:
return True
gecos_field = copy.deepcopy(pre_info)
gecos_field["homephone"] = homephone
cmd = 'usermod -c "{0}" {1}'.format(_build_gecos(gecos_field), name)
result = __salt__["cmd.run_stdall"](cmd)
state_std(kwargs, result)
post_info = info(name)
if post_info["homephone"] != pre_info["homephone"]:
return str(post_info["homephone"]) == homephone
return False
开发者ID:ckraemer,项目名称:salt,代码行数:25,代码来源:useradd.py
示例4: chfullname
def chfullname(name, fullname, **kwargs):
"""
Change the user's Full Name
CLI Example:
.. code-block:: bash
salt '*' user.chfullname foo "Foo Bar"
"""
fullname = str(fullname)
pre_info = _get_gecos(name)
if not pre_info:
return False
if fullname == pre_info["fullname"]:
return True
gecos_field = copy.deepcopy(pre_info)
gecos_field["fullname"] = fullname
cmd = 'usermod -c "{0}" {1}'.format(_build_gecos(gecos_field), name)
result = __salt__["cmd.run_stdall"](cmd)
state_std(kwargs, result)
post_info = info(name)
if post_info["fullname"] != pre_info["fullname"]:
return str(post_info["fullname"]) == fullname
return False
开发者ID:ckraemer,项目名称:salt,代码行数:25,代码来源:useradd.py
示例5: chroomnumber
def chroomnumber(name, roomnumber, **kwargs):
"""
Change the user's Room Number
CLI Example:
.. code-block:: bash
salt '*' user.chroomnumber foo 123
"""
roomnumber = str(roomnumber)
pre_info = _get_gecos(name)
if not pre_info:
return False
if roomnumber == pre_info["roomnumber"]:
return True
gecos_field = copy.deepcopy(pre_info)
gecos_field["roomnumber"] = roomnumber
cmd = 'usermod -c "{0}" {1}'.format(_build_gecos(gecos_field), name)
result = __salt__["cmd.run_stdall"](cmd)
state_std(kwargs, result)
post_info = info(name)
if post_info["roomnumber"] != pre_info["roomnumber"]:
return str(post_info["roomnumber"]) == roomnumber
return False
开发者ID:ckraemer,项目名称:salt,代码行数:25,代码来源:useradd.py
示例6: enable
def enable(name, **kwargs):
'''
Enable the named service to start at boot
CLI Example:
.. code-block:: bash
salt '*' service.enable <service name>
'''
osmajor = _osrel()[0]
if osmajor < '6':
cmd = 'update-rc.d -f {0} defaults 99'.format(name)
else:
cmd = 'update-rc.d {0} enable'.format(name)
try:
if int(osmajor) >= 6:
cmd = 'insserv {0} && '.format(name) + cmd
except ValueError:
if osmajor == 'testing/unstable' or osmajor == 'unstable':
cmd = 'insserv {0} && '.format(name) + cmd
result = __salt__['cmd.run_stdall'](cmd)
state_std(kwargs, result)
return not result['retcode']
开发者ID:MadeiraCloud,项目名称:salt,代码行数:25,代码来源:debian_service.py
示例7: update
def update(cwd, rev, force=False, user=None, **kwargs):
'''
Update to a given revision
cwd
The path to the Mercurial repository
rev
The revision to update to
force : False
Force an update
user : None
Run hg as a user other than what the minion runs as
CLI Example:
.. code-block:: bash
salt devserver1 hg.update /path/to/repo somebranch
'''
_check_hg()
cmd = 'hg update {0}{1}'.format(rev, ' -C' if force else '')
result = __salt__['cmd.run_stdall'](cmd, cwd=cwd, runas=user)
state_std(kwargs, result)
return result['stdout']
开发者ID:MadeiraCloud,项目名称:salt,代码行数:28,代码来源:hg.py
示例8: clone
def clone(cwd, repository, opts=None, user=None, **kwargs):
'''
Clone a new repository
cwd
The path to the Mercurial repository
repository
The hg URI of the repository
opts : None
Any additional options to add to the command line
user : None
Run hg as a user other than what the minion runs as
CLI Example:
.. code-block:: bash
salt '*' hg.clone /path/to/repo https://bitbucket.org/birkenfeld/sphinx
'''
_check_hg()
if not opts:
opts = ''
cmd = 'hg clone {0} {1} {2}'.format(repository, cwd, opts)
result = __salt__['cmd.run_stdall'](cmd, runas=user)
state_std(kwargs, result)
return result['stdout']
开发者ID:MadeiraCloud,项目名称:salt,代码行数:30,代码来源:hg.py
示例9: remount
def remount(name, device, mkmnt=False, fstype='', opts='defaults', **kwargs):
'''
Attempt to remount a device, if the device is not already mounted, mount
is called
CLI Example:
.. code-block:: bash
salt '*' mount.remount /mnt/foo /dev/sdz1 True
'''
if isinstance(opts, string_types):
opts = opts.split(',')
mnts = active()
if name in mnts:
# The mount point is mounted, attempt to remount it with the given data
if 'remount' not in opts:
opts.append('remount')
lopts = ','.join(opts)
args = '-o {0}'.format(lopts)
if fstype:
args += ' -t {0}'.format(fstype)
cmd = 'mount {0} {1} {2} '.format(args, device, name)
out = __salt__['cmd.run_stdall'](cmd)
state_std(kwargs, out)
if out['retcode']:
return out['stderr']
return True
# Mount a filesystem that isn't already
return mount(name, device, mkmnt, fstype, opts)
开发者ID:MadeiraCloud,项目名称:salt,代码行数:30,代码来源:mount.py
示例10: pull
def pull(cwd, opts=None, user=None, **kwargs):
'''
Perform a pull on the given repository
cwd
The path to the Mercurial repository
opts : None
Any additional options to add to the command line
user : None
Run hg as a user other than what the minion runs as
CLI Example:
.. code-block:: bash
salt '*' hg.pull /path/to/repo '-u'
'''
_check_hg()
if not opts:
opts = ''
result = __salt__['cmd.run_stdall']('hg pull {0}'.format(opts), cwd=cwd, runas=user)
state_std(kwargs, result)
return result['stdout']
开发者ID:MadeiraCloud,项目名称:salt,代码行数:26,代码来源:hg.py
示例11: revision
def revision(cwd, rev='tip', short=False, user=None, **kwargs):
'''
Returns the long hash of a given identifier (hash, branch, tag, HEAD, etc)
cwd
The path to the Mercurial repository
rev: tip
The revision
short: False
Return an abbreviated commit hash
user : None
Run hg as a user other than what the minion runs as
CLI Example:
.. code-block:: bash
salt '*' hg.revision /path/to/repo mybranch
'''
_check_hg()
cmd = 'hg id -i{short} {rev}'.format(
short=' --debug' if not short else '',
rev=' -r {0}'.format(rev))
result = __salt__['cmd.run_stdall'](cmd, cwd=cwd, runas=user)
state_std(kwargs, result)
if result['retcode'] == 0:
return result['stdout']
else:
return '', result
开发者ID:MadeiraCloud,项目名称:salt,代码行数:35,代码来源:hg.py
示例12: remove
def remove(name, user=None, conf_file=None, bin_env=None, **kwargs):
'''
Removes process/group from active config
user
user to run supervisorctl as
conf_file
path to supervisorctl config file
bin_env
path to supervisorctl bin or path to virtualenv with supervisor
installed
CLI Example:
.. code-block:: bash
salt '*' supervisord.remove <name>
'''
if name.endswith(':'):
name = name[:-1]
ret = __salt__['cmd.run_stdall'](
_ctl_cmd('remove', name, conf_file, bin_env), runas=user
)
state_std(kwargs, ret)
return _get_return(ret)
开发者ID:MadeiraCloud,项目名称:salt,代码行数:25,代码来源:supervisord.py
示例13: vgcreate
def vgcreate(vgname, devices, **kwargs):
'''
Create an LVM volume group
CLI Examples:
.. code-block:: bash
salt mymachine lvm.vgcreate my_vg /dev/sdb1,/dev/sdb2
salt mymachine lvm.vgcreate my_vg /dev/sdb1 clustered=y
'''
if not vgname or not devices:
return 'Error: vgname and device(s) are both required'
cmd = 'vgcreate {0}'.format(vgname)
for device in devices.split(','):
cmd += ' {0}'.format(device)
valid = ('clustered', 'maxlogicalvolumes', 'maxphysicalvolumes',
'vgmetadatacopies', 'metadatacopies', 'physicalextentsize',
'metadatatype', 'autobackup', 'addtag', 'alloc')
for var in kwargs['kwargs'].keys():
if kwargs['kwargs'][var] and var in valid:
cmd += ' --{0} {1}'.format(var, kwargs['kwargs'][var])
result = __salt__['cmd.run_all'](cmd)
state_std(kwargs, result)
if result['retcode'] != 0 or result['stderr']:
return result['stderr']
out = result['stdout'].splitlines()
vgdata = vgdisplay(vgname)
vgdata['Output from vgcreate'] = out[0].strip()
return vgdata
开发者ID:MadeiraCloud,项目名称:salt,代码行数:31,代码来源:linux_lvm.py
示例14: _git_run
def _git_run(cmd, cwd=None, runas=None, identity=None, **kwargs):
'''
simple, throw an exception with the error message on an error return code.
this function may be moved to the command module, spliced with
'cmd.run_all', and used as an alternative to 'cmd.run_all'. Some
commands don't return proper retcodes, so this can't replace 'cmd.run_all'.
'''
env = {}
if identity:
helper = _git_ssh_helper(identity)
env = {
'GIT_SSH': helper
}
result = __salt__['cmd.run_stdall'](cmd,
cwd=cwd,
runas=runas,
env=env,
**kwargs)
state_std(kwargs, result)
if identity:
os.unlink(helper)
retcode = result['retcode']
if retcode == 0:
return result['stdout']
else:
raise exceptions.CommandExecutionError(result['stderr'])
开发者ID:MadeiraCloud,项目名称:salt,代码行数:32,代码来源:git.py
示例15: pvcreate
def pvcreate(devices, **kwargs):
'''
Set a physical device to be used as an LVM physical volume
CLI Examples:
.. code-block:: bash
salt mymachine lvm.pvcreate /dev/sdb1,/dev/sdb2
salt mymachine lvm.pvcreate /dev/sdb1 dataalignmentoffset=7s
'''
if not devices:
return 'Error: at least one device is required'
cmd = 'pvcreate'
for device in devices.split(','):
cmd += ' {0}'.format(device)
valid = ('metadatasize', 'dataalignment', 'dataalignmentoffset',
'pvmetadatacopies', 'metadatacopies', 'metadataignore',
'restorefile', 'norestorefile', 'labelsector',
'setphysicalvolumesize', 'force', 'uuid', 'zero', 'metadatatype')
for var in kwargs['kwargs'].keys():
if kwargs['kwargs'][var] and var in valid:
cmd += ' --{0} {1}'.format(var, kwargs['kwargs'][var])
result = __salt__['cmd.run_all'](cmd)
state_std(kwargs, result)
if result['retcode'] != 0 or result['stderr']:
return result['stderr']
out = result['stdout'].splitlines()
return out[0]
开发者ID:MadeiraCloud,项目名称:salt,代码行数:30,代码来源:linux_lvm.py
示例16: install
def install(pkg=None,
dir=None,
runas=None,
**kwargs):
'''
Install an NPM package.
If no directory is specified, the package will be installed globally. If
no package is specified, the dependencies (from package.json) of the
package in the given directory will be installed.
pkg
A package name in any format accepted by NPM, including a version
identifier
dir
The target directory in which to install the package, or None for
global installation
runas
The user to run NPM with
CLI Example:
.. code-block:: bash
salt '*' npm.install coffee-script
salt '*' npm.install [email protected]
'''
if not _valid_version():
return '{0!r} is not available.'.format('npm.install')
cmd = 'unbuffer npm install' #'npm install --silent --json'
if dir is None:
cmd += ' --global'
if pkg:
cmd += ' "{0}"'.format(pkg)
result = __salt__['cmd.run_stdall'](cmd, cwd=dir, runas=runas)
state_std(kwargs, result)
if result['retcode'] != 0:
raise CommandExecutionError(result['stderr'])
# npm >1.2.21 is putting the output to stderr even though retcode is 0
npm_output = result['stdout'] or result['stderr']
for line in npm_output.splitlines():
if line.find(pkg) >= 0:
return [{
'name' : pkg,
'version' : line[line.find(pkg)+len(pkg):line.find(' ')] #EXAMPLE: [email protected] /usr/local/lib/node_modules/express
}]
return npm_output
开发者ID:MadeiraCloud,项目名称:salt,代码行数:57,代码来源:npm.py
示例17: set_hwclock
def set_hwclock(clock, **kwargs):
'''
Sets the hardware clock to be either UTC or localtime
CLI Example:
.. code-block:: bash
salt '*' timezone.set_hwclock UTC
'''
timezone = get_zone()
if 'Solaris' in __grains__['os_family']:
if 'sparc' in __grains__['cpuarch']:
return 'UTC is the only choice for SPARC architecture'
if clock == 'localtime':
cmd = 'rtc -z {0}'.format(timezone)
result = __salt__['cmd.run_stdall'](cmd)
state_std(kwargs, result)
return True
elif clock == 'UTC':
cmd = 'rtc -z GMT'
result = __salt__['cmd.run_stdall'](cmd)
state_std(kwargs, result)
return True
else:
zonepath = '/usr/share/zoneinfo/{0}'.format(timezone)
if not os.path.exists(zonepath):
return 'Zone does not exist: {0}'.format(zonepath)
if 'Solaris' not in __grains__['os_family']:
os.unlink('/etc/localtime')
os.symlink(zonepath, '/etc/localtime')
if 'Arch' in __grains__['os_family']:
__salt__['file.sed'](
'/etc/rc.conf', '^HARDWARECLOCK=.*', 'HARDWARECLOCK="{0}"'.format(
clock))
elif 'RedHat' in __grains__['os_family']:
__salt__['file.sed'](
'/etc/sysconfig/clock', '^ZONE=.*', 'ZONE="{0}"'.format(timezone))
elif 'Suse' in __grains__['os_family']:
__salt__['file.sed'](
'/etc/sysconfig/clock', '^ZONE=.*', 'ZONE="{0}"'.format(timezone))
elif 'Debian' in __grains__['os_family']:
if clock == 'UTC':
__salt__['file.sed']('/etc/default/rcS', '^UTC=.*', 'UTC=yes')
elif clock == 'localtime':
__salt__['file.sed']('/etc/default/rcS', '^UTC=.*', 'UTC=no')
elif 'Gentoo' in __grains__['os_family']:
__salt__['file.sed'](
'/etc/conf.d/hwclock', '^clock=.*', 'clock="{0}"'.format(clock))
return True
开发者ID:MadeiraCloud,项目名称:salt,代码行数:55,代码来源:timezone.py
示例18: write_cron_file_verbose
def write_cron_file_verbose(user, path, **kwargs):
'''
Writes the contents of a file to a user's crontab and return error message on error
CLI Example:
.. code-block:: bash
salt '*' cron.write_cron_file_verbose root /tmp/new_cron
'''
result = __salt__['cmd.run_stdall'](_get_cron_cmdstr(user, path))
state_std(kwargs, result)
return result
开发者ID:MadeiraCloud,项目名称:salt,代码行数:13,代码来源:cron.py
示例19: _write_cron_lines
def _write_cron_lines(user, lines, **kwargs):
'''
Takes a list of lines to be committed to a user's crontab and writes it
'''
path = salt.utils.mkstemp()
with salt.utils.fopen(path, 'w+') as fp_:
fp_.writelines(lines)
if __grains__['os'] == 'Solaris' and user != "root":
__salt__['cmd.run']('chown {0} {1}'.format(user, path))
ret = __salt__['cmd.run_stdall'](_get_cron_cmdstr(user, path))
state_std(kwargs, ret)
os.remove(path)
return ret
开发者ID:MadeiraCloud,项目名称:salt,代码行数:13,代码来源:cron.py
示例20: full_restart
def full_restart(name, **kwargs):
'''
Do a full restart (stop/start) of the named service
CLI Example:
.. code-block:: bash
salt '*' service.full_restart <service name>
'''
cmd = 'service {0} --full-restart'.format(name)
result = __salt__['cmd.run_stdall'](cmd)
state_std(kwargs, result)
return not result['retcode']
开发者ID:MadeiraCloud,项目名称:salt,代码行数:14,代码来源:upstart.py
注:本文中的salt.modules.state_std函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论