标签:centos ide dmi imp reload 运行 pkg www 不同
1、我是如何获知我有多少种系统?
cmd和state只要一执行就会自动去提取主机
1、注册admin组件
from django.contrib import admin # Register your models here. from Arya import models admin.site.register(models.Host) admin.site.register(models.HostGroup)
2、创建超级用户进入后台创建测试数据
python manage.py createsuperuser
3、默认操作系统类型
from django.db import models # Create your models here. class Host(models.Model): hostname = models.CharField(max_length=128,unique=True) key = models.TextField() status_choices = ((0,‘Waiting Approval‘), (1,‘Accepted‘), (2,‘Rejected‘)) os_type_choices =( (‘redhat‘,‘Redhat\CentOS‘), (‘ubuntu‘,‘Ubuntu‘), (‘suse‘,‘Suse‘), (‘windows‘,‘Windows‘), )
4、判断输入的命令有没有超过边界
#!/usr/bin/env python # -*- coding:utf-8 -*- # Author:luoahong class BaseSaltModule(object): def __init__(self,sys_argvs,db_models,settings): self.db_models = db_models self.settings = settings self.sys_argvs = sys_argvs def get_selected_os_types(self): data = {} for host in self.host_list: data[host.os_type] = [] print(‘--->data‘,data) return data def process(self): self.fetch_hosts() self.config_data_dic = self.get_selected_os_types() def require(self,*args,**kwargs): pass def fetch_hosts(self): print(‘--fetching hosts---‘) if ‘-h‘ in self.sys_argvs or ‘-g‘ in self.sys_argvs: host_list = [] if ‘-h‘ in self.sys_argvs: host_str_index = self.sys_argvs.index(‘-h‘) +1 if len(self.sys_argvs) <= host_str_index: exit("host argument must be provided after -h") else: #get the host str host_str = self.sys_argvs[host_str_index] host_str_list = host_str.split(‘,‘) host_list += self.db_models.Host.objects.filter(hostname__in=host_str_list) if ‘-g‘ in self.sys_argvs: group_str_index = self.sys_argvs.index(‘-g‘) +1 if len(self.sys_argvs) <= group_str_index: exit("group argument must be provided after -g") else: #get the group str group_str = self.sys_argvs[group_str_index] group_str_list = group_str.split(‘,‘) group_list = self.db_models.HostGroup.objects.filter(name__in=group_str_list) for group in group_list: host_list += group.hosts.select_related() self.host_list = set(host_list) return True print(‘----host list:‘, host_list) else: exit("host [-h] or group[-g] argument must be provided") def syntax_parser(self,section_name,mod_name,mod_data): print("-going to parser state data:",section_name,mod_name) for state_item in mod_data: print("\t",state_item) for key,val in state_item.items(): if hasattr(self,key): state_func = getattr(self,key) state_func(val) else: exit("Error:module [%s] has no argument [%s]" %( mod_name,key ))
apache: pkg.installed: [] service.running: - reload: True - watch: - file: /etc/httpd/conf/httpd.conf user.present: - uid: 87 #- username: alex - gid: 87 - home: /var/www/html - shell: /bin/nologin - require: - group: apache group.present: - gid: 87 - require: - pkg: apache /etc/httpd/conf/httpd.conf: file.managed: - source: salt://apache/httpd.conf - user: root - group: root - mode: 644
#!/usr/bin/env python # -*- coding:utf-8 -*- # Author:luoahong class BaseSaltModule(object): def __init__(self,sys_argvs,db_models,settings): self.db_models = db_models self.settings = settings self.sys_argvs = sys_argvs def get_selected_os_types(self): data = {} for host in self.host_list: data[host.os_type] = [] print(‘--->data‘,data) return data def process(self): self.fetch_hosts() self.config_data_dic = self.get_selected_os_types() def require(self,*args,**kwargs): pass def fetch_hosts(self): print(‘--fetching hosts---‘) if ‘-h‘ in self.sys_argvs or ‘-g‘ in self.sys_argvs: host_list = [] if ‘-h‘ in self.sys_argvs: host_str_index = self.sys_argvs.index(‘-h‘) +1 if len(self.sys_argvs) <= host_str_index: exit("host argument must be provided after -h") else: #get the host str host_str = self.sys_argvs[host_str_index] host_str_list = host_str.split(‘,‘) host_list += self.db_models.Host.objects.filter(hostname__in=host_str_list) if ‘-g‘ in self.sys_argvs: group_str_index = self.sys_argvs.index(‘-g‘) +1 if len(self.sys_argvs) <= group_str_index: exit("group argument must be provided after -g") else: #get the group str group_str = self.sys_argvs[group_str_index] group_str_list = group_str.split(‘,‘) group_list = self.db_models.HostGroup.objects.filter(name__in=group_str_list) for group in group_list: host_list += group.hosts.select_related() self.host_list = set(host_list) return True print(‘----host list:‘, host_list) else: exit("host [-h] or group[-g] argument must be provided") def syntax_parser(self,section_name,mod_name,mod_data): print("-going to parser state data:",section_name,mod_name) for state_item in mod_data: print("\t",state_item) for key,val in state_item.items(): if hasattr(self,key): state_func = getattr(self,key) state_func(val) else: exit("Error:module [%s] has no argument [%s]" %( mod_name,key ))
1、获主机信息
2、打印模块详细信息
打印结果截图
saltstack主机管理项目:编写插件基类-获取主机列表-提取yaml配置文件(四)
标签:centos ide dmi imp reload 运行 pkg www 不同
原文地址:https://www.cnblogs.com/luoahong/p/9426736.html