コード例 #1
0
ファイル: thread_cr.py プロジェクト: occi/TSP-CloudStack
    def run(self):

        # extracting list of indicator to be treated for the used paas
        crObj=TransformXmlToCr()
        crObj.readXml('listCRs.xml')
        crList=crObj.getcr()

        # for each indicator, a thread will be executed and run in order to extract his result
        crTh=[]
        i=0
        for cr in crList:
            crTh.append(threadCR(self.host,cr))
            crTh[i].start()
            i=i+1

        # waiting for all threads to be completed
        for th in crTh:
            th.join()

        f=open('content.log','r')
        fileContent=f.readlines()
        print fileContent
        f.close()
        f=open('content.log','w')
        f.write('')
        f.close()

        #browsing all decisions and choosing action to execute
        compactList=[]
        extendList=[]
        testAdd=False
        testRem=False
        testExt=False
        testCmpt=False
        for ind in fileContent:
            d=ind.split(',')
            if 'add' in d[1]:
                # adding vm
                testAdd=True
                break
            elif 'rem' in d[1]:
                # removing vm
                testRem=True
                break
            elif 'ext' in d[1]:
                # indicator will be extended
                testExt=True
                extendList.append(d[0])
            elif 'cmpt' in d[1]:
                testCmpt=True
                # indicator will be compacted.append(d[0])
                compactList.append(d[0])

        # choosing action to optimize
        # choosing vm to edit if removing or modifying
        number=len(self.listVMs)
        #choosing the last vm to edit
        choice=action(self.listVMs[number-1])
        if testAdd:
            # addingVM
            choice.add_vm()
        elif testRem:
            # removing VM
            choice.remove_vm()
        elif testExt:
            # extending VM
            choice.extend_vm(extendList)
        elif testCmpt:
            # compacting vm
            choice.compact_vm(compactList)
コード例 #2
0
ファイル: test.py プロジェクト: occi/TSP-CloudStack

#extracting list of vms that will be used to extract values
vmObj = TransformXmlToVM()
vmObj.readXml('listeVMsTest.xml')
vms = vmObj.getVM()
v = "%s,%s,%s" % (vms[0].host, vms[0].user, vms[0].password)
print 'VM:'
print v

cr=Indicator()
cr.name='disk'
cr.maxApp=100
cr.maxPhy=150
cr.minApp=0
th=threadCR(v,cr)
th.start()
th.join()
print 'Fin thread'
print file('content.log').read()







'''
#extracting of command from xml file:
cmdCl = TransformXmlToCmd()
cmdCl.readXml('cmdCrTest.xml')