Example #1
0
    def generateParamClass(self):
        #connector = OracleCMDBConnector('cmdb', 'cmdb123', 'cffexcmdb')
        #connector.connect()
        connector= RestCMDBConnector("192.168.1.3", "8080")
        connector.connector()
        
        self.param_classes[self.title] = {}
        self.param_classes[self.title][self.title_config] = {}
        self.param_classes[self.title][self.title_sshkey] = {}
        
        sshkey = {}

        for each in self.attributes:
            source = each['source']
            if source : host = source.split('|')
            for hostname in host :
                hostci = connector.getCI(hostname, 'HOST_OS')[0]
                ssh = connector.getCIByRelations(hostci.attributes['FAMILY_ID'], 
                                           'OSHASAUTHORIZATION', hostci.attributes['TIME'])[0]
                
                model = AuthorizationSSH()
                model.updateAttr(ssh)
                model.CITransformation()
                
                if each.has_key('user') :
                    comment = each['user'] + '@' + hostname

                self.param_classes[self.title][self.title_sshkey][hostname] = {}
                
                each.has_key('')
                if model.attributes[0]['key'] : 
                    self.param_classes[self.title][self.title_sshkey][hostname]['key'] = model.attributes[0]['key'] 
                if comment :
                    self.param_classes[self.title][self.title_sshkey][hostname]['comment']  = comment 
                if each.has_key('type') :
                    self.param_classes[self.title][self.title_sshkey][hostname]['type'] = each['type'] 
                if each.has_key('user') :
                    self.param_classes[self.title][self.title_sshkey][hostname]['username'] = each['user'] 
                if each.has_key('home') :
                    self.param_classes[self.title][self.title_sshkey][hostname]['home'] = each['home'] 
                if each.has_key('ensure') :
                    self.param_classes[self.title][self.title_sshkey][hostname]['ensure'] = each['ensure'] 
                
            #生成os_authorization中不是config部分yaml格式
            for key, value in each.items():
                if key in self.config_list : 
                    self.param_classes[self.title][self.title_config][key] = {}
                    self.param_classes[self.title][self.title_config][key]['value'] = {}
                    self.param_classes[self.title][self.title_config][key]['value'] = value 

            
        return self.param_classes
Example #2
0
File: User.py Project: cffex/Cersy
    def generateParamClass(self):
        conn = RestCMDBConnector("192.168.1.3", "8080")
        conn.connector()
        
        self.param_classes[self.title] = {}
        self.param_classes[self.title][self.title_group] = {}

        #原有user的属性,attributes为list,保存了同一个CI TYPE:OS_USER的多个CI
        for index in range(0, len(self.attributes)):
            each = self.attributes[index]
            name = each['name']
            self.param_classes[self.title][self.title_group][name] = {}
            export_list = []
            
            for key, value in each.items():            
                if key.startswith('export'):
                    export_list.append(re.sub('export_', '', key) + '=' + value)
                    continue
                self.param_classes[self.title][self.title_group][name][key] = {}
                self.param_classes[self.title][self.title_group][name][key] = value
            
            if len(export_list) != 0 :
                self.param_classes[self.title][self.title_group][name]['profile'] = export_list
             
            #生成users中需要建立信任关系的属性,因为可能会存在多个用户,所以使用列表形式
            vtime = self.parameters[index]["TIME"]
            #获取该HOST_CI和OS_USER的type fid。这里没有初始化为CI,所以访问的时候直接使用字典形式访问
            userCIType = conn.getCIType("OS_USER", timestamp = vtime)
            hostCIType = conn.getCIType("HOST_OS", timestamp = vtime)

            if len(userCIType) != 1 or len(hostCIType) != 1:
                self.log.output('ERROR', '[%s]: 获取的CI TYPE[HOST_OS|OS_USER],无法唯一确定CI TYPE' % 
                                self.__class__.__name__)
                sys.exit(-1)

            targetUserCIList = conn.getCIByRelations(sourcefid = self.parameters[index]["FAMILY_ID"],
                                targettype_fid = userCIType[0]["FAMILY_ID"] )
            #此用户没有信任关系需要建立
            if len(targetUserCIList) == 0:
                continue

            for eachUserCI in targetUserCIList :
                #获取该用户属于的主机,targetHost列表长度应为1
                targetHost = conn.getCIByRelations(targetfid = eachUserCI.parameters["FAMILY_ID"], 
                                sourcetype_fid = hostCIType[0]["FAMILY_ID"], location="source")

                if len(targetHost) != 1:
                    self.log.output('ERROR', '[%s]: 该用户所属的主机不唯一,异常并退出' %  
                                self.__class__.__name__)
                    sys.exit(-1)

                targetHostName = conn.getCI(ciFid = targetHost[0].parameters["FAMILY_ID"], 
                                            timestamp = vtime).parameters["NAME"]
                
                temp_name = eachUserCI.parameters['NAME']
                temp_key = eachUserCI.attributes["KEY"]
                temp_type = eachUserCI.attributes["PROTOCOL_TYPE"]
                temp_title = targetHostName + "@" + temp_name
                
                self.param_classes[self.title][self.title_group][name][self.title_ssh] = {}
                self.param_classes[self.title][self.title_group][name][self.title_ssh][temp_title] = {}
                self.param_classes[self.title][self.title_group][name][self.title_ssh][temp_title]["key"] = {}
                self.param_classes[self.title][self.title_group][name][self.title_ssh][temp_title]["type"] = {}
                self.param_classes[self.title][self.title_group][name][self.title_ssh][temp_title]["key"] = temp_key
                self.param_classes[self.title][self.title_group][name][self.title_ssh][temp_title]["type"] = temp_type
        
        conn.close()
        return self.param_classes
Example #3
0
File: Main.py Project: cffex/Cersy
#     connector = OracleCMDBConnector('cmdb', 'cmdb123', 'cffexcmdb')
#     connector.connect()
    
    connector= RestCMDBConnector("192.168.1.3", "8080")
    connector.connector()

    factory = PuppetModelElementFactory()
    modelElementList = []
    hash = HashGenerator()
    log = SysLog()
    
    #hostname = 'slave1'
    hostname = raw_input("Please input hostname: ")
    print "Begin to Generate YAML file, Please wait for a second..."
    ci_host = connector.getCI(ciName = hostname, ciType = "HOST_OS")

    #依据该字段进行查找其实不是非常的必要,只需要将于HOST_OS相关的所有ci找出来就可以了,但是使用该字段后,方便测试
    relationList = ['OSHASUSER',
                     'OSHASKERNEL', 'OSHASUSERGLOBAL',  'OSHASLOG', 'OSHASSERVICE',
                     'OSHASPACKAGE', 'OSHASSECURITY', 'OSHASTIMESYNCCLIENT', 'OSHASGROUP',
                     'OSHASAUTHORIZATION',
                    ]

    #这里认为根据主机找出的ci必须是唯一的,如果不唯一的,那么则报错
    for re in relationList :
        #获取与该os ic具有re关系的所有ci(list)
        CIList = connector.getCIByRelations(sourcefid = ci_host.parameters['FAMILY_ID'], relation = re, 
                                            timestamp = ci_host.parameters['TIME'])
        for index in range(0, len(CIList)):
            factory.CIInitialization(CIList[index])