saltstack主机管理项目:计主机管理项目命令分发器
Posted luoahong
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了saltstack主机管理项目:计主机管理项目命令分发器相关的知识,希望对你有一定的参考价值。
四、主机管理项目命令分发器
开发 命令格式如下:
01、salt.py 只是一个入口,没干什么事情
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
#!/usr/bin/env python # -*- coding:utf-8 -*- # Author:luoahong import os,sys if __name__ = = "__main__" : os.environ.setdefault( "DJANGO_SETTINGS_MODULE" , "Stark.settings" ) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) #print(BASE_DIR) sys.path.append(BASE_DIR) from Arya.action_list import actions from Arya.backends.utils import ArgvManagement obj = ArgvManagement(sys.argv) |
02、action_list.py 路由分发器
utils.py 创建了一个类
1
2
3
4
5
6
7
8
|
#!/usr/bin/env python # -*- coding:utf-8 -*- # Author:luoahong from Arya.plugins import cmd,state actions = { ‘cmd‘ : cmd.CMD, ‘state‘ :state.State } |
03、backends 建了一个目录
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
#!/usr/bin/env python # -*- coding:utf-8 -*- # Author:luoahong import sys from Arya import action_list import django django.setup() from Stark import settings from Arya import models class ArgvManagement( object ): ‘‘‘ 接收用户指令并分配到相应模块 ‘‘‘ def __init__( self ,argvs): self .argvs = argvs self .argv_parse() def help_msg( self ): print ( "Available modules:" ) for registered_module in action_list.actions: print ( " %s" % registered_module) exit() |
04、plugins 建立一个目录
cmd.py 创建两个类
1
2
3
4
5
6
7
|
#!/usr/bin/env python # -*- coding:utf-8 -*- # Author:luoahong from Arya.backends.base_module import BaseSaltModule class CMD(BaseSaltModule): print ( ‘in cmd module ‘ ) |
state.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
#!/usr/bin/env python # -*- coding:utf-8 -*- # Author:luoahong from Arya.backends.base_module import BaseSaltModule import os class State(BaseSaltModule): def load_state_files( self ,state_filename): from yaml import load, dump try : from yaml import CLoader as Loader, CDumper as Dumper except ImportError: from yaml import Loader, Dumper state_file_path = "%s/%s" % ( self .settings.SALT_CONFIG_FILES_DIR,state_filename) if os.path.isfile(state_file_path): with open (state_file_path) as f: data = load(f.read(), Loader = Loader) return data else : exit( "%s is not a valid yaml config file" % state_filename) |
以上是关于saltstack主机管理项目:计主机管理项目命令分发器的主要内容,如果未能解决你的问题,请参考以下文章
saltstack主机管理项目day23:主机管理项目需求分析-设计