Saltstack some common modules and API call methods

Source: Internet
Author: User
Tags diskusage saltstack

When we study the executable module, we find that many of our modules are well-established, which can help us to do our daily work, and write our own record operation:

1, using Salt.clien Invoke interface Operation Example:

>>> Import Salt.client
>>> client = Salt.client.LocalClient ()
>>> ret = client.cmd (' * ', ' test.ping ')
>>> ret
{' Monitor ': True}

We see that after calling the function localclient (), we execute the command salt ' * ' test.ping. Using this interface we can flexibly re-invoke the module development time to use

2. Status Module

Just found this module, originally want to do system monitoring time with mine call, now found this module is pretty suitable, can monitor, CPU, memory, hard disk, network, and so on some of our daily information: can view module source code:/usr/lib/python2.6/site-packages /salt/modules/status.py.

Source fragments, here are the functions we can manipulate.

def all_status():      ... ... ...      return { ‘cpuinfo‘ : cpuinfo(),              ‘cpustats‘ : cpustats(),              ‘diskstats‘ : diskstats(),              ‘diskusage‘ : diskusage(),              ‘loadavg‘ : loadavg(),              ‘meminfo‘ : meminfo(),              ‘netdev‘ : netdev(),              ‘netstats‘ : netstats(),              ‘uptime‘ : uptime(),              ‘vmstats‘ : vmstats(),              ‘w‘ : w()}

How to use:

[[email protected] python]# Salt ' * ' status.uptime
Monitor
11:40:50 up, 23:24, 1 user, Load average:0.00, 0.00, 0.00

API Interface Call Method:

>>> client.cmd (' * ', ' status.uptime ')
{' Monitor ': ' 11:41:52 up ', 23:25, 1 user, Load average:0.00, 0.00, 0.00 '}

3. System

System module is mainly used for daily operation of computer maintenance records, the source code is also in the above location:

system.halt        #停止正在运行的系统 system.init 3      #切换到字符界面,5是图形界面 system.poweroff system.reboot

system.shutdown

操作方法:不演示:

4、systemd

系统管理模块,这个也是一个非常有用的功能,我们可以用来检测我们的服务是否已经启动,源码自己查看:

  service.available sshd            #查看服务是否可用   service.disable <service name>    #设置开机启动的服务   service. enable <service name>   service.disabled <service name>   #查看服务是不是开机启动   service.enabled <service name>   service.get_disabled              #返回所有关闭的服务   service.get_enabled               #返回所有开启的服务   service.get_all                   #返回所有服务   service.reload <service name>     #重新载入指定的服务   service.restart <service name>    #重启服务   service.start <service name>   service.stop <service name>   service.status <service name>

  service.force_reload <service name>  #强制载入指定的服务

使用方法:

[[email protected] python]# salt ‘*‘ service.available sshd
monitor:
    True

api调用:

>>> client.cmd(‘*‘,‘service.available‘,[‘sshd‘])
{‘monitor‘: True}

Summary: Through the API interface call, we will find that generate a lot of the results we want, because it is a dictionary, we can easily manipulate the data received.







This article is from the "Little Luo" blog, please be sure to keep this source http://xiaoluoge.blog.51cto.com/9141967/1615905

Saltstack some common modules and API call methods

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.