Esempio n. 1
0
    def __init__(self,main_config):
	self.opts=master_config(main_config)
	self.wheel=Wheel(self.opts)
	self.client=LocalClient()
	self.connected_minions_list=self.wheel.call_func('minions.connected')
	self.key_dict=self.wheel.call_func('key.list_all')
	self.total=len(self.key_dict['minions'])+len(self.key_dict['minions_pre'])+len(self.key_dict['minions_denied'])+len(self.key_dict['minions_rejected'])
Esempio n. 2
0
class SaltByLocalApi(object):
    '''
    Saltapi class 通过salt本地接口调用,需和salt-master服务在同一台机器
    '''
    def __init__(self, main_config):
        self.opts = master_config(main_config)
        self.wheel = Wheel(self.opts)
        self.client = LocalClient()
        self.connected_minions_list = self.wheel.call_func('minions.connected')
        self.key_dict = self.wheel.call_func('key.list_all')
        self.total = len(self.key_dict['minions']) + len(
            self.key_dict['minions_pre']) + len(
                self.key_dict['minions_denied']) + len(
                    self.key_dict['minions_rejected'])

    def get_minions_key_status(self):
        reject = len(self.key_dict['minions_rejected'])
        unaccept = len(self.key_dict['minions_pre'])
        accept = len(self.key_dict['minions'])
        return [accept, reject, unaccept]

    def get_minions_status(self):
        return [
            self.total,
            len(self.connected_minions_list),
            self.total - len(self.connected_minions_list)
        ]

    def get_host_info(self):
        minions = self.connected_minions_list
        ret = self.client.cmd(
            minions,
            'grains.item', [
                'mem_total', 'osfullname', 'host', 'osrelease', 'num_cpus',
                'ipv4', 'group', 'area', 'usage'
            ],
            expr_form='list')
        host_info_dict = {}
        for k, v in ret.iteritems():
            v['ipv4'].remove('127.0.0.1')
            ips = '/'.join(v['ipv4']) if len(v['ipv4']) > 1 else v['ipv4'][0]
            values = [
                v['host'], ips, v['osfullname'] + v['osrelease'],
                str(v['num_cpus']) + ' cores',
                str(v['mem_total']) + ' MB', v['group'], v['area'], v['usage']
            ]
            host_info_dict[k] = values
        return host_info_dict

    def get_master_config(self):
        return self.opts

    def get_grains(self):
        if self.connected_minions_list is None or len(
                self.connected_minions_list) < 1:
            return None
        return self.client.cmd(self.connected_minions_list[0], 'grains.items',
                               [])
Esempio n. 3
0
class SaltByLocalApi(object):
    '''
    Saltapi class 通过salt本地接口调用,需和salt-master服务在同一台机器
    '''
    def __init__(self,main_config):
	self.opts=master_config(main_config)
	self.wheel=Wheel(self.opts)
	self.client=LocalClient()
	self.connected_minions_list=self.wheel.call_func('minions.connected')
	self.key_dict=self.wheel.call_func('key.list_all')
	self.total=len(self.key_dict['minions'])+len(self.key_dict['minions_pre'])+len(self.key_dict['minions_denied'])+len(self.key_dict['minions_rejected'])
    def get_minions_key_status(self):
	reject=len(self.key_dict['minions_rejected'])
	unaccept=len(self.key_dict['minions_pre'])
	accept=len(self.key_dict['minions'])
	return [accept,reject,unaccept]
    def get_minions_status(self):
	online=len(self.get_host_info())
        return [self.total,online,self.total-online]

    def get_host_info(self):
	minions=self.connected_minions_list
	ret=self.client.cmd(minions,'grains.item',['mem_total',
	    'osfullname',
	    'host',
	    'osrelease',
	    'num_cpus',
	    'ipv4',
	    'group',
	    'area',
	    'usage'],expr_form='list')
        host_info_dict={}
	for k,v in ret.iteritems():
	    v['ipv4'].remove('127.0.0.1')
	    ips='/'.join(v['ipv4']) if len(v['ipv4'])>1 else v['ipv4'][0]
	    values=[v['host'],
		    ips,
		    v['osfullname']+v['osrelease'],
		    str(v['num_cpus'])+' cores',
		    str(v['mem_total'])+' MB',
		    v['group'],
		    v['area'],
		    v['usage']]
	    host_info_dict[k]=values
        return host_info_dict
    def get_master_config(self):
	return self.opts
    def get_grains(self):
	if self.connected_minions_list is None or len(self.connected_minions_list)<1:
	    return None
	return self.client.cmd(self.connected_minions_list[0],'grains.items',[])