示例#1
0
 def __init__(self, ip):
     """
         Define objects by ip
     """
     l = my_ssx2.list_components(ip)
     for comp in l:
         self.add(ip=ip, ident=comp)
示例#2
0
文件: base.py 项目: mcold/SSX2
def get_var(ip, ident, path, login=login, password=password):
    """
        Get variable by path
    """
    
    path = unmake_ident(ident, path)
    l_path = [unmake_slash(ident)] + [x for x in path.split('/')[:-1] if x.strip() not in ['', None]]
    prove_path = ""
    l_elems = list()
    for sub_path in l_path:
        if not sub_path.upper() in l_elems and not len(l_elems) == 0: 
            return None
        
        prove_path = '/' + unmake_slash(prove_path + '/' + sub_path)
        l_elems = [x.upper().strip() for x in my_ssx2.list_components(ip=ip, path=prove_path)]
        if len(l_elems) == 0:
            return None
    
    if not path.split('/')[-1].upper() in [x.split(' ')[0] for x in l_elems]:
        return None

    l_cmd = list()
    l_cmd.append('connect {ip} {login} {password}'.format(ip=ip, login=login, password = password)) 
    path = unmake_ident(ident, path)
    l_cmd.append("varget '{identifier}{path}'".format(identifier=ident,path=make_var(path)))
    l_cmd.append('disconnect')
    cmd =  ";".join(l_cmd)
    cmd = 'ssx2 -c "' + cmd + '"'
    return os.popen(cmd).readline().strip()
示例#3
0
    def ls(self, path='/'):
        """
            Get content of directory
        """
        d = dict()

        path = '/{ident}/{path}'.format(ident=self.ident, path=path.strip('/'))
        self.ls_dir = [
            x for x in my_ssx2.list_components(self.ip, path)
            if x.strip() not in ['', None]
        ]
示例#4
0
 def get_webs(self):
     con_path = make_slash(self.ident + '/Statistics/AG/')
     l_connects = my_ssx2.list_components(ip=self.ip, path=con_path)
     l_ips = []
     l_webs = []
     for con_name in l_connects:
         try:
             c_path = con_path + con_name + '/' + 'Address'
             address = self.get_var(path=c_path).split(':')[0]
             l_ips.append(address)
         except AttributeError:
             pass
     l_ips = list(set(l_ips))
     l_agents = []
     for ip in l_ips:
         h = Host(ip=ip)
         l_new_agents = h.find(ip=self.ip, port=self.port, type="WEB")
         l_agents = l_agents + l_new_agents
     self.agents = l_agents
     for agent in self.agents:
         print(agent)