salt -N 'ceph' test.ping # Test connectivitysalt -E '^server10*' test.ping # Match by regex for connectivitysalt -S 192.168.150.101 test.ping # Match by agent IP addresssalt -S 192.168.150.0/24 test.ping # Match by IP subnetsalt -N 'ceph' cmd.run 'df -Th'# Check disk usage by groupsalt -N 'ceph' cmd.exec_code python 'import os; print os.system("df -Th")'# Execute Python codesalt -N 'ceph' cmd.exec_code perl 'print scalar localtime'# Execute Perl codesalt -G 'osrelease:6.3' cmd.run 'python -V'# Filter by grains and executesalt '*' smbios.get system-serial-number # Get server hardware serial number
salt -N 'ceph' disk.percent /data01 # Get disk usage percentagesalt -N 'ceph' disk.nodeusage /data01 # Get inode usagesalt -N 'ceph' xfs.info /data01 # Get XFS partition info
salt -N 'ceph' user.list_users # List all system userssalt -N 'ceph' user.info lianghaiqiang # Show user detailssalt -N 'ceph' user.delete lianghaiqiang remove=True force=True # Force delete user
salt -N 'ceph' timezone.get_zone # Get timezonesalt -N 'ceph' timezone.set_zone # Set timezonesalt -N 'ceph' system.reboot # Reboot systemsalt -N 'ceph' cron.list_tab root # List root's cron jobssalt -N 'ceph' cron.raw_cron root # List root's cron jobs in raw text format
Use four spaces for indentation; avoid using tabs, and never mix tabs with spaces.
Limit line length to 79 characters. Use backslashes for line continuation, but prefer parentheses instead.
Leave two blank lines between classes and top-level functions; leave one blank line between methods within a class.
Module structure order: module description and docstring, import statements, global variables, constants, others. Within import, arrange in order: standard library, third-party, local modules. Avoid writing multiple imports on one line.
Add one space on both sides of operators. Omit spaces around assignment operators in default function arguments. Do not add spaces before closing brackets (], }, )).
Comments must be in English, preferably complete sentences. Start with a capital letter, end with a period (or other punctuation), followed by two spaces before the next sentence. For phrases, punctuation may be omitted.
Always write docstrings for public modules, functions, classes, and methods. Non-public ones don’t require docstrings, but comments are acceptable (placed on the line immediately after def).
Naming Conventions
Avoid using single lowercase letter l or uppercase O as they can easily be confused.
Module names should be short and use all lowercase letters, optionally separated by underscores.
Package names should be short and use all lowercase letters without underscores.
Class names use CapWords. Internal classes use _CapWords.
Exception names use CapWords with an Error suffix.
Global variables should ideally be limited to module scope (like static in C). Two ways to achieve this: use __all__ mechanism or prefix with an underscore.
Function names use all lowercase letters, optionally separated by underscores.
Constant names use all uppercase letters, optionally separated by underscores.
Class attributes (methods and variables) use all lowercase letters, optionally separated by underscores.
Class attributes have three scopes: public, non-public, and subclass API—similar to public, private, protected in C++. Prefix non-public attributes with a single underscore.
If a class attribute conflicts with a keyword, append an underscore. Avoid abbreviations or other workarounds.
To prevent naming conflicts with subclasses, prefix certain class attributes with double underscores. For example, in class Foo, define __a; access via Foo._Foo__a to avoid ambiguity. If a subclass also uses Foo, this protection fails.
The first parameter of instance methods must be self. The first parameter of static methods must be cls.