Esempio n. 1
0
class Orchestrator(object):
	
	def __init__(self):

		self.deployResourceManager = DeployResourceManager()
		# role
		self.roleManager = RoleManager()

		# xmlcmb observer
		self.xmlcmdbobserver = XMLCMDBObserver()

		#target manager
		self.deployTargetManager = DeployTargetManager()
		self.deployTargetManager.importTargetList()
		
		#self.deployExecutionM = DeployExecManager()
		# role2deviceMappings
		self.role2deviceMappingManager = Role2DeviceManager()
		role2deviceMappingList = self.role2deviceMappingManager.mappings

		# deployschemaManager
		self.deploySchemaManager = DeploySchemaManager()
		self.deploySchemaManager.loadDeploySchema()

		self.deploySchemaList = self.deploySchemaManager.listDeploySchema()
		
		self.deploySchema = self.deploySchemaList[0]
		self.deploySchema.role2DeviceMappingList = role2deviceMappingList
		#self.role2deviceMappings = role2deviceMappingManager.getRole2Devices()

		# execution manager 
		self.executionManager = DeployExcutionManager()

		# resources manager
		self.resourceManager = DeployResourceManager()
Esempio n. 2
0
    def __init__(self):

        self.deployResourceManager = DeployResourceManager()
        # role
        self.roleManager = RoleManager()

        # xmlcmb observer
        self.xmlcmdbobserver = XMLCMDBObserver()

        #target manager
        self.deployTargetManager = DeployTargetManager()
        self.deployTargetManager.importTargetList()

        #self.deployExecutionM = DeployExecManager()
        # role2deviceMappings
        self.role2deviceMappingManager = Role2DeviceManager()
        role2deviceMappingList = self.role2deviceMappingManager.mappings

        # deployschemaManager
        self.deploySchemaManager = DeploySchemaManager()
        self.deploySchemaManager.loadDeploySchema()

        self.deploySchemaList = self.deploySchemaManager.listDeploySchema()

        self.deploySchema = self.deploySchemaList[0]
        self.deploySchema.role2DeviceMappingList = role2deviceMappingList
        #self.role2deviceMappings = role2deviceMappingManager.getRole2Devices()

        # execution manager
        self.executionManager = DeployExcutionManager()

        # resources manager
        self.resourceManager = DeployResourceManager()
Esempio n. 3
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!")
Esempio n. 4
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!")