Exemple #1
0
 def getTargetNamesByRoleUID(self, roleUID):
     targetNames = []
     dtm = DeployTargetManager()
     for mapping in self.loadTargetRoleMapping():
         tmp_roleUID = getoutCurlyBraces(mapping.text.split(":")[1])
         tmp_targetUID = getoutCurlyBraces(mapping.text.split(":")[0])
         if tmp_roleUID == roleUID:
             targetNames.append(dtm.getTargetNameByUID(tmp_targetUID))
     return targetNames
Exemple #2
0
 def getTargetNamesByRoleUID(self, roleUID):
     targetNames = []
     dtm = DeployTargetManager()
     for mapping in self.loadTargetRoleMapping():
         tmp_roleUID = getoutCurlyBraces(mapping.text.split(':')[1])
         tmp_targetUID = getoutCurlyBraces(mapping.text.split(':')[0])
         if tmp_roleUID == roleUID:
             targetNames.append(dtm.getTargetNameByUID(tmp_targetUID))
     return targetNames
Exemple #3
0
	def getHostByContainerUID(self, containerUID):

		for host in self.getHostlist():

			containers = host.findall("./Software/Containers")

			for container in containers:

				for ref in container._children:

					if ref.text != None and containerUID == getoutCurlyBraces(ref.text):

						return host
Exemple #4
0
    def getHostByContainerUID(self, containerUID):

        for host in self.getHostlist():

            containers = host.findall("./Software/Containers")

            for container in containers:

                for ref in container._children:

                    if ref.text != None and containerUID == getoutCurlyBraces(
                            ref.text):

                        return host
Exemple #5
0
	def init_config_files(self):
		print red('''
			INIT ROLE TO DEVICE MAPPING CONFIG FILE.
		''')
		# init paas
		print "Init role to device mapping file begin:"
		hostUIDUniqs = self.getUniqHost()
		r2dmM = Role2DeviceManager()
		roleM = RoleManager()
		xcobs = XMLCMDBObserver()
		# defin host role mapping dict
		host_paas_role = {}
		host_saas_role = {}
		zoo_role = {}

		for hostuid in hostUIDUniqs:
			# find role uid by host uid 
			# print hostuid
			roleUIDS = r2dmM.queryRoleByHostUID(hostuid)
			#print roleUIDS
			paas_roles = []
			saas_roles = []
			for roleuid in roleUIDS:
				role_name = roleM.queryRoleByUID(roleuid)
				if role_name in roleM.getPaasRoles():
					paas_roles.append(role_name)
				else:
					saas_roles.append(role_name)
			#print roles
			host = xcobs.getHostByUID(hostuid)
			host_ipaddr = host.findall('./Hardware/EthernetIF')[0].attrib['bindPrivateIP']
			#host_name = host.attrib['name']

			host_paas_role[host_ipaddr] = paas_roles
			host_saas_role[host_ipaddr] = saas_roles
			zoo_role[host_ipaddr] = ['Production_Persistence_Normal_Zookeeper']

		#print host_role

		pjsondata = json.dumps(host_paas_role)
		with open(ORC_PAAS_FILE, 'w+') as f:
			f.write(pjsondata)

		sjsondata = json.dumps(host_saas_role)
		with open(ORC_SAAS_FILE, 'w+') as f:
			f.write(sjsondata)

		zjsondata = json.dumps(zoo_role)
		with open(ORC_ZOO_FILE, 'w+') as f:
			f.write(zjsondata)

		print "count: %s" % len(hostUIDUniqs)
		print green("\nprepareing role<===>address json file ok!\n")

		''' 
			init chef role config file :
			include role define and target to role mapping.
			and then chef can use the config file that used ruby 
			lan written.
		'''

		print red("Init chef roles file begin:")
		dtm = DeployTargetManager()
		rm = RoleManager()
		dsmM = DeploySchemaManager()
		mappings = self.bind_deployschema.targetRoleMapping
		roleUIDs = [ getoutCurlyBraces(mapping.text.split(':')[1]) for mapping in mappings ]
		roleUIDs_uniq = list(set(roleUIDs))

		for roleUID in roleUIDs_uniq:
			roleName = rm.queryRoleByUID(roleUID)
			targetNames = dsmM.getTargetNamesByRoleUID(roleUID)
			if "openresty" in targetNames:
				targetNames.remove('openresty')
			if "rabbitmq-server" in targetNames:
				targetNames.remove('rabbitmq-server')
				targetNames.insert(0, 'rabbitmq')
			with open(CHEF_ROLE_CONFIG_FILE_PATH + roleName + '.rb' , 'w+') as f:
				f.write("name " + '"' + roleName + '"\n' \
						"description " + '"' + roleName +'"\n'\
						"run_list " + self.gen_recipestr_4_targetnames(targetNames))

		print "count: %s " % (len(roleUIDs_uniq))
		print green("preparing target===>role mapping config file ok!")
