本文整理汇总了Python中salt.modules.state_std函数的典型用法代码示例。如果您正苦于以下问题:Python state_std函数的具体用法?Python state_std怎么用?Python state_std使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了state_std函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
示例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)
示例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
示例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
示例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
示例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']
示例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']
示例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']
示例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)
示例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']
示例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
示例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)
示例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
示例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'])
示例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]