Exemplo n.º 1
0
    def initdomain(self):
        print red('''
			INIT CONFIG FILES.
		''')
        domain_name = self.bind_deployschema.schema_name
        cmdbobserver = XMLCMDBObserver()
        domain_dict = {}
        host_ip_dict = {}

        for host in cmdbobserver.getHostlist():
            ipaddrs = {'bindPrivateIP': []}
            ethernets = host.findall('./Hardware/EthernetIF')

            for ethernet in ethernets:
                if ethernet.attrib['bindPrivateIP']:
                    ipaddrs['bindPrivateIP'].append(
                        ethernet.attrib['bindPrivateIP'])
                if ethernet.attrib['bindPublicIP']:
                    ipaddrs['bindPublicIP'] = ethernet.attrib['bindPublicIP']
            host_ip_dict[host.attrib['name']] = ipaddrs
            domain_dict[host.attrib[
                'name']] = host.attrib['name'] + '.' + domain_name + '.com'

        print "init domain name and hostname config... \n"
        jsondata = json.dumps(domain_dict)
        with open(DOMAIN_FILE, 'w+') as f:
            f.write(jsondata)
        time.sleep(1)

        print "init ip node..."
        j = json.dumps(host_ip_dict)
        with open(HOST_IP_FILE, 'w+') as f:
            f.write(j)
        time.sleep(1)
Exemplo n.º 2
0
	def initdomain(self):
		print red('''
			INIT CONFIG FILES.
		''')
		domain_name = self.bind_deployschema.schema_name
		cmdbobserver = XMLCMDBObserver()
		domain_dict = {}
		host_ip_dict = {}

		for host in cmdbobserver.getHostlist():
			ipaddrs = {'bindPrivateIP' : []}
			ethernets = host.findall('./Hardware/EthernetIF')

			for ethernet in ethernets:
				if ethernet.attrib['bindPrivateIP']:
					ipaddrs['bindPrivateIP'].append(ethernet.attrib['bindPrivateIP'])
				if ethernet.attrib['bindPublicIP']:
					ipaddrs['bindPublicIP'] = ethernet.attrib['bindPublicIP']
			host_ip_dict[host.attrib['name']] = ipaddrs
			domain_dict[host.attrib['name']] = host.attrib['name'] + '.' + domain_name + '.com'

		print "init domain name and hostname config... \n"
		jsondata = json.dumps(domain_dict)
		with open(DOMAIN_FILE, 'w+') as f:
			f.write(jsondata)
		time.sleep(1)

		print "init ip node..."
		j = json.dumps(host_ip_dict)
		with open(HOST_IP_FILE, 'w+') as f:
			f.write(j)
		time.sleep(1)
Exemplo n.º 3
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()
Exemplo n.º 4
0
class DeploySchemaManager(object):

    deploySchemaList = []

    def __init__(self):
        self.xmlcmdbobserver = XMLCMDBObserver()
        pass

    def listDeploySchema(self):
        return self.deploySchemaList

    def loadDeploySchema(self):

        xmlparse = XMLParse(
            xml_file_path=DEPLOY_DESIGN_FILE_URL['DeploySchema'])
        deploySchema = xmlparse.query('DeploySchema')
        for schema in deploySchema:
            targetInstanceList = schema[0]._children
            containerInstanceList = schema[1]._children
            targetInstanceContainerInstanceMapping = schema[2]._children
            self.deploySchemaList.append(
                DeploySchema(targetInstList=targetInstanceList,
                             containerInstList=containerInstanceList,
                             targetRoleMapping=self.loadTargetRoleMapping(),
                             targetInstContainerMapping=
                             targetInstanceContainerInstanceMapping,
                             schema_name=self.xmlcmdbobserver.getDataCenter()
                             [0].attrib['name']))
        return

    def loadTargetRoleMapping(self):
        xmlparse = XMLParse(
            xml_file_path=DEPLOY_DESIGN_FILE_URL['TargetRoleMapping'])
        targetRoleMapping = xmlparse.query('TargetToRoleMapping')
        return targetRoleMapping[0]._children

    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

    def execDeploySchema(self):
        pass

    def querySchemaBySchemaName(self, schema_name):

        try:
            for schema in self.listDeploySchema():
                if schema.schema_name == schema_name:
                    return schema

        except Exception, msg:
            print msg
            return
Exemplo n.º 5
0
class DeploySchemaManager(object):

    deploySchemaList = []

    def __init__(self):
        self.xmlcmdbobserver = XMLCMDBObserver()
        pass

    def listDeploySchema(self):
        return self.deploySchemaList

    def loadDeploySchema(self):

        xmlparse = XMLParse(xml_file_path=DEPLOY_DESIGN_FILE_URL["DeploySchema"])
        deploySchema = xmlparse.query("DeploySchema")
        for schema in deploySchema:
            targetInstanceList = schema[0]._children
            containerInstanceList = schema[1]._children
            targetInstanceContainerInstanceMapping = schema[2]._children
            self.deploySchemaList.append(
                DeploySchema(
                    targetInstList=targetInstanceList,
                    containerInstList=containerInstanceList,
                    targetRoleMapping=self.loadTargetRoleMapping(),
                    targetInstContainerMapping=targetInstanceContainerInstanceMapping,
                    schema_name=self.xmlcmdbobserver.getDataCenter()[0].attrib["name"],
                )
            )
        return

    def loadTargetRoleMapping(self):
        xmlparse = XMLParse(xml_file_path=DEPLOY_DESIGN_FILE_URL["TargetRoleMapping"])
        targetRoleMapping = xmlparse.query("TargetToRoleMapping")
        return targetRoleMapping[0]._children

    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

    def execDeploySchema(self):
        pass

    def querySchemaBySchemaName(self, schema_name):

        try:
            for schema in self.listDeploySchema():
                if schema.schema_name == schema_name:
                    return schema

        except Exception, msg:
            print msg
            return
Exemplo n.º 6
0
 def __init__(self):
     self.xmlcmdbobserver = XMLCMDBObserver()
     pass
Exemplo n.º 7
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!")
Exemplo n.º 8
0
 def __init__(self):
     xcbo = XMLCMDBObserver()
     self._manageResource(xcbo.getDataCenter())
     self._manageResource(xcbo.getNetwork())
     self._manageResource(xcbo.getHostlist())
     self._manageResource(xcbo.getContainerlist())
Exemplo n.º 9
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!")
Exemplo n.º 10
0
 def __init__(self):
     self.xmlcmdbobserver = XMLCMDBObserver()
     pass