Exemple #6
0
    def init_config_files(self):
        print red('''
			INIT ROLE TO DEVICE MAPPING CONFIG FILE.
		''')
        # init paas
        print "Init role to device mapping file begin:"
        hostUIDUniqs = self.getUniqHost()
        r2dmM = Role2DeviceManager()
        roleM = RoleManager()
        xcobs = XMLCMDBObserver()
        # defin host role mapping dict
        host_paas_role = {}
        host_saas_role = {}
        zoo_role = {}

        for hostuid in hostUIDUniqs:
            # find role uid by host uid
            # print hostuid
            roleUIDS = r2dmM.queryRoleByHostUID(hostuid)
            #print roleUIDS
            paas_roles = []
            saas_roles = []
            for roleuid in roleUIDS:
                role_name = roleM.queryRoleByUID(roleuid)
                if role_name in roleM.getPaasRoles():
                    paas_roles.append(role_name)
                else:
                    saas_roles.append(role_name)
            #print roles
            host = xcobs.getHostByUID(hostuid)
            host_ipaddr = host.findall(
                './Hardware/EthernetIF')[0].attrib['bindPrivateIP']
            #host_name = host.attrib['name']

            host_paas_role[host_ipaddr] = paas_roles
            host_saas_role[host_ipaddr] = saas_roles
            zoo_role[host_ipaddr] = ['Production_Persistence_Normal_Zookeeper']

        #print host_role

        pjsondata = json.dumps(host_paas_role)
        with open(ORC_PAAS_FILE, 'w+') as f:
            f.write(pjsondata)

        sjsondata = json.dumps(host_saas_role)
        with open(ORC_SAAS_FILE, 'w+') as f:
            f.write(sjsondata)

        zjsondata = json.dumps(zoo_role)
        with open(ORC_ZOO_FILE, 'w+') as f:
            f.write(zjsondata)

        print "count: %s" % len(hostUIDUniqs)
        print green("\nprepareing role<===>address json file ok!\n")
        ''' 
			init chef role config file :
			include role define and target to role mapping.
			and then chef can use the config file that used ruby 
			lan written.
		'''

        print red("Init chef roles file begin:")
        dtm = DeployTargetManager()
        rm = RoleManager()
        dsmM = DeploySchemaManager()
        mappings = self.bind_deployschema.targetRoleMapping
        roleUIDs = [
            getoutCurlyBraces(mapping.text.split(':')[1])
            for mapping in mappings
        ]
        roleUIDs_uniq = list(set(roleUIDs))

        for roleUID in roleUIDs_uniq:
            roleName = rm.queryRoleByUID(roleUID)
            targetNames = dsmM.getTargetNamesByRoleUID(roleUID)
            if "openresty" in targetNames:
                targetNames.remove('openresty')
            if "rabbitmq-server" in targetNames:
                targetNames.remove('rabbitmq-server')
                targetNames.insert(0, 'rabbitmq')
            with open(CHEF_ROLE_CONFIG_FILE_PATH + roleName + '.rb',
                      'w+') as f:
                f.write("name " + '"' + roleName + '"\n' \
                  "description " + '"' + roleName +'"\n'\
                  "run_list " + self.gen_recipestr_4_targetnames(targetNames))

        print "count: %s " % (len(roleUIDs_uniq))
        print green("preparing target===>role mapping config file ok!")